Skip to content

Commit 8adc183

Browse files
author
Pieter Zandbergen
committed
Updated test
1 parent 8eeb9c2 commit 8adc183

File tree

3 files changed

+60
-90
lines changed

3 files changed

+60
-90
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/UrlTest.php

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
namespace Magento\Catalog\Model\ResourceModel;
99

10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\TestFramework\Fixture\DataFixtureStorage;
17+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
18+
use Magento\TestFramework\Fixture\DbIsolation;
1019
use Magento\TestFramework\Helper\Bootstrap;
1120
use PHPUnit\Framework\TestCase;
1221

@@ -15,28 +24,71 @@
1524
*/
1625
class UrlTest extends TestCase
1726
{
27+
private CategoryRepositoryInterface $categoryRepository;
28+
private DataFixtureStorage $fixtures;
29+
private StoreManagerInterface $storeManager;
1830
private Url $urlResource;
1931

20-
/**
21-
* @inheritdoc
22-
*/
2332
protected function setUp(): void
2433
{
2534
$objectManager = Bootstrap::getObjectManager();
35+
$this->categoryRepository = $objectManager->create(CategoryRepositoryInterface::class);
36+
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
37+
$this->storeManager = $objectManager->create(StoreManagerInterface::class);
2638
$this->urlResource = $objectManager->create(Url::class);
2739
}
2840

2941
/**
3042
* Test that scope is respected for the is_active flag.
3143
*
3244
* @return void
33-
* @magentoDataFixture Magento/Catalog/_files/categories_disabled_different_scopes.php
45+
* @throws NoSuchEntityException|CouldNotSaveException
3446
*/
47+
#[
48+
DbIsolation(true),
49+
DataFixture(CategoryFixture::class, [
50+
'name' => 'Enabled on default scope',
51+
'is_active' => '1',
52+
], 'c1'),
53+
DataFixture(CategoryFixture::class, [
54+
'name' => 'Disabled on default scope',
55+
'is_active' => '0',
56+
], 'c2'),
57+
DataFixture(CategoryFixture::class, [
58+
'name' => 'Enabled on default scope, disabled for store',
59+
'is_active' => '1',
60+
], 'c3'),
61+
DataFixture(CategoryFixture::class, [
62+
'name' => 'Disabled on default scope, enabled for store',
63+
'is_active' => '0',
64+
], 'c4'),
65+
]
3566
public function testIsActiveScope(): void
3667
{
37-
$categories = $this->urlResource->getCategories([3, 4, 5], 1);
38-
$this->assertTrue((bool) $categories[3]->getIsActive());
39-
$this->assertFalse((bool) $categories[4]->getIsActive());
40-
$this->assertFalse((bool) $categories[5]->getIsActive());
68+
// Get Store ID
69+
$storeId = (int) $this->storeManager->getStore('default')->getId();
70+
71+
// Get Category IDs
72+
$fixtureNames = ['c1', 'c2', 'c3', 'c4'];
73+
$categoryIds = array_combine($fixtureNames, array_map(function (string $fixtureName): int {
74+
return (int) $this->fixtures->get($fixtureName)->getId();
75+
}, $fixtureNames));
76+
77+
// Disable c3 for store
78+
$c3 = $this->categoryRepository->get($categoryIds['c3'], $storeId);
79+
$c3->setIsActive(false);
80+
$this->categoryRepository->save($c3);
81+
82+
// Enable c4 for store
83+
$c4 = $this->categoryRepository->get($categoryIds['c4'], $storeId);
84+
$c4->setIsActive(true);
85+
$this->categoryRepository->save($c4);
86+
87+
// Check categories
88+
$categories = $this->urlResource->getCategories($categoryIds, $storeId);
89+
$this->assertSame('1', $categories[$categoryIds['c1']]->getIsActive());
90+
$this->assertSame('0', $categories[$categoryIds['c2']]->getIsActive());
91+
$this->assertSame('0', $categories[$categoryIds['c3']]->getIsActive());
92+
$this->assertSame('1', $categories[$categoryIds['c4']]->getIsActive());
4193
}
4294
}

dev/tests/integration/testsuite/Magento/Catalog/_files/categories_disabled_different_scopes.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/Catalog/_files/categories_disabled_different_scopes_rollback.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)