Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomizeYourStoreTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Setup\Controller\CustomizeYourStore;
10 
11 class CustomizeYourStoreTest extends \PHPUnit\Framework\TestCase
12 {
16  private $controller;
17 
21  private $sampleDataState;
22 
26  private $lists;
27 
31  private $objectManager;
32 
36  private $moduleList;
37 
38  public function setup()
39  {
40  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
41  $this->objectManager = $this->createMock(\Magento\Framework\App\ObjectManager::class);
42  $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
43  $this->sampleDataState = $this->createMock(\Magento\Framework\Setup\SampleData\State::class);
44  $this->lists = $this->createMock(\Magento\Framework\Setup\Lists::class);
45  $this->moduleList = $this->createMock(\Magento\Framework\Module\FullModuleList::class);
46  $this->controller = new CustomizeYourStore($this->moduleList, $this->lists, $objectManagerProvider);
47  }
48 
55  public function testIndexAction($expected, $withSampleData)
56  {
57  if ($withSampleData) {
58  $this->moduleList->expects($this->once())->method('has')->willReturn(true);
59  $this->objectManager->expects($this->once())->method('get')->willReturn($this->sampleDataState);
60  $this->sampleDataState->expects($this->once())->method('isInstalled')
61  ->willReturn($expected['isSampleDataInstalled']);
62  $this->sampleDataState->expects($this->once())->method('hasError')
63  ->willReturn($expected['isSampleDataErrorInstallation']);
64  } else {
65  $this->moduleList->expects($this->once())->method('has')->willReturn(false);
66  $this->objectManager->expects($this->never())->method('get');
67  }
68  $this->lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']);
69  $this->lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']);
70  $this->lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']);
71 
72  $viewModel = $this->controller->indexAction();
73 
74  $this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
75  $this->assertTrue($viewModel->terminate());
76 
77  $variables = $viewModel->getVariables();
78  $this->assertArrayHasKey('timezone', $variables);
79  $this->assertArrayHasKey('currency', $variables);
80  $this->assertArrayHasKey('language', $variables);
81  $this->assertSame($expected, $variables);
82  }
83 
87  public function indexActionDataProvider()
88  {
89  $timezones = ['timezone' => ['America/New_York'=>'EST', 'America/Chicago' => 'CST']];
90  $currency = ['currency' => ['USD'=>'US Dollar', 'EUR' => 'Euro']];
91  $language = ['language' => ['en_US'=>'English (USA)', 'en_UK' => 'English (UK)']];
92  $sampleData = [
93  'isSampleDataInstalled' => false,
94  'isSampleDataErrorInstallation' => false
95  ];
96 
97  return [
98  'with_all_data' => [array_merge($timezones, $currency, $language, $sampleData), true],
99  'no_currency_data' => [array_merge($timezones, ['currency' => null], $language, $sampleData), true],
100  'no_timezone_data' => [array_merge(['timezone' => null], $currency, $language, $sampleData), true],
101  'no_language_data' => [array_merge($timezones, $currency, ['language' => null], $sampleData), true],
102  'empty_currency_data' => [array_merge($timezones, ['currency' => []], $language, $sampleData), true],
103  'empty_timezone_data' => [array_merge(['timezone' => []], $currency, $language, $sampleData), true],
104  'empty_language_data' => [array_merge($timezones, $currency, ['language' => []], $sampleData), true],
105  'no_sample_data' => [array_merge($timezones, $currency, $language, $sampleData), false],
106  ];
107  }
108 
109  public function testDefaultTimeZoneAction()
110  {
111  $jsonModel = $this->controller->defaultTimeZoneAction();
112  $this->assertInstanceOf(\Zend\View\Model\JsonModel::class, $jsonModel);
113  $this->assertArrayHasKey('defaultTimeZone', $jsonModel->getVariables());
114  }
115 }
return false
Definition: gallery.phtml:36
$viewModel