Skip to content

Commit 0695ce2

Browse files
authored
ENGCOM-7000: #27044 Integration Test to cover $storeId on Category Repository get() #27048
2 parents 13d42e2 + 93123ed commit 0695ce2

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
use Magento\Catalog\Api\CategoryRepositoryInterface;
1111
use Magento\Catalog\Api\CategoryRepositoryInterfaceFactory;
12-
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
1412
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1513
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
1616
use Magento\TestFramework\Helper\Bootstrap;
1717
use PHPUnit\Framework\TestCase;
1818

@@ -21,6 +21,11 @@
2121
*/
2222
class CategoryRepositoryTest extends TestCase
2323
{
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+
2429
/**
2530
* @var CategoryLayoutUpdateManager
2631
*/
@@ -77,13 +82,13 @@ public function testCustomLayout(): void
7782
{
7883
//New valid value
7984
$repo = $this->createRepo();
80-
$category = $repo->get(333);
85+
$category = $repo->get(self::FIXTURE_CATEGORY_ID);
8186
$newFile = 'test';
82-
$this->layoutManager->setCategoryFakeFiles(333, [$newFile]);
87+
$this->layoutManager->setCategoryFakeFiles(self::FIXTURE_CATEGORY_ID, [$newFile]);
8388
$category->setCustomAttribute('custom_layout_update_file', $newFile);
8489
$repo->save($category);
8590
$repo = $this->createRepo();
86-
$category = $repo->get(333);
91+
$category = $repo->get(self::FIXTURE_CATEGORY_ID);
8792
$this->assertEquals($newFile, $category->getCustomAttribute('custom_layout_update_file')->getValue());
8893

8994
//Setting non-existent value
@@ -126,4 +131,36 @@ public function testCategoryBehaviourAfterDelete(): void
126131
'Wrong categories was deleted'
127132
);
128133
}
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+
$categoryDefault = $categoryRepository->get(
147+
self::FIXTURE_TWO_STORES_CATEGORY_ID
148+
);
149+
150+
$this->assertSame('category-defaultstore', $categoryDefault->getUrlKey());
151+
152+
$categoryFirstStore = $categoryRepository->get(
153+
self::FIXTURE_TWO_STORES_CATEGORY_ID,
154+
self::FIXTURE_FIRST_STORE_CODE
155+
);
156+
157+
$this->assertSame('category-defaultstore', $categoryFirstStore->getUrlKey());
158+
159+
$categorySecondStore = $categoryRepository->get(
160+
self::FIXTURE_TWO_STORES_CATEGORY_ID,
161+
self::FIXTURE_SECOND_STORE_CODE
162+
);
163+
164+
$this->assertSame('category-fixturestore', $categorySecondStore->getUrlKey());
165+
}
129166
}

0 commit comments

Comments
 (0)