/** * Initialize ObjectManager */ private function initObjectManager() { if (!isset($this->objectManager)) { $objectManagerFactory = new ObjectManagerFactory(); $configFileName = isset($_ENV['testsuite_rule']) ? $_ENV['testsuite_rule'] : 'basic'; $configFilePath = realpath(MTF_BP . '/testsuites/' . $_ENV['testsuite_rule_path']); /** @var \Magento\Mtf\Config\DataInterface $configData */ $configData = $objectManagerFactory->getObjectManager()->create('Magento\\Mtf\\Config\\TestRunner'); $configData->setFileName($configFileName . '.xml')->load($configFilePath); $this->objectManager = $objectManagerFactory->create(['Magento\\Mtf\\Config\\TestRunner' => $configData]); } }
/** * Assert that created Store View can be found in Stores grid by name. * * @param Dashboard $dashboard * @return void */ public function processAssert(Dashboard $dashboard) { $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\GlobalConfig'); $newVersion = $config->get('version/0/value'); $dashboard->open(); \PHPUnit_Framework_Assert::assertTrue($dashboard->getFooter()->findVersion($newVersion)->isVisible()); }
/** * Prepare configuration settings for test. * * @param FixtureFactory $fixtureFactory * @return array */ public function __prepare(FixtureFactory $fixtureFactory) { $this->fixtureFactory = $fixtureFactory; $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\GlobalConfig'); $adminCred['username'] = $config->get('application/0/backendLogin/0/value'); $adminCred['password'] = $config->get('application/0/backendPassword/0/value'); $newVersion['Mage_All_Latest'] = $config->get('version/0/value'); $adminFixture = $this->fixtureFactory->createByCode('user', ['data' => $adminCred]); $connectFixture = $this->fixtureFactory->createByCode('connect', ['data' => $newVersion]); return ['adminUser' => $adminFixture, 'connect' => $connectFixture]; }
/** * Uninstall Magento before test. * * @return array */ public function __prepare() { $config = ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\DataInterface'); // Prepare config data $configData['dbHost'] = $config->get('install/0/host/0'); $configData['dbUser'] = $config->get('install/0/user/0'); $configData['dbPassword'] = $config->get('install/0/password/0'); $configData['dbName'] = $config->get('install/0/dbName/0'); $configData['web'] = $config->get('install/0/baseUrl/0'); $configData['admin'] = $config->get('install/0/backendName/0'); return ['configData' => $configData]; }
/** * Set tax class id. * * @param string $taxClassName * @return void * @throws \Exception */ protected function setTaxClassId($taxClassName) { $url = $_ENV['app_backend_url'] . 'tax/rule/new/'; $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->create('Magento\\Mtf\\Config\\DataInterface'); $curl = new BackendDecorator(new CurlTransport(), $config); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, [], CurlInterface::GET); $response = $curl->read(); $curl->close(); preg_match('~<option value="(\\d+)".*>' . $taxClassName . '</option>~', $response, $matches); if (!isset($matches[1]) || empty($matches[1])) { throw new \Exception('Product tax class id ' . $taxClassName . ' undefined!'); } $this->taxClassId = (int) $matches[1]; }
/** * Retrieves data from cURL response * * @throws \Exception * @return array */ public function getData() { /** @var \Magento\Mtf\Config\DataInterface $config */ $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\DataInterface'); $url = $_ENV['app_backend_url'] . $this->url; $curl = new BackendDecorator(new CurlTransport(), $config); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, [], CurlInterface::GET); $response = $curl->read(); $curl->close(); if ($this->isAll) { preg_match_all($this->regExpPattern, $response, $matches); } else { preg_match($this->regExpPattern, $response, $matches); } $countMatches = $this->isAll ? count($matches[1]) : count($matches); if ($countMatches == 0) { throw new \Exception('Matches array can\'t be empty.'); } return $matches; }
/** * Clear Magento instance: remove all tables in DB and use dump to load new ones, clear Magento cache * * @throws \Exception */ public function clearInstance() { $dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Framework\\Filesystem\\DirectoryList'); $configFilePool = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('\\Magento\\Framework\\Config\\File\\ConfigFilePool'); $driverPool = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('\\Magento\\Framework\\Filesystem\\DriverPool'); $reader = new Reader($dirList, $driverPool, $configFilePool); $deploymentConfig = new DeploymentConfig($reader); $host = $deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . ConfigOptionsListConstants::KEY_HOST); $user = $deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . ConfigOptionsListConstants::KEY_USER); $password = $deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . ConfigOptionsListConstants::KEY_PASSWORD); $database = $deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . ConfigOptionsListConstants::KEY_NAME); $fileName = MTF_BP . '/' . $database . '.sql'; if (!file_exists($fileName)) { echo 'Database dump was not found by path: ' . $fileName; return; } // Drop all tables in database $mysqli = new \mysqli($host, $user, $password, $database); $mysqli->query('SET foreign_key_checks = 0'); if ($result = $mysqli->query("SHOW TABLES")) { while ($row = $result->fetch_row()) { $mysqli->query('DROP TABLE ' . $row[0]); } } $mysqli->query('SET foreign_key_checks = 1'); $mysqli->close(); // Load database dump exec("mysql -u{$user} -p{$password} {$database} < {$fileName}", $output, $result); if ($result) { throw new \Exception('Database dump loading has been failed: ' . $output); } // Clear cache exec("rm -rf {$dirList->getPath(DirectoryList::VAR_DIR)}/*", $output, $result); if ($result) { throw new \Exception('Cleaning Magento cache has been failed: ' . $output); } }
/** * Clear Magento instance: remove all tables in DB and use dump to load new ones, clear Magento cache * * @throws \Exception */ public function clearInstance() { $dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Framework\\Filesystem\\DirectoryList'); $reader = new Reader($dirList); $deploymentConfig = new DeploymentConfig($reader); $dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; $database = $dbInfo['dbname']; $fileName = MTF_BP . '/' . $database . '.sql'; if (!file_exists($fileName)) { echo 'Database dump was not found by path: ' . $fileName; return; } // Drop all tables in database $mysqli = new \mysqli($host, $user, $password, $database); $mysqli->query('SET foreign_key_checks = 0'); if ($result = $mysqli->query("SHOW TABLES")) { while ($row = $result->fetch_row()) { $mysqli->query('DROP TABLE ' . $row[0]); } } $mysqli->query('SET foreign_key_checks = 1'); $mysqli->close(); // Load database dump exec("mysql -u{$user} -p{$password} {$database} < {$fileName}", $output, $result); if ($result) { throw new \Exception('Database dump loading has been failed: ' . $output); } // Clear cache exec("rm -rf {$dirList->getPath(DirectoryList::VAR_DIR)}/*", $output, $result); if ($result) { throw new \Exception('Cleaning Magento cache has been failed: ' . $output); } }
/** * Prepare configuration settings for test. * * @param FixtureFactory $fixtureFactory * @return array */ public function __prepare(FixtureFactory $fixtureFactory) { $this->fixtureFactory = $fixtureFactory; $config = ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\DataInterface'); // Prepare config data $configData['db_host'] = $config->get('install/0/host/0/value'); $configData['db_user'] = $config->get('install/0/user/0/value'); $configData['db_pass'] = $config->get('install/0/password/0/value'); $configData['db_name'] = $config->get('install/0/dbName/0/value'); $configData['unsecure_base_url'] = $config->get('install/0/baseUrl/0/value'); return ['configData' => $configData]; }
* NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magento.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magento.com for more information. * * @category Tests * @package Tests_Functional * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ umask(0); $mtfRoot = dirname(dirname(__FILE__)); $mtfRoot = str_replace('\\', '/', $mtfRoot); define('MTF_BP', $mtfRoot); define('MTF_TESTS_PATH', MTF_BP . '/tests/app/'); $appRoot = dirname(dirname(dirname(dirname(__DIR__)))); require __DIR__ . '/../vendor/autoload.php'; $objectManager = \Magento\Mtf\ObjectManagerFactory::getObjectManager(); \Magento\Mtf\ObjectManagerFactory::configure($objectManager);