aboutsummaryrefslogtreecommitdiffstats
path: root/tests/extension/manager_test.php
blob: 70c3543a69bb248176f673ff341cde41dafd606e (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
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/ext/bar/bar.php';
require_once dirname(__FILE__) . '/ext/moo/moo.php';

class phpbb_extension_manager_test extends phpbb_database_test_case
{
	protected $extension_manager;
	protected $class_loader;

	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml');
	}

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

		$this->extension_manager = new phpbb_extension_manager(
			$this->new_dbal(),
			'phpbb_ext',
			dirname(__FILE__) . '/',
			'.php',
			new phpbb_mock_cache
		);
	}

	public function test_available()
	{
		$this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_available()));
	}

	public function test_enabled()
	{
		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
	}

	public function test_configured()
	{
		$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
	}

	public function test_enable()
	{
		phpbb_ext_bar::$state = 0;

		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
		$this->extension_manager->enable('bar');
		$this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled()));
		$this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_configured()));

		$this->assertEquals(4, phpbb_ext_bar::$state);
	}

	public function test_disable()
	{
		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
		$this->extension_manager->disable('foo');
		$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled()));
		$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
	}

	public function test_purge()
	{
		phpbb_ext_moo::$purged = false;

		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
		$this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured()));
		$this->extension_manager->purge('moo');
		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
		$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured()));

		$this->assertTrue(phpbb_ext_moo::$purged);
	}
}