diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/config_php_file_test.php | 30 | ||||
| -rw-r--r-- | tests/di/create_container_test.php | 145 | ||||
| -rw-r--r-- | tests/di/fixtures/config/services.yml | 14 | ||||
| -rw-r--r-- | tests/di/fixtures/ext/vendor/available/config/services.yml | 2 | ||||
| -rw-r--r-- | tests/di/fixtures/ext/vendor/disabled/config/services.yml | 2 | ||||
| -rw-r--r-- | tests/di/fixtures/ext/vendor/enabled/config/services.yml | 2 | ||||
| -rw-r--r-- | tests/di/fixtures/other_config/services.yml | 14 | ||||
| -rw-r--r-- | tests/fixtures/config.php | 3 | ||||
| -rw-r--r-- | tests/fixtures/config_other.php | 3 | ||||
| -rw-r--r-- | tests/functional/mcp_test.php | 16 | ||||
| -rw-r--r-- | tests/functions/convert_30_dbms_to_31_test.php | 3 | ||||
| -rw-r--r-- | tests/mock/phpbb_di_container_builder.php | 20 | ||||
| -rw-r--r-- | tests/test_framework/phpbb_test_case_helpers.php | 20 | 
13 files changed, 235 insertions, 39 deletions
diff --git a/tests/config_php_file_test.php b/tests/config_php_file_test.php new file mode 100644 index 0000000000..c2e4eb21c7 --- /dev/null +++ b/tests/config_php_file_test.php @@ -0,0 +1,30 @@ +<?php +/** +* +* 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. +* +*/ + +class phpbb_config_php_file_test extends phpbb_test_case +{ +	public function test_default() +	{ +		$config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); +		$this->assertSame('bar', $config_php->get('foo')); +		$this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all()); +	} + +	public function test_set_config_file() +	{ +		$config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); +		$config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php'); +		$this->assertSame('foo', $config_php->get('bar')); +		$this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all()); +	} +} diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 8bf9f636fa..559c0b122c 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -14,47 +14,135 @@  namespace  {  	require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -	require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; -	class phpbb_di_container_test extends phpbb_test_case +	class phpbb_di_container_test extends \phpbb_test_case  	{ -		public function test_phpbb_create_container() +		protected $config_php; + +		/** +		* @var \phpbb\di\container_builder +		*/ +		protected $builder; +		protected $phpbb_root_path; +		protected $filename; + +		public function setUp()  		{ -			$phpbb_root_path = __DIR__ . '/../../phpBB/'; -			$extensions = array( -				new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), -				new \phpbb\di\extension\core($phpbb_root_path . 'config'), -			); -			$container = phpbb_create_container($extensions, $phpbb_root_path, 'php'); +			$this->phpbb_root_path = dirname(__FILE__) . '/'; +			$this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php'); +			$this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); + +			$this->filename = $this->phpbb_root_path . '../tmp/container.php'; +			if (is_file($this->filename)) +			{ +				unlink($this->filename); +			} + +			parent::setUp(); +		} +		public function test_default_container() +		{ +			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + +			// Checks the core services +			$this->assertTrue($container->hasParameter('core')); + +			// Checks compile_container +			$this->assertTrue($container->isFrozen()); + +			// Checks inject_config +			$this->assertTrue($container->hasParameter('dbal.dbhost')); + +			// Checks use_extensions +			$this->assertTrue($container->hasParameter('enabled')); +			$this->assertFalse($container->hasParameter('disabled')); +			$this->assertFalse($container->hasParameter('available')); + +			// Checks set_custom_parameters +			$this->assertTrue($container->hasParameter('core.root_path')); + +			// Checks dump_container +			$this->assertTrue(is_file($this->filename)); + +			// Checks the construction of a dumped container +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('phpbb_cache_container', $container); +			$this->assertFalse($container->isFrozen()); +			$container->getParameterBag(); // needed, otherwise the container is not marked as frozen +			$this->assertTrue($container->isFrozen());  		} -		public function test_phpbb_create_install_container() +		public function test_dump_container()  		{ -			$phpbb_root_path = __DIR__ . '/../../phpBB/'; -			$extensions = array( -				new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), -				new \phpbb\di\extension\core($phpbb_root_path . 'config'), -			); -			$container = phpbb_create_install_container($phpbb_root_path, 'php'); +			$this->builder->set_dump_container(false); +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); +			// Checks dump_container +			$this->assertFalse(is_file($this->filename)); + +			// Checks the construction of a dumped container +			$container = $this->builder->get_container(); +			$this->assertNotInstanceOf('phpbb_cache_container', $container);  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);  			$this->assertTrue($container->isFrozen());  		} -		public function test_phpbb_create_compiled_container() +		public function test_use_extensions()  		{ -			$phpbb_root_path = __DIR__ . '/../../phpBB/'; -			$config_file = __DIR__ . '/fixtures/config.php'; -			$extensions = array( -				new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), -				new \phpbb\di\extension\core($phpbb_root_path . 'config'), -			); -			$container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php'); +			$this->builder->set_use_extensions(false); +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + +			// Checks the core services +			$this->assertTrue($container->hasParameter('core')); + +			// Checks use_extensions +			$this->assertFalse($container->hasParameter('enabled')); +			$this->assertFalse($container->hasParameter('disabled')); +			$this->assertFalse($container->hasParameter('available')); +		} +		public function test_compile_container() +		{ +			$this->builder->set_compile_container(false); +			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); -			$this->assertTrue($container->isFrozen()); + +			// Checks compile_container +			$this->assertFalse($container->isFrozen()); +		} + +		public function test_inject_config() +		{ +			$this->builder->set_inject_config(false); +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + +			// Checks inject_config +			$this->assertFalse($container->hasParameter('dbal.dbhost')); +		} + +		public function test_set_config_path() +		{ +			$this->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/'); +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + +			$this->assertTrue($container->hasParameter('other_config')); +			$this->assertFalse($container->hasParameter('core')); +		} + +		public function test_set_custom_parameters() +		{ +			$this->builder->set_custom_parameters(array('my_parameter' => true)); +			$container = $this->builder->get_container(); +			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + +			$this->assertTrue($container->hasParameter('my_parameter')); +			$this->assertFalse($container->hasParameter('core.root_path'));  		}  	}  } @@ -102,5 +190,12 @@ namespace phpbb\db\driver  		function sql_like_expression($expression)  		{  		} + +		function sql_fetchrowset($query_id = false) +		{ +			return array( +				array('ext_name' => 'vendor/enabled'), +			); +		}  	}  } diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml new file mode 100644 index 0000000000..f2a22ae109 --- /dev/null +++ b/tests/di/fixtures/config/services.yml @@ -0,0 +1,14 @@ +parameters: +    core: true + +services: +    config.php: +        synthetic: true + +    dbal.conn: +        class: phpbb\db\driver\factory +        arguments: +            - @service_container + +    dispatcher: +        class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/ext/vendor/available/config/services.yml b/tests/di/fixtures/ext/vendor/available/config/services.yml new file mode 100644 index 0000000000..2ced431f5a --- /dev/null +++ b/tests/di/fixtures/ext/vendor/available/config/services.yml @@ -0,0 +1,2 @@ +parameters: +    available: true diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/services.yml new file mode 100644 index 0000000000..31ada384bf --- /dev/null +++ b/tests/di/fixtures/ext/vendor/disabled/config/services.yml @@ -0,0 +1,2 @@ +parameters: +    disabled: true diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/services.yml new file mode 100644 index 0000000000..88a7919ed1 --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled/config/services.yml @@ -0,0 +1,2 @@ +parameters: +    enabled: true diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml new file mode 100644 index 0000000000..c299bfc648 --- /dev/null +++ b/tests/di/fixtures/other_config/services.yml @@ -0,0 +1,14 @@ +parameters: +    other_config: true + +services: +    config.php: +        synthetic: true + +    dbal.conn: +        class: phpbb\db\driver\factory +        arguments: +            - @service_container + +    dispatcher: +        class: phpbb\db\driver\container_mock diff --git a/tests/fixtures/config.php b/tests/fixtures/config.php new file mode 100644 index 0000000000..ae9e8c22de --- /dev/null +++ b/tests/fixtures/config.php @@ -0,0 +1,3 @@ +<?php +$foo = 'bar'; +$foo_foo = 'bar bar'; diff --git a/tests/fixtures/config_other.php b/tests/fixtures/config_other.php new file mode 100644 index 0000000000..e0ecc17bb9 --- /dev/null +++ b/tests/fixtures/config_other.php @@ -0,0 +1,3 @@ +<?php +$bar = 'foo'; +$bar_bar = 'foo foo'; diff --git a/tests/functional/mcp_test.php b/tests/functional/mcp_test.php index 31d835f4fa..40615d66a5 100644 --- a/tests/functional/mcp_test.php +++ b/tests/functional/mcp_test.php @@ -64,4 +64,20 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case  		$crawler = self::submit($form);  		$this->assertContains($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text());  	} + +	public function test_delete_logs() +	{ +		$this->login(); +		$crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}"); +		$this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count()); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton($this->lang('DELETE_ALL'))->form(); +		$crawler = self::submit($form); + +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); + +		$this->assertCount(0, $crawler->filter('input[type=checkbox]')); +	}  } diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php index a3992aef5c..729c0a82f0 100644 --- a/tests/functions/convert_30_dbms_to_31_test.php +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -36,7 +36,8 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case  	{  		$expected = "phpbb\\db\\driver\\$input"; -		$output = phpbb_convert_30_dbms_to_31($input); +		$config_php_file = new \phpbb\config_php_file('', ''); +		$output = $config_php_file->convert_30_dbms_to_31($input);  		$this->assertEquals($expected, $output);  	} diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php new file mode 100644 index 0000000000..59cdf0bb2b --- /dev/null +++ b/tests/mock/phpbb_di_container_builder.php @@ -0,0 +1,20 @@ +<?php +/** +* +* 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. +* +*/ + +class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder +{ +	protected function get_container_filename() +	{ +		return $this->phpbb_root_path . '../../tmp/container.' . $this->php_ext; +	} +} diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index a29b6e1955..ade1bf6e23 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -142,17 +142,16 @@ class phpbb_test_case_helpers  			$test_config = dirname(__FILE__) . '/../test_config.php';  		} +		$config_php_file = new \phpbb\config_php_file('', ''); +  		if (file_exists($test_config))  		{ -			include($test_config); - -			if (!function_exists('phpbb_convert_30_dbms_to_31')) -			{ -				require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -			} +			$config_php_file->set_config_file($test_config); +			extract($config_php_file->get_all()); +			unset($dbpasswd);  			$config = array_merge($config, array( -				'dbms'		=> phpbb_convert_30_dbms_to_31($dbms), +				'dbms'		=> $config_php_file->convert_30_dbms_to_31($dbms),  				'dbhost'	=> $dbhost,  				'dbport'	=> $dbport,  				'dbname'	=> $dbname, @@ -183,13 +182,8 @@ class phpbb_test_case_helpers  		if (isset($_SERVER['PHPBB_TEST_DBMS']))  		{ -			if (!function_exists('phpbb_convert_30_dbms_to_31')) -			{ -				require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -			} -  			$config = array_merge($config, array( -				'dbms'		=> isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', +				'dbms'		=> isset($_SERVER['PHPBB_TEST_DBMS']) ? $config_php_file->convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',  				'dbhost'	=> isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',  				'dbport'	=> isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',  				'dbname'	=> isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',  | 
