/** * Test lost connection re-initializing * * @covers Varien_Db_Adapter_Pdo_Mysql::raw_query * @covers Varien_Db_Adapter_Pdo_Mysql::query * @throws Exception */ public function testWaitTimeout() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestSkipped('Test is designed to run on MySQL only.'); } if (!$this->_getConnection() instanceof Varien_Db_Adapter_Pdo_Mysql) { $this->markTestSkipped('This test is for Varien_Db_Adapter_Pdo_Mysql'); } try { $defaultWaitTimeout = $this->_getWaitTimeout(); $minWaitTimeout = 1; $this->_setWaitTimeout($minWaitTimeout); $this->assertEquals($minWaitTimeout, $this->_getWaitTimeout(), 'Wait timeout was not changed'); // Sleep for time greater than wait_timeout and try to perform query sleep($minWaitTimeout + 1); $result = $this->_getConnection()->raw_query('SELECT 1'); $this->assertInstanceOf('Varien_Db_Statement_Pdo_Mysql', $result); // Restore wait_timeout $this->_setWaitTimeout($defaultWaitTimeout); $this->assertEquals($defaultWaitTimeout, $this->_getWaitTimeout(), 'Default wait timeout was not restored'); } catch (Exception $e) { // Reset connection on failure to restore global variables $this->_getConnection()->closeConnection(); throw $e; } }
public function setUp() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestSkipped('Test is designed to run on MySQL only.'); } $this->_model = Mage::getModel('Mage_Core_Model_Resource'); }
/** * Isolate global application objects */ protected function _isolateApp() { if ($this->_hasNonIsolatedTests) { Magento_Test_Bootstrap::getInstance()->cleanupCache(); Magento_Test_Bootstrap::getInstance()->initialize(); $this->_hasNonIsolatedTests = false; } }
protected function setUp() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestSkipped('Test is designed to run on MySQL only.'); } $this->_model = Mage::getResourceModel('Mage_Core_Model_Resource_Helper_Mysql4', array('modulePrefix' => 'core')); $collection = Mage::getResourceModel('Mage_Core_Model_Resource_Store_Collection'); $this->_select = $collection->getSelect(); }
public function testDispatch() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Cant\'t test dispatch process without sending headers'); } $_SERVER['HTTP_HOST'] = 'localhost'; $this->_model->init(); /* empty action */ $this->_model->getRequest()->setRequestUri('core/index/index'); $this->_model->dispatch(); $this->assertEmpty($this->_model->getResponse()->getBody()); }
public function testToHtml() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestIncomplete('bug: MAGETWO-4227'); } $block = Mage::app()->getLayout()->createBlock('Mage_Rss_Block_Order_Status'); $this->assertEmpty($block->toHtml()); $uniqid = uniqid(); $order = $this->getMock('Varien_Object', array('formatPrice'), array(array('id' => $uniqid))); Mage::register('current_order', $order); $this->assertContains($uniqid, $block->toHtml()); }
public function testMatch() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test get match without sending headers'); } $request = new Magento_Test_Request(); $this->assertNull($this->_model->match($request)); $this->_model->collectRoutes('frontend', 'standard'); $this->assertInstanceOf('Mage_Core_Controller_Varien_Action', $this->_model->match($request)); $request->setRequestUri('core/index/index'); $this->assertInstanceOf('Mage_Core_Controller_Varien_Action', $this->_model->match($request)); $request->setPathInfo('not_exists/not_exists/not_exists')->setModuleName('not_exists')->setControllerName('not_exists')->setActionName('not_exists'); $this->assertNull($this->_model->match($request)); }
/** * Remove cache polluted by other tests excluding performance critical cache (configuration, ddl) */ protected function _cleanupCache() { /* * Cache cleanup relies on the initialized config object, which could be polluted from within a test. * For instance, any test could explicitly call Mage::reset() to destroy the config object. */ $expectedOptions = Magento_Test_Bootstrap::getInstance()->getAppOptions(); $actualOptions = Mage::getConfig() ? Mage::getConfig()->getOptions()->getData() : array(); $isConfigPolluted = array_intersect_assoc($expectedOptions, $actualOptions) !== $expectedOptions; if ($isConfigPolluted) { Magento_Test_Bootstrap::getInstance()->initialize(); } Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, array(Mage_Core_Model_Config::CACHE_TAG, Varien_Db_Adapter_Pdo_Mysql::DDL_CACHE_TAG, 'DB_PDO_MSSQL_DDL', 'DB_ORACLE_DDL')); }
} if (defined('TESTS_MODULE_CONFIG_FILES') && TESTS_MODULE_CONFIG_FILES) { $moduleEtcFiles = TESTS_MODULE_CONFIG_FILES; } else { $moduleEtcFiles = "../../../app/etc/modules/*.xml"; } $developerMode = false; if (defined('TESTS_MAGENTO_DEVELOPER_MODE') && TESTS_MAGENTO_DEVELOPER_MODE == 'enabled') { $developerMode = true; } /* Enable profiler if necessary */ if (defined('TESTS_PROFILER_FILE') && TESTS_PROFILER_FILE) { Magento_Profiler::registerOutput(new Magento_Profiler_Output_Csvfile($testsBaseDir . DIRECTORY_SEPARATOR . TESTS_PROFILER_FILE)); } /* Enable profiler with bamboo friendly output format */ if (defined('TESTS_BAMBOO_PROFILER_FILE') && defined('TESTS_BAMBOO_PROFILER_METRICS_FILE')) { Magento_Profiler::registerOutput(new Magento_Test_Profiler_OutputBamboo($testsBaseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_FILE, require $testsBaseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_METRICS_FILE)); } /* * Activate custom DocBlock annotations. * Note: order of registering (and applying) annotations is important. * To allow config fixtures to deal with fixture stores, data fixtures should be processed before config fixtures. */ $eventManager = new Magento_Test_EventManager(array(new Magento_Test_Annotation_AppIsolation(), new Magento_Test_Event_Transaction(new Magento_Test_EventManager(array(new Magento_Test_Annotation_DbIsolation(), new Magento_Test_Annotation_DataFixture("{$testsBaseDir}/testsuite")))), new Magento_Test_Annotation_ConfigFixture())); Magento_Test_Event_PhpUnit::setDefaultEventManager($eventManager); Magento_Test_Event_Magento::setDefaultEventManager($eventManager); /* Bootstrap the application */ Magento_Test_Bootstrap::setInstance(new Magento_Test_Bootstrap($magentoBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, 'etc/integration-tests-config.xml', $testsTmpDir, $cleanupAction, $developerMode)); Utility_Files::init(new Utility_Files($magentoBaseDir)); /* Unset declared global variables to release PHPUnit from maintaining their values between tests */ unset($testsBaseDir, $testsTmpDir, $magentoBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, $eventManager);
public function testSetGetResponse() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test get response without sending headers'); } $this->assertInstanceOf('Mage_Core_Controller_Response_Http', $this->_model->getResponse()); $this->_model->setResponse(new Magento_Test_Response()); $this->assertInstanceOf('Magento_Test_Response', $this->_model->getResponse()); }
/** * Set self instance for static access * * @param Magento_Test_Bootstrap $instance */ public static function setInstance(Magento_Test_Bootstrap $instance) { self::$_instance = $instance; }
/** * @magentoDataIsolation enabled * @magentoDataFixture mediaImportImageFixture */ public function testSaveMediaImage() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestIncomplete('bug: MAGETWO-4227'); } $attribute = Mage::getModel('Mage_Catalog_Model_Entity_Attribute'); $attribute->loadByCode('catalog_product', 'media_gallery'); $data = implode(',', array('sku', '_attribute_set', '_type', '_product_websites', 'name', 'price', 'description', 'short_description', 'weight', 'status', 'visibility', 'tax_class_id', '_media_attribute_id', '_media_image', '_media_label', '_media_position', '_media_is_disabled')) . "\n"; $data .= implode(',', array('test_sku', 'Default', Mage_Catalog_Model_Product_Type::DEFAULT_TYPE, 'base', 'Product Name', '9.99', 'Product description', 'Short desc.', '1', Mage_Catalog_Model_Product_Status::STATUS_ENABLED, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 0, $attribute->getId(), 'magento_image.jpg', 'Image Label', '1', '0')) . "\n"; $data = 'data://text/plain;base64,' . base64_encode($data); $fixture = new Mage_ImportExport_Model_Import_Source_Csv($data); foreach (new Mage_Catalog_Model_Resource_Product_Collection() as $product) { $this->fail("Unexpected precondition - product exists: '{$product->getId()}'."); } $this->_model->setSource($fixture)->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_APPEND))->isDataValid(); $this->_model->importData(); $resource = new Mage_Catalog_Model_Resource_Product(); $productId = $resource->getIdBySku('test_sku'); // fixture $product = Mage::getModel('Mage_Catalog_Model_Product'); $product->load($productId); $gallery = $product->getMediaGalleryImages(); $this->assertInstanceOf('Varien_Data_Collection', $gallery); $items = $gallery->getItems(); $this->assertCount(1, $items); $item = array_pop($items); $this->assertInstanceOf('Varien_Object', $item); $this->assertEquals('/m/a/magento_image.jpg', $item->getFile()); $this->assertEquals('Image Label', $item->getLabel()); }
/** * Remove cached configuration and reinitialize the application */ protected static function _refreshConfiguration() { Mage::app()->cleanCache(array(Mage_Core_Model_Config::CACHE_TAG)); Magento_Test_Bootstrap::getInstance()->initialize(); }
$moduleEtcFiles = "../../../app/etc/modules/*.xml"; } $isCleanupEnabled = defined('TESTS_CLEANUP') && TESTS_CLEANUP == 'enabled'; $isDeveloperMode = defined('TESTS_MAGENTO_DEVELOPER_MODE') && TESTS_MAGENTO_DEVELOPER_MODE == 'enabled'; /* Enable profiler if necessary */ if (defined('TESTS_PROFILER_FILE') && TESTS_PROFILER_FILE) { $driver = new Magento_Profiler_Driver_Standard(); $driver->registerOutput(new Magento_Profiler_Driver_Standard_Output_Csvfile(array('baseDir' => $testsBaseDir, 'filePath' => TESTS_PROFILER_FILE))); Magento_Profiler::add($driver); } /* Enable profiler with bamboo friendly output format */ if (defined('TESTS_BAMBOO_PROFILER_FILE') && defined('TESTS_BAMBOO_PROFILER_METRICS_FILE')) { $driver = new Magento_Profiler_Driver_Standard(); $driver->registerOutput(new Magento_Test_Profiler_OutputBamboo(array('baseDir' => $testsBaseDir, 'filePath' => TESTS_BAMBOO_PROFILER_FILE, 'metrics' => require $testsBaseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_METRICS_FILE))); Magento_Profiler::add($driver); } /* * Activate custom DocBlock annotations. * Note: order of registering (and applying) annotations is important. * To allow config fixtures to deal with fixture stores, data fixtures should be processed before config fixtures. */ $eventManager = new Magento_Test_EventManager(array(new Magento_Test_ClearProperties(), new Magento_Test_Annotation_AppIsolation(), new Magento_Test_Event_Transaction(new Magento_Test_EventManager(array(new Magento_Test_Annotation_DbIsolation(), new Magento_Test_Annotation_DataFixture("{$testsBaseDir}/testsuite")))), new Magento_Test_Annotation_ConfigFixture())); Magento_Test_Event_PhpUnit::setDefaultEventManager($eventManager); Magento_Test_Event_Magento::setDefaultEventManager($eventManager); /* Initialize object manager instance */ Mage::initializeObjectManager(null, new Magento_Test_ObjectManager()); /* Bootstrap the application */ Magento_Test_Bootstrap::setInstance(new Magento_Test_Bootstrap($magentoBaseDir, $testsBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, 'etc/integration-tests-config.xml', $testsTmpDir, new Magento_Shell(), $isCleanupEnabled, $isDeveloperMode)); Utility_Files::init(new Utility_Files($magentoBaseDir)); /* Unset declared global variables to release PHPUnit from maintaining their values between tests */ unset($testsBaseDir, $testsTmpDir, $magentoBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, $eventManager);
public static function setUpBeforeClass() { self::$_skinPublicDir = Mage::app()->getConfig()->getOptions()->getMediaDir() . '/skin'; self::$_fixtureTmpDir = Magento_Test_Bootstrap::getInstance()->getTmpDir() . '/publication'; }
/** * Bootstrap instance getter * * @return Magento_Test_Bootstrap */ protected function _getBootstrap() { return Magento_Test_Bootstrap::getInstance(); }
/** * Reset current working directory (CWD) */ protected function _resetWorkingDirectory() { chdir(Magento_Test_Bootstrap::getInstance()->getTestsDir()); }
public static function setUpBeforeClass() { self::$_options = Magento_Test_Bootstrap::getInstance()->getAppOptions(); }
/** * @todo refactor Mage_Core_Model_Store::getPriceFilter, it can return two different types */ public function testGetPriceFilter() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Currency operations use cookie and require ability to send headers.'); } $this->assertInstanceOf('Mage_Directory_Model_Currency_Filter', $this->_model->getPriceFilter()); }
public static function tearDownAfterClass() { Mage::app()->getConfig()->deleteConfig(self::SAMPLE_CONFIG_PATH); Magento_Test_Bootstrap::getInstance()->refreshConfiguration(); }
/** * @expectedException Exception */ public function testCleanupDirException($optionCode) { $this->_bootstrap->cleanupDir($optionCode); }
/** * @magentoConfigFixture current_store dev/log/active 1 * @magentoConfigFixture current_store dev/log/exception_file php://output * @magentoAppIsolation enabled */ public function testLogException() { // reinitialization is needed here, too Magento_Test_Bootstrap::getInstance()->reinitialize(); $msg = uniqid(); $exception = new Exception((string) $msg); Mage::logException($exception); $this->expectOutputRegex('/' . $msg . '/'); }
public function testProcessRequestTrue() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Test requires to send headers.'); } $model = new Mage_Core_Model_Cache(array('request_processors' => array('Mage_Core_Model_CacheTestRequestProcessor'))); Mage_Core_Model_CacheTestRequestProcessor::$isEnabled = true; $this->assertTrue($model->processRequest()); }
public function testGetTmpDir() { $this->assertEquals(self::$_tmpDir, $this->_bootstrap->getTmpDir()); }
public function saveDataProvider() { $dir = Magento_Test_Bootstrap::getInstance()->getTmpDir() . DIRECTORY_SEPARATOR; return $this->_prepareData(array(array($this->_getFixture('image_adapters_test.png'), array($dir . uniqid('test_image_adapter'))), array($this->_getFixture('image_adapters_test.png'), array($dir, uniqid('test_image_adapter'))))); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$_tmpMediaDir = realpath(Magento_Test_Bootstrap::getInstance()->getTmpDir()) . DIRECTORY_SEPARATOR . 'media'; self::$_tmpSkinDir = self::$_tmpMediaDir . DIRECTORY_SEPARATOR . 'skin'; }
if (defined('TESTS_GLOBAL_CONFIG_FILES') && TESTS_GLOBAL_CONFIG_FILES) { $globalEtcFiles = TESTS_GLOBAL_CONFIG_FILES; } else { $globalEtcFiles = "../../../app/etc/*.xml"; } $globalEtcFiles .= ';etc/integration-tests-config.xml'; if (defined('TESTS_MODULE_CONFIG_FILES') && TESTS_MODULE_CONFIG_FILES) { $moduleEtcFiles = TESTS_MODULE_CONFIG_FILES; } else { $moduleEtcFiles = "../../../app/etc/modules/*.xml"; } $developerMode = false; if (defined('TESTS_MAGENTO_DEVELOPER_MODE') && TESTS_MAGENTO_DEVELOPER_MODE == 'enabled') { $developerMode = true; } Magento_Test_Bootstrap::setInstance(new Magento_Test_Bootstrap(realpath("{$baseDir}/../../../"), $localXmlFile, $globalEtcFiles, $moduleEtcFiles, "{$baseDir}/tmp", $cleanupAction, $developerMode)); /* Enable profiler if necessary */ if (defined('TESTS_PROFILER_FILE') && TESTS_PROFILER_FILE) { Magento_Profiler::registerOutput(new Magento_Profiler_Output_Csvfile($baseDir . DIRECTORY_SEPARATOR . TESTS_PROFILER_FILE)); } /* Enable profiler with bamboo friendly output format */ if (defined('TESTS_BAMBOO_PROFILER_FILE') && defined('TESTS_BAMBOO_PROFILER_METRICS_FILE')) { Magento_Profiler::registerOutput(new Magento_Test_Profiler_OutputBamboo($baseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_FILE, require $baseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_METRICS_FILE)); } /* Activate custom annotations in doc comments */ /* * Note: order of registering (and applying) annotations is important. * To allow config fixtures to deal with fixture stores, data fixtures should be processed before config fixtures. */ Magento_Test_Listener::registerObserver('Magento_Test_Listener_Annotation_Isolation'); Magento_Test_Listener::registerObserver('Magento_Test_Listener_Annotation_Fixture');