PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

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