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