2012-07-28 14:59:55 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
2014-05-27 20:18:06 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2012-07-28 14:59:55 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-04-01 11:18:46 +02:00
|
|
|
class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
2012-07-28 14:59:55 -05:00
|
|
|
{
|
|
|
|
protected $class_loader;
|
|
|
|
protected $extension_manager;
|
2012-07-29 20:08:30 -05:00
|
|
|
|
|
|
|
protected $cache;
|
|
|
|
protected $config;
|
|
|
|
protected $db;
|
2014-06-28 13:36:17 +02:00
|
|
|
protected $db_tools;
|
|
|
|
protected $table_prefix;
|
2012-07-28 14:59:55 -05:00
|
|
|
protected $phpbb_root_path;
|
2012-07-29 20:08:30 -05:00
|
|
|
protected $phpEx;
|
2014-06-28 13:36:17 +02:00
|
|
|
protected $migrator;
|
2012-07-29 20:08:30 -05:00
|
|
|
protected $template;
|
|
|
|
protected $user;
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2012-07-29 20:08:30 -05:00
|
|
|
$this->cache = new phpbb_mock_cache();
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->config = new \phpbb\config\config(array(
|
2012-07-29 20:08:30 -05:00
|
|
|
'version' => '3.1.0',
|
|
|
|
));
|
|
|
|
$this->db = $this->new_dbal();
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->db_tools = new \phpbb\db\tools($this->db);
|
2012-07-28 14:59:55 -05:00
|
|
|
$this->phpbb_root_path = dirname(__FILE__) . '/';
|
2013-04-24 17:27:24 -05:00
|
|
|
$this->phpEx = 'php';
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->user = new \phpbb\user();
|
2013-02-13 21:12:50 -06:00
|
|
|
$this->table_prefix = 'phpbb_';
|
2012-07-29 20:08:30 -05:00
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->template = new \phpbb\template\twig\twig(
|
2013-09-26 15:34:44 +02:00
|
|
|
new \phpbb\path_helper(
|
2013-09-17 17:12:41 +02:00
|
|
|
new \phpbb\symfony_request(
|
2013-09-13 10:58:03 -05:00
|
|
|
new phpbb_mock_request()
|
|
|
|
),
|
2013-09-26 15:34:44 +02:00
|
|
|
new \phpbb\filesystem(),
|
2014-04-21 19:53:46 +02:00
|
|
|
$this->getMock('\phpbb\request\request'),
|
2013-09-13 10:58:03 -05:00
|
|
|
$this->phpbb_root_path,
|
|
|
|
$this->phpEx
|
|
|
|
),
|
2012-07-29 20:08:30 -05:00
|
|
|
$this->config,
|
|
|
|
$this->user,
|
2013-09-10 14:01:09 +02:00
|
|
|
new \phpbb\template\context()
|
2012-07-29 20:08:30 -05:00
|
|
|
);
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->migrator = new \phpbb\db\migrator(
|
2013-03-03 19:54:22 -06:00
|
|
|
$this->config,
|
|
|
|
$this->db,
|
|
|
|
$this->db_tools,
|
|
|
|
'phpbb_migrations',
|
|
|
|
$this->phpbb_root_path,
|
|
|
|
'php',
|
|
|
|
$this->table_prefix,
|
2014-02-05 09:57:36 -06:00
|
|
|
array(),
|
|
|
|
new \phpbb\db\migration\helper()
|
2013-03-03 19:54:22 -06:00
|
|
|
);
|
2013-05-01 14:09:08 -05:00
|
|
|
$container = new phpbb_mock_container_builder();
|
2014-06-28 13:36:17 +02:00
|
|
|
$container->set('migrator', $this->migrator);
|
2013-05-01 14:09:08 -05:00
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
$this->extension_manager = new \phpbb\extension\manager(
|
2013-05-01 14:09:08 -05:00
|
|
|
$container,
|
2012-07-30 13:36:51 -05:00
|
|
|
$this->db,
|
2012-07-29 20:08:30 -05:00
|
|
|
$this->config,
|
2013-09-26 15:34:44 +02:00
|
|
|
new \phpbb\filesystem(),
|
2014-05-12 02:31:52 +03:00
|
|
|
$this->user,
|
2012-07-28 14:59:55 -05:00
|
|
|
'phpbb_ext',
|
|
|
|
$this->phpbb_root_path,
|
2012-07-29 20:08:30 -05:00
|
|
|
$this->phpEx,
|
|
|
|
$this->cache
|
2012-07-28 14:59:55 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should fail from missing composer.json
|
|
|
|
public function test_bar()
|
|
|
|
{
|
2013-12-12 04:29:48 -08:00
|
|
|
$ext_name = 'vendor3/bar';
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2012-07-29 20:08:30 -05:00
|
|
|
$manager = $this->get_metadata_manager($ext_name);
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$manager->get_metadata();
|
|
|
|
}
|
2014-06-28 13:36:17 +02:00
|
|
|
catch (\phpbb\extension\exception $e)
|
|
|
|
{
|
|
|
|
$this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'));
|
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should be the same as a direct json_decode of the composer.json file
|
|
|
|
public function test_foo()
|
|
|
|
{
|
2013-12-12 04:29:48 -08:00
|
|
|
$ext_name = 'vendor2/foo';
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2012-07-29 20:08:30 -05:00
|
|
|
$manager = $this->get_metadata_manager($ext_name);
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$metadata = $manager->get_metadata();
|
|
|
|
}
|
2014-06-28 13:36:17 +02:00
|
|
|
catch (\phpbb\extension\exception $e)
|
2012-07-28 14:59:55 -05:00
|
|
|
{
|
|
|
|
$this->fail($e);
|
|
|
|
}
|
|
|
|
|
2013-12-12 04:29:48 -08:00
|
|
|
$json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/vendor2/foo/composer.json'), true);
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
$this->assertEquals($metadata, $json);
|
|
|
|
}
|
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
public function validator_non_existing_data()
|
2012-07-28 14:59:55 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
return array(
|
|
|
|
array('name'),
|
|
|
|
array('type'),
|
|
|
|
array('license'),
|
|
|
|
array('version'),
|
|
|
|
);
|
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider validator_non_existing_data
|
|
|
|
*/
|
|
|
|
public function test_validator_non_existing($field_name)
|
|
|
|
{
|
|
|
|
$manager = $this->get_metadata_manager('validator');
|
2012-07-28 14:59:55 -05:00
|
|
|
try
|
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
$manager->validate($field_name);
|
2012-08-27 17:39:32 -05:00
|
|
|
$this->fail('Exception not triggered');
|
|
|
|
}
|
2013-09-10 14:01:09 +02:00
|
|
|
catch(\phpbb\extension\exception $e)
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', $field_name));
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
2014-06-28 13:36:17 +02:00
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
public function test_validator_non_existing_authors()
|
|
|
|
{
|
|
|
|
$manager = $this->get_metadata_manager('validator');
|
2012-07-28 14:59:55 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$manager->validate_authors();
|
2012-08-27 17:39:32 -05:00
|
|
|
$this->fail('Exception not triggered');
|
|
|
|
}
|
2014-06-28 13:36:17 +02:00
|
|
|
catch (\phpbb\extension\exception $e)
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-05-12 02:17:37 +03:00
|
|
|
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors'));
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$manager->merge_metadata(array(
|
|
|
|
'authors' => array(
|
|
|
|
array(),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$manager->validate_authors();
|
2012-08-27 17:39:32 -05:00
|
|
|
$this->fail('Exception not triggered');
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
2014-06-28 13:36:17 +02:00
|
|
|
catch (\phpbb\extension\exception $e)
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-05-12 02:17:37 +03:00
|
|
|
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name'));
|
2012-08-27 17:39:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
public function validator_invalid_data()
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
return array(
|
|
|
|
array('name', 'asdf'),
|
|
|
|
array('type', 'asdf'),
|
|
|
|
array('license', ''),
|
|
|
|
array('version', ''),
|
|
|
|
);
|
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider validator_invalid_data
|
|
|
|
*/
|
|
|
|
public function test_validator_invalid($field_name, $field_value)
|
|
|
|
{
|
|
|
|
$manager = $this->get_metadata_manager('validator');
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
// Invalid data
|
|
|
|
$manager->set_metadata(array(
|
2014-06-28 13:36:17 +02:00
|
|
|
$field_name => $field_value,
|
2012-07-28 14:59:55 -05:00
|
|
|
));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
$manager->validate($field_name);
|
2012-08-27 17:39:32 -05:00
|
|
|
$this->fail('Exception not triggered');
|
|
|
|
}
|
2013-09-10 14:01:09 +02:00
|
|
|
catch(\phpbb\extension\exception $e)
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name));
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
2012-08-27 17:39:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_validator_valid()
|
|
|
|
{
|
|
|
|
$ext_name = 'validator';
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2012-08-27 17:39:32 -05:00
|
|
|
$manager = $this->get_metadata_manager($ext_name);
|
2012-07-28 14:59:55 -05:00
|
|
|
|
|
|
|
// Valid data
|
|
|
|
$manager->set_metadata(array(
|
|
|
|
'name' => 'test/foo',
|
2013-09-18 09:06:16 +01:00
|
|
|
'type' => 'phpbb-extension',
|
2014-03-27 23:27:30 -07:00
|
|
|
'license' => 'GPL v2',
|
2012-07-28 14:59:55 -05:00
|
|
|
'version' => '1.0.0',
|
|
|
|
));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->assertEquals(true, $manager->validate('enable'));
|
|
|
|
}
|
2013-09-10 14:01:09 +02:00
|
|
|
catch(\phpbb\extension\exception $e)
|
2012-07-28 14:59:55 -05:00
|
|
|
{
|
|
|
|
$this->fail($e);
|
|
|
|
}
|
2012-08-27 17:39:32 -05:00
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
public function validator_requirements_data()
|
2012-08-27 17:39:32 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'10.0.0',
|
|
|
|
'100.2.0',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
'Versions are not compared at the moment',
|
2014-06-28 13:06:46 +02:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
'5.3.0',
|
|
|
|
'3.1.0-beta',
|
|
|
|
true,
|
|
|
|
true,
|
2012-07-28 14:59:55 -05:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
'>' . phpversion(),
|
|
|
|
'>3.1.0',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
'Versions are not compared at the moment',
|
2012-07-28 14:59:55 -05:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
'<' . phpversion(),
|
|
|
|
'<3.1.0',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
'Versions are not compared at the moment',
|
2014-06-28 13:06:46 +02:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
phpversion(),
|
|
|
|
'3.1.0',
|
|
|
|
true,
|
|
|
|
true,
|
2012-07-28 14:59:55 -05:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
'>=' . phpversion(),
|
|
|
|
'>=3.1.0',
|
|
|
|
true,
|
|
|
|
true,
|
2014-06-28 13:06:46 +02:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
array(
|
|
|
|
'<=' . phpversion(),
|
|
|
|
'<=3.1.0',
|
|
|
|
true,
|
|
|
|
true,
|
2012-07-28 14:59:55 -05:00
|
|
|
),
|
2014-06-28 13:36:17 +02:00
|
|
|
);
|
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider validator_requirements_data
|
|
|
|
*/
|
|
|
|
public function test_validator_requirements($php_version, $phpbb_version, $expected_php, $expected_phpbb, $incomplete_reason = '')
|
|
|
|
{
|
|
|
|
if ($incomplete_reason)
|
2012-07-28 14:59:55 -05:00
|
|
|
{
|
2014-06-28 13:36:17 +02:00
|
|
|
$this->markTestIncomplete($incomplete_reason);
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
$ext_name = 'validator';
|
|
|
|
$manager = $this->get_metadata_manager($ext_name);
|
|
|
|
// Too high of requirements
|
2012-07-28 14:59:55 -05:00
|
|
|
$manager->merge_metadata(array(
|
|
|
|
'require' => array(
|
2014-06-28 13:36:17 +02:00
|
|
|
'php' => $php_version,
|
2014-06-28 13:06:46 +02:00
|
|
|
),
|
|
|
|
'extra' => array(
|
2014-07-02 16:23:20 +02:00
|
|
|
'soft-require' => array(
|
|
|
|
'phpbb/phpbb' => $phpbb_version, // config is set to 3.1.0
|
|
|
|
),
|
2012-07-28 14:59:55 -05:00
|
|
|
),
|
|
|
|
));
|
|
|
|
|
2014-06-28 13:36:17 +02:00
|
|
|
$this->assertEquals($expected_php, $manager->validate_require_php());
|
|
|
|
$this->assertEquals($expected_phpbb, $manager->validate_require_phpbb());
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|
2012-07-29 20:08:30 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an instance of the metadata manager
|
|
|
|
*
|
|
|
|
* @param string $ext_name
|
2013-04-04 21:36:32 +02:00
|
|
|
* @return phpbb_mock_metadata_manager
|
2012-07-29 20:08:30 -05:00
|
|
|
*/
|
|
|
|
private function get_metadata_manager($ext_name)
|
|
|
|
{
|
2013-04-04 21:36:32 +02:00
|
|
|
return new phpbb_mock_metadata_manager(
|
2012-07-29 20:08:30 -05:00
|
|
|
$ext_name,
|
2013-03-18 23:15:27 +01:00
|
|
|
$this->config,
|
2012-07-29 20:08:30 -05:00
|
|
|
$this->extension_manager,
|
|
|
|
$this->template,
|
2014-05-12 02:31:52 +03:00
|
|
|
$this->user,
|
2013-03-18 23:15:27 +01:00
|
|
|
$this->phpbb_root_path
|
2012-07-29 20:08:30 -05:00
|
|
|
);
|
|
|
|
}
|
2012-07-28 14:59:55 -05:00
|
|
|
}
|