|
11 | 11 | use Magento\Framework\View\LayoutInterface; |
12 | 12 | use Magento\TestFramework\Fixture\AppArea; |
13 | 13 | use Magento\TestFramework\Fixture\DataFixture; |
| 14 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 15 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
14 | 16 | use Magento\TestFramework\TestCase\AbstractBackendController; |
15 | 17 |
|
16 | 18 | /** |
|
19 | 21 | class TreeBlockTest extends AbstractBackendController |
20 | 22 | { |
21 | 23 |
|
| 24 | + /** |
| 25 | + * @var DataFixtureStorage |
| 26 | + */ |
| 27 | + private $fixtures; |
| 28 | + |
| 29 | + protected function setUp(): void |
| 30 | + { |
| 31 | + parent::setUp(); |
| 32 | + $this->fixtures = $this->_objectManager->get(DataFixtureStorageManager::class)->getStorage(); |
| 33 | + } |
| 34 | + |
22 | 35 | /** |
23 | 36 | * Test disabled categories in the tree block. |
24 | 37 | */ |
25 | 38 | #[ |
26 | 39 | AppArea('adminhtml'), |
27 | | - DataFixture(CategoryFixture::class, ['is_active' => false], as:'new_category'), |
| 40 | + DataFixture(CategoryFixture::class, as: 'c10'), |
| 41 | + DataFixture(CategoryFixture::class, ['parent_id' => '$c10.id$', 'is_active' => false], 'c11'), |
28 | 42 | ] |
29 | 43 | public function testDisabledCategoriesHtml() |
30 | 44 | { |
31 | | - $this->dispatch("backend/catalog/category/index/"); |
32 | | - $this->assertEquals(200, $this->getResponse()->getHttpResponseCode()); |
| 45 | + $category = $this->fixtures->get('c10'); |
33 | 46 | $layout = $this->_objectManager->get(LayoutInterface::class); |
34 | | - $categoryTree = $layout->getBlock('category.tree'); |
35 | | - $blockHtml = $categoryTree->toHtml(); |
36 | | - $this->assertStringContainsString('no-active-category', $blockHtml); |
| 47 | + $categoryTreeBlock = $layout->createBlock(Tree::class); |
| 48 | + $categoryTreeArray = $categoryTreeBlock->getTree($category); |
| 49 | + $this->assertCount(1, $categoryTreeArray); |
| 50 | + $this->assertArrayHasKey('a_attr', $categoryTreeArray[0]); |
| 51 | + $this->assertArrayHasKey('class', $categoryTreeArray[0]['a_attr']); |
| 52 | + $this->assertStringContainsString('no-active-category', $categoryTreeArray[0]['a_attr']['class']); |
37 | 53 | } |
38 | 54 | } |
0 commit comments