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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<?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__) . '/ext/vendor2/bar/ext.php';
require_once dirname(__FILE__) . '/ext/vendor2/foo/ext.php';
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.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 = $this->create_extension_manager();
}
public function test_available()
{
// barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure.
$this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_available()));
}
public function test_enabled()
{
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
}
public function test_configured()
{
$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
}
public function test_enable()
{
vendor2\bar\ext::$state = 0;
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
$this->extension_manager->enable('vendor2/bar');
$this->assertEquals(array('vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
$this->assertEquals(4, vendor2\bar\ext::$state);
}
public function test_disable()
{
vendor2\foo\ext::$disabled = false;
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
$this->extension_manager->disable('vendor2/foo');
$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
$this->assertTrue(vendor2\foo\ext::$disabled);
}
public function test_purge()
{
vendor\moo\ext::$purged = false;
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
$this->extension_manager->purge('vendor/moo');
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_configured()));
$this->assertTrue(vendor\moo\ext::$purged);
}
public function test_enabled_no_cache()
{
$extension_manager = $this->create_extension_manager(false);
$this->assertEquals(array('vendor2/foo'), array_keys($extension_manager->all_enabled()));
}
protected function create_extension_manager($with_cache = true)
{
$config = new \phpbb\config\config(array());
$db = $this->new_dbal();
$db_tools = new \phpbb\db\tools($db);
$phpbb_root_path = __DIR__ . './../../phpBB/';
$php_ext = 'php';
$table_prefix = 'phpbb_';
$migrator = new \phpbb\db\migrator(
$config,
$db,
$db_tools,
'phpbb_migrations',
$phpbb_root_path,
$php_ext,
$table_prefix,
array()
);
$container = new phpbb_mock_container_builder();
$container->set('migrator', $migrator);
return new \phpbb\extension\manager(
$container,
$db,
$config,
new \phpbb\filesystem(),
'phpbb_ext',
dirname(__FILE__) . '/',
$php_ext,
($with_cache) ? new phpbb_mock_cache() : null
);
}
}
|