|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Backend\Test\Unit\Setup; |
| 7 | + |
| 8 | +use Magento\Backend\Setup\ConfigOptionsList; |
| 9 | +use Magento\Framework\Config\File\ConfigFilePool; |
| 10 | + |
| 11 | +class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var ConfigOptionsList |
| 15 | + */ |
| 16 | + private $object; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig |
| 20 | + */ |
| 21 | + private $deploymentConfig; |
| 22 | + |
| 23 | + protected function setUp() |
| 24 | + { |
| 25 | + $this->object = new ConfigOptionsList(); |
| 26 | + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); |
| 27 | + } |
| 28 | + |
| 29 | + public function testGetOptions() |
| 30 | + { |
| 31 | + $options = $this->object->getOptions(); |
| 32 | + $this->assertInternalType('array', $options); |
| 33 | + foreach ($options as $option) { |
| 34 | + $this->assertInstanceOf('\Magento\Framework\Setup\Option\AbstractConfigOption', $option); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + public function testCreateConfig() |
| 39 | + { |
| 40 | + $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; |
| 41 | + $actualConfig = $this->object->createConfig($options, $this->deploymentConfig); |
| 42 | + |
| 43 | + $expectedData = [ |
| 44 | + [ |
| 45 | + 'file' => ConfigFilePool::APP_CONFIG, |
| 46 | + 'segment' => 'backend', |
| 47 | + 'data' => [ |
| 48 | + 'backend' => ['frontName' => 'admin'] |
| 49 | + ] |
| 50 | + ] |
| 51 | + ]; |
| 52 | + |
| 53 | + $this->assertInternalType('array', $actualConfig); |
| 54 | + /** @var \Magento\Framework\Config\Data\ConfigData $config */ |
| 55 | + foreach ($actualConfig as $i => $config) { |
| 56 | + $this->assertInstanceOf('\Magento\Framework\Config\Data\ConfigData', $config); |
| 57 | + $this->assertSame($expectedData[$i]['file'], $config->getFileKey()); |
| 58 | + $this->assertSame($expectedData[$i]['data'], $config->getData()); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public function testValidate() |
| 63 | + { |
| 64 | + $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; |
| 65 | + $errors = $this->object->validate($options); |
| 66 | + $this->assertEmpty($errors); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param array $options |
| 71 | + * @param string $expectedError |
| 72 | + * @dataProvider validateInvalidDataProvider |
| 73 | + */ |
| 74 | + public function testValidateInvalid(array $options, $expectedError) |
| 75 | + { |
| 76 | + $errors = $this->object->validate($options); |
| 77 | + $this->assertSame([$expectedError], $errors); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @return array |
| 82 | + */ |
| 83 | + public function validateInvalidDataProvider() |
| 84 | + { |
| 85 | + return [ |
| 86 | + [[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"], |
| 87 | + [ |
| 88 | + [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'], |
| 89 | + "Invalid backend frontname 'invalid frontname'" |
| 90 | + ], |
| 91 | + ]; |
| 92 | + } |
| 93 | +} |
0 commit comments