MediaWiki REL1_30
TemplateParserTest.php
Go to the documentation of this file.
1<?php
2
7
8 protected $templateDir;
9
10 protected function setUp() {
11 parent::setUp();
12
13 $this->setMwGlobals( [
14 'wgSecretKey' => 'foo',
15 ] );
16
17 $this->templateDir = dirname( __DIR__ ) . '/data/templates/';
18 }
19
26 public function testProcessTemplate( $name, $args, $result, $exception = false ) {
27 if ( $exception ) {
28 $this->setExpectedException( $exception );
29 }
30 $tp = new TemplateParser( $this->templateDir );
31 $this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
32 }
33
34 public static function provideProcessTemplate() {
35 return [
36 [
37 'foobar',
38 [],
39 "hello world!\n"
40 ],
41 [
42 'foobar_args',
43 [
44 'planet' => 'world',
45 ],
46 "hello world!\n",
47 ],
48 [
49 '../foobar',
50 [],
51 false,
52 'UnexpectedValueException'
53 ],
54 [
55 "\000../foobar",
56 [],
57 false,
58 'UnexpectedValueException'
59 ],
60 [
61 '/',
62 [],
63 false,
64 'UnexpectedValueException'
65 ],
66 [
67 // Allegedly this can strip ext in windows.
68 'baz<',
69 [],
70 false,
71 'UnexpectedValueException'
72 ],
73 [
74 '\\foo',
75 [],
76 false,
77 'UnexpectedValueException'
78 ],
79 [
80 'C:\bar',
81 [],
82 false,
83 'UnexpectedValueException'
84 ],
85 [
86 "foo\000bar",
87 [],
88 false,
89 'UnexpectedValueException'
90 ],
91 [
92 'nonexistenttemplate',
93 [],
94 false,
95 'RuntimeException',
96 ],
97 [
98 'has_partial',
99 [
100 'planet' => 'world',
101 ],
102 "Partial hello world!\n in here\n",
103 ],
104 [
105 'bad_partial',
106 [],
107 false,
108 'Exception',
109 ],
110 ];
111 }
112
113 public function testEnableRecursivePartials() {
114 $tp = new TemplateParser( $this->templateDir );
115 $data = [ 'r' => [ 'r' => [ 'r' => [] ] ] ];
116
117 $tp->enableRecursivePartials( true );
118 $this->assertEquals( 'rrr', $tp->processTemplate( 'recurse', $data ) );
119
120 $tp->enableRecursivePartials( false );
121 $this->setExpectedException( 'Exception' );
122 $tp->processTemplate( 'recurse', $data );
123 }
124
125}
if( $line===false) $args
Definition cdb.php:63
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
testProcessTemplate( $name, $args, $result, $exception=false)
provideProcessTemplate TemplateParser::processTemplate TemplateParser::getTemplate TemplateParser::ge...