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.

83 lines
2.7KB

  1. <?php
  2. class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
  3. HTMLPurifier_AttrDef_CSS_Composite
  4. {
  5. // we need to pass by ref to get the mocks in
  6. public function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs)
  7. {
  8. $this->defs =& $defs;
  9. }
  10. }
  11. class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
  12. {
  13. protected $def1, $def2;
  14. public function test()
  15. {
  16. generate_mock_once('HTMLPurifier_AttrDef');
  17. $config = HTMLPurifier_Config::createDefault();
  18. $context = new HTMLPurifier_Context();
  19. // first test: value properly validates on first definition
  20. // so second def is never called
  21. $def1 = new HTMLPurifier_AttrDefMock();
  22. $def2 = new HTMLPurifier_AttrDefMock();
  23. $defs = array(&$def1, &$def2);
  24. $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
  25. $input = 'FOOBAR';
  26. $output = 'foobar';
  27. $def1_params = array($input, $config, $context);
  28. $def1->expectOnce('validate', $def1_params);
  29. $def1->setReturnValue('validate', $output, $def1_params);
  30. $def2->expectNever('validate');
  31. $result = $def->validate($input, $config, $context);
  32. $this->assertIdentical($output, $result);
  33. // second test, first def fails, second def works
  34. $def1 = new HTMLPurifier_AttrDefMock();
  35. $def2 = new HTMLPurifier_AttrDefMock();
  36. $defs = array(&$def1, &$def2);
  37. $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
  38. $input = 'BOOMA';
  39. $output = 'booma';
  40. $def_params = array($input, $config, $context);
  41. $def1->expectOnce('validate', $def_params);
  42. $def1->setReturnValue('validate', false, $def_params);
  43. $def2->expectOnce('validate', $def_params);
  44. $def2->setReturnValue('validate', $output, $def_params);
  45. $result = $def->validate($input, $config, $context);
  46. $this->assertIdentical($output, $result);
  47. // third test, all fail, so composite faiils
  48. $def1 = new HTMLPurifier_AttrDefMock();
  49. $def2 = new HTMLPurifier_AttrDefMock();
  50. $defs = array(&$def1, &$def2);
  51. $def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
  52. $input = 'BOOMA';
  53. $output = false;
  54. $def_params = array($input, $config, $context);
  55. $def1->expectOnce('validate', $def_params);
  56. $def1->setReturnValue('validate', false, $def_params);
  57. $def2->expectOnce('validate', $def_params);
  58. $def2->setReturnValue('validate', false, $def_params);
  59. $result = $def->validate($input, $config, $context);
  60. $this->assertIdentical($output, $result);
  61. }
  62. }
  63. // vim: et sw=4 sts=4