StringHashParserTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $this->parser = new HTMLPurifier_StringHashParser();
  13. }
  14. /**
  15. * Assert that $file gets parsed into the form of $expect
  16. */
  17. protected function assertParse($file, $expect) {
  18. $result = $this->parser->parseFile(dirname(__FILE__) . '/StringHashParser/' . $file);
  19. $this->assertIdentical($result, $expect);
  20. }
  21. function testSimple() {
  22. $this->assertParse('Simple.txt', array(
  23. 'ID' => 'Namespace.Directive',
  24. 'TYPE' => 'string',
  25. 'CHAIN-ME' => '2',
  26. 'DESCRIPTION' => "Multiline\nstuff\n",
  27. 'EMPTY' => '',
  28. 'FOR-WHO' => "Single multiline\n",
  29. ));
  30. }
  31. function testOverrideSingle() {
  32. $this->assertParse('OverrideSingle.txt', array(
  33. 'KEY' => 'New',
  34. ));
  35. }
  36. function testAppendMultiline() {
  37. $this->assertParse('AppendMultiline.txt', array(
  38. 'KEY' => "Line1\nLine2\n",
  39. ));
  40. }
  41. function testDefault() {
  42. $this->parser->default = 'NEW-ID';
  43. $this->assertParse('Default.txt', array(
  44. 'NEW-ID' => 'DefaultValue',
  45. ));
  46. }
  47. function testError() {
  48. try {
  49. $this->parser->parseFile('NoExist.txt');
  50. } catch (HTMLPurifier_ConfigSchema_Exception $e) {
  51. $this->assertIdentical($e->getMessage(), 'File NoExist.txt does not exist');
  52. }
  53. }
  54. function testParseMultiple() {
  55. $result = $this->parser->parseMultiFile(dirname(__FILE__) . '/StringHashParser/Multi.txt');
  56. $this->assertIdentical(
  57. $result,
  58. array(
  59. array(
  60. 'ID' => 'Namespace.Directive',
  61. 'TYPE' => 'string',
  62. 'CHAIN-ME' => '2',
  63. 'DESCRIPTION' => "Multiline\nstuff\n",
  64. 'FOR-WHO' => "Single multiline\n",
  65. ),
  66. array(
  67. 'ID' => 'Namespace.Directive2',
  68. 'TYPE' => 'integer',
  69. 'CHAIN-ME' => '3',
  70. 'DESCRIPTION' => "M\nstuff\n",
  71. 'FOR-WHO' => "Single multiline2\n",
  72. )
  73. )
  74. );
  75. }
  76. }
  77. // vim: et sw=4 sts=4