ConfigSchemaTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
  3. {
  4. protected $schema;
  5. public function setup() {
  6. $this->schema = new HTMLPurifier_ConfigSchema();
  7. }
  8. function test_define() {
  9. $this->schema->add('Car.Seats', 5, 'int', false);
  10. $this->assertIdentical($this->schema->defaults['Car.Seats'], 5);
  11. $this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::INT);
  12. $this->schema->add('Car.Age', null, 'int', true);
  13. $this->assertIdentical($this->schema->defaults['Car.Age'], null);
  14. $this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::INT);
  15. }
  16. function test_defineAllowedValues() {
  17. $this->schema->add('QuantumNumber.Spin', 0.5, 'float', false);
  18. $this->schema->add('QuantumNumber.Current', 's', 'string', false);
  19. $this->schema->add('QuantumNumber.Difficulty', null, 'string', true);
  20. $this->schema->addAllowedValues( // okay, since default is null
  21. 'QuantumNumber.Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
  22. );
  23. $this->assertIdentical($this->schema->defaults['QuantumNumber.Difficulty'], null);
  24. $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->type, HTMLPurifier_VarParser::STRING);
  25. $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allow_null, true);
  26. $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allowed,
  27. array(
  28. 'easy' => true,
  29. 'medium' => true,
  30. 'hard' => true
  31. )
  32. );
  33. }
  34. function test_defineValueAliases() {
  35. $this->schema->add('Abbrev.HTH', 'Happy to Help', 'string', false);
  36. $this->schema->addAllowedValues(
  37. 'Abbrev.HTH', array(
  38. 'Happy to Help' => true,
  39. 'Hope that Helps' => true,
  40. 'HAIL THE HAND!' => true,
  41. )
  42. );
  43. $this->schema->addValueAliases(
  44. 'Abbrev.HTH', array(
  45. 'happy' => 'Happy to Help',
  46. 'hope' => 'Hope that Helps'
  47. )
  48. );
  49. $this->schema->addValueAliases( // delayed addition
  50. 'Abbrev.HTH', array(
  51. 'hail' => 'HAIL THE HAND!'
  52. )
  53. );
  54. $this->assertIdentical($this->schema->defaults['Abbrev.HTH'], 'Happy to Help');
  55. $this->assertIdentical($this->schema->info['Abbrev.HTH']->type, HTMLPurifier_VarParser::STRING);
  56. $this->assertIdentical($this->schema->info['Abbrev.HTH']->allowed,
  57. array(
  58. 'Happy to Help' => true,
  59. 'Hope that Helps' => true,
  60. 'HAIL THE HAND!' => true
  61. )
  62. );
  63. $this->assertIdentical($this->schema->info['Abbrev.HTH']->aliases,
  64. array(
  65. 'happy' => 'Happy to Help',
  66. 'hope' => 'Hope that Helps',
  67. 'hail' => 'HAIL THE HAND!'
  68. )
  69. );
  70. }
  71. function testAlias() {
  72. $this->schema->add('Home.Rug', 3, 'int', false);
  73. $this->schema->addAlias('Home.Carpet', 'Home.Rug');
  74. $this->assertTrue(!isset($this->schema->defaults['Home.Carpet']));
  75. $this->assertIdentical($this->schema->info['Home.Carpet']->key, 'Home.Rug');
  76. $this->assertIdentical($this->schema->info['Home.Carpet']->isAlias, true);
  77. }
  78. }
  79. // vim: et sw=4 sts=4