|
| 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\PageBuilder\Model\Stage; |
| 10 | + |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | + |
| 13 | +class UiComponentConfigTest extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \Magento\Framework\ObjectManagerInterface |
| 17 | + */ |
| 18 | + private $objectManager; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \Magento\Framework\Config\DataInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + private $dataInterfaceFactoryMock; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\PageBuilder\Model\Stage\Config\UiComponentConfig |
| 27 | + */ |
| 28 | + private $model; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 33 | + |
| 34 | + $this->dataInterfaceFactoryMock = $this->getMockBuilder(\Magento\Framework\Config\DataInterfaceFactory::class) |
| 35 | + ->setMethods(['create']) |
| 36 | + ->disableOriginalConstructor() |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $this->model = $this->objectManager->create( |
| 40 | + \Magento\PageBuilder\Model\Stage\Config\UiComponentConfig::class, |
| 41 | + [ |
| 42 | + 'configFactory' => $this->dataInterfaceFactoryMock |
| 43 | + ] |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Verify getFields will return the expected output given an example UI component configuration |
| 49 | + * |
| 50 | + * @param array $uiConfig |
| 51 | + * @param array $expectedFields |
| 52 | + * @dataProvider uiConfigDataProvider |
| 53 | + */ |
| 54 | + public function testGetFields(array $uiConfig, array $expectedFields) |
| 55 | + { |
| 56 | + $uiConfigMock = $this->createMock(\Magento\Framework\Config\DataInterface::class); |
| 57 | + $this->dataInterfaceFactoryMock->expects($this->once()) |
| 58 | + ->method('create') |
| 59 | + ->willReturn($uiConfigMock); |
| 60 | + $uiConfigMock->expects($this->once()) |
| 61 | + ->method('get') |
| 62 | + ->willReturn($uiConfig); |
| 63 | + |
| 64 | + $this->assertEquals($this->model->getFields('test_form'), $expectedFields); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Provide UI component config with expected output for 2 test cases, one with a normal field and another field |
| 69 | + * which sets a dataScope |
| 70 | + * |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + public function uiConfigDataProvider() : array |
| 74 | + { |
| 75 | + return [ |
| 76 | + [ |
| 77 | + [ |
| 78 | + 'children' => [ |
| 79 | + 'test_field_name' => [ |
| 80 | + 'arguments' => [ |
| 81 | + 'data' => [ |
| 82 | + 'config' => [ |
| 83 | + 'formElement' => 'text', |
| 84 | + 'componentType' => 'field', |
| 85 | + 'default' => 'default_value', |
| 86 | + 'visible' => 1, |
| 87 | + 'required' => 1, |
| 88 | + 'label' => __('Test Field Name') |
| 89 | + ] |
| 90 | + ] |
| 91 | + ] |
| 92 | + ], |
| 93 | + ] |
| 94 | + ], |
| 95 | + [ |
| 96 | + 'test_field_name' => [ |
| 97 | + 'default' => 'default_value' |
| 98 | + ] |
| 99 | + ] |
| 100 | + ], |
| 101 | + [ |
| 102 | + [ |
| 103 | + 'children' => [ |
| 104 | + 'test_datascope_name' => [ |
| 105 | + 'arguments' => [ |
| 106 | + 'data' => [ |
| 107 | + 'config' => [ |
| 108 | + 'dataScope' => 'namespace.test_datascope_name', |
| 109 | + 'formElement' => 'text', |
| 110 | + 'componentType' => 'field', |
| 111 | + 'default' => 'default_value', |
| 112 | + 'visible' => 1, |
| 113 | + 'required' => 1, |
| 114 | + 'label' => __('Test DataScope Name') |
| 115 | + ] |
| 116 | + ] |
| 117 | + ] |
| 118 | + ] |
| 119 | + ] |
| 120 | + ], |
| 121 | + [ |
| 122 | + 'namespace' => [ |
| 123 | + 'test_datascope_name' => [ |
| 124 | + 'default' => 'default_value' |
| 125 | + ] |
| 126 | + ] |
| 127 | + ] |
| 128 | + ] |
| 129 | + ]; |
| 130 | + } |
| 131 | +} |
0 commit comments