public function testCreate()
 {
     $serviceLocatorMock = $this->getMockForAbstractClass('Zend\\ServiceManager\\ServiceLocatorInterface', ['get']);
     $serviceLocatorMock->expects($this->once())->method('get')->with('Magento\\Framework\\Encryption\\Encryptor')->willReturn($this->getMockForAbstractClass('Magento\\Framework\\Encryption\\EncryptorInterface'));
     $adminAccountFactory = new AdminAccountFactory($serviceLocatorMock);
     $adminAccount = $adminAccountFactory->create($this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false), []);
     $this->assertInstanceOf('Magento\\Setup\\Model\\AdminAccount', $adminAccount);
 }
 /**
  * Validate admin user name and email.
  *
  * @param array $data
  * @return void
  * @throws \Exception
  */
 public function validate(array $data)
 {
     try {
         $dbConnection = $this->connectionFactory->create([ConfigOption::KEY_NAME => $data[ConfigOption::INPUT_KEY_DB_NAME], ConfigOption::KEY_HOST => $data[ConfigOption::INPUT_KEY_DB_HOST], ConfigOption::KEY_USER => $data[ConfigOption::INPUT_KEY_DB_USER], ConfigOption::KEY_PASSWORD => $data[ConfigOption::INPUT_KEY_DB_PASSWORD], ConfigOption::KEY_PREFIX => $data[ConfigOption::INPUT_KEY_DB_PREFIX]]);
         $userName = $data[AdminAccount::KEY_USER];
         $userEmail = $data[AdminAccount::KEY_EMAIL];
         $userTable = $dbConnection->getTableName('admin_user');
         $result = $dbConnection->fetchRow("SELECT user_id, username, email FROM {$userTable} WHERE username = :username OR email = :email", ['username' => $userName, 'email' => $userEmail]);
         $setup = $this->setupFactory->create();
         $adminAccount = $this->adminAccountFactory->create($setup, [AdminAccount::KEY_USER => $userName, AdminAccount::KEY_EMAIL => $userEmail]);
     } catch (\Exception $e) {
         return;
     }
     if (!empty($result)) {
         $adminAccount->validateUserMatches($result['username'], $result['email']);
     }
 }
예제 #3
0
 public function testInstall()
 {
     $request = [ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend'];
     $this->config->expects($this->atLeastOnce())->method('get')->willReturnMap([[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true], [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true]]);
     $allModules = ['Foo_One' => [], 'Bar_Two' => []];
     $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
     $setup = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
     $table = $this->getMock('Magento\\Framework\\DB\\Ddl\\Table', [], [], '', false);
     $connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $setup->expects($this->any())->method('getConnection')->willReturn($connection);
     $table->expects($this->any())->method('addColumn')->willReturn($table);
     $table->expects($this->any())->method('setComment')->willReturn($table);
     $table->expects($this->any())->method('addIndex')->willReturn($table);
     $connection->expects($this->any())->method('newTable')->willReturn($table);
     $resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource);
     $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $dataSetup = $this->getMock('Magento\\Setup\\Module\\DataSetup', [], [], '', false);
     $cacheManager = $this->getMock('Magento\\Framework\\App\\Cache\\Manager', [], [], '', false);
     $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
     $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
     $cacheManager->expects($this->any())->method('clean');
     $appState = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Framework\\App\\State');
     $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
     $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
     $this->objectManager->expects($this->any())->method('create')->will($this->returnValueMap([['Magento\\Framework\\App\\Cache\\Manager', [], $cacheManager], ['Magento\\Framework\\App\\State', [], $appState]]));
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\App\\State', $appState], ['Magento\\Framework\\App\\Cache\\Manager', $cacheManager]]));
     $this->adminFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Setup\\Model\\AdminAccount', [], [], '', false));
     $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
     $this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:');
     $this->logger->expects($this->at(1))->method('log')->with('File permissions check...');
     // at(2) invokes logMeta()
     $this->logger->expects($this->at(3))->method('log')->with('Enabling Maintenance Mode...');
     // at(4) - logMeta and so on...
     $this->logger->expects($this->at(5))->method('log')->with('Installing deployment configuration...');
     $this->logger->expects($this->at(7))->method('log')->with('Installing database schema:');
     $this->logger->expects($this->at(9))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(11))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(13))->method('log')->with('Schema post-updates:');
     $this->logger->expects($this->at(14))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(16))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(19))->method('log')->with('Installing user configuration...');
     $this->logger->expects($this->at(21))->method('log')->with('Enabling caches:');
     $this->logger->expects($this->at(25))->method('log')->with('Installing data...');
     $this->logger->expects($this->at(26))->method('log')->with('Data install/update:');
     $this->logger->expects($this->at(27))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(29))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(32))->method('log')->with('Installing admin user...');
     $this->logger->expects($this->at(34))->method('log')->with('Caches clearing:');
     $this->logger->expects($this->at(37))->method('log')->with('Disabling Maintenance Mode:');
     $this->logger->expects($this->at(39))->method('log')->with('Post installation file permissions check...');
     $this->logger->expects($this->at(41))->method('log')->with('Write installation date...');
     $this->logger->expects($this->at(43))->method('logSuccess')->with('Magento installation complete.');
     $this->logger->expects($this->at(45))->method('log')->with('Sample Data is installed with errors. See log file for details');
     $this->object->install($request);
 }
예제 #4
0
 public function testInstall()
 {
     $request = [DeploymentConfigMapper::KEY_DB_HOST => '127.0.0.1', DeploymentConfigMapper::KEY_DB_NAME => 'magento', DeploymentConfigMapper::KEY_DB_USER => 'magento', DeploymentConfigMapper::KEY_ENCRYPTION_KEY => 'encryption_key', DeploymentConfigMapper::KEY_BACKEND_FRONTNAME => 'backend'];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([[DbConfig::CONFIG_KEY, self::$dbConfig], [EncryptConfig::CONFIG_KEY, [EncryptConfig::KEY_ENCRYPTION_KEY => 'encryption_key']]]));
     $allModules = ['Foo_One' => [], 'Bar_Two' => []];
     $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
     $modules = ['Foo_One' => 1, 'Bar_Two' => 1];
     $this->deploymentConfig->expects($this->any())->method('getData')->willReturn($modules);
     $this->deploymentConfigFactory->expects($this->any())->method('create')->with($modules)->willReturn($this->deploymentConfig);
     $setup = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
     $table = $this->getMock('Magento\\Framework\\DB\\Ddl\\Table', [], [], '', false);
     $connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $setup->expects($this->any())->method('getConnection')->willReturn($connection);
     $table->expects($this->any())->method('addColumn')->willReturn($table);
     $table->expects($this->any())->method('setComment')->willReturn($table);
     $table->expects($this->any())->method('addIndex')->willReturn($table);
     $connection->expects($this->any())->method('newTable')->willReturn($table);
     $resource = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource);
     $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $dataSetup = $this->getMock('Magento\\Setup\\Module\\DataSetup', [], [], '', false);
     $cacheManager = $this->getMock('Magento\\Framework\\App\\Cache\\Manager', [], [], '', false);
     $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
     $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
     $this->objectManager->expects($this->any())->method('create')->will($this->returnValueMap([['Magento\\Setup\\Module\\Setup', ['resource' => $resource], $setup], ['Magento\\Setup\\Module\\DataSetup', [], $dataSetup], ['Magento\\Framework\\App\\Cache\\Manager', [], $cacheManager]]));
     $this->adminFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Setup\\Model\\AdminAccount', [], [], '', false));
     $this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:');
     $this->logger->expects($this->at(1))->method('log')->with('File permissions check...');
     // at(2) invokes logMeta()
     $this->logger->expects($this->at(3))->method('log')->with('Enabling Maintenance Mode...');
     // at(4) - logMeta and so on...
     $this->logger->expects($this->at(5))->method('log')->with('Installing deployment configuration...');
     $this->logger->expects($this->at(7))->method('log')->with('Installing database schema:');
     $this->logger->expects($this->at(9))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(11))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(13))->method('log')->with('Schema post-updates:');
     $this->logger->expects($this->at(14))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(16))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(19))->method('log')->with('Installing user configuration...');
     $this->logger->expects($this->at(21))->method('log')->with('Installing data...');
     $this->logger->expects($this->at(22))->method('log')->with('Data install/update:');
     $this->logger->expects($this->at(23))->method('log')->with("Module 'Foo_One':");
     $this->logger->expects($this->at(25))->method('log')->with("Module 'Bar_Two':");
     $this->logger->expects($this->at(28))->method('log')->with('Installing admin user...');
     $this->logger->expects($this->at(30))->method('log')->with('Enabling caches:');
     $this->logger->expects($this->at(31))->method('log')->with('Current status:');
     $this->logger->expects($this->at(34))->method('log')->with('Disabling Maintenance Mode:');
     $this->logger->expects($this->at(36))->method('log')->with('Post installation file permissions check...');
     $this->logger->expects($this->once())->method('logSuccess')->with('Magento installation complete.');
     $this->object->install($request);
 }
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     $this->logger->clear();
     $data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
     $this->config->setConfigData($data);
     $this->config->install();
     $this->setupFactory->setConfig($this->config->getConfigData());
     $moduleNames = array_keys($this->moduleList);
     foreach ($moduleNames as $moduleName) {
         $setup = $this->setupFactory->create($moduleName);
         $setup->applyUpdates();
         $this->logger->logSuccess($moduleName);
     }
     $this->logger->logSuccess('Artifact');
     // Set data to config
     $setup->addConfigData('web/seo/use_rewrites', isset($data['config']['rewrites']['allowed']) ? $data['config']['rewrites']['allowed'] : 0);
     $setup->addConfigData('web/unsecure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{unsecure_base_url}}');
     $setup->addConfigData('web/secure/use_in_frontend', isset($data['config']['https']['front']) ? $data['config']['https']['front'] : 0);
     $setup->addConfigData('web/secure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{secure_base_url}}');
     $setup->addConfigData('web/secure/use_in_adminhtml', isset($data['config']['https']['admin']) ? $data['config']['https']['admin'] : 0);
     $setup->addConfigData('general/locale/code', isset($data['store']['language']) ? $data['store']['language'] : 'en_US');
     $setup->addConfigData('general/locale/timezone', isset($data['store']['timezone']) ? $data['store']['timezone'] : 'America/Los_Angeles');
     $currencyCode = isset($data['store']['currency']) ? $data['store']['currency'] : 'USD';
     $setup->addConfigData('currency/options/base', $currencyCode);
     $setup->addConfigData('currency/options/default', $currencyCode);
     $setup->addConfigData('currency/options/allow', $currencyCode);
     // Create administrator account
     $this->adminAccountFactory->setConfig($this->config->getConfigData());
     $adminAccount = $this->adminAccountFactory->create($setup);
     $adminAccount->save();
     $this->logger->logSuccess('Admin User');
     if ($data['config']['encrypt']['type'] == 'magento') {
         $key = md5($this->random->getRandomString(10));
     } else {
         $key = $data['config']['encrypt']['key'];
     }
     $this->config->replaceTmpEncryptKey($key);
     $this->config->replaceTmpInstallDate(date('r'));
     $phpPath = $this->phpExecutablePath();
     exec($phpPath . 'php -f ' . escapeshellarg($this->systemConfig->create()->getMagentoBasePath() . '/dev/shell/run_data_fixtures.php'), $output, $exitCode);
     if ($exitCode !== 0) {
         $outputMsg = implode(PHP_EOL, $output);
         $this->logger->logError(new \Exception('Data Update Failed with Exit Code: ' . $exitCode . PHP_EOL . $outputMsg));
         $this->json->setVariable('success', false);
     } else {
         $this->logger->logSuccess('Data Updates');
         $this->json->setVariable('success', true);
     }
     $this->json->setVariable('key', $key);
     return $this->json;
 }
예제 #6
0
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     $this->logger->clear();
     $data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
     $this->config->setConfigData($data);
     $this->config->install();
     $this->setupFactory->setConfig($this->config->getConfigData());
     $moduleNames = array_keys($this->moduleList);
     foreach ($moduleNames as $moduleName) {
         $setup = $this->setupFactory->create($moduleName);
         $setup->applyUpdates();
         $this->logger->logSuccess($moduleName);
     }
     $this->logger->logSuccess('Artifact');
     // Set data to config
     $setup->addConfigData('web/seo/use_rewrites', isset($data['config']['rewrites']['allowed']) ? $data['config']['rewrites']['allowed'] : 0);
     $setup->addConfigData('web/unsecure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{unsecure_base_url}}');
     $setup->addConfigData('web/secure/use_in_frontend', isset($data['config']['https']['front']) ? $data['config']['https']['front'] : 0);
     $setup->addConfigData('web/secure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{secure_base_url}}');
     $setup->addConfigData('web/secure/use_in_adminhtml', isset($data['config']['https']['admin']) ? $data['config']['https']['admin'] : 0);
     $setup->addConfigData('general/locale/code', isset($data['store']['language']) ? $data['store']['language'] : 'en_US');
     $setup->addConfigData('general/locale/timezone', isset($data['store']['timezone']) ? $data['store']['timezone'] : 'America/Los_Angeles');
     $currencyCode = isset($data['store']['currency']) ? $data['store']['currency'] : 'USD';
     $setup->addConfigData('currency/options/base', $currencyCode);
     $setup->addConfigData('currency/options/default', $currencyCode);
     $setup->addConfigData('currency/options/allow', $currencyCode);
     // Create administrator account
     $this->adminAccountFactory->setConfig($this->config->getConfigData());
     $adminAccount = $this->adminAccountFactory->create($setup);
     $adminAccount->save();
     $this->logger->logSuccess('Admin User');
     if ($data['config']['encrypt']['type'] == 'magento') {
         $key = md5($this->random->getRandomString(10));
     } else {
         $key = $data['config']['encrypt']['key'];
     }
     $this->config->replaceTmpEncryptKey($key);
     $this->config->replaceTmpInstallDate(date('r'));
     $this->json->setVariable('success', true);
     $this->json->setVariable('key', $key);
     return $this->json;
 }
 /**
  * Creates admin account
  *
  * @param \ArrayObject|array $data
  * @return void
  */
 public function installAdminUser($data)
 {
     $this->assertDeploymentConfigExists();
     $setup = $this->setupFactory->create($this->context->getResources());
     $adminAccount = $this->adminAccountFactory->create($setup, (array)$data);
     $adminAccount->save();
 }
예제 #8
0
 /**
  * Creates admin account
  *
  * @param \ArrayObject|array $data
  * @return void
  */
 public function installAdminUser($data)
 {
     $this->assertDeploymentConfigExists();
     $setup = $this->objectManagerProvider->get()->create('Magento\\Setup\\Module\\Setup', ['resource' => $this->context->getResources()]);
     $adminAccount = $this->adminAccountFactory->create($setup, (array) $data);
     $adminAccount->save();
 }