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