2006-07-29 17:38:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_Composite_Test
|
|
|
|
extends HTMLPurifier_Strategy_Composite
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
public function __construct(&$strategies) {
|
2006-07-29 17:38:28 +00:00
|
|
|
$this->strategies =& $strategies;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// doesn't use Strategy harness
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_Strategy_CompositeTest extends HTMLPurifier_Harness
|
2006-07-29 17:38:28 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
function test() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
generate_mock_once('HTMLPurifier_Strategy');
|
2006-08-04 01:47:48 +00:00
|
|
|
generate_mock_once('HTMLPurifier_Config');
|
2006-10-01 21:55:13 +00:00
|
|
|
generate_mock_once('HTMLPurifier_Context');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
// setup a bunch of mock strategies to inject into our composite test
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$mock_1 = new HTMLPurifier_StrategyMock();
|
|
|
|
$mock_2 = new HTMLPurifier_StrategyMock();
|
|
|
|
$mock_3 = new HTMLPurifier_StrategyMock();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
// setup the object
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-01 01:57:22 +00:00
|
|
|
$strategies = array(&$mock_1, &$mock_2, &$mock_3);
|
2006-07-29 17:38:28 +00:00
|
|
|
$composite = new HTMLPurifier_Strategy_Composite_Test($strategies);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
// setup expectations
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
$input_1 = 'This is raw data';
|
|
|
|
$input_2 = 'Processed by 1';
|
|
|
|
$input_3 = 'Processed by 1 and 2';
|
|
|
|
$input_4 = 'Processed by 1, 2 and 3'; // expected output
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$config = new HTMLPurifier_ConfigMock();
|
|
|
|
$context = new HTMLPurifier_ContextMock();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-01 20:47:07 +00:00
|
|
|
$params_1 = array($input_1, $config, $context);
|
|
|
|
$params_2 = array($input_2, $config, $context);
|
|
|
|
$params_3 = array($input_3, $config, $context);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
$mock_1->expectOnce('execute', $params_1);
|
|
|
|
$mock_1->setReturnValue('execute', $input_2, $params_1);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
$mock_2->expectOnce('execute', $params_2);
|
|
|
|
$mock_2->setReturnValue('execute', $input_3, $params_2);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
$mock_3->expectOnce('execute', $params_3);
|
|
|
|
$mock_3->setReturnValue('execute', $input_4, $params_3);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
// perform test
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-01 20:47:07 +00:00
|
|
|
$output = $composite->execute($input_1, $config, $context);
|
2006-07-29 17:38:28 +00:00
|
|
|
$this->assertIdentical($input_4, $output);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|