Example #1
0
 public static function run()
 {
     global $argv, $argc;
     $usage = PHP_EOL . "  Usage: php [options] TestSuite.php <All|Misc|moduleName|TestClassName> [options]" . PHP_EOL . PHP_EOL . "    All               Run all tests." . PHP_EOL . "    Framework         Run all tests in framework/tests/functional." . PHP_EOL . "    Misc              Run the test suites in app/protected/tests/functional." . PHP_EOL . "    moduleName        Run the test suites in app/protected/modules/moduleName/tests/functional." . PHP_EOL . "    TestClassName     Run the tests in TestClassName.html, wherever that happens to be." . PHP_EOL . "    options" . PHP_EOL . "    -p                port Example: -p4044" . PHP_EOL . "    -h                host Example: -hhttp://www.sitetotest/app/" . PHP_EOL . "    -b                browser <*firefox|*iexplore> if not specified, will run all in browsers " . PHP_EOL . "    -c                test server control url Example: -chttp://www.sitetotest/controlUrl.php" . PHP_EOL . "                      Example: -b*firefox " . PHP_EOL . "    -userExtensions   Example: -userExtensions pathToTheUserExtensionJS " . PHP_EOL . PHP_EOL . "  Examples:" . PHP_EOL . PHP_EOL . "    php TestSuiteSelenium.php accounts (Run the tests in the Accounts module.)" . PHP_EOL . "    php TestSuiteSelenium.php RedBeanModelTest   (Run the test suite RedBeanModelTest.html.)" . PHP_EOL . PHP_EOL . PhpUnitServiceUtil::checkVersion();
     if ($argv[0] != 'TestSuite.php') {
         echo $usage;
         exit;
     } else {
         $whatToTest = $argv[1];
     }
     $whatToTestIsModuleDir = self::isWhatToTestAModule($whatToTest);
     $suiteNames = array();
     $htmlTestSuiteFiles = array();
     if ($whatToTest == 'All' || $whatToTest == 'Misc' || !$whatToTestIsModuleDir) {
         $compareToTest = $whatToTest;
         if ($whatToTest == 'Misc') {
             $compareToTest = null;
         }
         $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory($htmlTestSuiteFiles, '.', $compareToTest);
     }
     if ($whatToTest != 'Misc' && !$whatToTestIsModuleDir) {
         $compareToTest = $whatToTest;
         if ($whatToTest == 'Framework') {
             $compareToTest = null;
         }
         $frameworkTestSuiteDirectory = '../../core/tests/functional';
         $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory($htmlTestSuiteFiles, $frameworkTestSuiteDirectory, $compareToTest);
     }
     $moduleDirectoryName = '../../modules';
     if (is_dir($moduleDirectoryName)) {
         $moduleNames = scandir($moduleDirectoryName);
         foreach ($moduleNames as $moduleName) {
             if ($moduleName != '.' && $moduleName != '..') {
                 $moduleFunctionalTestDirectoryName = "{$moduleDirectoryName}/{$moduleName}/tests/functional";
                 if (is_dir($moduleFunctionalTestDirectoryName)) {
                     if ($whatToTest == 'All' || $whatToTest == $moduleName || strtolower($whatToTest) == $moduleName || !$whatToTestIsModuleDir) {
                         if ($whatToTest == $moduleName || strtolower($whatToTest) == $moduleName) {
                             $compareToTest = null;
                         } else {
                             $compareToTest = $whatToTest;
                         }
                         $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory($htmlTestSuiteFiles, $moduleFunctionalTestDirectoryName, $compareToTest);
                     }
                 }
             }
         }
     }
     if (count($htmlTestSuiteFiles) == 0) {
         echo $usage;
         echo "  No tests found for '{$whatToTest}'.\n" . PHP_EOL;
         exit;
     }
     echo 'Suites to run:' . PHP_EOL;
     foreach ($htmlTestSuiteFiles as $pathToSuite) {
         if (in_array(basename($pathToSuite), $suiteNames)) {
             echo 'Cannot run tests because there are 2 test suites with the same name.' . PHP_EOL;
             echo 'The duplicate found is here: ' . $pathToSuite . PHP_EOL;
             exit;
         }
         $suiteNames[] = basename($pathToSuite);
         echo $pathToSuite . PHP_EOL;
     }
     echo 'Running Test Suites using Selenium RC v2:' . PHP_EOL;
     $browsersToRun = self::resolveBrowserFromParameter();
     foreach ($browsersToRun as $browserId => $browserDisplayName) {
         self::clearPreviousTestResultsByServerAndBrowser(self::getServerByServerControlUrl(self::resolveHostFromParameterAndConstant()), $browserDisplayName);
         foreach ($htmlTestSuiteFiles as $pathToSuite) {
             if (!self::isInstallationTest($pathToSuite)) {
                 echo "Restoring test db" . PHP_EOL;
                 self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restore'));
                 echo "Restored test db" . PHP_EOL;
                 if (!self::isInstallationTest($pathToSuite)) {
                     echo "Set user default time zone." . PHP_EOL;
                     self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'setUserDefaultTimezone'));
                     echo "User default time zone set." . PHP_EOL;
                 }
                 echo "Clear cache on remote server" . PHP_EOL;
                 self::remoteAction(self::resolveHostFromParameterAndConstant(), array('clearCache' => '1', 'ignoreBrowserCheck' => '1'));
                 //Eventually remove this since in code for 2.5.9 this is removed
             } else {
                 echo "Uninstall zurmo" . PHP_EOL;
                 self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'backupRemovePerInstance'));
             }
             echo "Cache cleared" . PHP_EOL;
             echo 'Running test suite: ';
             echo $pathToSuite . PHP_EOL;
             $host = self::resolveHostFromParameterAndConstant();
             $hostFilePart = str_replace('http://', '', $host);
             $hostFilePart = str_replace('https://', '', $hostFilePart);
             $hostFilePart = str_replace('/', '', $hostFilePart);
             $hostFilePart = $hostFilePart . '.';
             $testResultFileNamePrefix = str_replace('../', '', $pathToSuite);
             $testResultFileNamePrefix = str_replace('/', '.', $testResultFileNamePrefix);
             $testResultFileNamePrefix = str_replace('\\', '.', $testResultFileNamePrefix);
             $testResultFileNamePrefix = str_replace('..', '', $testResultFileNamePrefix);
             $testResultFileNamePrefix = str_replace('.html', '', $testResultFileNamePrefix);
             $testResultsFileName = $testResultFileNamePrefix . '.' . str_replace(' ', '', $browserDisplayName) . '.TestResults.html';
             $finalTestResultsPath = TEST_RESULTS_PATH . $hostFilePart . $testResultsFileName;
             $finalCommand = 'java -jar "' . SELENIUM_SERVER_PATH . '" ';
             $finalCommand .= '-port ' . self::resolvePortFromParameterAndConstant();
             $finalCommand .= ' -htmlSuite ' . $browserId . ' ';
             $finalCommand .= $host . ' ' . realPath($pathToSuite) . ' ' . $finalTestResultsPath;
             $finalCommand .= ' -userExtensions ' . self::resolveUserExtensionsJsFromParameterAndConstant();
             echo $finalCommand . PHP_EOL;
             exec($finalCommand);
             echo 'Restoring test db';
             self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restore'));
             if (self::isInstallationTest($pathToSuite)) {
                 self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restorePerInstance'));
             }
         }
     }
     echo 'Functional Run Complete.' . PHP_EOL;
     self::updateTestResultsSummaryAndDetailsFiles();
 }
Example #2
0
 public static function suite()
 {
     global $argv;
     PhpUnitServiceUtil::checkVersion();
     $usage = PHP_EOL . "  Usage: phpunit [phpunit options] TestSuite.php <All|Framework|Misc|moduleName|TestClassName> [custom options]" . PHP_EOL . PHP_EOL . "    All                     Run all tests." . PHP_EOL . "    Framework               Run the tests in app/protected/extensions/framework/tests/unit." . PHP_EOL . "    Misc                    Run the tests in app/protected/tests/unit." . PHP_EOL . "    moduleName              Run the tests in app/protected/modules/moduleName/tests/unit." . PHP_EOL . "    TestClassName           Run the tests in TestClassName.php, wherever that happens to be." . PHP_EOL . PHP_EOL . "  Custom Options:" . PHP_EOL . PHP_EOL . "    --only-walkthroughs     For the specified test, only includes tests under a walkthroughs directory." . PHP_EOL . "    --exclude-walkthroughs  For the specified test, exclude tests under a walkthroughs directory." . PHP_EOL . "    --only-benchmarks       For the specified test, only includes tests under a benchmarks directory." . PHP_EOL . "    --exclude-benchmarks    For the specified test, exclude tests under a benchmarks directory." . PHP_EOL . "    --reuse-schema          Reload a previously auto build database. (Will auto build if there is no" . PHP_EOL . "                            previous one. The auto built schema is dumped to the system temp dir in" . PHP_EOL . "                            autobuild.sql.)" . PHP_EOL . PHP_EOL . "  Examples:" . PHP_EOL . PHP_EOL . "    phpunit --verbose TestSuite.php accounts (Run the tests in the Accounts module.)" . PHP_EOL . "    phpunit TestSuite.php RedBeanModelTest   (Run the tests in RedBeanModelTest.php.)" . PHP_EOL . PHP_EOL . "    To run specific tests use the phpunit --filter <regex> option." . PHP_EOL . "    phpunit has its own options. Check phpunit --help." . PHP_EOL . PHP_EOL;
     // Not Coding Standard
     $onlyWalkthroughs = self::customOptionSet('--only-walkthroughs', $argv);
     $excludeWalkthroughs = self::customOptionSet('--exclude-walkthroughs', $argv);
     $onlyBenchmarks = self::customOptionSet('--only-benchmarks', $argv);
     $excludeBenchmarks = self::customOptionSet('--exclude-benchmarks', $argv);
     $reuse = self::customOptionSet('--reuse-schema', $argv);
     if ($argv[count($argv) - 2] != 'TestSuite.php') {
         echo $usage;
         exit(static::ERROR_INVOCATION_WITHOUT_TESTSUITE);
     }
     if ($onlyWalkthroughs && $onlyBenchmarks) {
         echo $usage;
         echo "It doesn't have sense to select both \"--only-walkthroughs\" and \"--only-benchmarks\" options. " . PHP_EOL . PHP_EOL;
         exit(static::ERROR_WALKTHROUGH_AND_BENCHMARK_SELECTED);
     }
     $whatToTest = $argv[count($argv) - 1];
     $includeUnitTests = !$onlyWalkthroughs && !$onlyBenchmarks;
     $includeWalkthroughs = !$excludeWalkthroughs && !$onlyBenchmarks;
     $includeBenchmarks = !$excludeBenchmarks && !$onlyWalkthroughs;
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->setName("{$whatToTest} Tests");
     self::buildAndAddSuiteFromDirectory($suite, 'Framework', COMMON_ROOT . '/protected/core/tests/unit', $whatToTest, true, false, $includeBenchmarks);
     $moduleDirectoryName = COMMON_ROOT . '/protected/modules';
     if (is_dir($moduleDirectoryName)) {
         $moduleNames = scandir($moduleDirectoryName);
         foreach ($moduleNames as $moduleName) {
             if ($moduleName != '.' && $moduleName != '..') {
                 $moduleUnitTestDirectoryName = "{$moduleDirectoryName}/{$moduleName}/tests/unit";
                 self::buildAndAddSuiteFromDirectory($suite, $moduleName, $moduleUnitTestDirectoryName, $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
             }
         }
     }
     self::buildAndAddSuiteFromDirectory($suite, 'Misc', COMMON_ROOT . '/protected/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     self::buildAndAddSuiteFromDirectory($suite, 'Commands', COMMON_ROOT . '/protected/commands/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     ////////////////////////////////////////////////////////////////////////////////
     // Temporary - See Readme.txt in the notSupposedToBeHere directory.
     self::buildAndAddSuiteFromDirectory($suite, 'BadDependencies', COMMON_ROOT . '/protected/tests/unit/notSupposedToBeHere', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     ////////////////////////////////////////////////////////////////////////////////
     if ($suite->count() == 0) {
         echo $usage;
         echo "  No tests found for '{$whatToTest}'." . PHP_EOL . PHP_EOL;
         exit(static::ERROR_TEST_NOT_FOUND);
     }
     echo "Testing with database: '" . Yii::app()->db->connectionString . '\', ' . 'username: \'' . Yii::app()->db->username . "'." . PHP_EOL;
     static::setupDatabaseConnection();
     // get rid of any caches from last execution, this ensure we rebuild any required tables
     // without this some of many_many tables have issues as we use cache to determine
     // if we need to rebuild those.
     ForgetAllCacheUtil::forgetAllCaches();
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageLogger = new MessageLogger($messageStreamer);
     $messageLogger->logDateTimeStamp = false;
     if (!$reuse) {
         if (!is_writable(sys_get_temp_dir())) {
             echo PHP_EOL . PHP_EOL . "Temp directory must be writable to store reusable schema" . PHP_EOL;
             // Not Coding Standard
             echo "Temp directory: " . sys_get_temp_dir() . PHP_EOL . PHP_EOL;
             // Not Coding Standard
             exit(static::ERROR_TEMP_DIR_NOT_WRITABLE);
         }
         echo "Auto building database schema..." . PHP_EOL;
         ZurmoRedBean::$writer->wipeAll();
         InstallUtil::autoBuildDatabase($messageLogger, true);
         $messageLogger->printMessages();
         // recreate all tables, we know there aren't existing because we just did a wipeAll();
         static::rebuildReadPermissionsTables(true, true, $messageStreamer);
         assert('RedBeanDatabase::isSetup()');
         Yii::app()->user->userModel = InstallUtil::createSuperUser('super', 'super');
         echo "Saving auto built schema..." . PHP_EOL;
         $schemaFile = sys_get_temp_dir() . '/autobuilt.sql';
         $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         assert('$success == 1');
         $databaseName = $matches[1];
         preg_match("/mysql:host=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         $host = $matches[1];
         $systemOutput = system('mysqldump -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' -h ' . $host . ' ' . $databaseName . " > {$schemaFile}");
         if ($systemOutput != null) {
             echo 'Dumping schema using system command. Output: ' . $systemOutput . PHP_EOL . PHP_EOL;
         }
     } else {
         echo PHP_EOL;
         static::buildDependentTestModels($messageLogger);
         $messageLogger->printMessages();
     }
     echo PHP_EOL;
     static::closeDatabaseConnection();
     return $suite;
 }
Example #3
0
 public static function suite()
 {
     global $argv, $freeze;
     PhpUnitServiceUtil::checkVersion();
     $usage = "\n" . "  Usage: phpunit [phpunit options] TestSuite.php <All|Framework|Misc|moduleName|TestClassName> [custom options]\n" . "\n" . "    All                     Run all tests.\n" . "    Framework               Run the tests in app/protected/extensions/framework/tests/unit.\n" . "    Misc                    Run the tests in app/protected/tests/unit.\n" . "    moduleName              Run the tests in app/protected/modules/moduleName/tests/unit.\n" . "    TestClassName           Run the tests in TestClassName.php, wherever that happens to be.\n" . "\n" . "  Custom Options:\n" . "\n" . "    --only-walkthroughs     For the specified test, only includes tests under a walkthroughs directory.\n" . "    --exclude-walkthroughs  For the specified test, exclude tests under a walkthroughs directory.\n" . "    --only-benchmarks       For the specified test, only includes tests under a benchmarks directory.\n" . "    --exclude-benchmarks    For the specified test, exclude tests under a benchmarks directory.\n" . "    --reuse-schema          Reload a previously auto build database. (Will auto build if there is no\n" . "                            previous one. The auto built schema is dumped to the system temp dir in\n" . "                            autobuild.sql.)\n" . "    --no-freeze             Don't auto build and freeze the database.\n" . "\n" . "  Examples:\n" . "\n" . "    phpunit --verbose TestSuite.php accounts (Run the tests in the Accounts module.)\n" . "    phpunit TestSuite.php RedBeanModelTest   (Run the tests in RedBeanModelTest.php.)\n" . "\n" . "  Note:\n" . "\n" . "    Framework and Misc tests run only when -no-freeze is specified.\n" . "\n" . "    To run specific tests use the phpunit --filter <regex> option.\n" . "    phpunit has its own options. Check phpunit --help.\n\n";
     // Not Coding Standard
     $onlyWalkthroughs = self::customOptionSet('--only-walkthroughs', $argv);
     $excludeWalkthroughs = self::customOptionSet('--exclude-walkthroughs', $argv);
     $onlyBenchmarks = self::customOptionSet('--only-benchmarks', $argv);
     $excludeBenchmarks = self::customOptionSet('--exclude-benchmarks', $argv);
     $reuse = self::customOptionSet('--reuse-schema', $argv);
     $freeze = !self::customOptionSet('--no-freeze', $argv);
     if ($freeze == true && FORCE_NO_FREEZE == true) {
         echo "\n\nBecause forceNoFreeze is set to TRUE in debugTest, you cannot run unit tests in frozen mode\n\n";
         // Not Coding Standard
         exit;
     }
     if ($argv[count($argv) - 2] != 'TestSuite.php') {
         echo $usage;
         exit;
     }
     if ($onlyWalkthroughs && $onlyBenchmarks) {
         echo $usage;
         echo "It doesn't have sense to select both \"--only-walkthroughs\" and \"--only-benchmarks\" options. \n\n";
         exit;
     }
     $whatToTest = $argv[count($argv) - 1];
     $includeUnitTests = !$onlyWalkthroughs && !$onlyBenchmarks;
     $includeWalkthroughs = !$excludeWalkthroughs && !$onlyBenchmarks;
     $includeBenchmarks = !$excludeBenchmarks && !$onlyWalkthroughs;
     echo "Testing with database: '" . Yii::app()->db->connectionString . '\', ' . 'username: \'' . Yii::app()->db->username . "'.\n";
     if ($freeze && !$reuse) {
         if (!is_writable(sys_get_temp_dir())) {
             echo "\n\nTemp directory must be writable to store reusable schema\n";
             // Not Coding Standard
             echo "Temp directory: " . sys_get_temp_dir() . "\n\n";
             // Not Coding Standard
             exit;
         }
         InstallUtil::connectToDatabaseWithConnectionString(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password);
         echo "Auto building database schema...\n";
         InstallUtil::dropAllTables();
         Yii::app()->user->userModel = InstallUtil::createSuperUser('super', 'super');
         $messageLogger = new MessageLogger();
         InstallUtil::autoBuildDatabase($messageLogger);
         $messageLogger->printMessages();
         ReadPermissionsOptimizationUtil::rebuild();
         assert('RedBeanDatabase::isSetup()');
         echo "Saving auto built schema...\n";
         $schemaFile = sys_get_temp_dir() . '/autobuilt.sql';
         $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         assert('$success == 1');
         $databaseName = $matches[1];
         $systemOutput = system('mysqldump -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' ' . $databaseName . " > {$schemaFile}");
         if ($systemOutput != null) {
             echo 'Dumping schema using system command. Output: ' . $systemOutput . "\n\n";
         }
         InstallUtil::close();
         echo "Database closed.\n";
         assert('!RedBeanDatabase::isSetup()');
     }
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->setName("{$whatToTest} Tests");
     if (!$freeze) {
         self::buildAndAddSuiteFromDirectory($suite, 'Framework', COMMON_ROOT . '/protected/core/tests/unit', $whatToTest, true, false, $includeBenchmarks);
     }
     $moduleDirectoryName = COMMON_ROOT . '/protected/modules';
     if (is_dir($moduleDirectoryName)) {
         $moduleNames = scandir($moduleDirectoryName);
         foreach ($moduleNames as $moduleName) {
             if ($moduleName != '.' && $moduleName != '..') {
                 $moduleUnitTestDirectoryName = "{$moduleDirectoryName}/{$moduleName}/tests/unit";
                 self::buildAndAddSuiteFromDirectory($suite, $moduleName, $moduleUnitTestDirectoryName, $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
             }
         }
     }
     if (!$freeze) {
         self::buildAndAddSuiteFromDirectory($suite, 'Misc', COMMON_ROOT . '/protected/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
         self::buildAndAddSuiteFromDirectory($suite, 'Commands', COMMON_ROOT . '/protected/commands/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
         ////////////////////////////////////////////////////////////////////////////////
         // Temporary - See Readme.txt in the notSupposedToBeHere directory.
         self::buildAndAddSuiteFromDirectory($suite, 'BadDependencies', COMMON_ROOT . '/protected/tests/unit/notSupposedToBeHere', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
         ////////////////////////////////////////////////////////////////////////////////
     }
     if ($suite->count() == 0) {
         echo $usage;
         echo "  No tests found for '{$whatToTest}'.\n\n";
         exit;
     }
     return $suite;
 }