|
| 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\Layer\Category; |
| 9 | + |
| 10 | +use Magento\Catalog\Api\CategoryRepositoryInterface; |
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test cases item collection provider. |
| 17 | + * |
| 18 | + * @see \Magento\Catalog\Model\Layer\Category\ItemCollectionProvider |
| 19 | + * @magentoAppArea frontend |
| 20 | + */ |
| 21 | +class ItemCollectionProviderTest extends TestCase |
| 22 | +{ |
| 23 | + /** @var ObjectManagerInterface */ |
| 24 | + private $objectManager; |
| 25 | + |
| 26 | + /** @var CategoryRepositoryInterface */ |
| 27 | + private $categoryRepository; |
| 28 | + |
| 29 | + /** @var ItemCollectionProvider */ |
| 30 | + private $itemCollectionProvider; |
| 31 | + |
| 32 | + /** |
| 33 | + * @inheritdoc |
| 34 | + */ |
| 35 | + protected function setUp(): void |
| 36 | + { |
| 37 | + parent::setUp(); |
| 38 | + |
| 39 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 40 | + $this->itemCollectionProvider = $this->objectManager->get(ItemCollectionProvider::class); |
| 41 | + $this->categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @magentoDbIsolation disabled |
| 46 | + * @magentoDataFixture Magento/Catalog/_files/category_product.php |
| 47 | + * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php |
| 48 | + * |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function testGetCollection(): void |
| 52 | + { |
| 53 | + $category = $this->categoryRepository->get(333); |
| 54 | + $collectionProduct = $this->itemCollectionProvider->getCollection($category); |
| 55 | + $this->assertEquals('simple333', $collectionProduct->getFirstItem()->getSku()); |
| 56 | + $this->assertCount(1, $collectionProduct->getItems()); |
| 57 | + } |
| 58 | +} |
0 commit comments