Exemplo n.º 1
0
 /**
  * PHPUnit default function.
  * Redefine this method only if you really need to do so.
  * In any other cases redefine the getRequest() one
  *
  * @return void
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function setUp()
 {
     parent::setUp();
     \Includes\Utils\FileManager::copyRecursive(dirname(__FILE__) . LC_DS . 'SubstutionalSkin' . LC_DS . 'scripts' . LC_DS . 'CDev', LC_DIR_MODULES . 'CDev');
     \Includes\Utils\FileManager::copyRecursive(dirname(__FILE__) . LC_DS . 'SubstutionalSkin' . LC_DS . 'scripts' . LC_DS . 'CDev', LC_DIR_CACHE_CLASSES . 'XLite' . LC_DS . 'Module' . LC_DS . 'CDev');
     \Includes\Utils\FileManager::copyRecursive(dirname(__FILE__) . LC_DS . 'SubstutionalSkin' . LC_DS . 'skins', LC_DIR_SKINS);
     $skin = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->findOneBy(array('name' => 'TestSkin', 'author' => 'CDev'));
     if (!$skin) {
         $skin = new \XLite\Model\Module();
         $skin->setAuthor('CDev');
         $skin->setName('TestSkin');
         $skin->setMajorVersion('1.0');
         $skin->setMinorVersion('0');
         $skin->setModuleName('TestSkin');
         $skin->setAuthorName('CDev');
         \XLite\Core\Database::getEM()->persist($skin);
     }
     $skin->setInstalled(true);
     $skin->setEnabled(true);
     \XLite\Core\Database::getEM()->flush();
     \XLite\Core\Database::getCacheDriver()->deleteAll();
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_COMPILE . 'skins');
 }
Exemplo n.º 2
0
 /**
  * Restore database from common backup
  *
  * @return void
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function doRestoreDb($path = null, $drop = true, $doNotAssert = false)
 {
     $message = '';
     $result = xlite_restore_sql_from_backup($path, false, $drop, $message);
     if (!$doNotAssert) {
         $this->assertTrue($result, $message);
     }
     \Includes\Utils\FileManager::copyRecursive(LC_DIR . '/.dev/tests/images', LC_DIR_IMAGES);
 }
Exemplo n.º 3
0
 /**
  * Creates the phpunit test suite
  *
  * @return PHPUnit_Framework_TestSuite
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite(ROOT_TEST_SUITE_NAME);
     $deploy = null;
     $includes = false;
     $includeTests = array();
     $excludes = array();
     $ds = preg_quote(LC_DS, '/');
     if (defined('INCLUDE_ONLY_TESTS')) {
         $includes = array_map('trim', explode(',', INCLUDE_ONLY_TESTS));
         if (in_array('LOCAL_TESTS', $includes)) {
             $k = array_search('LOCAL_TESTS', $includes);
             unset($includes[$k]);
         }
         if (in_array('NOWEB', $includes)) {
             if (!defined('SELENIUM_DISABLED')) {
                 define('SELENIUM_DISABLED', true);
             }
             $k = array_search('NOWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('ONLYWEB', $includes)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('ONLYWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('DEPLOY_DRUPAL', $includes)) {
             $deploy = 'Drupal';
         } elseif (in_array('DEPLOY_STANDALONE', $includes)) {
             $deploy = 'Standalone';
         }
         if (!is_null($deploy)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('DEPLOY_' . strtoupper($deploy), $includes);
             if (!defined('DIR_TESTS')) {
                 define('DIR_TESTS', 'Deploy' . LC_DS . $deploy);
             }
             unset($includes[$k]);
         }
         if (in_array('W3C', $includes)) {
             if (!defined('W3C_VALIDATION')) {
                 define('W3C_VALIDATION', true);
             }
             $k = array_search('W3C', $includes);
             unset($includes[$k]);
         }
         foreach ($includes as $k => $v) {
             if ('-' == substr($v, 0, 1)) {
                 $excludes[] = substr($v, 1);
                 unset($includes[$k]);
             }
         }
         foreach ($includes as $k => $v) {
             $tmp = explode(':', $v, 2);
             $includes[$k] = $tmp[0];
             if (isset($tmp[1])) {
                 $includeTests[$tmp[0]] = $tmp[1];
             }
         }
     }
     if (isset($deploy) && !defined('DEPLOYMENT_TEST')) {
         define('DEPLOYMENT_TEST', true);
     }
     // Include abstract classes
     $classesDir = dirname(__FILE__);
     $pattern = '/^' . preg_quote($classesDir, '/') . '.*' . $ds . '(?:\\w*Abstract|A[A-Z][a-z]\\w*)\\.php$/Ss';
     $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
     $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $filePath => $fileObject) {
         if (preg_match($pattern, $filePath, $matches)) {
             require_once $filePath;
         }
     }
     // Include fake classes
     if (!defined('DEPLOYMENT_TEST')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'FakeClass' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '.+\\.php$/Ss';
         $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($iterator as $filePath => $fileObject) {
             if (preg_match($pattern, $filePath, $matches)) {
                 require_once $filePath;
             }
         }
     }
     if (!isset($deploy) || !$deploy) {
         \Includes\Utils\FileManager::unlinkRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, __DIR__ . '/images/');
         //xlite_make_sql_backup();
     }
     // Classes tests
     if (!defined('UNITS_DISABLED')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'Classes' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z]\\w+)\\.php$/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $class = XLite_Tests_TestCase::CLASS_PREFIX . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $suite->addTest(new PHPUnit_Framework_TestSuite(new ReflectionClass($class)));
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     // Web tests
     if (!defined('SELENIUM_DISABLED')) {
         if (!defined('DIR_TESTS')) {
             define('DIR_TESTS', 'Web');
         }
         $classesDir = dirname(__FILE__) . LC_DS . constant('DIR_TESTS') . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z]\\w+)\\.php/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $classPrefix = !isset($deploy) ? XLite_Tests_SeleniumTestCase::CLASS_PREFIX : 'XLite_Deploy_' . $deploy . '_';
                     $class = $classPrefix . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $seleniumSuite = new PHPUnit_Framework_TestSuite();
                     $seleniumSuite->addTestSuite($class);
                     $suite->addTest($seleniumSuite);
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     error_reporting(E_ALL);
     return $suite;
 }
Exemplo n.º 4
0
function xlite_make_sql_backup($path = null)
{
    // DB backup
    echo PHP_EOL . 'DB backup ... ';
    \Includes\Utils\FileManager::unlinkRecursive(__DIR__ . '/images');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images/product');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images/category');
    \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, __DIR__ . '/images');
    $result = true;
    if (!isset($path)) {
        $path = dirname(__FILE__) . LC_DS . 'dump.sql';
    }
    if (file_exists(dirname($path))) {
        if (file_exists($path)) {
            unlink($path);
        }
        $config = \XLite::getInstance()->getOptions('database_details');
        $cmd = defined('TEST_MYSQLDUMP_BIN') ? TEST_MYSQLDUMP_BIN : 'mysqldump';
        $cmd .= ' --opt -h' . $config['hostspec'];
        if ($config['port']) {
            $cmd .= ' -P' . $config['port'];
        }
        $cmd .= ' -u' . $config['username'] . ('' == $config['password'] ? '' : ' -p' . $config['password']);
        if ($config['socket']) {
            $cmd .= ' -S' . $config['socket'];
        }
        $cmd .= ' ' . $config['database'];
        exec('echo "SET autocommit=0;
        SET unique_checks=0;
        SET foreign_key_checks=0;" > ' . $path . '
        ' . $cmd . ' >> ' . $path . '
        echo "COMMIT;" >> ' . $path);
        echo 'done' . PHP_EOL;
        sleep(1);
    } else {
        $result = false;
    }
    if (!$result) {
        echo 'ignored' . PHP_EOL;
    }
    return $result;
}