Skip to content

Commit 663f023

Browse files
author
OlgaVasyltsun
committed
MC-36048: Unexpected behavior of sorting in the Magento Admin Panel
1 parent 0d7cf24 commit 663f023

File tree

7 files changed

+112
-10
lines changed

7 files changed

+112
-10
lines changed

app/code/Magento/Theme/Plugin/Data/Collection.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Theme\Plugin\Data;
99

10+
use Magento\Framework\Data\Collection as DataCollection;
11+
1012
/**
1113
* Plugin to return last page if current page greater then collection size.
1214
*/
@@ -15,14 +17,14 @@ class Collection
1517
/**
1618
* Return last page if current page greater then last page.
1719
*
18-
* @param \Magento\Framework\Data\Collection $subject
20+
* @param DataCollection $subject
1921
* @param int $result
2022
* @return int
2123
*/
22-
public function afterGetCurPage(\Magento\Framework\Data\Collection $subject, int $result)
24+
public function afterGetCurPage(DataCollection $subject, int $result): int
2325
{
2426
if ($result > $subject->getLastPageNumber()) {
25-
$result = $subject->getLastPageNumber();
27+
$result = 1;
2628
}
2729

2830
return $result;

app/code/Magento/Theme/etc/adminhtml/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@
4141
</argument>
4242
</arguments>
4343
</type>
44-
<type name="Magento\Framework\Data\Collection">
45-
<plugin name="currentPageDetection" type="Magento\Theme\Plugin\Data\Collection" />
46-
</type>
4744
</config>

app/code/Magento/Theme/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,7 @@
326326
<argument name="filesystemDriver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
327327
</arguments>
328328
</type>
329+
<type name="Magento\Framework\Data\Collection">
330+
<plugin name="currentPageDetection" type="Magento\Theme\Plugin\Data\Collection" />
331+
</type>
329332
</config>

app/code/Magento/Theme/etc/frontend/di.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,4 @@
3737
<argument name="filePath" xsi:type="string">css/critical.css</argument>
3838
</arguments>
3939
</type>
40-
41-
<type name="Magento\Framework\Data\Collection">
42-
<plugin name="currentPageDetection" type="Magento\Theme\Plugin\Data\Collection" />
43-
</type>
4440
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Framework\Data\Collection">
10+
<plugin name="currentPageDetection" disabled="true"/>
11+
</type>
12+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Framework\Data\Collection">
10+
<plugin name="currentPageDetection" disabled="true"/>
11+
</type>
12+
</config>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ResourceModel\Attribute;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Tests \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
16+
*/
17+
class CollectionTest extends TestCase
18+
{
19+
/**
20+
* @var CollectionFactory .
21+
*/
22+
private $attributesCollectionFactory;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$objectManager = Bootstrap::getObjectManager();
30+
$this->attributesCollectionFactory = $objectManager->get(CollectionFactory::class);
31+
}
32+
33+
/**
34+
* @magentoAppArea adminhtml
35+
* @dataProvider attributesCollectionGetCurrentPageDataProvider
36+
*
37+
* @param array|null $condition
38+
* @param int $currentPage
39+
* @param int $expectedCurrentPage
40+
* @return void
41+
*/
42+
public function testAttributesCollectionGetCurrentPage(
43+
?array $condition,
44+
int $currentPage,
45+
int $expectedCurrentPage
46+
): void {
47+
$attributeCollection = $this->attributesCollectionFactory->create();
48+
$attributeCollection->setCurPage($currentPage)->setPageSize(20);
49+
50+
if ($condition !== null) {
51+
$attributeCollection->addFieldToFilter('is_global', $condition);
52+
}
53+
54+
$this->assertEquals($expectedCurrentPage, (int)$attributeCollection->getCurPage());
55+
}
56+
57+
/**
58+
* @return array[]
59+
*/
60+
public function attributesCollectionGetCurrentPageDataProvider(): array
61+
{
62+
return [
63+
[
64+
'condition' => null,
65+
'currentPage' => 1,
66+
'expectedCurrentPage' => 1,
67+
],
68+
[
69+
'condition' => ['eq' => 0],
70+
'currentPage' => 1,
71+
'expectedCurrentPage' => 1,
72+
],
73+
[
74+
'condition' => ['eq' => 0],
75+
'currentPage' => 15,
76+
'expectedCurrentPage' => 1,
77+
],
78+
];
79+
}
80+
}

0 commit comments

Comments
 (0)