multitest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /** @file
  3. * Multiple PHP Versions test
  4. *
  5. * This file tests HTML Purifier in all versions of PHP. Arguments
  6. * are specified like --arg=opt, allowed arguments are:
  7. * - quiet (q), if specified no informative messages are enabled (please use
  8. * this if you're outputting XML)
  9. * - distro, allowed values 'normal' or 'standalone', by default all
  10. * distributions are tested. "--standalone" is a shortcut for
  11. * "--distro=standalone".
  12. * - quick, run only the most recent versions of each release series
  13. * - disable-flush, by default flush is run, this disables it
  14. * - file (f), xml, type: these correspond to the parameters in index.php
  15. *
  16. * @note
  17. * It requires a script called phpv that takes an extra argument (the
  18. * version number of PHP) before all other arguments. Contact me if you'd
  19. * like to set up a similar script. The name of the script can be
  20. * edited with $phpv
  21. *
  22. * @note
  23. * Also, configuration must be set up with a variable called
  24. * $versions_to_test specifying version numbers to pass to $phpv
  25. */
  26. define('HTMLPurifierTest', 1);
  27. chdir(dirname(__FILE__));
  28. $php = 'php'; // for safety
  29. require_once 'common.php';
  30. if (!SimpleReporter::inCli()) {
  31. echo 'Multitest only available from command line';
  32. exit;
  33. }
  34. $AC = array(); // parameters
  35. $AC['file'] = '';
  36. $AC['xml'] = false;
  37. $AC['quiet'] = false;
  38. $AC['php'] = $php;
  39. $AC['disable-phpt'] = false;
  40. $AC['disable-flush'] = false;
  41. $AC['type'] = '';
  42. $AC['distro'] = ''; // valid values are normal/standalone
  43. $AC['quick'] = false; // run the latest version on each release series
  44. $AC['standalone'] = false; // convenience for --distro=standalone
  45. // Legacy parameters
  46. $AC['only-phpt'] = false; // --type=phpt
  47. $AC['exclude-normal'] = false; // --distro=standalone
  48. $AC['exclude-standalone'] = false; // --distro=normal
  49. $AC['verbose'] = false;
  50. $aliases = array(
  51. 'f' => 'file',
  52. 'q' => 'quiet',
  53. 'v' => 'verbose',
  54. );
  55. htmlpurifier_parse_args($AC, $aliases);
  56. // Backwards compat extra parsing
  57. if ($AC['only-phpt']) {
  58. $AC['type'] = 'phpt';
  59. }
  60. if ($AC['exclude-normal']) $AC['distro'] = 'standalone';
  61. elseif ($AC['exclude-standalone']) $AC['distro'] = 'normal';
  62. elseif ($AC['standalone']) $AC['distro'] = 'standalone';
  63. if ($AC['xml']) {
  64. $reporter = new XmlReporter();
  65. } else {
  66. $reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
  67. }
  68. // Regenerate any necessary files
  69. if (!$AC['disable-flush']) htmlpurifier_flush($AC['php'], $reporter);
  70. $file_arg = '';
  71. require 'test_files.php';
  72. if ($AC['file']) {
  73. $test_files_lookup = array_flip($test_files);
  74. if (isset($test_files_lookup[$AC['file']])) {
  75. $file_arg = '--file=' . $AC['file'];
  76. } else {
  77. throw new Exception("Invalid file passed");
  78. }
  79. }
  80. // This allows us to get out of having to do dry runs.
  81. $size = count($test_files);
  82. $type_arg = '';
  83. if ($AC['type']) $type_arg = '--type=' . $AC['type'];
  84. if ($AC['quick']) {
  85. $seriesArray = array();
  86. foreach ($versions_to_test as $version) {
  87. $series = substr($version, 0, strpos($version, '.', strpos($version, '.') + 1));
  88. if (!isset($seriesArray[$series])) {
  89. $seriesArray[$series] = $version;
  90. continue;
  91. }
  92. if (version_compare($version, $seriesArray[$series], '>')) {
  93. $seriesArray[$series] = $version;
  94. }
  95. }
  96. $versions_to_test = array_values($seriesArray);
  97. }
  98. // Setup the test
  99. $test = new TestSuite('HTML Purifier Multiple Versions Test');
  100. foreach ($versions_to_test as $version) {
  101. // Support for arbitrarily forcing flushes by wrapping the suspect
  102. // version name in an array()
  103. $flush_arg = '';
  104. if (is_array($version)) {
  105. $version = $version[0];
  106. $flush_arg = '--flush';
  107. }
  108. if ($AC['type'] !== 'phpt') {
  109. $break = true;
  110. switch ($AC['distro']) {
  111. case '':
  112. $break = false;
  113. case 'normal':
  114. $test->add(
  115. new CliTestCase(
  116. "$phpv $version index.php --xml $flush_arg $type_arg --disable-phpt $file_arg",
  117. $AC['quiet'], $size
  118. )
  119. );
  120. if ($break) break;
  121. case 'standalone':
  122. $test->add(
  123. new CliTestCase(
  124. "$phpv $version index.php --xml $flush_arg $type_arg --standalone --disable-phpt $file_arg",
  125. $AC['quiet'], $size
  126. )
  127. );
  128. if ($break) break;
  129. }
  130. }
  131. if (!$AC['disable-phpt'] && (!$AC['type'] || $AC['type'] == 'phpt')) {
  132. $test->add(
  133. new CliTestCase(
  134. $AC['php'] . " index.php --xml --php \"$phpv $version\" --type=phpt",
  135. $AC['quiet'], $size
  136. )
  137. );
  138. }
  139. }
  140. // This is the HTML Purifier website's test XML file. We could
  141. // add more websites, i.e. more configurations to test.
  142. // $test->add(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1'));
  143. $test->run($reporter);
  144. // vim: et sw=4 sts=4