Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / AttrValidator_ErrorsTest.php
blobeca491df83e6d0b600ad6ebb9b947edc16f7d5f7
1 <?php
3 class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
6 public function setup() {
7 parent::setup();
8 $config = HTMLPurifier_Config::createDefault();
9 $this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
10 $this->context->register('Locale', $this->language);
11 $this->collector = new HTMLPurifier_ErrorCollector($this->context);
12 $this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
15 protected function invoke($input) {
16 $validator = new HTMLPurifier_AttrValidator();
17 $validator->validateToken($input, $this->config, $this->context);
20 function testAttributesTransformedGlobalPre() {
21 $this->config->set('HTML.DefinitionID',
22 'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre');
23 $def = $this->config->getHTMLDefinition(true);
24 generate_mock_once('HTMLPurifier_AttrTransform');
25 $transform = new HTMLPurifier_AttrTransformMock();
26 $input = array('original' => 'value');
27 $output = array('class' => 'value'); // must be valid
28 $transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
29 $def->info_attr_transform_pre[] = $transform;
31 $token = new HTMLPurifier_Token_Start('span', $input, 1);
32 $this->invoke($token);
34 $result = $this->collector->getRaw();
35 $expect = array(
36 array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
38 $this->assertIdentical($result, $expect);
41 function testAttributesTransformedLocalPre() {
42 $this->config->set('HTML.TidyLevel', 'heavy');
43 $input = array('align' => 'right');
44 $output = array('style' => 'text-align:right;');
45 $token = new HTMLPurifier_Token_Start('p', $input, 1);
46 $this->invoke($token);
47 $result = $this->collector->getRaw();
48 $expect = array(
49 array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
51 $this->assertIdentical($result, $expect);
54 // too lazy to check for global post and global pre
56 function testAttributeRemoved() {
57 $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
58 $this->invoke($token);
59 $result = $this->collector->getRaw();
60 $expect = array(
61 array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
63 $this->assertIdentical($result, $expect);
68 // vim: et sw=4 sts=4