|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\CategoryRepositoryInterface;
|
11 | 11 | use Magento\Catalog\Api\CategoryRepositoryInterfaceFactory;
|
12 |
| -use Magento\Framework\Exception\LocalizedException; |
13 |
| -use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager; |
14 | 12 | use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
|
15 | 13 | use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
|
| 14 | +use Magento\Framework\Exception\LocalizedException; |
| 15 | +use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager; |
16 | 16 | use Magento\TestFramework\Helper\Bootstrap;
|
17 | 17 | use PHPUnit\Framework\TestCase;
|
18 | 18 |
|
|
21 | 21 | */
|
22 | 22 | class CategoryRepositoryTest extends TestCase
|
23 | 23 | {
|
| 24 | + private const FIXTURE_CATEGORY_ID = 333; |
| 25 | + private const FIXTURE_TWO_STORES_CATEGORY_ID = 555; |
| 26 | + private const FIXTURE_SECOND_STORE_CODE = 'fixturestore'; |
| 27 | + private const FIXTURE_FIRST_STORE_CODE = 'default'; |
| 28 | + |
24 | 29 | /**
|
25 | 30 | * @var CategoryLayoutUpdateManager
|
26 | 31 | */
|
@@ -77,13 +82,13 @@ public function testCustomLayout(): void
|
77 | 82 | {
|
78 | 83 | //New valid value
|
79 | 84 | $repo = $this->createRepo();
|
80 |
| - $category = $repo->get(333); |
| 85 | + $category = $repo->get(self::FIXTURE_CATEGORY_ID); |
81 | 86 | $newFile = 'test';
|
82 |
| - $this->layoutManager->setCategoryFakeFiles(333, [$newFile]); |
| 87 | + $this->layoutManager->setCategoryFakeFiles(self::FIXTURE_CATEGORY_ID, [$newFile]); |
83 | 88 | $category->setCustomAttribute('custom_layout_update_file', $newFile);
|
84 | 89 | $repo->save($category);
|
85 | 90 | $repo = $this->createRepo();
|
86 |
| - $category = $repo->get(333); |
| 91 | + $category = $repo->get(self::FIXTURE_CATEGORY_ID); |
87 | 92 | $this->assertEquals($newFile, $category->getCustomAttribute('custom_layout_update_file')->getValue());
|
88 | 93 |
|
89 | 94 | //Setting non-existent value
|
@@ -126,4 +131,30 @@ public function testCategoryBehaviourAfterDelete(): void
|
126 | 131 | 'Wrong categories was deleted'
|
127 | 132 | );
|
128 | 133 | }
|
| 134 | + |
| 135 | + /** |
| 136 | + * Verifies whether `get()` method `$storeId` attribute works as expected. |
| 137 | + * |
| 138 | + * @magentoDbIsolation enabled |
| 139 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 140 | + * @magentoDataFixture Magento/Catalog/_files/category_with_two_stores.php |
| 141 | + */ |
| 142 | + public function testGetCategoryForProvidedStore() |
| 143 | + { |
| 144 | + $categoryRepository = $this->repositoryFactory->create(); |
| 145 | + |
| 146 | + $categoryFirstStore = $categoryRepository->get( |
| 147 | + self::FIXTURE_TWO_STORES_CATEGORY_ID, |
| 148 | + self::FIXTURE_FIRST_STORE_CODE |
| 149 | + ); |
| 150 | + |
| 151 | + $this->assertSame('category-defaultstore', $categoryFirstStore->getUrlKey()); |
| 152 | + |
| 153 | + $categorySecondStore = $categoryRepository->get( |
| 154 | + self::FIXTURE_TWO_STORES_CATEGORY_ID, |
| 155 | + self::FIXTURE_SECOND_STORE_CODE |
| 156 | + ); |
| 157 | + |
| 158 | + $this->assertSame('category-fixturestore', $categorySecondStore->getUrlKey()); |
| 159 | + } |
129 | 160 | }
|
0 commit comments