CompositeTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class HTMLPurifier_Strategy_Composite_Test
  3. extends HTMLPurifier_Strategy_Composite
  4. {
  5. public function __construct(&$strategies) {
  6. $this->strategies =& $strategies;
  7. }
  8. }
  9. // doesn't use Strategy harness
  10. class HTMLPurifier_Strategy_CompositeTest extends HTMLPurifier_Harness
  11. {
  12. function test() {
  13. generate_mock_once('HTMLPurifier_Strategy');
  14. generate_mock_once('HTMLPurifier_Config');
  15. generate_mock_once('HTMLPurifier_Context');
  16. // setup a bunch of mock strategies to inject into our composite test
  17. $mock_1 = new HTMLPurifier_StrategyMock();
  18. $mock_2 = new HTMLPurifier_StrategyMock();
  19. $mock_3 = new HTMLPurifier_StrategyMock();
  20. // setup the object
  21. $strategies = array(&$mock_1, &$mock_2, &$mock_3);
  22. $composite = new HTMLPurifier_Strategy_Composite_Test($strategies);
  23. // setup expectations
  24. $input_1 = 'This is raw data';
  25. $input_2 = 'Processed by 1';
  26. $input_3 = 'Processed by 1 and 2';
  27. $input_4 = 'Processed by 1, 2 and 3'; // expected output
  28. $config = new HTMLPurifier_ConfigMock();
  29. $context = new HTMLPurifier_ContextMock();
  30. $params_1 = array($input_1, $config, $context);
  31. $params_2 = array($input_2, $config, $context);
  32. $params_3 = array($input_3, $config, $context);
  33. $mock_1->expectOnce('execute', $params_1);
  34. $mock_1->setReturnValue('execute', $input_2, $params_1);
  35. $mock_2->expectOnce('execute', $params_2);
  36. $mock_2->setReturnValue('execute', $input_3, $params_2);
  37. $mock_3->expectOnce('execute', $params_3);
  38. $mock_3->setReturnValue('execute', $input_4, $params_3);
  39. // perform test
  40. $output = $composite->execute($input_1, $config, $context);
  41. $this->assertIdentical($input_4, $output);
  42. }
  43. }
  44. // vim: et sw=4 sts=4