aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template/includephp_test.php
blob: a3dc9bd5c572121000616937e3ed4a20a166e230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/template_test_case.php';

class phpbb_template_includephp_test extends phpbb_template_template_test_case
{
	public function test_includephp_relative()
	{
		$this->setup_engine(array('tpl_allow_php' => true));

		$this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");

		$this->template->set_filenames(array('test' => 'includephp_relative.html'));
		$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
	}

	public function test_includephp_variables()
	{
		$this->setup_engine(array('tpl_allow_php' => true));

		$this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php");

		$this->template->set_filenames(array('test' => 'includephp_variables.html'));
		$this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
	}

	public function test_includephp_absolute()
	{
		global $phpbb_root_path;

		$path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc';
		$this->assertTrue(phpbb_is_absolute($path_to_php));
		$template_text = "Path is absolute.\n<!-- INCLUDEPHP $path_to_php -->";

		$cache_dir = dirname($phpbb_root_path . 'cache') . '/';
		$fp = fopen($cache_dir . 'includephp_absolute.html', 'w');
		fputs($fp, $template_text);
		fclose($fp);

		$this->setup_engine(array('tpl_allow_php' => true));

		$this->style->set_custom_style('tests', $cache_dir, array(), '');

		$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");

		$this->template->set_filenames(array('test' => 'includephp_absolute.html'));
		$this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
	}
}