Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ConfigSchemaTest.php 3.5KB

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