aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/Strategy/CompositeTest.php
blob: 8be422cc97b9123a35edc9fb0438f940553531da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

class HTMLPurifier_Strategy_Composite_Test
    extends HTMLPurifier_Strategy_Composite
{

    public function __construct(&$strategies) {
        $this->strategies =& $strategies;
    }

}

// doesn't use Strategy harness
class HTMLPurifier_Strategy_CompositeTest extends HTMLPurifier_Harness
{

    function test() {

        generate_mock_once('HTMLPurifier_Strategy');
        generate_mock_once('HTMLPurifier_Config');
        generate_mock_once('HTMLPurifier_Context');

        // setup a bunch of mock strategies to inject into our composite test

        $mock_1 = new HTMLPurifier_StrategyMock();
        $mock_2 = new HTMLPurifier_StrategyMock();
        $mock_3 = new HTMLPurifier_StrategyMock();

        // setup the object

        $strategies = array(&$mock_1, &$mock_2, &$mock_3);
        $composite = new HTMLPurifier_Strategy_Composite_Test($strategies);

        // setup expectations

        $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

        $config  = new HTMLPurifier_ConfigMock();
        $context = new HTMLPurifier_ContextMock();

        $params_1 = array($input_1, $config, $context);
        $params_2 = array($input_2, $config, $context);
        $params_3 = array($input_3, $config, $context);

        $mock_1->expectOnce('execute', $params_1);
        $mock_1->setReturnValue('execute', $input_2, $params_1);

        $mock_2->expectOnce('execute', $params_2);
        $mock_2->setReturnValue('execute', $input_3, $params_2);

        $mock_3->expectOnce('execute', $params_3);
        $mock_3->setReturnValue('execute', $input_4, $params_3);

        // perform test

        $output = $composite->execute($input_1, $config, $context);
        $this->assertIdentical($input_4, $output);

    }

}

// vim: et sw=4 sts=4