2011-06-09 05:13:26 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2011 phpBB Group
|
2012-01-02 17:14:00 +00:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2011-06-09 05:13:26 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-10-14 00:52:36 +02:00
|
|
|
require_once dirname(__FILE__) . '/ext/bar/ext.php';
|
2011-11-18 18:15:39 +01:00
|
|
|
require_once dirname(__FILE__) . '/ext/foo/ext.php';
|
2011-10-14 01:30:50 +02:00
|
|
|
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php';
|
2011-06-09 05:13:26 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2013-02-13 21:12:50 -06:00
|
|
|
$this->extension_manager = $this->create_extension_manager();
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_available()
|
|
|
|
{
|
2013-05-12 22:21:16 +02:00
|
|
|
$this->assertEquals(array('bar', 'barfoo', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available()));
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_enabled()
|
|
|
|
{
|
|
|
|
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_configured()
|
|
|
|
{
|
2011-10-14 01:30:50 +02:00
|
|
|
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_enable()
|
|
|
|
{
|
2011-10-14 00:52:36 +02:00
|
|
|
phpbb_ext_bar_ext::$state = 0;
|
2011-08-29 17:17:40 -04:00
|
|
|
|
2011-06-09 05:13:26 +02:00
|
|
|
$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()));
|
2011-10-14 01:30:50 +02:00
|
|
|
$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
|
2011-08-29 17:17:40 -04:00
|
|
|
|
2011-10-14 00:52:36 +02:00
|
|
|
$this->assertEquals(4, phpbb_ext_bar_ext::$state);
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_disable()
|
|
|
|
{
|
2011-11-18 18:15:39 +01:00
|
|
|
phpbb_ext_foo_ext::$disabled = false;
|
|
|
|
|
2011-06-09 05:13:26 +02:00
|
|
|
$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()));
|
2011-10-14 01:30:50 +02:00
|
|
|
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
|
2011-11-18 18:15:39 +01:00
|
|
|
|
|
|
|
$this->assertTrue(phpbb_ext_foo_ext::$disabled);
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_purge()
|
|
|
|
{
|
2011-10-14 01:30:50 +02:00
|
|
|
phpbb_ext_vendor_moo_ext::$purged = false;
|
2011-08-29 17:17:40 -04:00
|
|
|
|
2011-06-09 05:13:26 +02:00
|
|
|
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
|
2011-10-14 01:30:50 +02:00
|
|
|
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured()));
|
|
|
|
$this->extension_manager->purge('vendor/moo');
|
2011-06-09 05:13:26 +02:00
|
|
|
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled()));
|
|
|
|
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured()));
|
2011-08-29 17:17:40 -04:00
|
|
|
|
2011-10-14 01:30:50 +02:00
|
|
|
$this->assertTrue(phpbb_ext_vendor_moo_ext::$purged);
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|
2011-08-29 20:14:23 -04:00
|
|
|
|
|
|
|
public function test_enabled_no_cache()
|
|
|
|
{
|
2013-02-13 21:12:50 -06:00
|
|
|
$extension_manager = $this->create_extension_manager(false);
|
|
|
|
|
|
|
|
$this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled()));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function create_extension_manager($with_cache = true)
|
|
|
|
{
|
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
$config = new \phpbb\config\config(array());
|
2013-02-13 21:12:50 -06:00
|
|
|
$db = $this->new_dbal();
|
2013-09-10 14:01:09 +02:00
|
|
|
$db_tools = new \phpbb\db\tools($db);
|
2013-02-13 21:12:50 -06:00
|
|
|
$phpbb_root_path = __DIR__ . './../../phpBB/';
|
|
|
|
$php_ext = 'php';
|
|
|
|
$table_prefix = 'phpbb_';
|
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
$migrator = new \phpbb\db\migrator(
|
2013-03-02 11:37:58 -06:00
|
|
|
$config,
|
|
|
|
$db,
|
|
|
|
$db_tools,
|
|
|
|
'phpbb_migrations',
|
|
|
|
$phpbb_root_path,
|
|
|
|
$php_ext,
|
|
|
|
$table_prefix,
|
|
|
|
array()
|
|
|
|
);
|
2013-05-01 14:09:08 -05:00
|
|
|
$container = new phpbb_mock_container_builder();
|
|
|
|
$container->set('migrator', $migrator);
|
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
return new \phpbb\extension\manager(
|
2013-05-01 14:09:08 -05:00
|
|
|
$container,
|
2013-03-03 19:54:22 -06:00
|
|
|
$db,
|
|
|
|
$config,
|
2013-09-10 14:01:09 +02:00
|
|
|
new \phpbb\filesystem(),
|
2013-03-03 19:54:22 -06:00
|
|
|
'phpbb_ext',
|
|
|
|
dirname(__FILE__) . '/',
|
2013-04-24 17:41:27 -05:00
|
|
|
$php_ext,
|
2013-03-03 19:54:22 -06:00
|
|
|
($with_cache) ? new phpbb_mock_cache() : null
|
|
|
|
);
|
2011-08-29 20:14:23 -04:00
|
|
|
}
|
2011-06-09 05:13:26 +02:00
|
|
|
}
|