|
| 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\Swatches\Observer; |
| 9 | + |
| 10 | +use Magento\Framework\DataObject; |
| 11 | +use Magento\Swatches\Model\Swatch; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\Framework\Event\ManagerInterface; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test checks that swatch types are added to the other attribute types |
| 17 | + */ |
| 18 | +class AddSwatchAttributeTypeObserverTest extends \PHPUnit\Framework\TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @magentoAppArea adminhtml |
| 22 | + */ |
| 23 | + public function testAddSwatchAttributeTypes() |
| 24 | + { |
| 25 | + $objectManager = Bootstrap::getObjectManager(); |
| 26 | + $eventManager = $objectManager->get(ManagerInterface::class); |
| 27 | + $response = new DataObject(); |
| 28 | + $response->setTypes([]); |
| 29 | + |
| 30 | + $eventManager->dispatch( |
| 31 | + 'adminhtml_product_attribute_types', |
| 32 | + ['response' => $response] |
| 33 | + ); |
| 34 | + |
| 35 | + $responseTypes = $response->getTypes(); |
| 36 | + |
| 37 | + self::assertGreaterThan(0, count($responseTypes)); |
| 38 | + |
| 39 | + /* Iterate through values since other types (not swatches) might be added by observers */ |
| 40 | + $responseTypeValues = []; |
| 41 | + foreach ($responseTypes as $responseType) { |
| 42 | + $responseTypeValues[] = $responseType['value']; |
| 43 | + } |
| 44 | + |
| 45 | + self::assertTrue(in_array(Swatch::SWATCH_TYPE_VISUAL_ATTRIBUTE_FRONTEND_INPUT, $responseTypeValues)); |
| 46 | + self::assertTrue(in_array(Swatch::SWATCH_TYPE_TEXTUAL_ATTRIBUTE_FRONTEND_INPUT, $responseTypeValues)); |
| 47 | + } |
| 48 | +} |
0 commit comments