Current File : /home/jvzmxxx/wiki1/tests/phpunit/includes/TemplateParserTest.php
<?php

/**
 * @group Templates
 */
class TemplateParserTest extends MediaWikiTestCase {

	protected $templateDir;

	protected function setUp() {
		parent::setUp();

		$this->setMwGlobals( [
			'wgSecretKey' => 'foo',
		] );

		$this->templateDir = dirname( __DIR__ ) . '/data/templates/';
	}

	/**
	 * @dataProvider provideProcessTemplate
	 * @covers TemplateParser::processTemplate
	 * @covers TemplateParser::getTemplate
	 * @covers TemplateParser::getTemplateFilename
	 */
	public function testProcessTemplate( $name, $args, $result, $exception = false ) {
		if ( $exception ) {
			$this->setExpectedException( $exception );
		}
		$tp = new TemplateParser( $this->templateDir );
		$this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
	}

	public static function provideProcessTemplate() {
		return [
			[
				'foobar',
				[],
				"hello world!\n"
			],
			[
				'foobar_args',
				[
					'planet' => 'world',
				],
				"hello world!\n",
			],
			[
				'../foobar',
				[],
				false,
				'UnexpectedValueException'
			],
			[
				'nonexistenttemplate',
				[],
				false,
				'RuntimeException',
			],
			[
				'has_partial',
				[
					'planet' => 'world',
				],
				"Partial hello world!\n in here\n",
			],
			[
				'bad_partial',
				[],
				false,
				'Exception',
			],
		];
	}
}