PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/app/protected/tests/functional/TestSuite.php

https://bitbucket.org/ddonthula/zurmo
PHP | 749 lines | 713 code | 10 blank | 26 comment | 36 complexity | 76f5b7aed22bd0896e83d515f5e5745b MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
  24. * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
  25. ********************************************************************************/
  26. $basePath = realpath(dirname(__FILE__) . '/../../../');
  27. require_once('../PhpUnitServiceUtil.php');
  28. require_once 'File/Iterator.php';
  29. require_once('File/Iterator/Factory.php');
  30. if (is_file($basePath . '/protected/config/debugTest.php'))
  31. {
  32. require_once($basePath . '/protected/config/debugTest.php');
  33. }
  34. else
  35. {
  36. copy($basePath . '/protected/config/debugDIST.php', $basePath . '/protected/config/debugTest.php');
  37. die('Please configure functional tests in config file ' . $basePath . '/protected/config/debugTest.php');
  38. }
  39. define('SELENIUM_SERVER_PATH', $seleniumServerPath);
  40. define('TEST_BASE_URL', $seleniumTestBaseUrl);
  41. define('TEST_RESULTS_URL', $seleniumTestResultUrl);
  42. define('TEST_RESULTS_PATH', $seleniumTestResultsPath);
  43. //following is path to the user-extension.js, so as to enable the use of global variables
  44. define('USER_EXTENSIONS_JS_PATH', './assets/extensions/user-extensions.js');
  45. define('SELENIUM_SERVER_PORT', $seleniumServerPort);
  46. define('BROWSERS_TO_RUN', $seleniumBrowsersToRun);
  47. define('TEST_BASE_CONTROL_URL', $seleniumControlUrl);
  48. class TestSuite
  49. {
  50. public static function run()
  51. {
  52. global $argv, $argc;
  53. $usage = "\n" .
  54. " Usage: php [options] TestSuite.php <All|Misc|moduleName|TestClassName> [options]\n" .
  55. "\n" .
  56. " All Run all tests.\n" .
  57. " Framework Run all tests in framework/tests/functional.\n" .
  58. " Misc Run the test suites in app/protected/tests/functional.\n" .
  59. " moduleName Run the test suites in app/protected/modules/moduleName/tests/functional.\n" .
  60. " TestClassName Run the tests in TestClassName.html, wherever that happens to be.\n" .
  61. " options\n" .
  62. " -p port Example: -p4044\n" .
  63. " -h host Example: -hhttp://www.sitetotest/app/\n" .
  64. " -b browser <*firefox|*iexplore> if not specified, will run all in browsers \n" .
  65. " -c test server control url Example: -chttp://www.sitetotest/controlUrl.php\n" .
  66. " Example: -b*firefox \n" .
  67. " -userExtensions Example: -userExtensions pathToTheUserExtensionJS \n" .
  68. "\n" .
  69. " Examples:\n" .
  70. "\n" .
  71. " php TestSuiteSelenium.php accounts (Run the tests in the Accounts module.)\n" .
  72. " php TestSuiteSelenium.php RedBeanModelTest (Run the test suite RedBeanModelTest.html.)\n" .
  73. "\n" .
  74. " Note:\n" .
  75. "\n" ;
  76. PhpUnitServiceUtil::checkVersion();
  77. if ($argv[0] != 'TestSuite.php')
  78. {
  79. echo $usage;
  80. exit;
  81. }
  82. else
  83. {
  84. $whatToTest = $argv[1];
  85. }
  86. $whatToTestIsModuleDir = self::isWhatToTestAModule($whatToTest);
  87. $suiteNames = array();
  88. $htmlTestSuiteFiles = array();
  89. if ($whatToTest == 'All' || $whatToTest == 'Misc' || !$whatToTestIsModuleDir)
  90. {
  91. $compareToTest = $whatToTest;
  92. if ($whatToTest == 'Misc')
  93. {
  94. $compareToTest = null;
  95. }
  96. $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory($htmlTestSuiteFiles, '.', $compareToTest);
  97. }
  98. if ($whatToTest != 'Misc' && !$whatToTestIsModuleDir)
  99. {
  100. $compareToTest = $whatToTest;
  101. if ($whatToTest == 'Framework')
  102. {
  103. $compareToTest = null;
  104. }
  105. $frameworkTestSuiteDirectory = '../../core/tests/functional';
  106. $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory(
  107. $htmlTestSuiteFiles, $frameworkTestSuiteDirectory, $compareToTest);
  108. }
  109. $moduleDirectoryName = '../../modules';
  110. if (is_dir($moduleDirectoryName))
  111. {
  112. $moduleNames = scandir($moduleDirectoryName);
  113. foreach ($moduleNames as $moduleName)
  114. {
  115. if ($moduleName != '.' &&
  116. $moduleName != '..')
  117. {
  118. $moduleFunctionalTestDirectoryName = "$moduleDirectoryName/$moduleName/tests/functional";
  119. if (is_dir($moduleFunctionalTestDirectoryName))
  120. {
  121. if ($whatToTest == 'All' ||
  122. // Allow specifying 'Users' for the module name 'users'.
  123. $whatToTest == $moduleName ||
  124. strtolower($whatToTest) == $moduleName || !$whatToTestIsModuleDir)
  125. {
  126. if ($whatToTest == $moduleName || strtolower($whatToTest) == $moduleName)
  127. {
  128. $compareToTest = null;
  129. }
  130. else
  131. {
  132. $compareToTest = $whatToTest;
  133. }
  134. $htmlTestSuiteFiles = self::buildSuiteFromSeleneseDirectory(
  135. $htmlTestSuiteFiles, $moduleFunctionalTestDirectoryName, $compareToTest);
  136. }
  137. }
  138. }
  139. }
  140. }
  141. if (count($htmlTestSuiteFiles) == 0)
  142. {
  143. echo $usage;
  144. echo " No tests found for '$whatToTest'.\n\n";
  145. exit;
  146. }
  147. echo 'Suites to run:' . "\n";
  148. foreach ($htmlTestSuiteFiles as $pathToSuite)
  149. {
  150. if (in_array(basename($pathToSuite), $suiteNames))
  151. {
  152. echo 'Cannot run tests because there are 2 test suites with the same name.' . "\n";
  153. echo 'The duplicate found is here: ' . $pathToSuite . "\n";
  154. exit;
  155. }
  156. $suiteNames[] = basename($pathToSuite);
  157. echo $pathToSuite . "\n";
  158. }
  159. echo 'Running Test Suites using Selenium RC v2:' . "\n";
  160. $browsersToRun = self::resolveBrowserFromParameter();
  161. foreach ($browsersToRun as $browserId => $browserDisplayName)
  162. {
  163. self::clearPreviousTestResultsByServerAndBrowser(self::getServerByServerControlUrl(self::resolveHostFromParameterAndConstant()),
  164. $browserDisplayName);
  165. foreach ($htmlTestSuiteFiles as $pathToSuite)
  166. {
  167. if (!self::isInstallationTest($pathToSuite))
  168. {
  169. echo 'Restoring test db';
  170. self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restore'));
  171. echo "Restored test db";
  172. if (!self::isInstallationTest($pathToSuite))
  173. {
  174. echo 'Set user default time zone.';
  175. self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'setUserDefaultTimezone'));
  176. echo "User default time zone set.";
  177. }
  178. echo 'Clear cache on remote server';
  179. self::remoteAction(self::resolveHostFromParameterAndConstant(), array('clearCache' => '1',
  180. 'ignoreBrowserCheck' => '1'));
  181. }
  182. else
  183. {
  184. echo 'Uninstall zurmo';
  185. self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'backupRemovePerInstance'));
  186. }
  187. echo "Cache cleared";
  188. echo 'Running test suite: ';
  189. echo $pathToSuite . "\n";
  190. $host = self::resolveHostFromParameterAndConstant();
  191. $hostFilePart = str_replace('http://', '', $host);
  192. $hostFilePart = str_replace('https://', '', $hostFilePart);
  193. $hostFilePart = str_replace('/', '', $hostFilePart);
  194. $hostFilePart = $hostFilePart . '.';
  195. $testResultFileNamePrefix = str_replace('../', '', $pathToSuite);
  196. $testResultFileNamePrefix = str_replace('/', '.', $testResultFileNamePrefix);
  197. $testResultFileNamePrefix = str_replace('\\', '.', $testResultFileNamePrefix);
  198. $testResultFileNamePrefix = str_replace('..', '', $testResultFileNamePrefix);
  199. $testResultFileNamePrefix = str_replace('.html', '', $testResultFileNamePrefix);
  200. $testResultsFileName = $testResultFileNamePrefix . '.' . str_replace(' ', '', $browserDisplayName) . '.TestResults.html';
  201. $finalTestResultsPath = TEST_RESULTS_PATH . $hostFilePart . $testResultsFileName;
  202. $finalCommand = 'java -jar "' . SELENIUM_SERVER_PATH .'" ';
  203. $finalCommand .= '-port ' . self::resolvePortFromParameterAndConstant();
  204. $finalCommand .= ' -htmlSuite ' . $browserId . ' ';
  205. $finalCommand .= $host . ' ' . realPath($pathToSuite) . ' ' . $finalTestResultsPath;
  206. $finalCommand .= ' -userExtensions ' . self::resolveUserExtensionsJsFromParameterAndConstant();
  207. echo $finalCommand . "\n";
  208. exec($finalCommand);
  209. echo 'Restoring test db';
  210. self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restore'));
  211. if (self::isInstallationTest($pathToSuite))
  212. {
  213. self::remoteAction(self::resolveServerControlUrlFromParameterAndConstant(), array('action' => 'restorePerInstance'));
  214. }
  215. }
  216. }
  217. echo 'Functional Run Complete.' . "\n";
  218. self::updateTestResultsSummaryAndDetailsFiles();
  219. }
  220. public static function buildSuiteFromSeleneseDirectory($htmlTestSuiteFiles, $directoryName, $whatToTest = null)
  221. {
  222. $files = array_merge(
  223. self::getSeleneseFiles($directoryName, '.html')
  224. );
  225. foreach ($files as $file)
  226. {
  227. if (!strpos($file, 'TestSuite') === false)
  228. {
  229. if ( $whatToTest == null || $whatToTest == 'All' ||
  230. ($whatToTest . '.html' == basename($file) && $whatToTest != null))
  231. {
  232. $htmlTestSuiteFiles[] = $file;
  233. }
  234. }
  235. }
  236. return $htmlTestSuiteFiles;
  237. }
  238. /**
  239. * @param string $directory
  240. * @param string $suffix
  241. * @return array
  242. * @since Method available since Release 3.3.0
  243. */
  244. protected static function getSeleneseFiles($directory, $suffix)
  245. {
  246. $files = array();
  247. $iterator = File_Iterator_Factory::getFileIterator($directory, $suffix);
  248. foreach ($iterator as $file)
  249. {
  250. if (!in_array($file, $files))
  251. {
  252. $files[] = (string)$file;
  253. }
  254. }
  255. return $files;
  256. }
  257. /**
  258. * @return true if what to test is a module directory
  259. */
  260. protected static function isWhatToTestAModule($whatToTest)
  261. {
  262. $moduleDirectoryName = '../../modules';
  263. if (is_dir($moduleDirectoryName))
  264. {
  265. $moduleNames = scandir($moduleDirectoryName);
  266. foreach ($moduleNames as $moduleName)
  267. {
  268. if ($moduleName != '.' &&
  269. $moduleName != '..')
  270. {
  271. $moduleFunctionalTestDirectoryName = "$moduleDirectoryName/$moduleName/tests/functional";
  272. if (is_dir($moduleFunctionalTestDirectoryName))
  273. {
  274. if (// Allow specifying 'Users' for the module name 'users'.
  275. $whatToTest == $moduleName ||
  276. ucfirst($whatToTest) == $moduleName)
  277. {
  278. return true;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. return false;
  285. }
  286. protected static function resolvePortFromParameterAndConstant()
  287. {
  288. global $argv, $argc;
  289. for ($i = 0; $i < ($argc); $i++)
  290. {
  291. if (substr($argv[$i], 0, 2) == '-p')
  292. {
  293. return substr($argv[$i], 2);
  294. }
  295. }
  296. return SELENIUM_SERVER_PORT;
  297. }
  298. protected static function resolveHostFromParameterAndConstant()
  299. {
  300. global $argv, $argc;
  301. for ($i = 0; $i < ($argc); $i++)
  302. {
  303. if (substr($argv[$i], 0, 2) == '-h')
  304. {
  305. return substr($argv[$i], 2);
  306. }
  307. }
  308. return TEST_BASE_URL;
  309. }
  310. protected static function resolveServerControlUrlFromParameterAndConstant()
  311. {
  312. global $argv, $argc;
  313. for ($i = 0; $i < ($argc); $i++)
  314. {
  315. if (substr($argv[$i], 0, 2) == '-c')
  316. {
  317. return substr($argv[$i], 2);
  318. }
  319. }
  320. return TEST_BASE_CONTROL_URL;
  321. }
  322. protected static function resolveUserExtensionsJsFromParameterAndConstant()
  323. {
  324. global $argv, $argc;
  325. for ($i = 0; $i < ($argc); $i++)
  326. {
  327. if (substr($argv[$i], 0, 16) == '-userExtensions ')
  328. {
  329. return substr($argv[$i], 16);
  330. }
  331. }
  332. return USER_EXTENSIONS_JS_PATH;
  333. }
  334. protected static function resolveBrowserFromParameter()
  335. {
  336. global $argv, $argc;
  337. $browserData = self::getBrowsersData();
  338. for ($i = 0; $i < ($argc); $i++)
  339. {
  340. if (substr($argv[$i], 0, 2) == '-b')
  341. {
  342. $browsersToRun = substr($argv[$i], 2);
  343. if ($browsersToRun == BROWSERS_TO_RUN)
  344. {
  345. return $this->getBrowsersData();
  346. }
  347. if (!in_array($browsersToRun,
  348. array('*iexplore', '*firefox', '*googlechrome')))
  349. {
  350. echo 'Invalid Browser specified.' . "\n";
  351. echo 'Specified Browser: ' . $browsersToRun . "\n";
  352. exit;
  353. }
  354. foreach ($browserData as $id => $name)
  355. {
  356. if ($id == $browsersToRun)
  357. {
  358. return array($id => $name);
  359. }
  360. }
  361. }
  362. }
  363. return self::getBrowsersData();
  364. }
  365. protected static function getServerByServerControlUrl($url)
  366. {
  367. if (stristr($url, 'dev9.zurmo.com'))
  368. {
  369. return 'dev9.zurmo.com';
  370. }
  371. elseif (stristr($url, 'dev8.zurmo.com'))
  372. {
  373. return 'dev8.zurmo.com';
  374. }
  375. return 'Unknown';
  376. }
  377. protected static function getBrowsersData()
  378. {
  379. return array(
  380. '*firefox' => 'FireFox',
  381. '*iexplore' => 'Internet Explorer',
  382. '*googlechrome' => 'Chrome',
  383. );
  384. }
  385. protected static function updateTestResultsSummaryAndDetailsFiles()
  386. {
  387. $data = array();
  388. if (is_dir(TEST_RESULTS_PATH))
  389. {
  390. $resultsNames = scandir(TEST_RESULTS_PATH);
  391. foreach ($resultsNames as $resultFile)
  392. {
  393. if ($resultFile != '.' &&
  394. $resultFile != '..' &&
  395. $resultFile != 'Summary.html' &&
  396. $resultFile != 'Details.html')
  397. {
  398. $data[] = array(
  399. 'fileName' => $resultFile,
  400. 'modifiedDate' => date ("F d Y H:i:s.", filemtime(TEST_RESULTS_PATH . $resultFile)),
  401. 'status' => self::getResultFileStatusByFileName($resultFile),
  402. 'browser' => self::getResultFileBrowserByFileName($resultFile),
  403. 'server' => self::getResultServerByFileName($resultFile),
  404. );
  405. }
  406. }
  407. }
  408. self::makeResultsDetailsFile($data);
  409. self::makeResultsSummaryFile($data);
  410. }
  411. protected static function clearPreviousTestResultsByServerAndBrowser($server, $browserDisplayName)
  412. {
  413. if (is_dir(TEST_RESULTS_PATH))
  414. {
  415. $resultsNames = scandir(TEST_RESULTS_PATH);
  416. foreach ($resultsNames as $resultFile)
  417. {
  418. if ($resultFile != '.' &&
  419. $resultFile != '..' &&
  420. stristr($resultFile, strtolower($browserDisplayName)) &&
  421. stristr($resultFile, strtolower($server)))
  422. {
  423. unlink(TEST_RESULTS_PATH . $resultFile);
  424. }
  425. }
  426. }
  427. }
  428. protected static function getResultFileStatusByFileName($resultFile)
  429. {
  430. $contents = file_get_contents(TEST_RESULTS_PATH . $resultFile);
  431. $contents = str_replace('"', '', $contents);
  432. $contents = strtolower($contents);
  433. $pieces = explode('id=suitetable', $contents); // Not Coding Standard
  434. if (!empty($pieces[1]))
  435. {
  436. $pieces = explode('</table>', $pieces[1]);
  437. $pieces = explode('<tr class=title', $pieces[0]); // Not Coding Standard
  438. $pieces = explode('>', $pieces[1]);
  439. return trim($pieces[0]);
  440. }
  441. return 'Unknown';
  442. }
  443. protected static function getResultFileBrowserByFileName($resultFile)
  444. {
  445. if (stristr($resultFile, 'firefox'))
  446. {
  447. return 'Firefox';
  448. }
  449. elseif (stristr($resultFile, 'internetexplorer'))
  450. {
  451. return 'IE';
  452. }
  453. elseif (stristr($resultFile, 'chrome'))
  454. {
  455. return 'Chrome';
  456. }
  457. return 'Unknown';
  458. }
  459. protected static function getResultServerByFileName($resultFile)
  460. {
  461. if (stristr($resultFile, 'dev9.zurmo.com'))
  462. {
  463. return 'dev9.zurmo.com';
  464. }
  465. elseif (stristr($resultFile, 'dev8.zurmo.com'))
  466. {
  467. return 'dev8.zurmo.com';
  468. }
  469. return 'Unknown';
  470. }
  471. protected static function makeResultsDetailsFile($data)
  472. {
  473. $fileName = TEST_RESULTS_PATH . 'Details.html';
  474. $content = '<html>';
  475. $content .= '<table border="1" width="100%">' . "\n";
  476. $content .= '<tr>' . "\n";
  477. $content .= '<td>Status</td>' . "\n";
  478. $content .= '<td>Server</td>' . "\n";
  479. $content .= '<td>Browser</td>' . "\n";
  480. $content .= '<td>Date</td>' . "\n";
  481. $content .= '<td>File</td>' . "\n";
  482. $content .= '</tr>' . "\n";
  483. foreach ($data as $info)
  484. {
  485. $link = '<a href="' . TEST_RESULTS_URL . $info['fileName'] . '">' . $info['fileName'] . '</a>';
  486. $statusColor = 'bgcolor="red"';
  487. if ($info['status']=='status_passed')
  488. {
  489. $statusColor = 'bgcolor="green"';
  490. }
  491. $content .= '<tr>' . "\n";
  492. $content .= '<td ' . $statusColor . '>' . $info['status'] . '</td>' . "\n";
  493. $content .= '<td>' . $info['server'] . '</td>' . "\n";
  494. $content .= '<td>' . $info['browser'] . '</td>' . "\n";
  495. $content .= '<td>' . $info['modifiedDate'] . '</td>' . "\n";
  496. $content .= '<td>' . $link . '</td>' . "\n";
  497. $content .= '</tr>' . "\n";
  498. }
  499. $content .= '</table>' . "\n";
  500. $content .= '</html>' . "\n";
  501. if (is_writable(TEST_RESULTS_PATH))
  502. {
  503. if (!$handle = fopen($fileName, 'w'))
  504. {
  505. echo "Cannot open file ($fileName)";
  506. exit;
  507. }
  508. // Write $somecontent to our opened file.
  509. if (fwrite($handle, $content) === false)
  510. {
  511. echo "Cannot write to file ($fileName)";
  512. exit;
  513. }
  514. fclose($handle);
  515. }
  516. else
  517. {
  518. echo "The file $fileName is not writable";
  519. }
  520. }
  521. protected static function makeResultsSummaryFile($data)
  522. {
  523. $content = '<html>';
  524. $content .= '<table border="1" width="100%">' . "\n";
  525. $content .= '<tr>' . "\n";
  526. $content .= '<td>Status</td>' . "\n";
  527. $content .= '<td>Server</td>' . "\n";
  528. $content .= '<td>Browser</td>' . "\n";
  529. $content .= '<td>Date</td>' . "\n";
  530. $content .= '<td>Test Passed</td>' . "\n";
  531. $content .= '<td>Tests Failed</td>' . "\n";
  532. $content .= '<td>Details</td>' . "\n";
  533. $content .= '</tr>' . "\n";
  534. $link = '<a href="' . TEST_RESULTS_URL . 'Details.html">Details</a>';
  535. $allBrowsersStats = array();
  536. foreach ($data as $info)
  537. {
  538. if (count($allBrowsersStats) == 0 || !in_array($info['browser'], $allBrowsersStats))
  539. {
  540. $allBrowsersStats[$info['server']][$info['browser']] = array();
  541. $allBrowsersStats[$info['server']][$info['browser']]['testsPassed'] = 0;
  542. $allBrowsersStats[$info['server']][$info['browser']]['testsFailed'] = 0;
  543. $allBrowsersStats[$info['server']][$info['browser']]['modifiedDate'] = 0;
  544. }
  545. }
  546. foreach ($data as $info)
  547. {
  548. if ($info['status']=='status_passed')
  549. {
  550. $allBrowsersStats[$info['server']][$info['browser']]['testsPassed']++;
  551. }
  552. else
  553. {
  554. $allBrowsersStats[$info['server']][$info['browser']]['testsFailed']++;
  555. }
  556. if (strtotime($allBrowsersStats[$info['server']][$info['browser']]['modifiedDate']) < strtotime($info['modifiedDate']))
  557. {
  558. $allBrowsersStats[$info['server']][$info['browser']]['modifiedDate'] = $info['modifiedDate'];
  559. }
  560. }
  561. foreach ($allBrowsersStats as $server => $serverStats)
  562. {
  563. foreach ($serverStats as $browser => $browserStats)
  564. {
  565. if ($browserStats['testsFailed'] > 0 || $browserStats['testsPassed'] <= 0)
  566. {
  567. $status = 'status_failed';
  568. }
  569. else
  570. {
  571. $status = 'status_passed';
  572. }
  573. $statusColor = 'bgcolor="red"';
  574. if ($status == 'status_passed')
  575. {
  576. $statusColor = 'bgcolor="green"';
  577. }
  578. $content .= '<tr>' . "\n";
  579. $content .= '<td ' . $statusColor . '>' . $status . '</td>' . "\n";
  580. $content .= '<td>' . $server . '</td>' . "\n";
  581. $content .= '<td>' . $browser . '</td>' . "\n";
  582. $content .= '<td>' . $browserStats['modifiedDate'] . '</td>' . "\n";
  583. $content .= '<td>' . $browserStats['testsPassed'] . '</td>' . "\n";
  584. $content .= '<td>' . $browserStats['testsFailed'] . '</td>' . "\n";
  585. $content .= '<td>' . $link . '</td>' . "\n";
  586. $content .= '</tr>' . "\n";
  587. }
  588. }
  589. $content .= '</table>' . "\n";
  590. $content .= '</html>' . "\n";
  591. $fileName = TEST_RESULTS_PATH . 'Summary.html';
  592. if (is_writable(TEST_RESULTS_PATH))
  593. {
  594. if (!$handle = fopen($fileName, 'w'))
  595. {
  596. echo "Cannot open file ($fileName)";
  597. exit;
  598. }
  599. // Write $somecontent to our opened file.
  600. if (fwrite($handle, $content) === false)
  601. {
  602. echo "Cannot write to file ($fileName)";
  603. exit;
  604. }
  605. fclose($handle);
  606. }
  607. else
  608. {
  609. echo "The file $fileName is not writable";
  610. }
  611. }
  612. /**
  613. * Restore database
  614. * @param string url
  615. * @param string $action
  616. */
  617. protected static function remoteAction($url, $params)
  618. {
  619. if (!$url)
  620. {
  621. echo "Invalid db control url";
  622. exit;
  623. }
  624. if (isset($params['action']) && in_array($params['action'], array('restore', 'backupRemovePerInstance', 'restorePerInstance', 'setUserDefaultTimezone')))
  625. {
  626. $url = $url . "?action=" . urlencode($params['action']);
  627. }
  628. elseif (isset($params['clearCache']) && $params['clearCache'] == '1' &&
  629. isset($params['ignoreBrowserCheck']) && $params['ignoreBrowserCheck'] == '1')
  630. {
  631. $url = $url . "index.php/zurmo/default/login?clearCache=1&ignoreBrowserCheck=1"; // Not Coding Standard
  632. }
  633. else
  634. {
  635. echo "Invalid params";
  636. exit;
  637. }
  638. $ch = curl_init();
  639. curl_setopt($ch, CURLOPT_URL, $url);
  640. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  641. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  642. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
  643. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
  644. curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
  645. curl_exec($ch);
  646. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  647. $error_info = curl_error($ch);
  648. curl_close($ch);
  649. if ($httpcode == 200)
  650. {
  651. return true;
  652. }
  653. else
  654. {
  655. echo $error_info;
  656. exit;
  657. }
  658. }
  659. /**
  660. * Determine is suite is installation test suite.
  661. * @param string $path
  662. * @return boolen
  663. */
  664. protected static function isInstallationTest($path)
  665. {
  666. $position = strpos($path, 'InstallationTestSuite.html');
  667. if ($position !== false)
  668. {
  669. return true;
  670. }
  671. else
  672. {
  673. return false;
  674. }
  675. }
  676. /**
  677. * Determine is suite is actually default timezone test.
  678. * @param string $path
  679. * @return boolen
  680. */
  681. protected static function isDefaultTimeZoneTest($path)
  682. {
  683. $position = strpos($path, DIRECTORY_SEPARATOR . 'TestSuite.html');
  684. if ($position !== false)
  685. {
  686. return true;
  687. }
  688. else
  689. {
  690. return false;
  691. }
  692. }
  693. }
  694. $testRunner = new TestSuite();
  695. $testRunner->run();
  696. ?>