ConfigTest.php 22.9 KB
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
<?php

class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
{

    protected $schema;
    protected $oldFactory;

    public function setUp()
    {
        // set up a dummy schema object for testing
        $this->schema = new HTMLPurifier_ConfigSchema();
    }

    // test functionality based on ConfigSchema

    public function testNormal()
    {
        $this->schema->add('Element.Abbr', 'H', 'string', false);
        $this->schema->add('Element.Name', 'hydrogen', 'istring', false);
        $this->schema->add('Element.Number', 1, 'int', false);
        $this->schema->add('Element.Mass', 1.00794, 'float', false);
        $this->schema->add('Element.Radioactive', false, 'bool', false);
        $this->schema->add('Element.Isotopes', array(1 => true, 2 => true, 3 => true), 'lookup', false);
        $this->schema->add('Element.Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
        $this->schema->add('Element.IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
        $this->schema->add('Element.Object', new stdClass(), 'mixed', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        // test default value retrieval
        $this->assertIdentical($config->get('Element.Abbr'), 'H');
        $this->assertIdentical($config->get('Element.Name'), 'hydrogen');
        $this->assertIdentical($config->get('Element.Number'), 1);
        $this->assertIdentical($config->get('Element.Mass'), 1.00794);
        $this->assertIdentical($config->get('Element.Radioactive'), false);
        $this->assertIdentical($config->get('Element.Isotopes'), array(1 => true, 2 => true, 3 => true));
        $this->assertIdentical($config->get('Element.Traits'), array('nonmetallic', 'odorless', 'flammable'));
        $this->assertIdentical($config->get('Element.IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'));
        $this->assertIdentical($config->get('Element.Object'), new stdClass());

        // test setting values
        $config->set('Element.Abbr', 'Pu');
        $config->set('Element.Name', 'PLUTONIUM'); // test decaps
        $config->set('Element.Number', '94'); // test parsing
        $config->set('Element.Mass', '244.'); // test parsing
        $config->set('Element.Radioactive', true);
        $config->set('Element.Isotopes', array(238, 239)); // test inversion
        $config->set('Element.Traits', 'nuclear, heavy, actinide'); // test parsing
        $config->set('Element.IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
        $config->set('Element.Object', false); // unmodeled

        $this->expectError('Cannot set undefined directive Element.Metal to value');
        $config->set('Element.Metal', true);

        $this->expectError('Value for Element.Radioactive is of invalid type, should be bool');
        $config->set('Element.Radioactive', 'very');

        // test value retrieval
        $this->assertIdentical($config->get('Element.Abbr'), 'Pu');
        $this->assertIdentical($config->get('Element.Name'), 'plutonium');
        $this->assertIdentical($config->get('Element.Number'), 94);
        $this->assertIdentical($config->get('Element.Mass'), 244.);
        $this->assertIdentical($config->get('Element.Radioactive'), true);
        $this->assertIdentical($config->get('Element.Isotopes'), array(238 => true, 239 => true));
        $this->assertIdentical($config->get('Element.Traits'), array('nuclear', 'heavy', 'actinide'));
        $this->assertIdentical($config->get('Element.IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
        $this->assertIdentical($config->get('Element.Object'), false);

        $this->expectError('Cannot retrieve value of undefined directive Element.Metal');
        $config->get('Element.Metal');

    }

    public function testEnumerated()
    {
        // case sensitive
        $this->schema->add('Instrument.Manufacturer', 'Yamaha', 'string', false);
        $this->schema->addAllowedValues('Instrument.Manufacturer', array(
            'Yamaha' => true, 'Conn-Selmer' => true, 'Vandoren' => true,
            'Laubin' => true, 'Buffet' => true, 'other' => true));
        $this->schema->addValueAliases('Instrument.Manufacturer', array(
            'Selmer' => 'Conn-Selmer'));

        // case insensitive
        $this->schema->add('Instrument.Family', 'woodwind', 'istring', false);
        $this->schema->addAllowedValues('Instrument.Family', array(
            'brass' => true, 'woodwind' => true, 'percussion' => true,
            'string' => true, 'keyboard' => true, 'electronic' => true));
        $this->schema->addValueAliases('Instrument.Family', array(
            'synth' => 'electronic'));

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        // case sensitive

        $config->set('Instrument.Manufacturer', 'Vandoren');
        $this->assertIdentical($config->get('Instrument.Manufacturer'), 'Vandoren');

        $config->set('Instrument.Manufacturer', 'Selmer');
        $this->assertIdentical($config->get('Instrument.Manufacturer'), 'Conn-Selmer');

        $this->expectError('Value not supported, valid values are: Yamaha, Conn-Selmer, Vandoren, Laubin, Buffet, other');
        $config->set('Instrument.Manufacturer', 'buffet');

        // case insensitive

        $config->set('Instrument.Family', 'brass');
        $this->assertIdentical($config->get('Instrument.Family'), 'brass');

        $config->set('Instrument.Family', 'PERCUSSION');
        $this->assertIdentical($config->get('Instrument.Family'), 'percussion');

        $config->set('Instrument.Family', 'synth');
        $this->assertIdentical($config->get('Instrument.Family'), 'electronic');

        $config->set('Instrument.Family', 'Synth');
        $this->assertIdentical($config->get('Instrument.Family'), 'electronic');

    }

    public function testNull()
    {
        $this->schema->add('ReportCard.English', null, 'string', true);
        $this->schema->add('ReportCard.Absences', 0, 'int', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        $config->set('ReportCard.English', 'B-');
        $this->assertIdentical($config->get('ReportCard.English'), 'B-');

        $config->set('ReportCard.English', null); // not yet graded
        $this->assertIdentical($config->get('ReportCard.English'), null);

        // error
        $this->expectError('Value for ReportCard.Absences is of invalid type, should be int');
        $config->set('ReportCard.Absences', null);

    }

    public function testAliases()
    {
        $this->schema->add('Home.Rug', 3, 'int', false);
        $this->schema->addAlias('Home.Carpet', 'Home.Rug');

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        $this->assertIdentical($config->get('Home.Rug'), 3);

        $this->expectError('Cannot get value from aliased directive, use real name Home.Rug');
        $config->get('Home.Carpet');

        $this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug');
        $config->set('Home.Carpet', 999);
        $this->assertIdentical($config->get('Home.Rug'), 999);

    }

    // test functionality based on method

    public function test_getBatch()
    {
        $this->schema->add('Variables.TangentialAcceleration', 'a_tan', 'string', false);
        $this->schema->add('Variables.AngularAcceleration', 'alpha', 'string', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        // grab a namespace
        $this->assertIdentical(
            $config->getBatch('Variables'),
            array(
                'TangentialAcceleration' => 'a_tan',
                'AngularAcceleration' => 'alpha'
            )
        );

        // grab a non-existant namespace
        $this->expectError('Cannot retrieve undefined namespace Constants');
        $config->getBatch('Constants');

    }

    public function test_loadIni()
    {
        $this->schema->add('Shortcut.Copy', 'c', 'istring', false);
        $this->schema->add('Shortcut.Paste', 'v', 'istring', false);
        $this->schema->add('Shortcut.Cut', 'x', 'istring', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;

        $config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');

        $this->assertIdentical($config->get('Shortcut.Copy'), 'q');
        $this->assertIdentical($config->get('Shortcut.Paste'), 'p');
        $this->assertIdentical($config->get('Shortcut.Cut'), 't');

    }

    public function test_getHTMLDefinition()
    {
        // we actually want to use the old copy, because the definition
        // generation routines have dependencies on configuration values

        $config = HTMLPurifier_Config::createDefault();
        $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
        $config->autoFinalize = false;

        $def = $config->getCSSDefinition();
        $this->assertIsA($def, 'HTMLPurifier_CSSDefinition');

        $def  = $config->getHTMLDefinition();
        $def2 = $config->getHTMLDefinition();
        $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
        $this->assertTrue($def === $def2);
        $this->assertTrue($def->setup);

        $old_def = clone $def2;

        $config->set('HTML.Doctype', 'HTML 4.01 Transitional');
        $def = $config->getHTMLDefinition();
        $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
        $this->assertTrue($def !== $old_def);
        $this->assertTrue($def->setup);

    }

    public function test_getHTMLDefinition_deprecatedRawError()
    {
        $config = HTMLPurifier_Config::createDefault();
        $config->chatty = false;
        // test deprecated retrieval of raw definition
        $config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
        $config->set('HTML.DefinitionRev', 3);
        $this->expectError("Useless DefinitionID declaration");
        $def = $config->getHTMLDefinition(true);
        $this->assertEqual(false, $def->setup);

        // auto initialization
        $config->getHTMLDefinition();
        $this->assertTrue($def->setup);
    }

    public function test_getHTMLDefinition_optimizedRawError()
    {
        $this->expectException(new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"));
        $config = HTMLPurifier_Config::createDefault();
        $config->getHTMLDefinition(false, true);
    }

    public function test_getHTMLDefinition_rawAfterSetupError()
    {
        $this->expectException(new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup"));
        $config = HTMLPurifier_Config::createDefault();
        $config->chatty = false;
        $config->getHTMLDefinition();
        $config->getHTMLDefinition(true);
    }

    public function test_getHTMLDefinition_inconsistentOptimizedError()
    {
        $this->expectError("Useless DefinitionID declaration");
        $this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
        $config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError'));
        $config->chatty = false;
        $config->getHTMLDefinition(true, false);
        $config->getHTMLDefinition(true, true);
    }

    public function test_getHTMLDefinition_inconsistentOptimizedError2()
    {
        $this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
        $config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError2'));
        $config->chatty = false;
        $config->getHTMLDefinition(true, true);
        $config->getHTMLDefinition(true, false);
    }

    public function test_getHTMLDefinition_rawError()
    {
        $config = HTMLPurifier_Config::createDefault();
        $this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID'));
        $def = $config->getHTMLDefinition(true, true);
    }

    public function test_getCSSDefinition()
    {
        $config = HTMLPurifier_Config::createDefault();
        $def = $config->getCSSDefinition();
        $this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
    }

    public function test_getDefinition()
    {
        $this->schema->add('Cache.DefinitionImpl', null, 'string', true);
        $config = new HTMLPurifier_Config($this->schema);
        $this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
        $config->getDefinition('Crust');
    }

    public function test_loadArray()
    {
        // setup a few dummy namespaces/directives for our testing
        $this->schema->add('Zoo.Aadvark', 0, 'int', false);
        $this->schema->add('Zoo.Boar',    0, 'int', false);
        $this->schema->add('Zoo.Camel',   0, 'int', false);
        $this->schema->add('Zoo.Others', array(), 'list', false);

        $config_manual   = new HTMLPurifier_Config($this->schema);
        $config_loadabbr = new HTMLPurifier_Config($this->schema);
        $config_loadfull = new HTMLPurifier_Config($this->schema);

        $config_manual->set('Zoo.Aadvark', 3);
        $config_manual->set('Zoo.Boar', 5);
        $config_manual->set('Zoo.Camel', 2000); // that's a lotta camels!
        $config_manual->set('Zoo.Others', array('Peacock', 'Dodo')); // wtf!

        // condensed form
        $config_loadabbr->loadArray(array(
            'Zoo.Aadvark' => 3,
            'Zoo.Boar' => 5,
            'Zoo.Camel' => 2000,
            'Zoo.Others' => array('Peacock', 'Dodo')
        ));

        // fully expanded form
        $config_loadfull->loadArray(array(
            'Zoo' => array(
                'Aadvark' => 3,
                'Boar' => 5,
                'Camel' => 2000,
                'Others' => array('Peacock', 'Dodo')
            )
        ));

        $this->assertIdentical($config_manual, $config_loadabbr);
        $this->assertIdentical($config_manual, $config_loadfull);

    }

    public function test_create()
    {
        $this->schema->add('Cake.Sprinkles', 666, 'int', false);
        $this->schema->add('Cake.Flavor', 'vanilla', 'string', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->set('Cake.Sprinkles', 42);

        // test flat pass-through
        $created_config = HTMLPurifier_Config::create($config, $this->schema);
        $this->assertIdentical($config, $created_config);

        // test loadArray
        $created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42), $this->schema);
        $this->assertIdentical($config, $created_config);

        // test loadIni
        $created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini', $this->schema);
        $this->assertIdentical($config, $created_config);

    }

    public function test_finalize()
    {
        // test finalization

        $this->schema->add('Poem.Meter', 'iambic', 'string', false);

        $config = new HTMLPurifier_Config($this->schema);
        $config->autoFinalize = false;
        $config->chatty = false;

        $config->set('Poem.Meter', 'irregular');

        $config->finalize();

        $this->expectError('Cannot set directive after finalization');
        $config->set('Poem.Meter', 'vedic');

        $this->expectError('Cannot load directives after finalization');
        $config->loadArray(array('Poem.Meter' => 'octosyllable'));

        $this->expectError('Cannot load directives after finalization');
        $config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini');

    }

    public function test_loadArrayFromForm()
    {
        $this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
        $this->schema->add('Pancake.Served', true, 'bool', false);
        $this->schema->add('Toppings.Syrup', true, 'bool', false);
        $this->schema->add('Toppings.Flavor', 'maple', 'string', false);
        $this->schema->add('Toppings.Strawberries', 3, 'int', false);
        $this->schema->add('Toppings.Calories', 2000, 'int', true);
        $this->schema->add('Toppings.DefinitionID', null, 'string', true);
        $this->schema->add('Toppings.DefinitionRev', 1, 'int', false);
        $this->schema->add('Toppings.Protected', 1, 'int', false);

        $get = array(
            'breakfast' => array(
                'Pancake.Mix' => 'nasty',
                'Pancake.Served' => '0',
                'Toppings.Syrup' => '0',
                'Toppings.Flavor' => "juice",
                'Toppings.Strawberries' => '999',
                'Toppings.Calories' => '',
                'Null_Toppings.Calories' => '1',
                'Toppings.DefinitionID' => '<argh>',
                'Toppings.DefinitionRev' => '65',
                'Toppings.Protected' => '4',
            )
        );

        $config_expect = HTMLPurifier_Config::create(array(
            'Pancake.Served' => false,
            'Toppings.Syrup' => false,
            'Toppings.Flavor' => "juice",
            'Toppings.Strawberries' => 999,
            'Toppings.Calories' => null
        ), $this->schema);

        $config_result = HTMLPurifier_Config::loadArrayFromForm(
            $get, 'breakfast',
            array('Pancake.Served', 'Toppings', '-Toppings.Protected'),
            false, // mq fix
            $this->schema
        );

        $this->assertEqual($config_expect, $config_result);

        /*
        MAGIC QUOTES NOT TESTED!!!

        $get = array(
            'breakfast' => array(
                'Pancake.Mix' => 'n\\asty'
            )
        );
        $config_expect = HTMLPurifier_Config::create(array(
            'Pancake.Mix' => 'n\\asty'
        ));
        $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false);
        $this->assertEqual($config_expect, $config_result);
        */
    }

    public function test_getAllowedDirectivesForForm()
    {
        $this->schema->add('Unused.Unused', 'Foobar', 'string', false);
        $this->schema->add('Partial.Allowed', true, 'bool', false);
        $this->schema->add('Partial.Unused', 'Foobar', 'string', false);
        $this->schema->add('All.Allowed', true, 'bool', false);
        $this->schema->add('All.Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
        $this->schema->add('All.DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
        $this->schema->add('All.DefinitionRev', 2, 'int', false); // auto-blacklisted

        $input = array('Partial.Allowed', 'All', '-All.Blacklisted');
        $output = HTMLPurifier_Config::getAllowedDirectivesForForm($input, $this->schema);
        $expect = array(
            array('Partial', 'Allowed'),
            array('All', 'Allowed')
        );

        $this->assertEqual($output, $expect);

    }

    public function testDeprecatedAPI()
    {
        $this->schema->add('Foo.Bar', 2, 'int', false);
        $config = new HTMLPurifier_Config($this->schema);
        $config->chatty = false;
        $this->expectError('Using deprecated API: use $config->set(\'Foo.Bar\', ...) instead');
        $config->set('Foo', 'Bar', 4);
        $this->expectError('Using deprecated API: use $config->get(\'Foo.Bar\') instead');
        $this->assertIdentical($config->get('Foo', 'Bar'), 4);
    }

    public function testInherit()
    {
        $this->schema->add('Phantom.Masked', 25, 'int', false);
        $this->schema->add('Phantom.Unmasked', 89, 'int', false);
        $this->schema->add('Phantom.Latemasked', 11, 'int', false);
        $config = new HTMLPurifier_Config($this->schema);
        $config->set('Phantom.Masked', 800);
        $subconfig = HTMLPurifier_Config::inherit($config);
        $config->set('Phantom.Latemasked', 100, 'int', false);
        $this->assertIdentical($subconfig->get('Phantom.Masked'), 800);
        $this->assertIdentical($subconfig->get('Phantom.Unmasked'), 89);
        $this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
    }

    public function testSerialize()
    {
        $config = HTMLPurifier_Config::createDefault();
        $config->set('HTML.Allowed', 'a');
        $config2 = unserialize($config->serialize());
        $this->assertIdentical($config->get('HTML.Allowed'), $config2->get('HTML.Allowed'));
    }

    public function testDefinitionCachingNothing()
    {
        list($mock, $config) = $this->setupCacheMock('HTML');
        // should not touch the cache
        $mock->expectNever('get');
        $mock->expectNever('add');
        $mock->expectNever('set');
        $config->getDefinition('HTML', true);
        $config->getDefinition('HTML', true);
        $config->getDefinition('HTML');
        $this->teardownCacheMock();
    }

    public function testDefinitionCachingOptimized()
    {
        list($mock, $config) = $this->setupCacheMock('HTML');
        $mock->expectNever('set');
        $config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->testDefinitionCachingOptimized');
        $mock->expectOnce('get');
        $mock->setReturnValue('get', null);
        $this->assertTrue($config->maybeGetRawHTMLDefinition());
        $this->assertTrue($config->maybeGetRawHTMLDefinition());
        $mock->expectOnce('add');
        $config->getDefinition('HTML');
        $this->teardownCacheMock();
    }

    public function testDefinitionCachingOptimizedHit()
    {
        $fake_config = HTMLPurifier_Config::createDefault();
        $fake_def = $fake_config->getHTMLDefinition();
        list($mock, $config) = $this->setupCacheMock('HTML');
        // should never frob cache
        $mock->expectNever('add');
        $mock->expectNever('set');
        $config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->testDefinitionCachingOptimizedHit');
        $mock->expectOnce('get');
        $mock->setReturnValue('get', $fake_def);
        $this->assertNull($config->maybeGetRawHTMLDefinition());
        $config->getDefinition('HTML');
        $config->getDefinition('HTML');
        $this->teardownCacheMock();
    }

    protected function setupCacheMock($type)
    {
        // inject our definition cache mock globally (borrowed from
        // DefinitionFactoryTest)
        generate_mock_once("HTMLPurifier_DefinitionCacheFactory");
        $factory = new HTMLPurifier_DefinitionCacheFactoryMock();
        $this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
        HTMLPurifier_DefinitionCacheFactory::instance($factory);
        generate_mock_once("HTMLPurifier_DefinitionCache");
        $mock = new HTMLPurifier_DefinitionCacheMock();
        $config = HTMLPurifier_Config::createDefault();
        $factory->setReturnValue('create', $mock, array($type, $config));
        return array($mock, $config);
    }
    protected function teardownCacheMock()
    {
        HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
    }

}

// vim: et sw=4 sts=4