public function watermarkDataProvider() { $_tmpPath = Magento_Test_Environment::getInstance()->getTmpDir(); $imageAbsent = $_tmpPath . DIRECTORY_SEPARATOR . md5(time() + microtime(true)) . '2'; $imageExists = $_tmpPath . DIRECTORY_SEPARATOR . md5(time() + microtime(true)) . '1'; touch($imageExists); return array(array('', Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT), array($imageAbsent, Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT), array($imageExists, Varien_Image_Adapter_ImageMagick::ERROR_WRONG_IMAGE)); }
public function testCleanDir() { $dir = self::$_tmpDir . '/subtmp'; mkdir($dir, 0777); $fileName = $dir . '/file.tmp'; touch($fileName); try { $this->_environment->cleanDir(self::$_tmpDir); $this->assertFalse(is_dir($dir)); } catch (Exception $e) { if (file_exists($fileName)) { unlink($fileName); } rmdir($dir); throw $e; } }
* versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package unit_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ require __DIR__ . '/../../../../app/code/core/Mage/Core/functions.php'; define('TESTS_TEMP_DIR', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tmp'); $includePaths = array("./framework", './testsuite', '../../../app/', '../../../app/code/core', '../../../lib', get_include_path()); set_include_path(implode(PATH_SEPARATOR, $includePaths)); spl_autoload_register('magentoAutoloadForUnitTests'); function magentoAutoloadForUnitTests($class) { $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { $fileName = $path . DIRECTORY_SEPARATOR . $file; if (file_exists($fileName)) { include $file; if (class_exists($class, false) || interface_exists($class, false)) { return true; } } } return false; } $tmpDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tmp'; $instance = new Magento_Test_Environment($tmpDir); Magento_Test_Environment::setInstance($instance); $instance->cleanTmpDir()->cleanTmpDirOnShutdown();
public function tearDown() { Magento_Test_Environment::getInstance()->cleanDir(self::$_tmpDir); }
protected function setUp() { do { $this->_actualCsvFile = Magento_Test_Environment::getInstance()->getTmpDir() . DIRECTORY_SEPARATOR . md5(time() + microtime(true)); } while (file_exists($this->_actualCsvFile)); }
/** * Write Data into File * * @param bool $callback * @return string */ protected function _writeFile($callback = false) { $ioFile = new Varien_Io_File(); $path = Magento_Test_Environment::getInstance()->getTmpDir(); $name = md5(microtime()); $file = $path . DIRECTORY_SEPARATOR . $name . '.xml'; $ioFile->open(array('path' => $path)); $ioFile->streamOpen($file, 'w+'); $ioFile->streamLock(true); if (!$callback) { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData)); } else { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData), array($this, 'callbackMethod')); } $convert->write($ioFile); $ioFile->streamUnlock(); $ioFile->streamClose(); return $file; }
/** * Set self instance for static access * * @param Magento_Test_Environment $instance */ public static function setInstance(Magento_Test_Environment $instance) { self::$_instance = $instance; }
/** * @covers Mage_Captcha_Model_Zend::getImgDir * @covers Mage_Captcha_Helper_Data::getImgDir */ public function testGetImgDir() { $captchaTmpDir = Magento_Test_Environment::getInstance()->getTmpDir() . DIRECTORY_SEPARATOR . 'captcha'; $option = $this->_getOptionStub(); $option->expects($this->once())->method('getDir')->will($this->returnValue($captchaTmpDir)); $this->_object->setOption($option); $this->assertEquals($this->_object->getImgDir(), $captchaTmpDir . DIRECTORY_SEPARATOR . 'captcha' . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR); }