summaryrefslogtreecommitdiff
path: root/tests/UnitTests/simpletest/test/xml_test.php
blob: afb3faf92ddeef0074fe00ef1145f26cbe7865f8 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
    // $Id: xml_test.php,v 1.16 2004/09/24 22:55:38 lastcraft Exp $
    
    require_once(dirname(__FILE__) . '/../xml.php');
    
    Mock::generate('SimpleScorer');
    
    if (! function_exists('xml_parser_create')) {
        SimpleTestOptions::ignore('TestOfXmlStructureParsing');
        SimpleTestOptions::ignore('TestOfXmlResultsParsing');
    }
    
    class TestOfNestingTags extends UnitTestCase {
        
        function testGroupSize() {
            $nesting = new NestingGroupTag(array('SIZE' => 2));
            $this->assertEqual($nesting->getSize(), 2);
        }
    }
    
    class TestOfXmlStructureParsing extends UnitTestCase {
        
        function testValidXml() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectNever('paintGroupStart');
            $listener->expectNever('paintGroupEnd');
            $listener->expectNever('paintCaseStart');
            $listener->expectNever('paintCaseEnd');
            $parser = &new SimpleTestXmlParser($listener);
            $this->assertTrue($parser->parse("<?xml version=\"1.0\"?>\n"));
            $this->assertTrue($parser->parse("<run>\n"));
            $this->assertTrue($parser->parse("</run>\n"));
        }
        
        function testEmptyGroup() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintGroupStart', array('a_group', 7));
            $listener->expectOnce('paintGroupEnd', array('a_group'));
            $parser = &new SimpleTestXmlParser($listener);
            $parser->parse("<?xml version=\"1.0\"?>\n");
            $parser->parse("<run>\n");
            $this->assertTrue($parser->parse("<group size=\"7\">\n"));
            $this->assertTrue($parser->parse("<name>a_group</name>\n"));
            $this->assertTrue($parser->parse("</group>\n"));
            $parser->parse("</run>\n");
            $listener->tally();
        }
        
        function testEmptyCase() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintCaseStart', array('a_case'));
            $listener->expectOnce('paintCaseEnd', array('a_case'));
            $parser = &new SimpleTestXmlParser($listener);
            $parser->parse("<?xml version=\"1.0\"?>\n");
            $parser->parse("<run>\n");
            $this->assertTrue($parser->parse("<case>\n"));
            $this->assertTrue($parser->parse("<name>a_case</name>\n"));
            $this->assertTrue($parser->parse("</case>\n"));
            $parser->parse("</run>\n");
            $listener->tally();
        }
        
        function testEmptyMethod() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintCaseStart', array('a_case'));
            $listener->expectOnce('paintCaseEnd', array('a_case'));
            $listener->expectOnce('paintMethodStart', array('a_method'));
            $listener->expectOnce('paintMethodEnd', array('a_method'));
            $parser = &new SimpleTestXmlParser($listener);
            $parser->parse("<?xml version=\"1.0\"?>\n");
            $parser->parse("<run>\n");
            $parser->parse("<case>\n");
            $parser->parse("<name>a_case</name>\n");
            $this->assertTrue($parser->parse("<test>\n"));
            $this->assertTrue($parser->parse("<name>a_method</name>\n"));
            $this->assertTrue($parser->parse("</test>\n"));
            $parser->parse("</case>\n");
            $parser->parse("</run>\n");
            $listener->tally();
        }
        
        function testNestedGroup() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectArgumentsAt(0, 'paintGroupStart', array('a_group', 7));
            $listener->expectArgumentsAt(1, 'paintGroupStart', array('b_group', 3));
            $listener->expectCallCount('paintGroupStart', 2);
            $listener->expectArgumentsAt(0, 'paintGroupEnd', array('b_group'));
            $listener->expectArgumentsAt(1, 'paintGroupEnd', array('a_group'));
            $listener->expectCallCount('paintGroupEnd', 2);
            $parser = &new SimpleTestXmlParser($listener);
            $parser->parse("<?xml version=\"1.0\"?>\n");
            $parser->parse("<run>\n");
            $this->assertTrue($parser->parse("<group size=\"7\">\n"));
            $this->assertTrue($parser->parse("<name>a_group</name>\n"));
            $this->assertTrue($parser->parse("<group size=\"3\">\n"));
            $this->assertTrue($parser->parse("<name>b_group</name>\n"));
            $this->assertTrue($parser->parse("</group>\n"));
            $this->assertTrue($parser->parse("</group>\n"));
            $parser->parse("</run>\n");
            $listener->tally();
        }
    }
    
    class AnyOldSignal {
        var $stuff = true;
    }
    
    class TestOfXmlResultsParsing extends UnitTestCase {
        
        function sendValidStart(&$parser) {
            $parser->parse("<?xml version=\"1.0\"?>\n");
            $parser->parse("<run>\n");
            $parser->parse("<case>\n");
            $parser->parse("<name>a_case</name>\n");
            $parser->parse("<test>\n");
            $parser->parse("<name>a_method</name>\n");
        }
        
        function sendValidEnd(&$parser) {
            $parser->parse("</test>\n");
            $parser->parse("</case>\n");
            $parser->parse("</run>\n");
        }
        
        function testPass() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintPass', array('a_message'));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse("<pass>a_message</pass>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
        
        function testFail() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintFail', array('a_message'));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse("<fail>a_message</fail>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
        
        function testException() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintException', array('a_message'));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse("<exception>a_message</exception>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
        
        function testSignal() {
            $signal = new AnyOldSignal();
            $signal->stuff = "Hello";
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintSignal', array('a_signal', $signal));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse(
                    "<signal type=\"a_signal\"><![CDATA[" .
                    serialize($signal) . "]]></signal>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
        
        function testMessage() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintMessage', array('a_message'));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse("<message>a_message</message>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
        
        function testFormattedMessage() {
            $listener = &new MockSimpleScorer($this);
            $listener->expectOnce('paintFormattedMessage', array("\na\tmessage\n"));
            $parser = &new SimpleTestXmlParser($listener);
            $this->sendValidStart($parser);
            $this->assertTrue($parser->parse("<formatted><![CDATA[\na\tmessage\n]]></formatted>\n"));
            $this->sendValidEnd($parser);
            $listener->tally();
        }
    }
?>