2007-06-18 03:05:18 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
|
2007-06-18 03:05:18 +00:00
|
|
|
{
|
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
protected $language, $generator, $line;
|
|
|
|
protected $collector;
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function setup() {
|
2007-06-25 00:48:26 +00:00
|
|
|
generate_mock_once('HTMLPurifier_Language');
|
2007-06-26 02:49:21 +00:00
|
|
|
generate_mock_once('HTMLPurifier_Generator');
|
2008-05-26 04:05:48 +00:00
|
|
|
parent::setup();
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->language = new HTMLPurifier_LanguageMock();
|
|
|
|
$this->language->setReturnValue('getErrorName', 'Error', array(E_ERROR));
|
|
|
|
$this->language->setReturnValue('getErrorName', 'Warning', array(E_WARNING));
|
|
|
|
$this->language->setReturnValue('getErrorName', 'Notice', array(E_NOTICE));
|
|
|
|
// this might prove to be troublesome if we need to set config
|
|
|
|
$this->generator = new HTMLPurifier_Generator($this->config, $this->context);
|
|
|
|
$this->line = false;
|
|
|
|
$this->context->register('Locale', $this->language);
|
|
|
|
$this->context->register('CurrentLine', $this->line);
|
|
|
|
$this->context->register('Generator', $this->generator);
|
|
|
|
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
|
2007-06-25 00:48:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:05:18 +00:00
|
|
|
function test() {
|
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$language = $this->language;
|
|
|
|
$language->setReturnValue('getMessage', 'Message 1', array('message-1'));
|
|
|
|
$language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param')));
|
2007-06-25 00:48:26 +00:00
|
|
|
$language->setReturnValue('formatMessage', ' at line 23', array('ErrorCollector: At line', array('line' => 23)));
|
2008-08-16 04:41:34 +00:00
|
|
|
$language->setReturnValue('formatMessage', ' at line 3', array('ErrorCollector: At line', array('line' => 3)));
|
2007-06-26 02:49:21 +00:00
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->line = 23;
|
|
|
|
$this->collector->send(E_ERROR, 'message-1');
|
2007-06-25 01:08:57 +00:00
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->line = 3;
|
|
|
|
$this->collector->send(E_WARNING, 'message-2', 'param');
|
2007-06-18 03:05:18 +00:00
|
|
|
|
|
|
|
$result = array(
|
2008-08-16 04:41:34 +00:00
|
|
|
0 => array(23, E_ERROR, 'Message 1', array()),
|
|
|
|
1 => array(3, E_WARNING, 'Message 2', array())
|
2007-06-18 03:05:18 +00:00
|
|
|
);
|
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical($this->collector->getRaw(), $result);
|
2007-06-18 03:05:18 +00:00
|
|
|
|
2007-06-25 00:48:26 +00:00
|
|
|
$formatted_result =
|
2007-06-27 02:03:15 +00:00
|
|
|
'<ul><li><strong>Warning</strong>: Message 2 at line 3</li>'.
|
|
|
|
'<li><strong>Error</strong>: Message 1 at line 23</li></ul>';
|
2007-06-18 03:05:18 +00:00
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
|
2007-06-24 23:20:35 +00:00
|
|
|
|
2007-06-25 00:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoErrors() {
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors'));
|
2007-06-25 01:08:57 +00:00
|
|
|
|
2007-06-25 00:48:26 +00:00
|
|
|
$formatted_result = '<p>No errors</p>';
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical(
|
|
|
|
$this->collector->getHTMLFormatted($this->config),
|
|
|
|
$formatted_result
|
|
|
|
);
|
2007-06-25 00:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoLineNumbers() {
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
|
|
|
|
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
|
2007-06-25 01:08:57 +00:00
|
|
|
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->collector->send(E_ERROR, 'message-1');
|
|
|
|
$this->collector->send(E_ERROR, 'message-2');
|
2007-06-24 23:20:35 +00:00
|
|
|
|
2007-06-25 00:48:26 +00:00
|
|
|
$result = array(
|
2008-08-16 04:41:34 +00:00
|
|
|
0 => array(false, E_ERROR, 'Message 1', array()),
|
|
|
|
1 => array(false, E_ERROR, 'Message 2', array())
|
2007-06-25 00:48:26 +00:00
|
|
|
);
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical($this->collector->getRaw(), $result);
|
2007-06-18 03:05:18 +00:00
|
|
|
|
2007-06-25 00:48:26 +00:00
|
|
|
$formatted_result =
|
2007-06-27 02:03:15 +00:00
|
|
|
'<ul><li><strong>Error</strong>: Message 1</li>'.
|
|
|
|
'<li><strong>Error</strong>: Message 2</li></ul>';
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
|
2007-06-18 03:05:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-26 02:49:21 +00:00
|
|
|
function testContextSubstitutions() {
|
|
|
|
|
2007-06-26 19:33:37 +00:00
|
|
|
$current_token = false;
|
2008-05-26 04:05:48 +00:00
|
|
|
$this->context->register('CurrentToken', $current_token);
|
2007-06-26 19:33:37 +00:00
|
|
|
|
|
|
|
// 0
|
|
|
|
$current_token = new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 32);
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->language->setReturnValue('formatMessage', 'Token message',
|
2007-06-26 19:33:37 +00:00
|
|
|
array('message-data-token', array('CurrentToken' => $current_token)));
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->collector->send(E_NOTICE, 'message-data-token');
|
2007-06-26 19:33:37 +00:00
|
|
|
|
|
|
|
$current_attr = 'href';
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->language->setReturnValue('formatMessage', '$CurrentAttr.Name => $CurrentAttr.Value',
|
2007-06-26 19:33:37 +00:00
|
|
|
array('message-attr', array('CurrentToken' => $current_token)));
|
|
|
|
|
|
|
|
// 1
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->collector->send(E_NOTICE, 'message-attr'); // test when context isn't available
|
2007-06-26 02:49:21 +00:00
|
|
|
|
2007-06-26 19:33:37 +00:00
|
|
|
// 2
|
2008-05-26 04:05:48 +00:00
|
|
|
$this->context->register('CurrentAttr', $current_attr);
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->collector->send(E_NOTICE, 'message-attr');
|
2007-06-26 02:49:21 +00:00
|
|
|
|
|
|
|
$result = array(
|
2008-08-16 04:41:34 +00:00
|
|
|
0 => array(32, E_NOTICE, 'Token message', array()),
|
|
|
|
1 => array(32, E_NOTICE, '$CurrentAttr.Name => $CurrentAttr.Value', array()),
|
|
|
|
2 => array(32, E_NOTICE, 'href => http://example.com', array())
|
2007-06-26 02:49:21 +00:00
|
|
|
);
|
2008-08-16 04:41:34 +00:00
|
|
|
$this->assertIdentical($this->collector->getRaw(), $result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-05 21:25:35 +00:00
|
|
|
/*
|
2008-08-16 04:41:34 +00:00
|
|
|
function testNestedErrors() {
|
|
|
|
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
|
|
|
|
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
|
|
|
|
$this->language->setReturnValue('formatMessage', 'End Message', array('end-message', array(1 => 'param')));
|
|
|
|
$this->language->setReturnValue('formatMessage', ' at line 4', array('ErrorCollector: At line', array('line' => 4)));
|
|
|
|
|
|
|
|
$this->line = 4;
|
|
|
|
$this->collector->start();
|
|
|
|
$this->collector->send(E_WARNING, 'message-1');
|
|
|
|
$this->collector->send(E_NOTICE, 'message-2');
|
|
|
|
$this->collector->end(E_NOTICE, 'end-message', 'param');
|
|
|
|
|
|
|
|
$expect = array(
|
|
|
|
0 => array(4, E_NOTICE, 'End Message', array(
|
|
|
|
0 => array(4, E_WARNING, 'Message 1', array()),
|
|
|
|
1 => array(4, E_NOTICE, 'Message 2', array()),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
$result = $this->collector->getRaw();
|
|
|
|
$this->assertIdentical($result, $expect);
|
|
|
|
|
|
|
|
$formatted_expect =
|
|
|
|
'<ul><li><strong>Notice</strong>: End Message at line 4<ul>'.
|
|
|
|
'<li><strong>Warning</strong>: Message 1 at line 4</li>'.
|
|
|
|
'<li><strong>Notice</strong>: Message 2 at line 4</li></ul>'.
|
|
|
|
'</li></ul>';
|
|
|
|
$formatted_result = $this->collector->getHTMLFormatted($this->config);
|
|
|
|
$this->assertIdentical($formatted_result, $formatted_expect);
|
|
|
|
|
|
|
|
}
|
2008-09-05 21:25:35 +00:00
|
|
|
*/
|
2007-06-26 02:49:21 +00:00
|
|
|
|
2007-06-18 03:05:18 +00:00
|
|
|
}
|
|
|
|
|