Skip to content

Commit ad68a19

Browse files
committed
MC-39642: Create automated test for: "Use choser during create catalog price rule"
1 parent cd857f9 commit ad68a19

File tree

1 file changed

+52
-8
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Category/Checkboxes

1 file changed

+52
-8
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Category/Checkboxes/TreeTest.php

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,66 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Block\Adminhtml\Category\Checkboxes;
79

10+
use Magento\Catalog\Helper\DefaultCategory;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
817
/**
18+
* Checks category chooser block behaviour
19+
*
20+
* @see \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree
21+
*
922
* @magentoAppArea adminhtml
1023
* @magentoDbIsolation enabled
1124
* @magentoAppIsolation enabled
1225
*/
13-
class TreeTest extends \PHPUnit\Framework\TestCase
26+
class TreeTest extends TestCase
1427
{
15-
/** @var \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree */
16-
protected $block;
28+
/** @var ObjectManagerInterface */
29+
private $objectManager;
30+
31+
/** @var Tree */
32+
private $block;
33+
34+
/** @var SerializerInterface */
35+
private $json;
1736

37+
/** @var DefaultCategory */
38+
private $defaultCategoryHelper;
39+
40+
/**
41+
* @inheritdoc
42+
*/
1843
protected function setUp(): void
1944
{
20-
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
21-
\Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree::class
22-
);
45+
$this->objectManager = Bootstrap::getObjectManager();
46+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Tree::class);
47+
$this->json = $this->objectManager->get(SerializerInterface::class);
48+
$this->defaultCategoryHelper = $this->objectManager->get(DefaultCategory::class);
2349
}
2450

25-
public function testSetGetCategoryIds()
51+
/**
52+
* @return void
53+
*/
54+
public function testSetGetCategoryIds(): void
2655
{
2756
$this->block->setCategoryIds([1, 4, 7, 56, 2]);
2857
$this->assertEquals([1, 4, 7, 56, 2], $this->block->getCategoryIds());
2958
}
3059

3160
/**
3261
* @magentoDataFixture Magento/Catalog/_files/categories.php
62+
*
63+
* @return void
3364
*/
34-
public function testGetTreeJson()
65+
public function testGetTreeJson(): void
3566
{
3667
$jsonTree = $this->block->getTreeJson();
3768
$this->assertStringContainsString('Default Category (4)', $jsonTree);
@@ -45,4 +76,17 @@ public function testGetTreeJson()
4576
$this->assertStringContainsString('Category 12 (2)', $jsonTree);
4677
$this->assertStringMatchesFormat('%s"path":"1\/2\/%s\/%s\/%s"%s', $jsonTree);
4778
}
79+
80+
/**
81+
* @return void
82+
*/
83+
public function testGetTreeJsonWithSelectedCategory(): void
84+
{
85+
$this->block->setCategoryIds($this->defaultCategoryHelper->getId());
86+
$result = $this->json->unserialize($this->block->getTreeJson());
87+
$item = reset($result);
88+
$this->assertNotEmpty($item);
89+
$this->assertStringContainsString('Default Category', $item['text']);
90+
$this->assertTrue($item['checked']);
91+
}
4892
}

0 commit comments

Comments
 (0)