/** * @param bool $isEnable * @param string $expectedMessage * * @dataProvider executeAllDataProvider */ public function testExecuteAll($isEnable, $expectedMessage) { $this->fullModuleList->expects($this->once())->method('getNames')->will($this->returnValue(['Magento_Module1', 'Magento_Module2'])); $this->status->expects($this->once())->method('getModulesToChange')->with($isEnable, ['Magento_Module1', 'Magento_Module2'])->will($this->returnValue(['Magento_Module1'])); $this->status->expects($this->any())->method('checkConstraints')->will($this->returnValue([])); $this->status->expects($this->once())->method('setIsEnabled')->with($isEnable, ['Magento_Module1']); $commandTester = $isEnable ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); $input = ['--all' => true]; $commandTester->execute($input); $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay()); }
private function setUpPassValidation() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true); $packageMap = [['Magento_A', 'magento/package-a'], ['Magento_B', 'magento/package-b']]; $this->packageInfo->expects($this->any())->method('getPackageName')->will($this->returnValueMap($packageMap)); $this->fullModuleList->expects($this->any())->method('has')->willReturn(true); }
public function testComponentsAction() { $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface', [], [], '', false); $this->objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager); $objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Module\\PackageInfoFactory', $this->packageInfoFactoryMock], ['Magento\\Framework\\Module\\FullModuleList', $this->fullModuleListMock], ['Magento\\Framework\\Module\\ModuleList', $this->enabledModuleListMock]]); $this->packageInfoFactoryMock->expects($this->once())->method('create')->willReturn($this->packageInfo); $this->fullModuleListMock->expects($this->once())->method('getNames')->willReturn(['magento/sample-module1']); $this->packageInfo->expects($this->once())->method('getModuleName')->willReturn('Sample_Module'); $this->packageInfo->expects($this->exactly(2))->method('getPackageName')->willReturn($this->componentData['magento/sample-module-one']['name']); $this->packageInfo->expects($this->exactly(2))->method('getVersion')->willReturn($this->componentData['magento/sample-module-one']['version']); $this->enabledModuleListMock->expects($this->once())->method('has')->willReturn(true); $this->composerInformationMock->expects($this->once())->method('getInstalledMagentoPackages')->willReturn($this->componentData); $this->composerInformationMock->expects($this->once())->method('isPackageInComposerJson')->willReturn(true); $this->packagesAuth->expects($this->once())->method('getAuthJsonData')->willReturn(['username' => 'someusername', 'password' => 'somepassword']); $this->packagesData->expects($this->once())->method('syncPackagesData')->willReturn($this->lastSyncData); $jsonModel = $this->controller->componentsAction(); $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertTrue($variables['success']); $expected = [['name' => 'magento/sample-module-one', 'type' => 'magento2-module', 'version' => '1.0.0', 'update' => false, 'uninstall' => true, 'vendor' => 'magento', 'moduleName' => 'Sample_Module', 'enable' => true, 'disable' => false]]; $this->assertEquals($expected, $variables['components']); $this->assertArrayHasKey('total', $variables); $this->assertEquals(1, $variables['total']); $this->assertEquals($this->lastSyncData, $variables['lastSyncData']); }
public function testUpdateActionSuccessDisable() { $content = '{"packages":[{"name":"vendor\\/package"}],"type":"disable",' . '"headerTitle": "Disable Package 1" }'; $this->request->expects($this->any())->method('getContent')->willReturn($content); $this->fullModuleList->expects($this->once())->method('has')->willReturn(true); $write = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], '', false); $this->filesystem->expects($this->once())->method('getDirectoryWrite')->willReturn($write); $write->expects($this->once())->method('writeFile')->with('.type.json', '{"type":"disable","headerTitle":"Disable Package 1","titles":["D"]}'); $this->controller->setEvent($this->mvcEvent); $this->controller->dispatch($this->request, $this->response); $this->controller->updateAction(); }
/** * @param array $expected * @param $withSampleData * * @dataProvider indexActionDataProvider */ public function testIndexAction($expected, $withSampleData) { if ($withSampleData) { $this->moduleList->expects($this->once())->method('has')->willReturn(true); $this->objectManager->expects($this->once())->method('get')->willReturn($this->sampleDataState); $this->sampleDataState->expects($this->once())->method('isInstalled')->willReturn($expected['isSampleDataInstalled']); $this->sampleDataState->expects($this->once())->method('hasError')->willReturn($expected['isSampleDataErrorInstallation']); } else { $this->moduleList->expects($this->once())->method('has')->willReturn(false); $this->objectManager->expects($this->never())->method('get'); } $this->lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']); $this->lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']); $this->lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $viewModel); $this->assertTrue($viewModel->terminate()); $variables = $viewModel->getVariables(); $this->assertArrayHasKey('timezone', $variables); $this->assertArrayHasKey('currency', $variables); $this->assertArrayHasKey('language', $variables); $this->assertSame($expected, $variables); }
public function testComponentsAction() { $this->fullModuleListMock->expects($this->once()) ->method('getNames') ->willReturn(['magento/sample-module1']); $this->packageInfo->expects($this->once()) ->method('getModuleName') ->willReturn('Sample_Module'); $this->packageInfo->expects($this->exactly(2)) ->method('getPackageName') ->willReturn($this->componentData['magento/sample-module-one']['name']); $this->packageInfo->expects($this->exactly(2)) ->method('getVersion') ->willReturn($this->componentData['magento/sample-module-one']['version']); $this->enabledModuleListMock->expects($this->once()) ->method('has') ->willReturn(true); $this->composerInformationMock->expects($this->once()) ->method('getInstalledMagentoPackages') ->willReturn($this->componentData); $this->composerInformationMock->expects($this->once()) ->method('isPackageInComposerJson') ->willReturn(true); $this->updatePackagesCacheMock->expects($this->once()) ->method('getPackagesForUpdate') ->willReturn($this->lastSyncData); $jsonModel = $this->controller->componentsAction(); $this->assertInstanceOf('Zend\View\Model\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('success', $variables); $this->assertTrue($variables['success']); $expected = [[ 'name' => 'magento/sample-module-one', 'type' => 'magento2-module', 'version' => '1.0.0', 'update' => false, 'uninstall' => true, 'vendor' => 'magento', 'moduleName' => 'Sample_Module', 'enable' => true, 'disable' => false ]]; $this->assertEquals($expected, $variables['components']); $this->assertArrayHasKey('total', $variables); $this->assertEquals(1, $variables['total']); $this->assertEquals($this->lastSyncData, $variables['lastSyncData']); }
/** * @param bool $isEnable * @param string $expectedMessage * * @dataProvider executeAllDataProvider */ public function testExecuteAll($isEnable, $expectedMessage) { $setupUpgradeMessage = 'To make sure that the enabled modules are properly registered, run \'setup:upgrade\'.'; $this->fullModuleListMock->expects($this->once())->method('getNames')->will($this->returnValue(['Magento_Module1', 'Magento_Module2'])); $this->statusMock->expects($this->once())->method('getModulesToChange')->with($isEnable, ['Magento_Module1', 'Magento_Module2'])->will($this->returnValue(['Magento_Module1'])); $this->statusMock->expects($this->any())->method('checkConstraints')->will($this->returnValue([])); $this->statusMock->expects($this->once())->method('setIsEnabled')->with($isEnable, ['Magento_Module1']); if ($isEnable) { $this->deploymentConfigMock->expects($this->once())->method('isAvailable')->willReturn(['Magento_Module1']); } else { $this->deploymentConfigMock->expects($this->never())->method('isAvailable'); } $commandTester = $this->getCommandTester($isEnable); $input = ['--all' => true]; $commandTester->execute($input); $output = $commandTester->getDisplay(); $this->assertStringMatchesFormat($expectedMessage, $output); if ($isEnable) { $this->assertContains($setupUpgradeMessage, $output); } else { $this->assertNotContains($setupUpgradeMessage, $output); } }
/** * @param string $type * @param int $has * @param bool $moduleExists * @param string $errorMessage * @dataProvider validatePayLoadNegativeCasesDataProvider */ public function testValidatePayLoadNegativeCases($type, $has, $moduleExists, $errorMessage) { $this->fullModuleList->expects($this->exactly($has))->method('has')->willReturn($moduleExists); $this->assertStringStartsWith($errorMessage, $this->model->validatePayload($type)); }