Make svn_log_limit more resilient against empty cache entries.
[xhtml-compiler.git] / tests / XHTMLCompiler / FilterManagerTest.php
blob2a61fa01b63e41c06ff0d8158f5d6674bc70b97f
1 <?php
3 class XHTMLCompiler_FilterManagerTest_DOMFilter extends XHTMLCompiler_DOMFilter
5 protected $name = 'Test';
6 function process(DOMDocument $dom, $page, $manager) {
7 $dom->getElementById('document')->appendChild($dom->createElement('p', 'DOMFilter'));
11 class XHTMLCompiler_FilterManagerTest extends UnitTestCase
14 function test_addFilter() {
15 $manager = new XHTMLCompiler_FilterManager();
16 $filter = new XHTMLCompiler_DOMFilterMock($this);
17 $filter->expectOnce('getName');
18 $filter->setReturnValue('getName', 'filter');
19 $filter->setReturnValue('getXCAttributesDefined', array());
20 $manager->addDOMFilter($filter);
21 $filter->tally();
24 function test_addFilter_Duplicate() {
25 $manager = new XHTMLCompiler_FilterManager();
26 $filter = new XHTMLCompiler_DOMFilterMock($this);
27 $filter->setReturnValue('getName', 'filter');
28 $filter->setReturnValue('getXCAttributesDefined', array());
29 $filter2 = new XHTMLCompiler_DOMFilterMock($this);
30 $filter2->setReturnValue('getName', 'filter');
31 $manager->addDOMFilter($filter);
32 $this->expectException();
33 $manager->addDOMFilter($filter2);
36 function test_process() {
37 $manager = new XHTMLCompiler_FilterManager();
38 $page = new XHTMLCompiler_PageMock();
39 $input = '1';
41 // using new IsAExpectation('XHTMLCompiler_FilterManager')
42 // since SimpleTest chokes on recursive dependencies
44 $pre_text_filter = new XHTMLCompiler_TextFilterMock($this);
45 $pre_text_filter->setReturnValue('getName', 'banana-filter');
46 $pre_text_filter->expectOnce('process', array('1', $page, new IsAExpectation('XHTMLCompiler_FilterManager')));
47 $pre_text_filter->setReturnValue('process', '2');
48 $pre_text_filter2 = new XHTMLCompiler_TextFilterMock($this);
49 $pre_text_filter2->setReturnValue('getName', 'apple-filter');
50 $pre_text_filter2->expectOnce('process', array('2', $page, new IsAExpectation('XHTMLCompiler_FilterManager')));
51 $pre_text_filter2->setReturnValue('process',
52 '<?xml version="1.0" encoding="UTF-8"?>
53 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
54 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
55 xmlns:proprietary="urn:foobar:foofoofoo">
56 <head><title>Hmmm...</title></head>
57 <body id="document"><p>Meta.</p></body>
58 </html>
59 ');
61 // the first two DOMFilters are duds that don't do anything
62 $dom_filter = new XHTMLCompiler_DOMFilterMock($this);
63 $dom_filter->setReturnValue('getName', 'filter');
64 $dom_filter->setReturnValue('getXCAttributesDefined', array());
65 $dom_filter->expectOnce('process');
66 $dom_filter2 = new XHTMLCompiler_DOMFilterMock($this);
67 $dom_filter2->setReturnValue('getName', 'filter2');
68 $dom_filter2->setReturnValue('getXCAttributesDefined', array());
69 $dom_filter2->expectOnce('process');
70 $dom_filter3 = new XHTMLCompiler_FilterManagerTest_DOMFilter();
72 $post_text_filter = new XHTMLCompiler_TextFilterMock($this);
73 $post_text_filter->setReturnValue('getName', 'Masumune Plus!');
74 $post_text_filter->expectOnce('process', array(new PatternExpectation('/Meta.+?DOMFilter/s'), $page, new IsAExpectation('XHTMLCompiler_FilterManager')));
75 $post_text_filter->setReturnValue('process', '3');
76 $post_text_filter2 = new XHTMLCompiler_TextFilterMock($this);
77 $post_text_filter2->setReturnValue('getName', 'Piffle-rockers');
78 $post_text_filter2->expectOnce('process', array('3', $page, new IsAExpectation('XHTMLCompiler_FilterManager')));
79 $post_text_filter2->setReturnValue('process',
80 '<?xml version="1.0" encoding="UTF-8"?>
81 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
82 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
83 <head><title>Hmmm...</title></head>
84 <body><b><p>Hotdog.</p></b></body>
85 </html>
86 ');
88 $manager->addPreTextFilter($pre_text_filter);
89 $manager->addPreTextFilter($pre_text_filter2);
90 $manager->addDOMFilter($dom_filter);
91 $manager->addDOMFilter($dom_filter2);
92 $manager->addDOMFilter($dom_filter3);
93 $manager->addPostTextFilter($post_text_filter);
94 $manager->addPostTextFilter($post_text_filter2);
96 $text = $manager->process('1', $page);
98 // assert that the final PostTextFilter worked
99 $this->assertPattern('/Hotdog/', $text);
101 // assert that the validation errors were caught and
102 // displayed accordingly
103 $this->assertPattern('/Error/i', $text);
105 // assert that all proprietary namespaces were scrubbed
106 $this->assertNoPattern('/proprietary/', $text);
108 $dom_filter->tally();
109 $dom_filter2->tally();
110 $pre_text_filter->tally();
111 $pre_text_filter2->tally();
112 $post_text_filter->tally();
113 $post_text_filter2->tally();