Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * All-use harness, use this rather than SimpleTest's
  4. */
  5. class HTMLPurifier_Harness extends UnitTestCase
  6. {
  7. public function __construct($name = null)
  8. {
  9. parent::__construct($name);
  10. }
  11. /**
  12. * @type HTMLPurifier_Config
  13. */
  14. protected $config;
  15. /**
  16. * @type HTMLPurifier_Context
  17. */
  18. protected $context;
  19. /**
  20. * @type HTMLPurifier
  21. */
  22. protected $purifier;
  23. /**
  24. * Generates easily accessible default config/context, as well as
  25. * a convenience purifier for integration testing.
  26. */
  27. public function setUp()
  28. {
  29. list($this->config, $this->context) = $this->createCommon();
  30. $this->config->set('Output.Newline', '
  31. ');
  32. $this->purifier = new HTMLPurifier();
  33. }
  34. /**
  35. * Asserts a purification. Good for integration testing.
  36. * @param string $input
  37. * @param string $expect
  38. */
  39. public function assertPurification($input, $expect = null)
  40. {
  41. if ($expect === null) {
  42. $expect = $input;
  43. }
  44. $result = $this->purifier->purify($input, $this->config);
  45. $this->assertIdentical($expect, $result);
  46. }
  47. /**
  48. * Accepts config and context and prepares them into a valid state
  49. * @param &$config Reference to config variable
  50. * @param &$context Reference to context variable
  51. */
  52. protected function prepareCommon(&$config, &$context)
  53. {
  54. $config = HTMLPurifier_Config::create($config);
  55. if (!$context) {
  56. $context = new HTMLPurifier_Context();
  57. }
  58. }
  59. /**
  60. * Generates default configuration and context objects
  61. * @return Defaults in form of array($config, $context)
  62. */
  63. protected function createCommon()
  64. {
  65. return array(HTMLPurifier_Config::createDefault(), new HTMLPurifier_Context);
  66. }
  67. /**
  68. * Normalizes a string to Unix (\n) endings
  69. */
  70. protected function normalize(&$string)
  71. {
  72. $string = str_replace(array("\r\n", "\r"), "\n", $string);
  73. }
  74. /**
  75. * If $expect is false, ignore $result and check if status failed.
  76. * Otherwise, check if $status if true and $result === $expect.
  77. * @param $status Boolean status
  78. * @param $result Mixed result from processing
  79. * @param $expect Mixed expectation for result
  80. */
  81. protected function assertEitherFailOrIdentical($status, $result, $expect)
  82. {
  83. if ($expect === false) {
  84. $this->assertFalse($status, 'Expected false result, got true');
  85. } else {
  86. $this->assertTrue($status, 'Expected true result, got false');
  87. $this->assertIdentical($result, $expect);
  88. }
  89. }
  90. public function getTests()
  91. {
  92. // __onlytest makes only one test get triggered
  93. foreach (get_class_methods(get_class($this)) as $method) {
  94. if (strtolower(substr($method, 0, 10)) == '__onlytest') {
  95. $this->reporter->paintSkip('All test methods besides ' . $method);
  96. return array($method);
  97. }
  98. }
  99. return parent::getTests();
  100. }
  101. }
  102. // vim: et sw=4 sts=4