public static function setUpDatabase() { $dsn = ezpTestRunner::dsn()->parts; switch ($dsn['phptype']) { case 'mysql': case 'mysqli': $backend = 'eZDFSFileHandlerMySQLiBackend'; break; case 'postgresql': $backend = 'eZDFSFileHandlerPostgresqlBackend'; if (!class_exists('eZDFSFileHandlerPostgresqlBackend')) { self::markTestSkipped("Missing extension 'ezpostgresqlcluster', skipping PostgreSQL DFS tests"); } break; default: self::markTestSkipped("Unsupported database type '{$dsn['phptype']}'"); } // We need to clear the existing handler if it was loaded before the INI // settings changes eZClusterFileHandler::resetHandler(); unset($GLOBALS['eZClusterInfo']); // Load database parameters for cluster // The same DSN than the relational database is used ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'FileHandler', 'eZDFSFileHandler'); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBHost', $dsn['host']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBPort', $dsn['port']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBSocket', $dsn['socket']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBName', $dsn['database']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBUser', $dsn['user']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBPassword', $dsn['password']); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'MountPointPath', self::getDfsPath()); ezpINIHelper::setINISetting('file.ini', 'eZDFSClusteringSettings', 'DBBackend', $backend); }
protected function setUp() { if (!in_array(ezpTestRunner::dsn()->dbsyntax, array('mysql', 'mysqli'))) { self::markTestSkipped("Not running MySQL nor MysQLi, skipping"); } parent::setUp(); }
/** * Setup webdav test siteaccess & fills $this->files with all the * .request files found in the regression directory, recursively. */ public function __construct() { $siteaccess = strtolower(__CLASS__); // List of values that should be placed in temporary site.ini file for webdav testing $replace = array(); $dsn = ezpTestRunner::dsn(); $replace['@ezc_siteaccess@'] = $siteaccess; $replace['@ezc_db_phptype@'] = $dsn->phptype; $replace['@ezc_db_server@'] = $dsn->server; $replace['@ezc_db_port@'] = $dsn->port ? $dsn->port : ''; $replace['@ezc_db_user@'] = $dsn->user; $replace['@ezc_db_password@'] = $dsn->password; $replace['@ezc_db_database@'] = $dsn->database; $replace['@ezc_db_socket@'] = $dsn->socket ? 'enabled' : 'disabled'; // replace $replace values in site.ini.append.php.replace $contents = file_get_contents(dirname(__FILE__) . '/siteaccess/site.ini.append.php.replace'); foreach ($replace as $key => $replacement) { $contents = str_replace($key, $replacement, $contents); } // create siteaccess folder if (!file_exists('settings/siteaccess/' . $siteaccess)) { mkdir('settings/siteaccess/' . $siteaccess); } // store site.ini.append.php file file_put_contents('settings/siteaccess/' . $siteaccess . '/site.ini.append.php', $contents); // setup ini system to read siteaccess $ini = eZINI::instance(); $ini->prependOverrideDir('siteaccess/' . $siteaccess, false, 'siteaccess', 'siteaccess'); $ini->loadCache(); // load tests $this->readDirRecursively(dirname(__FILE__) . '/regression', $this->files, 'request'); parent::__construct(); }
/** * Test setup * * Load an instance of file.ini * Assigns DB parameters for cluster **/ public function setUp() { parent::setUp(); // We need to clear the existing handler if it was loaded before the INI // settings changes eZClusterFileHandler::resetHandler(); unset($GLOBALS['eZClusterInfo']); // Load database parameters for cluster // The same DSN than the relational database is used $dsn = ezpTestRunner::dsn()->parts; switch ($dsn['phptype']) { case 'mysql': case 'mysqli': $backend = 'eZDBFileHandlerMysqliBackend'; break; case 'postgresql': $backend = 'eZDBFileHandlerPostgresqlBackend'; break; default: $this->markTestSkipped("Unsupported database type '{$dsn['phptype']}'"); } ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'FileHandler', 'eZDBFileHandler'); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBHost', $dsn['host']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBPort', $dsn['port']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBSocket', $dsn['socket']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBName', $dsn['database']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBUser', $dsn['user']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBPassword', $dsn['password']); ezpINIHelper::setINISetting('file.ini', 'ClusteringSettings', 'DBBackend', $backend); // ezpTestDatabaseHelper::insertSqlData( $this->sharedFixture, $this->sqlFiles ); $this->db = $this->sharedFixture; }
/** * Test setup * * Load an instance of file.ini * Assigns DB parameters for cluster **/ public function setUp() { if (!$this->sharedFixture instanceof eZMySQLDB) { self::markTestSkipped("Not using mysql interface, skipping"); } parent::setUp(); // We need to clear the existing handler if it was loaded before the INI // settings changes if (isset($GLOBALS['eZClusterFileHandler_chosen_handler']) and !$GLOBALS['eZClusterFileHandler_chosen_handler'] instanceof eZDFSFileHandler) { unset($GLOBALS['eZClusterFileHandler_chosen_handler']); } // Load database parameters for cluster // The same DSN than the relational database is used $fileINI = eZINI::instance('file.ini'); $this->previousFileHandler = $fileINI->variable('ClusteringSettings', 'FileHandler'); $fileINI->setVariable('ClusteringSettings', 'FileHandler', 'eZDFSFileHandler'); $dsn = ezpTestRunner::dsn()->parts; $fileINI->setVariable('eZDFSClusteringSettings', 'DBHost', $dsn['host']); $fileINI->setVariable('eZDFSClusteringSettings', 'DBPort', $dsn['port']); $fileINI->setVariable('eZDFSClusteringSettings', 'DBSocket', $dsn['socket']); $fileINI->setVariable('eZDFSClusteringSettings', 'DBName', $dsn['database']); $fileINI->setVariable('eZDFSClusteringSettings', 'DBUser', $dsn['user']); $fileINI->setVariable('eZDFSClusteringSettings', 'DBPassword', $dsn['password']); $fileINI->setVariable('eZDFSClusteringSettings', 'MountPointPath', $this->DFSPath); if (!file_exists($this->DFSPath)) { eZDir::doMkdir($this->DFSPath, 0755); $this->haveToRemoveDFSPath = true; } ezpTestDatabaseHelper::insertSqlData($this->sharedFixture, $this->sqlFiles); $this->db = $this->sharedFixture; }
protected function setUp() { if (ezpTestRunner::dsn()->dbsyntax !== "postgresql") { self::markTestSkipped("Not running PostgresSQL, skipping"); } parent::setUp(); ezpTestDatabaseHelper::clean($this->sharedFixture); }
protected function tearDown() { if (ezpTestRunner::dbPerTest()) { $db = eZDB::instance(); $db->close(); } parent::tearDown(); }
public static function tearDownAfterClass() { // We need to clean up after this test case, since database will not // be reset by the suite it initialisation has happened once, see pull req. #234 // Next: Suite which always prepares the db for you. $db = ezpTestDatabaseHelper::create(ezpTestRunner::dsn()); ezpTestDatabaseHelper::clean($db); ezpTestDatabaseHelper::insertDefaultData($db); }
protected function setUp() { if (!in_array(ezpTestRunner::dsn()->dbsyntax, array('mysql', 'mysqli'))) { self::markTestSkipped("Not running MySQL nor MysQLi, skipping"); } parent::setUp(); // clean up the database so that the tests are independant from the ezp database ezpTestDatabaseHelper::clean($this->sharedFixture); }
/** * Test setup * * Load an instance of file.ini * Assigns DB parameters for cluster */ public function setUp() { if ( ezpTestRunner::dsn()->dbsyntax !== 'mysql' && ezpTestRunner::dsn()->dbsyntax !== 'mysqli' ) self::markTestSkipped( "Not running MySQL, skipping" ); parent::setUp(); $this->sharedFixture = ezpTestDatabaseHelper::create( ezpTestRunner::dsn() ); ezpTestDatabaseHelper::insertSqlData( $this->sharedFixture, array( 'tests/tests/kernel/classes/clusterfilehandlers/sql/cluster_dfs_schema.sql' ) ); // We need to clear the existing handler if it was loaded before the INI // settings changes if ( !eZClusterFileHandler::$globalHandler instanceof eZDFSFileHandler ) eZClusterFileHandler::$globalHandler = null; unset( $GLOBALS['eZClusterInfo'] ); // Load database parameters for cluster // The same DSN than the relational database is used $fileINI = eZINI::instance( 'file.ini' ); $this->previousFileHandler = $fileINI->variable( 'ClusteringSettings', 'FileHandler' ); $fileINI->setVariable( 'ClusteringSettings', 'FileHandler', 'eZDFSFileHandler' ); $dsn = ezpTestRunner::dsn()->parts; switch ( $dsn['phptype'] ) { case 'mysql': $backend = 'eZDFSFileHandlerMySQLBackend'; break; case 'mysqli': $backend = 'eZDFSFileHandlerMySQLiBackend'; break; default: $this->markTestSkipped( "Unsupported database type '{$dsn['phptype']}'" ); } $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBBackend', $backend ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBHost', $dsn['host'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBPort', $dsn['port'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBSocket', $dsn['socket'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBName', $dsn['database'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBUser', $dsn['user'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'DBPassword', $dsn['password'] ); $fileINI->setVariable( 'eZDFSClusteringSettings', 'MountPointPath', $this->DFSPath ); if ( !file_exists( $this->DFSPath ) ) { eZDir::doMkdir( $this->DFSPath, 0755 ); $this->haveToRemoveDFSPath = true; } $this->db = $this->sharedFixture; }
/** * Sets up the database enviroment */ protected function setUp() { if (!ezpTestRunner::dbPerTest()) { $dsn = ezpTestRunner::dsn(); $this->sharedFixture = ezpTestDatabaseHelper::create($dsn); if ($this->insertDefaultData === true) { ezpTestDatabaseHelper::insertDefaultData($this->sharedFixture); } if (count($this->sqlFiles > 0)) { ezpTestDatabaseHelper::insertSqlData($this->sharedFixture, $this->sqlFiles); } eZDB::setInstance($this->sharedFixture); } }
/** * Fills $this->files with all the .request files found in the regression * directory, recursively. */ public function __construct() { $siteaccess = strtolower(__CLASS__); if (ezcBaseFeatures::classExists('eZSiteAccessHelper', true)) { require_once 'siteaccesscreator.php'; // - ./siteaccess/site.ini.append.php.replace is copied over site.ini.append.php, // with certain values replaced dynamically (@ezc_siteaccess@ and // @ezc_webdav_database@) // - the extension ezsiteaccesshelper is called to create the siteaccess with // the same name as this class (in lowercase), and it will copy the site.ini.append.php // file to the ezp/siteaccess/@ezc_siteaccess@ folder // - the extension ezsiteaccesshelper is called to enable the created siteaccess // in ezp/siteaccess/override/site.ini.append.php $replace = array(); $replace['@ezc_siteaccess@'] = $siteaccess; $replace['@ezc_webdav_database@'] = ezpTestRunner::dsn()->database; $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'siteaccess'; try { // replace @ezc_siteaccess@ and @ezc_webdav_database@ in site.ini.append.php // with respective values $contents = file_get_contents($templateDir . DIRECTORY_SEPARATOR . 'site.ini.append.php.replace'); if (count($replace) > 0) { foreach ($replace as $key => $replacement) { $contents = str_replace($key, $replacement, $contents); } } file_put_contents($templateDir . DIRECTORY_SEPARATOR . 'site.ini.append.php', $contents); ezpSiteAccessCreator::$docRoot = eZSys::rootDir() . DIRECTORY_SEPARATOR; ezpSiteAccessCreator::createSiteAccess($siteaccess, $templateDir); } catch (Exception $e) { // eZSiteAccessHelper::createSiteAccess throws an exception // if the siteaccess exists already // var_dump( $e->getMessage() ); } } else { die("The WebDAV test suite requires the extension eZSiteAccessHelper in order to create a siteaccess.\n"); } $basePath = dirname(__FILE__) . '/regression'; $this->readDirRecursively($basePath, $this->files, 'request'); parent::__construct(); }
/** * Test setup * * Load an instance of file.ini * Assigns DB parameters for cluster **/ public function setUp() { parent::setUp(); if (!$this->sharedFixture instanceof eZMySQLDB and !$this->sharedFixture instanceof eZMySQLiDB) { self::markTestSkipped("Not using mysql interface, skipping"); } // We need to clear the existing handler if it was loaded before the INI // settings changes if (isset($GLOBALS['eZClusterFileHandler_chosen_handler']) and !$GLOBALS['eZClusterFileHandler_chosen_handler'] instanceof eZDBFileHandler) { unset($GLOBALS['eZClusterFileHandler_chosen_handler']); } unset($GLOBALS['eZClusterInfo']); // Load database parameters for cluster // The same DSN than the relational database is used $fileINI = eZINI::instance('file.ini'); $this->previousFileHandler = $fileINI->variable('ClusteringSettings', 'FileHandler'); $fileINI->setVariable('ClusteringSettings', 'FileHandler', 'eZDBFileHandler'); $dsn = ezpTestRunner::dsn()->parts; switch ($dsn['phptype']) { case 'mysql': $backend = 'eZDBFileHandlerMysqlBackend'; break; case 'mysqli': $backend = 'eZDBFileHandlerMysqliBackend'; break; default: $this->markTestSkipped("Unsupported database type '{$dsn['phptype']}'"); } $fileINI->setVariable('ClusteringSettings', 'DBBackend', $backend); $fileINI->setVariable('ClusteringSettings', 'DBHost', $dsn['host']); $fileINI->setVariable('ClusteringSettings', 'DBPort', $dsn['port']); $fileINI->setVariable('ClusteringSettings', 'DBSocket', $dsn['socket']); $fileINI->setVariable('ClusteringSettings', 'DBName', $dsn['database']); $fileINI->setVariable('ClusteringSettings', 'DBUser', $dsn['user']); $fileINI->setVariable('ClusteringSettings', 'DBPassword', $dsn['password']); // ezpTestDatabaseHelper::insertSqlData( $this->sharedFixture, $this->sqlFiles ); $this->db = $this->sharedFixture; }
protected function getClass() { require_once( $this->sourceFile ); $this->class = ezpTestRunner::getClassName( $this->sourceFile ); $this->testClass = $this->class . "Test"; }
/** * Returns true/false if the database should be created per database * * @return bool */ static public function dbPerTest() { $testRunner = ezpTestRunner::instance(); if( array_key_exists( 'db-per-test', $testRunner->arguments ) ) { return $testRunner->arguments['db-per-test']; } return false; }
} $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\n" . "sets up an eZ Publish testing environment" . "\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true)); // Override INI override folder from settings/override to // tests/settings to not read local override settings $ini = eZINI::instance(); $ini->setOverrideDirs(array(array('tests/settings', true)), 'override'); $ini->loadCache(); // Be sure to have clean content language data eZContentLanguage::expireCache(); $script->startup(); // $options = $script->getOptions(); $script->initialize(); // Avoids Fatal error: eZ Publish did not finish its request if die() is used. eZExecution::setCleanExit(); $version = PHPUnit_Runner_Version::id(); if (version_compare($version, '3.5.0') == -1 && $version !== '@package_version@') { die("PHPUnit 3.5.0 (or later) is required to run this test suite.\n"); } require_once 'PHP/CodeCoverage.php'; $codeCoverage = new PHP_CodeCoverage(); $codeCoverage->filter()->addFileToBlacklist(__FILE__, 'PHPUNIT'); //require_once 'bootstrap.php'; try { $runner = ezpTestRunner::instance(); $runner->run($_SERVER['argv']); } catch (Exception $e) { $cli->error($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()); $cli->error($e->getTraceAsString()); } $script->shutdown();
/** * Tests the name trunk automatic creation (at backend level) * @dataProvider providerForTestNameTrunk */ public function testNameTrunk($path, $scope, $expectedNameTrunk, $expectedCacheType) { // postgres doesn't use nametrunk if (ezpTestRunner::dsn()->parts['phptype'] == 'postgresql') { self::markTestSkipped("name_trunk isn't used by postgresql"); } $ch = self::createFile($path, false, array('scope' => $scope)); self::assertEquals($expectedNameTrunk, $ch->metaData['name_trunk']); self::assertEquals($expectedCacheType, $ch->cacheType); }
/** * Returns true/false if the database should be created per test * * @return bool */ public static function dbPerTest() { $testRunner = ezpTestRunner::instance(); return $testRunner->arguments['db-per-test']; }
/** * Processes all console options * * If the help option is specified by the user the help text will be * displayed and the program will exit. * * @param ezcConsoleInput $consoleInput */ protected static function processConsoleArguments($consoleInput) { try { $consoleInput->process(); } catch (ezcConsoleOptionException $e) { die($e->getMessage() . "\n"); } if ($consoleInput->getOption("help")->value) { self::displayHelp(self::$consoleInput); exit; } if ($consoleInput->getOption('php-binary')->value) { self::$phpBinary = $consoleInput->getOption('php-binary')->value; } }
* File containing the runtests CLI script * * @copyright Copyright (C) 1999-2010 eZ Systems AS. All rights reserved. * @license http://ez.no/licenses/gnu_gpl GNU GPLv2 * @package tests */ set_time_limit(0); require_once 'autoload.php'; require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'tests/toolkit/ezptestrunner.php'; // Exclude the test system from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter(getcwd() . '/tests'); // Whitelist all eZ Publish kernel files $baseDir = getcwd(); $autoloadArray = (include 'autoload/ezp_kernel.php'); foreach ($autoloadArray as $class => $file) { // Exclude files from the tests directory if (strpos($file, 'tests') !== 0) { PHPUnit_Util_Filter::addFileToWhitelist("{$baseDir}/{$file}"); } } $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\n" . "sets up an eZ Publish testing environment" . "\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true)); $script->startup(); // $options = $script->getOptions(); $script->initialize(); // Avoids Fatal error: eZ Publish did not finish its request if die() is used. eZExecution::setCleanExit(); ezpTestRunner::main(); $script->shutdown();