|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Catalog\Model\Layer\Filter\DataProvider; |
| 9 | + |
| 10 | +use Magento\Catalog\Api\Data\CategoryInterfaceFactory; |
| 11 | +use Magento\Catalog\Model\Layer\Category as CategoryLayer; |
| 12 | +use Magento\Framework\ObjectManagerInterface; |
| 13 | +use Magento\Framework\Registry; |
| 14 | +use Magento\TestFramework\Helper\Bootstrap; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * Class for test Category Data Provider |
| 19 | + * |
| 20 | + * @see \Magento\Catalog\Model\Layer\Filter\DataProvider\Category |
| 21 | + * |
| 22 | + * @magentoAppArea adminhtml |
| 23 | + */ |
| 24 | +class CategoryTest extends TestCase |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @var ObjectManagerInterface |
| 28 | + */ |
| 29 | + private $objectManager; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var Category |
| 33 | + */ |
| 34 | + private $provider; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var CategoryInterfaceFactory |
| 38 | + */ |
| 39 | + private $categoryFactory; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var Registry |
| 43 | + */ |
| 44 | + private $registry; |
| 45 | + |
| 46 | + /** |
| 47 | + * @inheritdoc |
| 48 | + */ |
| 49 | + protected function setUp(): void |
| 50 | + { |
| 51 | + parent::setUp(); |
| 52 | + |
| 53 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 54 | + $this->categoryFactory = $this->objectManager->get(CategoryInterfaceFactory::class); |
| 55 | + $layer = $this->objectManager->get(CategoryLayer::class); |
| 56 | + $this->provider = $this->objectManager->create(Category::class, ['layer' => $layer]); |
| 57 | + $this->registry = $this->objectManager->get(Registry::class); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @return void |
| 62 | + */ |
| 63 | + public function testIsValidNotExistsCategory(): void |
| 64 | + { |
| 65 | + $this->registry->register('current_category', $this->categoryFactory->create()); |
| 66 | + $this->provider->setCategoryId(375211); |
| 67 | + $this->assertFalse($this->provider->isValid()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @magentoDataFixture Magento/Catalog/_files/inactive_category.php |
| 72 | + * |
| 73 | + * @return void |
| 74 | + */ |
| 75 | + public function testIsValidNotActiveCategory(): void |
| 76 | + { |
| 77 | + $this->provider->setCategoryId(111); |
| 78 | + $this->assertFalse($this->provider->isValid()); |
| 79 | + } |
| 80 | +} |
0 commit comments