aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/metadata_manager_test.php
blob: c639cad80944947d8cccf0f0c68742501b378bc5 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';

/**
* @group functional
*/
class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
{
	protected $phpbb_extension_manager;

	static private $helpers;

	static protected $fixtures = array(
		'foo/bar/',
	);

	/**
	* This should only be called once before the tests are run.
	* This is used to copy the fixtures to the phpBB install
	*/
	static public function setUpBeforeClass()
	{
		global $phpbb_root_path;
		parent::setUpBeforeClass();

		self::$helpers = new phpbb_test_case_helpers(self);

		if (!file_exists($phpbb_root_path . 'ext/foo/bar/'))
		{
			self::$helpers->makedirs($phpbb_root_path . 'ext/foo/bar/');
		}

		foreach (self::$fixtures as $fixture)
		{
			self::$helpers->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture);
		}
	}

	/**
	* This should only be called once after the tests are run.
	* This is used to remove the fixtures from the phpBB install
	*/
	static public function tearDownAfterClass()
	{
		global $phpbb_root_path;

		foreach (self::$fixtures as $fixture)
		{
			self::$helpers->empty_dir($phpbb_root_path . 'ext/' . $fixture);
		}
		self::$helpers->empty_dir($phpbb_root_path . 'ext/foo/');
	}

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

		$this->phpbb_extension_manager = $this->get_extension_manager();

		$this->purge_cache();
		$this->phpbb_extension_manager->enable('foo/bar');

		$this->login();
		$this->admin_login();
		$this->add_lang('acp/extensions');
	}

	public function test_extensions_list()
	{
		$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
		$this->assert_response_success();

		$this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#page-body')->text());
		$this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#page-body')->text());
		$this->assertContains('Details', $crawler->filter('#page-body')->text());
	}

	public function test_extensions_details()
	{
		$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid);
		$this->assert_response_success();

		// Test whether the details are displayed
		$this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#page-body')->text());
		$this->assertContains('foo/bar', $crawler->filter('#page-body')->text());

		// Details should be html escaped
		$this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#page-body')->text());
		// The Crawler parses the text, so we can not see whether it was escaped anymore
		// To test this, we grab the content of the response directly
		// $this->assertContains('&gt;=5.3', $$crawler->filter('#page-body')->text());
		$this->assertContains('&gt;=5.3', $this->client->getResponse()->getContent());
	}

	public function test_extensions_details_notexists()
	{
		$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid);
		$this->assert_response_success();

		// Error message because the files do not exist
		$this->assertContains('The required file does not exist:', $crawler->filter('#page-body')->text());
	}
}