Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / tests / phpunit / includes / TemplateParserTest.php
1 <?php
2
3 /**
4 * @group Templates
5 */
6 class TemplateParserTest extends MediaWikiTestCase {
7
8 protected $templateDir;
9
10 protected function setUp() {
11 parent::setUp();
12
13 $this->setMwGlobals( array(
14 'wgSecretKey' => 'foo',
15 'wgMemc' => new EmptyBagOStuff(),
16 ) );
17
18 $this->templateDir = dirname( __DIR__ ) . '/data/templates/';
19 }
20
21 /**
22 * @dataProvider provideProcessTemplate
23 * @covers TemplateParser::processTemplate
24 * @covers TemplateParser::getTemplate
25 * @covers TemplateParser::getTemplateFilename
26 */
27 public function testProcessTemplate( $name, $args, $result, $exception = false ) {
28 if ( $exception ) {
29 $this->setExpectedException( $exception );
30 }
31 $tp = new TemplateParser( $this->templateDir );
32 $this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
33 }
34
35 public static function provideProcessTemplate() {
36 return array(
37 array(
38 'foobar',
39 array(),
40 "hello world!\n"
41 ),
42 array(
43 'foobar_args',
44 array(
45 'planet' => 'world',
46 ),
47 "hello world!\n",
48 ),
49 array(
50 '../foobar',
51 array(),
52 false,
53 'UnexpectedValueException'
54 ),
55 array(
56 'nonexistenttemplate',
57 array(),
58 false,
59 'RuntimeException',
60 ),
61 array(
62 'has_partial',
63 array(
64 'planet' => 'world',
65 ),
66 "Partial hello world!\n in here\n",
67 ),
68 array(
69 'bad_partial',
70 array(),
71 false,
72 'Exception',
73 ),
74 );
75 }
76 }