Skip to content

Commit ceb0887

Browse files
committed
Merge remote-tracking branch 'performance-ce/MCP-807' into MCP-811
2 parents 836e464 + 4bf488d commit ceb0887

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Collection
2323
*/
2424
public function afterGetCurPage(DataCollection $subject, int $result): int
2525
{
26-
if ($result > $subject->getLastPageNumber()) {
26+
if ($result > 1 && $result > $subject->getLastPageNumber()) {
2727
$result = 1;
2828
}
2929

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Test\Unit\Plugin;
9+
10+
use Magento\Framework\Data\Collection;
11+
use Magento\Theme\Plugin\Data\Collection as CollectionPlugin;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* This Unit Test covers a Plugin (not Collection), overriding the `curPage` (current page)
17+
*
18+
* @see \Magento\Framework\Data\Collection
19+
*/
20+
class CollectionTest extends TestCase
21+
{
22+
/**
23+
* @var Collection|MockObject
24+
*/
25+
private $dataCollectionMock;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
$this->dataCollectionMock = $this->getMockBuilder(Collection::class)
33+
->disableOriginalConstructor()
34+
->onlyMethods(['getLastPageNumber'])
35+
->getMock();
36+
}
37+
38+
/**
39+
* Test covers use-case for the first page of results. We don't expect calculation of the last page to be executed.
40+
*
41+
* @return void
42+
*/
43+
public function testCurrentPageIsNotOverriddenIfFirstPage(): void
44+
{
45+
// Given
46+
$currentPagePlugin = new CollectionPlugin();
47+
48+
// Expects
49+
$this->dataCollectionMock->expects($this->never())
50+
->method('getLastPageNumber');
51+
52+
// When
53+
$currentPagePlugin->afterGetCurPage($this->dataCollectionMock, 1);
54+
}
55+
56+
/**
57+
* Test covers use-case for non-first page of results. We expect calculation of the last page to be executed.
58+
*
59+
* @return void
60+
*/
61+
public function testCurrentPageIsOverriddenIfNotAFirstPage(): void
62+
{
63+
// Given
64+
$currentPagePlugin = new CollectionPlugin();
65+
66+
// Expects
67+
$this->dataCollectionMock->expects($this->once())
68+
->method('getLastPageNumber');
69+
70+
// When
71+
$currentPagePlugin->afterGetCurPage($this->dataCollectionMock, 2);
72+
}
73+
}

0 commit comments

Comments
 (0)