Fix standards-compliance issue with YouTube filter with double hyphens.
[htmlpurifier/bfroehle.git] / tests / HTMLPurifier / ErrorCollectorTest.php
blob09becba53d41b14979a378000f5eb07da3570064
1 <?php
3 /**
4 * @warning HTML output is in flux, but eventually needs to be stabilized.
5 */
6 class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
9 protected $language, $generator, $line;
10 protected $collector;
12 public function setup() {
13 generate_mock_once('HTMLPurifier_Language');
14 generate_mock_once('HTMLPurifier_Generator');
15 parent::setup();
16 $this->language = new HTMLPurifier_LanguageMock();
17 $this->language->setReturnValue('getErrorName', 'Error', array(E_ERROR));
18 $this->language->setReturnValue('getErrorName', 'Warning', array(E_WARNING));
19 $this->language->setReturnValue('getErrorName', 'Notice', array(E_NOTICE));
20 // this might prove to be troublesome if we need to set config
21 $this->generator = new HTMLPurifier_Generator($this->config, $this->context);
22 $this->line = false;
23 $this->context->register('Locale', $this->language);
24 $this->context->register('CurrentLine', $this->line);
25 $this->context->register('Generator', $this->generator);
26 $this->collector = new HTMLPurifier_ErrorCollector($this->context);
29 function test() {
31 $language = $this->language;
32 $language->setReturnValue('getMessage', 'Message 1', array('message-1'));
33 $language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param')));
34 $language->setReturnValue('formatMessage', ' at line 23', array('ErrorCollector: At line', array('line' => 23)));
35 $language->setReturnValue('formatMessage', ' at line 3', array('ErrorCollector: At line', array('line' => 3)));
37 $this->line = 23;
38 $this->collector->send(E_ERROR, 'message-1');
40 $this->line = 3;
41 $this->collector->send(E_WARNING, 'message-2', 'param');
43 $result = array(
44 0 => array(23, E_ERROR, 'Message 1', array()),
45 1 => array(3, E_WARNING, 'Message 2', array())
48 $this->assertIdentical($this->collector->getRaw(), $result);
51 $formatted_result =
52 '<ul><li><strong>Warning</strong>: Message 2 at line 3</li>'.
53 '<li><strong>Error</strong>: Message 1 at line 23</li></ul>';
55 $this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
60 function testNoErrors() {
61 $this->language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors'));
63 $formatted_result = '<p>No errors</p>';
64 $this->assertIdentical(
65 $this->collector->getHTMLFormatted($this->config),
66 $formatted_result
70 function testNoLineNumbers() {
71 $this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
72 $this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
74 $this->collector->send(E_ERROR, 'message-1');
75 $this->collector->send(E_ERROR, 'message-2');
77 $result = array(
78 0 => array(false, E_ERROR, 'Message 1', array()),
79 1 => array(false, E_ERROR, 'Message 2', array())
81 $this->assertIdentical($this->collector->getRaw(), $result);
84 $formatted_result =
85 '<ul><li><strong>Error</strong>: Message 1</li>'.
86 '<li><strong>Error</strong>: Message 2</li></ul>';
87 $this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
91 function testContextSubstitutions() {
93 $current_token = false;
94 $this->context->register('CurrentToken', $current_token);
96 // 0
97 $current_token = new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 32);
98 $this->language->setReturnValue('formatMessage', 'Token message',
99 array('message-data-token', array('CurrentToken' => $current_token)));
100 $this->collector->send(E_NOTICE, 'message-data-token');
102 $current_attr = 'href';
103 $this->language->setReturnValue('formatMessage', '$CurrentAttr.Name => $CurrentAttr.Value',
104 array('message-attr', array('CurrentToken' => $current_token)));
106 // 1
107 $this->collector->send(E_NOTICE, 'message-attr'); // test when context isn't available
109 // 2
110 $this->context->register('CurrentAttr', $current_attr);
111 $this->collector->send(E_NOTICE, 'message-attr');
113 $result = array(
114 0 => array(32, E_NOTICE, 'Token message', array()),
115 1 => array(32, E_NOTICE, '$CurrentAttr.Name => $CurrentAttr.Value', array()),
116 2 => array(32, E_NOTICE, 'href => http://example.com', array())
118 $this->assertIdentical($this->collector->getRaw(), $result);
123 function testNestedErrors() {
124 $this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
125 $this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
126 $this->language->setReturnValue('formatMessage', 'End Message', array('end-message', array(1 => 'param')));
127 $this->language->setReturnValue('formatMessage', ' at line 4', array('ErrorCollector: At line', array('line' => 4)));
129 $this->line = 4;
130 $this->collector->start();
131 $this->collector->send(E_WARNING, 'message-1');
132 $this->collector->send(E_NOTICE, 'message-2');
133 $this->collector->end(E_NOTICE, 'end-message', 'param');
135 $expect = array(
136 0 => array(4, E_NOTICE, 'End Message', array(
137 0 => array(4, E_WARNING, 'Message 1', array()),
138 1 => array(4, E_NOTICE, 'Message 2', array()),
141 $result = $this->collector->getRaw();
142 $this->assertIdentical($result, $expect);
144 $formatted_expect =
145 '<ul><li><strong>Notice</strong>: End Message at line 4<ul>'.
146 '<li><strong>Warning</strong>: Message 1 at line 4</li>'.
147 '<li><strong>Notice</strong>: Message 2 at line 4</li></ul>'.
148 '</li></ul>';
149 $formatted_result = $this->collector->getHTMLFormatted($this->config);
150 $this->assertIdentical($formatted_result, $formatted_expect);
157 // vim: et sw=4 sts=4