/** * @param array $expected * * @dataProvider indexActionDataProvider */ public function testIndexActionWithError(array $expected) { $this->modules->expects($this->once())->method('getAllModules')->willReturn($expected['modules']); $this->status->expects($this->once())->method('checkConstraints')->willReturn(['ModuleA', 'ModuleB']); $jsonModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertArrayHasKey('error', $variables); $this->assertFalse($variables['success']); }
/** * Verifies component dependency for enable/disable actions * * @return JsonModel */ public function enableDisableDependencyCheckAction() { $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS; $data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); try { if (empty($data['packages'])) { throw new \Exception('No packages have been found.'); } if (empty($data['type'])) { throw new \Exception('Can not determine the flow.'); } $modules = $data['packages']; $isEnable = $data['type'] !== 'disable'; $modulesToChange = []; foreach ($modules as $module) { if (!isset($module['name'])) { throw new \Exception('Can not find module name.'); } $modulesToChange[] = $module['name']; } $constraints = $this->moduleStatus->checkConstraints($isEnable, $modulesToChange); $data = []; if ($constraints) { $data['errorMessage'] = "Unable to change status of modules because of the following constraints: " . implode("<br>", $constraints); $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR; } } catch (\Exception $e) { $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR; $data['errorMessage'] = $e->getMessage(); } $data['responseType'] = $responseType; return new JsonModel($data); }
/** * @param bool $isEnable * * @dataProvider executeWithConstraintsDataProvider */ public function testExecuteNoChanges($isEnable) { $this->status->expects($this->once())->method('getModulesToChange')->with($isEnable, ['Magento_Module1', 'Magento_Module2'])->will($this->returnValue([])); $this->status->expects($this->never())->method('setIsEnabled'); $commandTester = $isEnable ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); $commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]); $this->assertStringMatchesFormat('No modules were changed%a', $commandTester->getDisplay()); }
/** * @dataProvider getModulesToChangeDataProvider * @param bool $firstEnabled * @param bool $secondEnabled * @param bool $thirdEnabled * @param bool $isEnabled * @param string[] $expected */ public function testGetModulesToChange($firstEnabled, $secondEnabled, $thirdEnabled, $isEnabled, $expected) { $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn($firstEnabled); $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn($secondEnabled); $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn($thirdEnabled); $result = $this->object->getModulesToChange($isEnabled, ['Module_Foo', 'Module_Bar', 'Module_Baz']); $this->assertEquals($expected, $result); }