Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InstallStoreConfigurationCommandTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Symfony\Component\Console\Tester\CommandTester;
14 use Magento\Framework\Validator\Url as UrlValidator;
15 use Magento\Framework\Validator\Locale as LocaleValidator;
16 use Magento\Framework\Validator\Timezone as TimezoneValidator;
17 use Magento\Framework\Validator\Currency as CurrencyValidator;
18 
22 class InstallStoreConfigurationCommandTest extends \PHPUnit\Framework\TestCase
23 {
27  private $deploymentConfig;
28 
32  private $installerFactory;
33 
37  private $installer;
38 
42  private $objectManager;
43 
47  private $localeValidatorMock;
48 
52  private $timezoneValidatorMock;
53 
57  private $currencyValidatorMock;
58 
62  private $urlValidatorMock;
63 
67  private $command;
68 
69  protected function setUp()
70  {
71  $this->urlValidatorMock = $this->createMock(UrlValidator::class);
72  $this->localeValidatorMock = $this->createMock(LocaleValidator::class);
73  $this->timezoneValidatorMock = $this->createMock(TimezoneValidator::class);
74  $this->currencyValidatorMock = $this->createMock(CurrencyValidator::class);
75 
76  $this->installerFactory = $this->createMock(\Magento\Setup\Model\InstallerFactory::class);
77  $this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
78  $this->installer = $this->createMock(\Magento\Setup\Model\Installer::class);
79  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
80  $this->objectManager = $this->getMockForAbstractClass(
81  \Magento\Framework\ObjectManagerInterface::class,
82  [],
83  '',
84  false
85  );
86  $objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
87  $this->command = new InstallStoreConfigurationCommand(
88  $this->installerFactory,
89  $this->deploymentConfig,
90  $objectManagerProvider,
91  $this->localeValidatorMock,
92  $this->timezoneValidatorMock,
93  $this->currencyValidatorMock,
94  $this->urlValidatorMock
95  );
96  }
97 
98  public function testExecute()
99  {
100  $this->deploymentConfig->expects($this->once())
101  ->method('isAvailable')
102  ->will($this->returnValue(true));
103  $this->installer->expects($this->once())
104  ->method('installUserConfig');
105  $this->installerFactory->expects($this->once())
106  ->method('create')
107  ->will($this->returnValue($this->installer));
108  $tester = new CommandTester($this->command);
109  $tester->execute([]);
110  }
111 
112  public function testExecuteNotInstalled()
113  {
114  $this->deploymentConfig->expects($this->once())
115  ->method('isAvailable')
116  ->will($this->returnValue(false));
117  $this->installerFactory->expects($this->never())
118  ->method('create');
119  $tester = new CommandTester($this->command);
120  $tester->execute([]);
121  $this->assertStringMatchesFormat(
122  "Store settings can't be saved because the Magento application is not installed.%w",
123  $tester->getDisplay()
124  );
125  }
126 
132  public function testExecuteInvalidData(array $option, $error)
133  {
134  $this->localeValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
135  $this->timezoneValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
136  $this->currencyValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
137  $this->urlValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
138 
139  $this->deploymentConfig->expects($this->once())
140  ->method('isAvailable')
141  ->will($this->returnValue(true));
142  $this->installerFactory->expects($this->never())
143  ->method('create');
144  $commandTester = new CommandTester($this->command);
145  $commandTester->execute($option);
146  $this->assertContains($error, $commandTester->getDisplay());
147  }
148 
152  public function validateDataProvider()
153  {
154  return [
155  [
156  ['--' . StoreConfigurationDataMapper::KEY_BASE_URL => 'sampleUrl'],
157  'Command option \'' . StoreConfigurationDataMapper::KEY_BASE_URL . '\': Invalid URL \'sampleUrl\'.'
158  ],
159  [
160  ['--' . StoreConfigurationDataMapper::KEY_BASE_URL => 'http://example.com_test'],
161  'Command option \'' . StoreConfigurationDataMapper::KEY_BASE_URL
162  . '\': Invalid URL \'http://example.com_test\'.'
163  ],
164  [
165  ['--' . StoreConfigurationDataMapper::KEY_LANGUAGE => 'sampleLanguage'],
166  'Command option \'' . StoreConfigurationDataMapper::KEY_LANGUAGE
167  . '\': Invalid value. To see possible values, run command \'bin/magento info:language:list\'.'
168  ],
169  [
170  ['--' . StoreConfigurationDataMapper::KEY_TIMEZONE => 'sampleTimezone'],
171  'Command option \'' . StoreConfigurationDataMapper::KEY_TIMEZONE
172  . '\': Invalid value. To see possible values, run command \'bin/magento info:timezone:list\'.'
173  ],
174  [
175  ['--' . StoreConfigurationDataMapper::KEY_CURRENCY => 'sampleLanguage'],
176  'Command option \'' . StoreConfigurationDataMapper::KEY_CURRENCY
177  . '\': Invalid value. To see possible values, run command \'bin/magento info:currency:list\'.'
178  ],
179  [
180  ['--' . StoreConfigurationDataMapper::KEY_USE_SEF_URL => 'invalidValue'],
182  . '\': Invalid value. Possible values (0|1).'
183  ],
184  [
185  ['--' . StoreConfigurationDataMapper::KEY_IS_SECURE => 'invalidValue'],
186  'Command option \'' . StoreConfigurationDataMapper::KEY_IS_SECURE
187  . '\': Invalid value. Possible values (0|1).'
188  ],
189  [
190  ['--' . StoreConfigurationDataMapper::KEY_BASE_URL_SECURE => 'http://www.sample.com'],
192  . '\': Invalid URL \'http://www.sample.com\'.'
193  ],
194  [
195  ['--' . StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN => 'invalidValue'],
197  . '\': Invalid value. Possible values (0|1).'
198  ],
199  [
200  ['--' . StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => 'invalidValue'],
202  . '\': Invalid value. Possible values (0|1).'
203  ],
204 
205  ];
206  }
207 }
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9