public function testHas()
 {
     $this->setLoadAllExpectation(false);
     $this->setLoadConfigExpectation();
     $this->assertTrue($this->model->has('foo'));
     $this->assertFalse($this->model->has('bar'));
 }
 /**
  * Constructor
  *
  * @param ModuleList $list
  * @param ModuleList\Loader $loader
  * @param PackageInfoFactory $packageInfoFactory
  */
 public function __construct(ModuleList $list, ModuleList\Loader $loader, PackageInfoFactory $packageInfoFactory)
 {
     $this->enabledModuleList = $list->getNames();
     $this->fullModuleList = $loader->load();
     $packageInfo = $packageInfoFactory->create();
     $this->graph = $this->createGraph($packageInfo);
 }
 public function testCheckDependenciesWhenEnableModules()
 {
     $this->listMock->expects($this->any())->method('getNames')->will($this->returnValue(['C']));
     $this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
     $actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D']);
     $expected = ['B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']], 'D' => ['A' => ['D', 'A'], 'E' => ['D', 'A', 'B', 'E']]];
     $this->assertEquals($expected, $actual);
 }
Example #4
0
 /**
  * @return ViewModel
  */
 public function indexAction()
 {
     if ($this->moduleList->has('Magento_SampleData')) {
         /** @var \Magento\Framework\Setup\SampleData\State $sampleData */
         $sampleData = $this->objectManagerProvider->get()->get('Magento\\Framework\\Setup\\SampleData\\State');
         $isSampleDataErrorInstallation = $sampleData->hasError();
     } else {
         $isSampleDataErrorInstallation = false;
     }
     $view = new ViewModel(['isSampleDataErrorInstallation' => $isSampleDataErrorInstallation]);
     $view->setTerminal(true);
     return $view;
 }
 /**
  * @param string $mode
  * @param string $requestedPath
  * @param string $requestedModule
  * @param bool $moduleExists
  * @param string $expectedFile
  * @param array $expectedParams
  *
  * @dataProvider launchDataProvider
  */
 public function testLaunch($mode, $requestedPath, $requestedModule, $moduleExists, $expectedFile, array $expectedParams)
 {
     $this->state->expects($this->once())->method('getMode')->will($this->returnValue($mode));
     $this->state->expects($this->once())->method('setAreaCode')->with('area');
     $this->configLoader->expects($this->once())->method('load')->with('area')->will($this->returnValue(['config']));
     $this->objectManager->expects($this->once())->method('configure')->with(['config']);
     $this->request->expects($this->once())->method('get')->with('resource')->will($this->returnValue($requestedPath));
     $this->moduleList->expects($this->any())->method('has')->with($requestedModule)->will($this->returnValue($moduleExists));
     $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $asset->expects($this->once())->method('getSourceFile')->will($this->returnValue('resource/file.css'));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($expectedFile, $expectedParams)->will($this->returnValue($asset));
     $this->publisher->expects($this->once())->method('publish')->with($asset);
     $this->response->expects($this->once())->method('setFilePath')->with('resource/file.css');
     $this->object->launch();
 }
 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']);
 }
 /**
  * Get Components info action
  *
  * @return \Zend\View\Model\JsonModel
  * @throws \RuntimeException
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function componentsAction()
 {
     $lastSyncData = $this->updatePackagesCache->getPackagesForUpdate();
     $components = $this->composerInformation->getInstalledMagentoPackages();
     $allModules = $this->getAllModules();
     $components = array_replace_recursive($components, $allModules);
     foreach ($components as $component) {
         $components[$component['name']]['update'] = false;
         $components[$component['name']]['uninstall'] = false;
         $components[$component['name']]['moduleName'] = $this->packageInfo->getModuleName($component['name']);
         if ($this->composerInformation->isPackageInComposerJson($component['name'])) {
             if ($component['type'] !== \Magento\Framework\Composer\ComposerInformation::METAPACKAGE_PACKAGE_TYPE) {
                 $components[$component['name']]['uninstall'] = true;
             }
             if (isset($lastSyncData['packages'][$component['name']]['latestVersion']) && version_compare($lastSyncData['packages'][$component['name']]['latestVersion'], $component['version'], '>')) {
                 $components[$component['name']]['update'] = true;
             }
         }
         if ($component['type'] === \Magento\Framework\Composer\ComposerInformation::MODULE_PACKAGE_TYPE) {
             $components[$component['name']]['enable'] = $this->enabledModuleList->has($components[$component['name']]['moduleName']);
             $components[$component['name']]['disable'] = !$components[$component['name']]['enable'];
         } else {
             $components[$component['name']]['enable'] = false;
             $components[$component['name']]['disable'] = false;
         }
         $componentNameParts = explode('/', $component['name']);
         $components[$component['name']]['vendor'] = $componentNameParts[0];
     }
     $packagesForInstall = $this->marketplaceManager->getPackagesForInstall();
     $lastSyncData = $this->formatLastSyncData($packagesForInstall, $lastSyncData);
     return new \Zend\View\Model\JsonModel(['success' => true, 'components' => array_values($components), 'total' => count($components), 'lastSyncData' => $lastSyncData]);
 }
Example #8
0
 /**
  * Load data from module translation files
  *
  * @return $this
  */
 protected function _loadModuleTranslation()
 {
     $currentModule = $this->getControllerModuleName();
     $allModulesExceptCurrent = array_diff($this->_moduleList->getNames(), [$currentModule]);
     $this->loadModuleTranslationByModulesList($allModulesExceptCurrent);
     $this->loadModuleTranslationByModulesList([$currentModule]);
     return $this;
 }
Example #9
0
 /**
  * Load data from module translation files
  *
  * @param bool $forceReload
  * @return $this
  */
 protected function _loadModuleTranslation($forceReload = false)
 {
     foreach ($this->_moduleList->getModules() as $module) {
         $moduleFilePath = $this->_getModuleTranslationFile($module['name'], $this->getLocale());
         $this->_addData($this->_getFileData($moduleFilePath), false, $forceReload);
     }
     return $this;
 }
Example #10
0
 /**
  * Load data from module translation files
  *
  * @return $this
  */
 protected function _loadModuleTranslation()
 {
     foreach ($this->_moduleList->getNames() as $module) {
         $moduleFilePath = $this->_getModuleTranslationFile($module, $this->getLocale());
         $this->_addData($this->_getFileData($moduleFilePath));
     }
     return $this;
 }
 /**
  * Check if enabling module will conflict any modules
  *
  * @param string[] $moduleNames
  * @param string[] $currentlyEnabledModules
  *
  * @return array
  */
 public function checkConflictsWhenEnableModules($moduleNames, $currentlyEnabledModules = null)
 {
     $masterList = isset($currentlyEnabledModules) ? $currentlyEnabledModules : $this->list->getNames();
     // union of currently enabled modules and to-be-enabled modules
     $enabledModules = array_unique(array_merge($masterList, $moduleNames));
     $conflictsAll = [];
     foreach ($moduleNames as $moduleName) {
         $conflicts = [];
         foreach ($enabledModules as $enabledModule) {
             $messages = $this->getConflictMessages($enabledModule, $moduleName);
             if (!empty($messages)) {
                 $conflicts[] = implode("\n", $messages);
             }
         }
         $conflictsAll[$moduleName] = $conflicts;
     }
     return $conflictsAll;
 }
 public function testLoadDataNoTheme()
 {
     $forceReload = true;
     $this->expectsSetConfig(null, null);
     $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue([]));
     $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('frontend'));
     $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue([]));
     $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue([]));
     $this->assertEquals($this->translate, $this->translate->loadData(null, $forceReload));
 }
Example #13
0
 /**
  * Get a list of modules that will be changed
  *
  * @param bool $isEnabled
  * @param string[] $modules
  * @return string[]
  */
 public function getModulesToChange($isEnabled, $modules)
 {
     $changed = [];
     foreach ($this->getAllModules($modules) as $name) {
         $currentStatus = $this->list->has($name);
         if (in_array($name, $modules)) {
             if ($isEnabled != $currentStatus) {
                 $changed[] = $name;
             }
         }
     }
     return $changed;
 }
Example #14
0
 /**
  * Load library vendor
  */
 private function loader()
 {
     /** @var \Magento\Framework\App\ObjectManager $objectManager */
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $productMetadata = $objectManager->get('Magento\\Framework\\App\\ProductMetadataInterface');
     $timezone = $objectManager->create('\\Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     /** @var \Magento\Framework\App\ProductMetadataInterface $productMetadata */
     //set the store timezone to the script
     date_default_timezone_set($timezone->getConfigTimezone());
     \PagSeguro\Library::initialize();
     \PagSeguro\Library::cmsVersion()->setName("Magento")->setRelease($productMetadata->getVersion());
     \PagSeguro\Library::moduleVersion()->setName($this->_moduleList->getOne('UOL_PagSeguro')['name'])->setRelease($this->_moduleList->getOne('UOL_PagSeguro')['setup_version']);
 }
Example #15
0
 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']);
 }
 /**
  * Parse path to identify parts needed for searching original file
  *
  * @param string $path
  * @throws \InvalidArgumentException
  * @return array
  */
 protected function parsePath($path)
 {
     $path = ltrim($path, '/');
     $parts = explode('/', $path, 6);
     if (count($parts) < 5) {
         throw new \InvalidArgumentException("Requested path '{$path}' is wrong.");
     }
     $result = [];
     $result['area'] = $parts[0];
     $result['theme'] = $parts[1] . '/' . $parts[2];
     $result['locale'] = $parts[3];
     if (count($parts) >= 6 && $this->moduleList->has($parts[4])) {
         $result['module'] = $parts[4];
     } else {
         $result['module'] = '';
         if (isset($parts[5])) {
             $parts[5] = $parts[4] . '/' . $parts[5];
         } else {
             $parts[5] = $parts[4];
         }
     }
     $result['file'] = $parts[5];
     return $result;
 }
 public function testIsModuleInfoAvailableNoConfig()
 {
     $this->config->expects($this->at(0))->method('get')->willReturn(['modules' => 'testModule']);
     $this->config->expects($this->at(1))->method('get')->willReturn(null);
     $this->assertFalse($this->model->isModuleInfoAvailable());
 }
Example #18
0
 public function testIsModuleInfoAvailableNoConfig()
 {
     $this->config->expects($this->once())->method('isAvailable')->willReturn(true);
     $this->config->expects($this->once())->method('getConfigData')->willReturn(null);
     $this->assertFalse($this->model->isModuleInfoAvailable());
 }
Example #19
0
 /**
  * Check if active module 'name' exists
  *
  * @param string $name
  * @return bool
  */
 protected function isModule($name)
 {
     return null !== $this->moduleList->getModule($name);
 }