Skip to content

Commit

Permalink
ENGCOM-7000: #27044 Integration Test to cover $storeId on Category …
Browse files Browse the repository at this point in the history
…Repository `get()` #27048
  • Loading branch information
slavvka committed Feb 28, 2020
2 parents 13d42e2 + 93123ed commit 0695ce2
Showing 1 changed file with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\CategoryRepositoryInterfaceFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

Expand All @@ -21,6 +21,11 @@
*/
class CategoryRepositoryTest extends TestCase
{
private const FIXTURE_CATEGORY_ID = 333;
private const FIXTURE_TWO_STORES_CATEGORY_ID = 555;
private const FIXTURE_SECOND_STORE_CODE = 'fixturestore';
private const FIXTURE_FIRST_STORE_CODE = 'default';

/**
* @var CategoryLayoutUpdateManager
*/
Expand Down Expand Up @@ -77,13 +82,13 @@ public function testCustomLayout(): void
{
//New valid value
$repo = $this->createRepo();
$category = $repo->get(333);
$category = $repo->get(self::FIXTURE_CATEGORY_ID);
$newFile = 'test';
$this->layoutManager->setCategoryFakeFiles(333, [$newFile]);
$this->layoutManager->setCategoryFakeFiles(self::FIXTURE_CATEGORY_ID, [$newFile]);
$category->setCustomAttribute('custom_layout_update_file', $newFile);
$repo->save($category);
$repo = $this->createRepo();
$category = $repo->get(333);
$category = $repo->get(self::FIXTURE_CATEGORY_ID);
$this->assertEquals($newFile, $category->getCustomAttribute('custom_layout_update_file')->getValue());

//Setting non-existent value
Expand Down Expand Up @@ -126,4 +131,36 @@ public function testCategoryBehaviourAfterDelete(): void
'Wrong categories was deleted'
);
}

/**
* Verifies whether `get()` method `$storeId` attribute works as expected.
*
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
* @magentoDataFixture Magento/Catalog/_files/category_with_two_stores.php
*/
public function testGetCategoryForProvidedStore()
{
$categoryRepository = $this->repositoryFactory->create();

$categoryDefault = $categoryRepository->get(
self::FIXTURE_TWO_STORES_CATEGORY_ID
);

$this->assertSame('category-defaultstore', $categoryDefault->getUrlKey());

$categoryFirstStore = $categoryRepository->get(
self::FIXTURE_TWO_STORES_CATEGORY_ID,
self::FIXTURE_FIRST_STORE_CODE
);

$this->assertSame('category-defaultstore', $categoryFirstStore->getUrlKey());

$categorySecondStore = $categoryRepository->get(
self::FIXTURE_TWO_STORES_CATEGORY_ID,
self::FIXTURE_SECOND_STORE_CODE
);

$this->assertSame('category-fixturestore', $categorySecondStore->getUrlKey());
}
}

0 comments on commit 0695ce2

Please sign in to comment.