|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options; |
| 10 | + |
| 11 | +use Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Visual; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class \Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options\VisualTest |
| 15 | + */ |
| 16 | +class VisualTest extends \PHPUnit\Framework\TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var \PHPUnit_Framework_MockObject_MockObject|Visual |
| 20 | + */ |
| 21 | + private $model; |
| 22 | + |
| 23 | + /** |
| 24 | + * Setup environment for test |
| 25 | + */ |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $this->model = $this->getMockBuilder(Visual::class) |
| 29 | + ->disableOriginalConstructor() |
| 30 | + ->setMethods(['getReadOnly', 'canManageOptionDefaultOnly', 'getOptionValues', 'getUrl']) |
| 31 | + ->getMock(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Test getJsonConfig with getReadOnly() is true and canManageOptionDefaultOnly() is false |
| 36 | + */ |
| 37 | + public function testGetJsonConfigDataSet1() |
| 38 | + { |
| 39 | + $testCase1 = [ |
| 40 | + 'dataSet' => [ |
| 41 | + 'read_only' => true, |
| 42 | + 'can_manage_option_default_only' => false, |
| 43 | + 'upload_action_url' => 'http://magento.com/admin/swatches/iframe/show', |
| 44 | + 'option_values' => [ |
| 45 | + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), |
| 46 | + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), |
| 47 | + ] |
| 48 | + ], |
| 49 | + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . |
| 50 | + '"uploadActionUrl":"http:\/\/magento.com\/admin\/swatches\/iframe\/show","isSortable":0,"isReadOnly":1}' |
| 51 | + |
| 52 | + ]; |
| 53 | + |
| 54 | + $this->executeTest($testCase1); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test getJsonConfig with getReadOnly() is false and canManageOptionDefaultOnly() is false |
| 59 | + */ |
| 60 | + public function testGetJsonConfigDataSet2() |
| 61 | + { |
| 62 | + $testCase1 = [ |
| 63 | + 'dataSet' => [ |
| 64 | + 'read_only' => false, |
| 65 | + 'can_manage_option_default_only' => false, |
| 66 | + 'upload_action_url' => 'http://magento.com/admin/swatches/iframe/show', |
| 67 | + 'option_values' => [ |
| 68 | + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), |
| 69 | + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), |
| 70 | + ] |
| 71 | + ], |
| 72 | + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . |
| 73 | + '"uploadActionUrl":"http:\/\/magento.com\/admin\/swatches\/iframe\/show","isSortable":1,"isReadOnly":0}' |
| 74 | + ]; |
| 75 | + |
| 76 | + $this->executeTest($testCase1); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Execute test for getJsonConfig() function |
| 81 | + */ |
| 82 | + public function executeTest($testCase) |
| 83 | + { |
| 84 | + $this->model->expects($this->any())->method('getReadOnly') |
| 85 | + ->willReturn($testCase['dataSet']['read_only']); |
| 86 | + $this->model->expects($this->any())->method('canManageOptionDefaultOnly') |
| 87 | + ->willReturn($testCase['dataSet']['can_manage_option_default_only']); |
| 88 | + $this->model->expects($this->any())->method('getOptionValues')->willReturn( |
| 89 | + $testCase['dataSet']['option_values'] |
| 90 | + ); |
| 91 | + $this->model->expects($this->any())->method('getUrl') |
| 92 | + ->willReturn($testCase['dataSet']['upload_action_url']); |
| 93 | + |
| 94 | + $this->assertEquals($testCase['expectedResult'], $this->model->getJsonConfig()); |
| 95 | + } |
| 96 | +} |
0 commit comments