Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

98 lines
2.5KB

  1. <?php
  2. /**
  3. * @note Sample input files are located in the StringHashParser/ directory.
  4. */
  5. class HTMLPurifier_StringHashParserTest extends UnitTestCase
  6. {
  7. /**
  8. * Instance of ConfigSchema_StringHashParser being tested.
  9. */
  10. protected $parser;
  11. public function setup()
  12. {
  13. $this->parser = new HTMLPurifier_StringHashParser();
  14. }
  15. /**
  16. * Assert that $file gets parsed into the form of $expect
  17. */
  18. protected function assertParse($file, $expect)
  19. {
  20. $result = $this->parser->parseFile(dirname(__FILE__) . '/StringHashParser/' . $file);
  21. $this->assertIdentical($result, $expect);
  22. }
  23. public function testSimple()
  24. {
  25. $this->assertParse('Simple.txt', array(
  26. 'ID' => 'Namespace.Directive',
  27. 'TYPE' => 'string',
  28. 'CHAIN-ME' => '2',
  29. 'DESCRIPTION' => "Multiline\nstuff\n",
  30. 'EMPTY' => '',
  31. 'FOR-WHO' => "Single multiline\n",
  32. ));
  33. }
  34. public function testOverrideSingle()
  35. {
  36. $this->assertParse('OverrideSingle.txt', array(
  37. 'KEY' => 'New',
  38. ));
  39. }
  40. public function testAppendMultiline()
  41. {
  42. $this->assertParse('AppendMultiline.txt', array(
  43. 'KEY' => "Line1\nLine2\n",
  44. ));
  45. }
  46. public function testDefault()
  47. {
  48. $this->parser->default = 'NEW-ID';
  49. $this->assertParse('Default.txt', array(
  50. 'NEW-ID' => 'DefaultValue',
  51. ));
  52. }
  53. public function testError()
  54. {
  55. try {
  56. $this->parser->parseFile('NoExist.txt');
  57. } catch (HTMLPurifier_ConfigSchema_Exception $e) {
  58. $this->assertIdentical($e->getMessage(), 'File NoExist.txt does not exist');
  59. }
  60. }
  61. public function testParseMultiple()
  62. {
  63. $result = $this->parser->parseMultiFile(dirname(__FILE__) . '/StringHashParser/Multi.txt');
  64. $this->assertIdentical(
  65. $result,
  66. array(
  67. array(
  68. 'ID' => 'Namespace.Directive',
  69. 'TYPE' => 'string',
  70. 'CHAIN-ME' => '2',
  71. 'DESCRIPTION' => "Multiline\nstuff\n",
  72. 'FOR-WHO' => "Single multiline\n",
  73. ),
  74. array(
  75. 'ID' => 'Namespace.Directive2',
  76. 'TYPE' => 'integer',
  77. 'CHAIN-ME' => '3',
  78. 'DESCRIPTION' => "M\nstuff\n",
  79. 'FOR-WHO' => "Single multiline2\n",
  80. )
  81. )
  82. );
  83. }
  84. }
  85. // vim: et sw=4 sts=4