|
| 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\Rss; |
| 9 | + |
| 10 | +use Magento\Catalog\Test\Fixture\Category as CategoryFixture; |
| 11 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 12 | +use Magento\Config\Model\Config as ConfigModel; |
| 13 | +use Magento\Framework\App\Area; |
| 14 | +use Magento\Framework\App\Config\ConfigResource\ConfigInterface as ConfigResource; |
| 15 | +use Magento\Framework\Indexer\IndexerRegistry; |
| 16 | +use Magento\Store\Model\StoreManagerInterface; |
| 17 | +use Magento\TestFramework\Fixture\AppArea; |
| 18 | +use Magento\TestFramework\Fixture\DataFixture; |
| 19 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 20 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 21 | +use Magento\TestFramework\Fixture\DbIsolation; |
| 22 | +use Magento\TestFramework\Helper\Bootstrap; |
| 23 | +use PHPUnit\Framework\TestCase; |
| 24 | + |
| 25 | +#[ |
| 26 | + AppArea(Area::AREA_ADMINHTML), |
| 27 | + DbIsolation(false), |
| 28 | +] |
| 29 | +class CategoryTest extends TestCase |
| 30 | +{ |
| 31 | + /** |
| 32 | + * @var DataFixtureStorage |
| 33 | + */ |
| 34 | + private $fixtureStorage; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var Category |
| 38 | + */ |
| 39 | + private $model; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var StoreManagerInterface |
| 43 | + */ |
| 44 | + private $storeManager; |
| 45 | + |
| 46 | + protected function setUp(): void |
| 47 | + { |
| 48 | + $configModel = Bootstrap::getObjectManager()->create(ConfigModel::class); |
| 49 | + $configModel->setDataByPath('rss/catalog/category', 1); |
| 50 | + $configModel->save(); |
| 51 | + $indexerRegistry = Bootstrap::getObjectManager()->get(IndexerRegistry::class); |
| 52 | + $indexerRegistry->get('catalogsearch_fulltext')->reindexAll(); |
| 53 | + |
| 54 | + $this->fixtureStorage = DataFixtureStorageManager::getStorage(); |
| 55 | + $this->model = Bootstrap::getObjectManager()->create(Category::class); |
| 56 | + $this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class); |
| 57 | + } |
| 58 | + |
| 59 | + protected function tearDown(): void |
| 60 | + { |
| 61 | + $configResource = Bootstrap::getObjectManager()->get(ConfigResource::class); |
| 62 | + $configResource->deleteConfig('rss/catalog/category'); |
| 63 | + } |
| 64 | + |
| 65 | + #[ |
| 66 | + DataFixture(CategoryFixture::class, as: 'c1'), |
| 67 | + DataFixture(ProductFixture::class, ['sku' => 'p1', 'category_ids' => ['$c1.id$']], 'p1'), |
| 68 | + ] |
| 69 | + public function testGetProductCollection(): void |
| 70 | + { |
| 71 | + $category = $this->fixtureStorage->get('c1'); |
| 72 | + $store = $this->storeManager->getStore('default'); |
| 73 | + $productCollection = $this->model->getProductCollection($category, $store->getId()); |
| 74 | + self::assertEquals(1, $productCollection->count()); |
| 75 | + $product = $productCollection->getFirstItem(); |
| 76 | + self::assertEquals('p1', $product->getSku()); |
| 77 | + } |
| 78 | +} |
0 commit comments