/**
  * 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]);
 }
 /**
  * Run Composer dependency check for uninstall
  *
  * @param array $packages
  * @return array
  * @throws \RuntimeException
  */
 public function runUninstallReadinessCheck(array $packages)
 {
     try {
         $packagesAndTypes = $this->composerInfo->getRootRequiredPackageTypesByName();
         $dependencies = $this->packageDependencyChecker->checkDependencies($packages, true);
         $messages = [];
         $themes = [];
         foreach ($packages as $package) {
             if (!isset($packagesAndTypes[$package])) {
                 throw new \RuntimeException('Package ' . $package . ' not found in the system.');
             }
             switch ($packagesAndTypes[$package]) {
                 case ComposerInformation::METAPACKAGE_PACKAGE_TYPE:
                     unset($dependencies[$package]);
                     break;
                 case ComposerInformation::THEME_PACKAGE_TYPE:
                     $themes[] = $package;
                     break;
             }
             if (!empty($dependencies[$package])) {
                 $messages[] = $package . " has the following dependent package(s): " . implode(', ', $dependencies[$package]);
             }
         }
         if (!empty($themes)) {
             $messages = array_merge($messages, $this->themeDependencyChecker->checkChildThemeByPackagesName($themes));
         }
         if (!empty($messages)) {
             throw new \RuntimeException(implode(PHP_EOL, $messages));
         }
         return ['success' => true];
     } catch (\RuntimeException $e) {
         $message = str_replace(PHP_EOL, '<br/>', htmlspecialchars($e->getMessage()));
         return ['success' => false, 'error' => $message];
     }
 }
 /**
  * @param array $packageList
  * @param string $expectedVersion
  * @dataProvider testGetVersionGitInstallationDataProvider
  */
 public function testGetVersion($packageList, $expectedVersion)
 {
     $this->composerInformationMock->expects($this->any())->method('getSystemPackages')->willReturn($packageList);
     $productVersion = $this->productMetadata->getVersion();
     $this->assertNotEmpty($productVersion, 'Empty product version');
     $this->assertEquals($expectedVersion, $productVersion);
 }
 /**
  * @param string $packageName
  * @param boolean $expected
  * @dataProvider isMagentoRootDataProvider
  */
 public function testIsMagentoRoot($packageName, $expected)
 {
     $rootPackageMock = $this->getMockForAbstractClass(\Composer\Package\RootPackageInterface::class);
     $this->composerMock->expects($this->once())->method('getPackage')->willReturn($rootPackageMock);
     $rootPackageMock->method('getName')->willReturn($packageName);
     $this->assertEquals($expected, $this->composerInformation->isMagentoRoot());
 }
 public function testRunUninstallReadinessCheckWithError()
 {
     $packages = ['verndor/module' => 'magento2-module', 'verndor/theme' => 'magento2-theme', 'verndor/metapackage' => 'metapackage', 'verndor/language' => 'magento2-language'];
     $this->composerInfo->expects($this->once())->method('getRootRequiredPackageTypesByName')->willReturn($packages);
     $this->packageDependencyChecker->expects($this->once())->method('checkDependencies')->with(array_keys($packages))->willReturn([]);
     $this->themeDependencyChecker->expects($this->once())->method('checkChildThemeByPackagesName')->with(['verndor/theme'])->willReturn(['Error message']);
     $result = $this->uninstallDependencyCheck->runUninstallReadinessCheck(array_keys($packages));
     $this->assertEquals(['success' => false, 'error' => 'Error message'], $result);
 }
 public function testComponentsActionWithError()
 {
     $this->composerInformation->expects($this->once())->method('getInstalledMagentoPackages')->will($this->throwException(new \Exception("Test error message")));
     $jsonModel = $this->controller->componentsAction();
     $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('responseType', $variables);
     $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']);
 }
Example #7
0
 /**
  * @covers \Magento\Setup\Controller\Connect::saveAuthJsonAction
  */
 public function testSaveAuthJsonActionWithError()
 {
     $this->connectManager->expects($this->once())->method('checkCredentialsAction')->will($this->throwException(new \Exception()));
     $this->composerInformation->expects($this->never())->method('saveAuthJson');
     $jsonModel = $this->controller->saveAuthJsonAction();
     $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('success', $variables);
     $this->assertArrayHasKey('message', $variables);
     $this->assertFalse($variables['success']);
 }
Example #8
0
 /**
  * Retrieve list of sample data packages from suggests
  *
  * @return array
  */
 public function getSampleDataPackages()
 {
     $installExtensions = [];
     $suggests = $this->composerInformation->getSuggestedPackages();
     $suggests = array_merge($suggests, $this->getSuggestsFromModules());
     foreach ($suggests as $name => $version) {
         if (strpos($version, self::SAMPLE_DATA_SUGGEST) === 0) {
             $installExtensions[$name] = substr($version, strlen(self::SAMPLE_DATA_SUGGEST));
         }
     }
     return $installExtensions;
 }
 public function testGetPackagesForUpdate()
 {
     $packageName = 'magento/module-store';
     $this->setupDirectory('testSkeleton');
     /** @var \Magento\Setup\Model\UpdatePackagesCache $updatePackagesCache */
     $updatePackagesCache = $this->objectManager->create('Magento\\Setup\\Model\\UpdatePackagesCache', ['applicationFactory' => new MagentoComposerApplicationFactory($this->composerJsonFinder, $this->directoryList), 'filesystem' => $this->filesystem, 'dateTime' => new DateTime(), 'composerInformation' => $this->composerInformation]);
     $requiredPackages = $this->composerInformation->getInstalledMagentoPackages();
     $this->assertArrayHasKey($packageName, $requiredPackages);
     $this->assertTrue($updatePackagesCache->syncPackagesForUpdate());
     $packagesForUpdate = $updatePackagesCache->getPackagesForUpdate();
     $this->assertArrayHasKey('packages', $packagesForUpdate);
     $this->assertArrayHasKey($packageName, $packagesForUpdate['packages']);
     $this->assertTrue(version_compare($packagesForUpdate['packages'][$packageName]['latestVersion'], $requiredPackages[$packageName]['version'], '>'));
 }
    /**
     * @param string $ceCurrentVersion
     * @param array $expectedResult
     *
     * @dataProvider getAllowedEnterpriseVersionsDataProvider
     */
    public function testGetAllowedEnterpriseVersions($ceCurrentVersion, $expectedResult)
    {
        $this->composerAppFactory->expects($this->once())
            ->method('createInfoCommand')
            ->willReturn($this->infoCommand);
        $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation);
        $this->infoCommand->expects($this->once())
            ->method('run')
            ->with('magento/product-enterprise-edition')
            ->willReturn(['available_versions' => ['1.0.0', '1.0.1', '1.0.2']]);
        $require = $this->getMock('\Composer\Package\Link', [], [], '', false);
        $constraintMock = $this->getMock('\Composer\Package\LinkConstraint\VersionConstraint', [], [], '', false);
        $constraintMock->expects($this->any())->method('getPrettyString')
            ->willReturn('1.0.1');
        $require->expects($this->any())
            ->method('getConstraint')
            ->willReturn($constraintMock);

        $this->composerInformation->expects($this->any())
            ->method('getPackageRequirements')
            ->willReturn(['magento/product-community-edition' => $require]);
        $this->assertEquals(
            $expectedResult,
            $this->systemPackage->getAllowedEnterpriseVersions($ceCurrentVersion)
        );
    }
 /**
  * Execute uninstall on a component
  *
  * @param array $component
  * @return void
  * @throw \RuntimeException
  */
 private function executeComponent(array $component)
 {
     if (!isset($component[self::COMPONENT_NAME])) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Job parameter format is incorrect');
     }
     $componentName = $component[self::COMPONENT_NAME];
     $installedPackages = $this->composerInformation->getInstalledMagentoPackages();
     if (isset($installedPackages[$componentName]['type'])) {
         $type = $installedPackages[$componentName]['type'];
     } else {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Component type not set');
     }
     if (!in_array($type, [self::COMPONENT_MODULE, self::COMPONENT_THEME, self::COMPONENT_LANGUAGE, self::COMPONENT])) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Unknown component type');
     }
     switch ($type) {
         case self::COMPONENT_MODULE:
             $dataOption = isset($this->params[self::DATA_OPTION]) && $this->params[self::DATA_OPTION] === 'true';
             $this->moduleUninstall->uninstall($this->output, $componentName, $dataOption);
             break;
         case self::COMPONENT_THEME:
             $this->themeUninstall->uninstall($this->output, $componentName);
             break;
     }
 }
 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']);
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage error
  */
 public function testExecuteUpdateFails()
 {
     $this->updater->expects($this->once())->method('createUpdaterTask')->willReturn('error');
     $this->composerInformation->expects($this->once())->method('getInstalledMagentoPackages')->willReturn(['vendor/language-a' => ['type' => JobComponentUninstall::COMPONENT_LANGUAGE]]);
     $this->job = new JobComponentUninstall($this->composerInformation, $this->moduleUninstallHelper, $this->themeUninstallHelper, $this->objectManagerProvider, $this->output, $this->quence, $this->status, $this->updater, 'setup:component:uninstall', ['components' => [[JobComponentUninstall::COMPONENT_NAME => 'vendor/language-a']]]);
     $this->job->execute();
 }
Example #14
0
 /**
  * Checks PHP extensions
  *
  * @return array
  */
 public function checkPhpExtensions()
 {
     try {
         $required = $this->composerInformation->getRequiredExtensions();
         $current = $this->phpInformation->getCurrent();
     } catch (\Exception $e) {
         return [
             'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR,
             'data' => [
                 'error' => 'phpExtensionError',
                 'message' => 'Cannot determine required PHP extensions: ' . $e->getMessage()
             ],
         ];
     }
     $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
     $missing = array_values(array_diff($required, $current));
     if ($missing) {
         $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
     }
     return [
         'responseType' => $responseType,
         'data' => [
             'required' => $required,
             'missing' => $missing,
         ],
     ];
 }
Example #15
0
 /**
  * Retrieve all available versions for a package
  *
  * @param string $package
  * @return array
  * @throws \RuntimeException
  */
 private function getPackageAvailableVersions($package)
 {
     $magentoRepositories = $this->composerInformation->getRootRepositories();
     // Check we have only one repo.magento.com repository
     if (count($magentoRepositories) === 1 && strpos($magentoRepositories[0], $this->packagesAuth->getCredentialBaseUrl())) {
         $packagesJsonData = $this->getPackagesJson();
         if ($packagesJsonData) {
             $packagesJsonData = json_decode($packagesJsonData, true);
         } else {
             $packagesJsonData['packages'] = [];
         }
         if (isset($packagesJsonData['packages'][$package])) {
             $packageVersions = $packagesJsonData['packages'][$package];
             uksort($packageVersions, 'version_compare');
             $packageVersions = array_reverse($packageVersions);
             return array_keys($packageVersions);
         }
     } else {
         $versionsPattern = '/^versions\\s*\\:\\s(.+)$/m';
         $commandParams = [self::PARAM_COMMAND => self::COMPOSER_SHOW, self::PARAM_PACKAGE => $package, self::PARAM_AVAILABLE => true];
         $applicationFactory = $this->objectManagerProvider->get()->get('Magento\\Framework\\Composer\\MagentoComposerApplicationFactory');
         /** @var \Magento\Composer\MagentoComposerApplication $application */
         $application = $applicationFactory->create();
         $result = $application->runComposerCommand($commandParams);
         $matches = [];
         preg_match($versionsPattern, $result, $matches);
         if (isset($matches[1])) {
             return explode(', ', $matches[1]);
         }
     }
     throw new \RuntimeException(sprintf('Couldn\'t get available versions for package %s', $package));
 }
 public function testCheckPhpExtensionsFailed()
 {
     $this->composerInfo->expects($this->once())->method('getRequiredExtensions')->willReturn(['a', 'b', 'c']);
     $this->phpInfo->expects($this->once())->method('getCurrent')->willReturn(['a', 'b']);
     $expected = ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['required' => ['a', 'b', 'c'], 'missing' => ['c']]];
     $this->assertEquals($expected, $this->phpReadinessCheck->checkPhpExtensions());
 }
 /**
  * Validates user input
  *
  * @param string $package
  *
  * @return bool
  */
 private function validate($package)
 {
     $installedPackages = $this->composerInfo->getRootRequiredPackageTypesByName();
     if (isset($installedPackages[$package]) && $installedPackages[$package] === 'magento2-language') {
         return true;
     }
     return false;
 }
 public function testGetPackagesForUpdate()
 {
     $packageName = 'magento/module-store';
     $this->setupDirectory('testSkeleton');
     /** @var UpdatePackagesCache $updatePackagesCache|\PHPUnit_Framework_MockObject_MockObject */
     $updatePackagesCache = $this->getMock('Magento\\Setup\\Model\\UpdatePackagesCache', [], [], '', false);
     $packages = ['packages' => [$packageName => ['latestVersion' => '1000.100.200']]];
     $updatePackagesCache->expects($this->once())->method('syncPackagesForUpdate')->willReturn(true);
     $updatePackagesCache->expects($this->once())->method('getPackagesForUpdate')->willReturn($packages);
     $requiredPackages = $this->composerInformation->getInstalledMagentoPackages();
     $this->assertArrayHasKey($packageName, $requiredPackages);
     $this->assertTrue($updatePackagesCache->syncPackagesForUpdate());
     $packagesForUpdate = $updatePackagesCache->getPackagesForUpdate();
     $this->assertArrayHasKey('packages', $packagesForUpdate);
     $this->assertArrayHasKey($packageName, $packagesForUpdate['packages']);
     $this->assertTrue(version_compare($packagesForUpdate['packages'][$packageName]['latestVersion'], $requiredPackages[$packageName]['version'], '>'));
 }
 public function testExecutePackageNoLanguage()
 {
     $dependencies['vendor/language-ua_ua'] = [];
     $this->dependencyChecker->expects($this->once())->method('checkDependencies')->with(['vendor/language-ua_ua'])->willReturn($dependencies);
     $this->composerInfo->expects($this->once())->method('getRootRequiredPackagesAndTypes')->willReturn(['vendor/language-ua_ua' => 'library']);
     $this->remove->expects($this->never())->method('remove');
     $this->cache->expects($this->never())->method('clean');
     $this->tester->execute(['package' => ['vendor/language-ua_ua']]);
     $this->assertContains('Package vendor/language-ua_ua is not a Magento language and will be skipped', $this->tester->getDisplay());
     $this->assertContains('Nothing is removed.', $this->tester->getDisplay());
 }
 /**
  * Retrieve list of unknown packages
  *
  * @param string[] $themePaths
  * @return string[]
  */
 protected function getUnknownPackages($themePaths)
 {
     $installedPackages = $this->composer->getRootRequiredPackages();
     $result = [];
     foreach ($themePaths as $themePath) {
         if (array_search($this->themePackageInfo->getPackageName($themePath), $installedPackages) === false) {
             $result[] = $themePath;
         }
     }
     return $result;
 }
Example #21
0
 /**
  * Get Components info action
  *
  * @return \Zend\View\Model\JsonModel
  * @throws \RuntimeException
  */
 public function componentsAction()
 {
     $objectManager = $this->objectManagerProvider->get();
     $enabledModuleList = $objectManager->get('Magento\\Framework\\Module\\ModuleList');
     $this->fullModuleList = $objectManager->get('Magento\\Framework\\Module\\FullModuleList');
     $this->packageInfo = $objectManager->get('Magento\\Framework\\Module\\PackageInfoFactory')->create();
     $lastSyncData = [];
     $authDetails = $this->packagesAuth->getAuthJsonData();
     if ($authDetails) {
         $lastSyncData = $this->packagesData->syncPackagesData();
     }
     $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'] = $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];
     }
     return new \Zend\View\Model\JsonModel(['success' => true, 'components' => array_values($components), 'total' => count($components), 'lastSyncData' => $lastSyncData]);
 }
 /**
  * Get Components from composer info command
  *
  * @return JsonModel
  * @throws \RuntimeException
  */
 public function componentsAction()
 {
     try {
         $components = $this->composerInformation->getInstalledMagentoPackages();
         foreach ($components as $component) {
             if (!$this->composerInformation->isPackageInComposerJson($component['name'])) {
                 unset($components[$component['name']]);
                 continue;
             }
             $componentNameParts = explode('/', $component['name']);
             $packageInfo = $this->infoCommand->run($component['name']);
             if (!$packageInfo) {
                 throw new \RuntimeException('Package info not found for ' . $component['name']);
             }
             if ($packageInfo[InfoCommand::NEW_VERSIONS]) {
                 $currentVersion = $packageInfo[InfoCommand::CURRENT_VERSION];
                 $components[$component['name']]['version'] = $currentVersion;
                 $versions = [];
                 foreach ($packageInfo[InfoCommand::NEW_VERSIONS] as $version) {
                     $versions[] = ['id' => $version, 'name' => $version];
                 }
                 $versions[] = ['id' => $packageInfo[InfoCommand::CURRENT_VERSION], 'name' => $packageInfo[InfoCommand::CURRENT_VERSION]];
                 $versions[0]['name'] .= ' (latest)';
                 $versions[count($versions) - 1]['name'] .= ' (current)';
                 $components[$component['name']]['vendor'] = $componentNameParts[0];
                 $components[$component['name']]['updates'] = $versions;
                 $components[$component['name']]['dropdownId'] = 'dd_' . $component['name'];
                 $components[$component['name']]['checkboxId'] = 'cb_' . $component['name'];
             } else {
                 unset($components[$component['name']]);
             }
         }
         return new JsonModel(['components' => array_values($components), 'total' => count($components), 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]);
     } catch (\Exception $e) {
         return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR]);
     }
 }
Example #23
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']);
 }
 /**
  * @param string $currentCE
  * @param array $enterpriseVersions
  * @param string $maxVersion
  * @return array
  */
 public function filterEeVersions($currentCE, $enterpriseVersions, $maxVersion)
 {
     $eeVersions = [];
     foreach ($enterpriseVersions['available_versions'] as $version) {
         $requires = $this->composerInfo->getPackageRequirements('magento/product-enterprise-edition', $version);
         if (array_key_exists('magento/product-community-edition', $requires)) {
             /** @var \Composer\Package\Link $ceRequire */
             $ceRequire = $requires['magento/product-community-edition'];
             if (version_compare($ceRequire->getConstraint()->getPrettyString(), $currentCE, '>=')) {
                 $name = 'Version ' . $version . ' EE';
                 if ($maxVersion == $version) {
                     $name .= ' (latest)';
                 }
                 $eeVersions[] = ['id' => $version, 'name' => $name];
             }
         }
     }
     return $eeVersions;
 }
Example #25
0
 /**
  * Validate given full theme paths
  *
  * @param string[] $themePaths
  * @return string[]
  */
 private function validate($themePaths)
 {
     $messages = [];
     $unknownPackages = [];
     $unknownThemes = [];
     $installedPackages = $this->composer->getRootRequiredPackages();
     foreach ($themePaths as $themePath) {
         if (array_search($this->getPackageName($themePath), $installedPackages) === false) {
             $unknownPackages[] = $themePath;
         }
         if (!$this->themeCollection->hasTheme($this->themeCollection->getThemeByFullPath($themePath))) {
             $unknownThemes[] = $themePath;
         }
     }
     $unknownPackages = array_diff($unknownPackages, $unknownThemes);
     if (!empty($unknownPackages)) {
         $text = count($unknownPackages) > 1 ? ' are not installed Composer packages' : ' is not an installed Composer package';
         $messages[] = '<error>' . implode(', ', $unknownPackages) . $text . '</error>';
     }
     if (!empty($unknownThemes)) {
         $messages[] = '<error>Unknown theme(s): ' . implode(', ', $unknownThemes) . '</error>';
     }
     return $messages;
 }
 /**
  * Validate list of modules against installed composer packages and return error messages
  *
  * @param string[] $modules
  * @return string[]
  */
 protected function validate(array $modules)
 {
     $messages = [];
     $unknownPackages = [];
     $unknownModules = [];
     $installedPackages = $this->composer->getRootRequiredPackages();
     foreach ($modules as $module) {
         if (array_search($this->packageInfo->getPackageName($module), $installedPackages) === false) {
             $unknownPackages[] = $module;
         }
         if (!$this->fullModuleList->has($module)) {
             $unknownModules[] = $module;
         }
     }
     $unknownPackages = array_diff($unknownPackages, $unknownModules);
     if (!empty($unknownPackages)) {
         $text = count($unknownPackages) > 1 ? ' are not installed composer packages' : ' is not an installed composer package';
         $messages[] = '<error>' . implode(', ', $unknownPackages) . $text . '</error>';
     }
     if (!empty($unknownModules)) {
         $messages[] = '<error>Unknown module(s): ' . implode(', ', $unknownModules) . '</error>';
     }
     return $messages;
 }