Skip to content

Commit 23ea249

Browse files
authored
Merge pull request #5997 from magento-tsg/2.4-develop-pr73
[TSG] Fixes for 2.4 (pr73) (2.4-develop)
2 parents 9f619bf + c33d405 commit 23ea249

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Theme\Plugin\Data;
9+
10+
use Magento\Framework\Data\Collection as DataCollection;
11+
12+
/**
13+
* Plugin to return last page if current page greater then collection size.
14+
*/
15+
class Collection
16+
{
17+
/**
18+
* Return last page if current page greater then last page.
19+
*
20+
* @param DataCollection $subject
21+
* @param int $result
22+
* @return int
23+
*/
24+
public function afterGetCurPage(DataCollection $subject, int $result): int
25+
{
26+
if ($result > $subject->getLastPageNumber()) {
27+
$result = 1;
28+
}
29+
30+
return $result;
31+
}
32+
}

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>
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)