diff options
Diffstat (limited to 'tests/dbal')
| -rw-r--r-- | tests/dbal/auto_increment_test.php | 3 | ||||
| -rw-r--r-- | tests/dbal/boolean_processor_test.php | 306 | ||||
| -rw-r--r-- | tests/dbal/connect_test.php | 4 | ||||
| -rw-r--r-- | tests/dbal/db_tools_test.php | 9 | ||||
| -rw-r--r-- | tests/dbal/fixtures/boolean_processor.xml | 84 | ||||
| -rw-r--r-- | tests/dbal/migrator_test.php | 7 | ||||
| -rw-r--r-- | tests/dbal/migrator_tool_module_test.php | 13 | ||||
| -rw-r--r-- | tests/dbal/migrator_tool_permission_test.php | 2 | 
8 files changed, 413 insertions, 15 deletions
| diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index 1ed8ea29e3..39eb6835ff 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -30,7 +30,8 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->tools = $factory->get($this->db);  		$this->table_data = array(  			'COLUMNS'		=> array( diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php new file mode 100644 index 0000000000..8662485ac8 --- /dev/null +++ b/tests/dbal/boolean_processor_test.php @@ -0,0 +1,306 @@ +<?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. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_boolean_processor_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); +	} + +	public function test_single_not_like() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +			), +			'WHERE'		=> array('u.username_clean', 'NOT_LIKE', 'gr' . $db->get_any_char()), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '1'), +			array('user_id' => '2'), +			array('user_id' => '3'), +			array('user_id' => '6'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_single_like() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +			), +			'WHERE'		=> array('u.username_clean', 'LIKE', 'gr' . $db->get_any_char()), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '4'), +			array('user_id' => '5'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_single_not_in() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +			), +			'WHERE'		=> array('u.user_id', 'NOT_IN', array(3,4,5)), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '1'), +			array('user_id' => '2'), +			array('user_id' => '6'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_single_in() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +			), +			'WHERE'		=> array('u.user_id', 'IN', array(3,4,5)), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '3'), +			array('user_id' => '4'), +			array('user_id' => '5'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_and_of_or_of_and() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +				'phpbb_user_group'	=> 'ug', +			), +			'LEFT_JOIN'	=> array( +				array( +					'FROM'	=> array( +						'phpbb_banlist'	=> 'b', +					), +					'ON'	=> 'u.user_id = b.ban_userid', +				), +			), +			'WHERE'		=> array('AND', +				array('OR', +					array('AND', +						array('ug.user_id', 'IN', array(1, 2, 3, 4)), +						array('ug.group_id', '=', 2), +					), +					array('AND', +						array('ug.group_id', '=', 1), +						array('b.ban_id', 'IS_NOT', NULL), +					), +				), +				array('u.user_id', '=', 'ug.user_id'), +			), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '2'), +			array('user_id' => '4'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_triple_and_with_in() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +				'phpbb_user_group'	=> 'ug', +			), +			'WHERE'		=> array('AND', +				array('ug.user_id', 'IN', array(1, 2, 3, 4)), +				array('ug.group_id', '=', 1), +				array('u.user_id', '=', 'ug.user_id'), +			), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('user_id' => '1'), +			array('user_id' => '2'), +			array('user_id' => '3'), +			), $db->sql_fetchrowset($result), +			($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +		); + +	} + +	public function test_double_and_with_not_of_or() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.user_id', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +				'phpbb_user_group'	=> 'ug', +			), +			'WHERE'		=> array('AND', +				array('NOT', +					array('OR', +						array('ug.group_id', '=', 1), +						array('ug.group_id', '=', 2), +					), +				), +				array('u.user_id', '=', 'ug.user_id'), +			), +			'ORDER_BY'	=> 'u.user_id', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array(), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} + +	public function test_triple_and_with_is_null() +	{ +		$db = $this->new_dbal(); + +		$db->sql_return_on_error(true); + +		$sql_ary = array( +			'SELECT'	=> 'u.username', +			'FROM'		=> array( +				'phpbb_users'		=> 'u', +				'phpbb_user_group'	=> 'ug', +			), +			'LEFT_JOIN'	=> array( +				array( +					'FROM'	=> array( +						'phpbb_banlist'	=> 'b', +					), +					'ON'	=> 'u.user_id = b.ban_userid', +				), +			), +			'WHERE'		=> array('AND', +				array('ug.group_id', '=', 1), +				array('u.user_id', '=', 'ug.user_id'), +				array('b.ban_id', 'IS', NULL), +			), +			'ORDER_BY'	=> 'u.username', +		); +		$sql = $db->sql_build_query('SELECT', $sql_ary); +		$result = $db->sql_query($sql); + +		$db->sql_return_on_error(false); + +		$this->assertEquals(array( +			array('username' => 'helper'), +			array('username' => 'mass email'), +			), $db->sql_fetchrowset($result), +				($result === false) ? +				"SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : +				var_export($sql, true) . '   ' . var_export($result, true) +			); +	} +} diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 1ae34bd2b6..edf57189cb 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -22,7 +22,9 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case  	public function test_failing_connect()  	{ -		global $phpbb_root_path, $phpEx; +		global $phpbb_root_path, $phpEx, $phpbb_filesystem; + +		$phpbb_filesystem = new phpbb\filesystem\filesystem();  		$config = $this->get_database_config(); diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 5832b966d8..aa0b6ccf48 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  {  	/** @var \phpbb\db\driver\driver_interface */  	protected $db; -	/** @var \phpbb\db\tools */ +	/** @var \phpbb\db\tools\tools_interface */  	protected $tools;  	protected $table_exists;  	protected $table_data; @@ -32,7 +32,8 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->tools = $factory->get($this->db);  		$this->table_data = array(  			'COLUMNS'		=> array( @@ -340,7 +341,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  	public function test_perform_schema_changes_drop_tables()  	{ -		$db_tools = $this->getMock('\phpbb\db\tools', array( +		$db_tools = $this->getMock('\phpbb\db\tools\tools', array(  			'sql_table_exists',  			'sql_table_drop',  		), array(&$this->db)); @@ -366,7 +367,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  	public function test_perform_schema_changes_drop_columns()  	{ -		$db_tools = $this->getMock('\phpbb\db\tools', array( +		$db_tools = $this->getMock('\phpbb\db\tools\tools', array(  			'sql_column_exists',  			'sql_column_remove',  		), array(&$this->db)); diff --git a/tests/dbal/fixtures/boolean_processor.xml b/tests/dbal/fixtures/boolean_processor.xml new file mode 100644 index 0000000000..c5da677116 --- /dev/null +++ b/tests/dbal/fixtures/boolean_processor.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_banlist"> +		<column>ban_id</column> +		<column>ban_userid</column> +		<row> +			<value>1</value> +			<value>2</value> +		</row> +	</table> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<row> +			<value>1</value> +			<value>mass email</value> +			<value>mass email</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>banned</value> +			<value>banned</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>helper</value> +			<value>helper</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>GroupBPal</value> +			<value>groupbpal</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>GroupBPal2</value> +			<value>groupBPal2</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>6</value> +			<value>not in group</value> +			<value>not in group</value> +			<value></value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_user_group"> +		<column>user_id</column> +		<column>group_id</column> +		<row> +			<value>1</value> +			<value>1</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +		</row> +		<row> +			<value>4</value> +			<value>2</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +		</row> +	</table> +</dataset> diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4c4306888c..f52e6ea63d 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -38,7 +38,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->db_tools = $factory->get($this->db);  		$this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); @@ -62,14 +63,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case  		);  		$container->set('migrator', $this->migrator);  		$container->set('dispatcher', new phpbb_mock_event_dispatcher()); -		$user = new \phpbb\user('\phpbb\datetime');  		$this->extension_manager = new \phpbb\extension\manager(  			$container,  			$this->db,  			$this->config, -			new phpbb\filesystem(), -			$user, +			new phpbb\filesystem\filesystem(),  			'phpbb_ext',  			dirname(__FILE__) . '/../../phpBB/',  			'php', diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 08c3e979b8..a71334f23f 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -27,19 +27,24 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case  		parent::setup(); -		// Force add_log function to not be used +		// Disable the logs  		$skip_add_log = true;  		$db = $this->db = $this->new_dbal(); -		$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); -		$user = $this->user = new \phpbb\user('\phpbb\user'); +		$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = $this->user = new \phpbb\user($lang, '\phpbb\datetime');  		$cache = new phpbb_mock_cache;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$auth = $this->getMock('\phpbb\auth\auth');  		$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); -		$this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); +		$phpbb_extension_manager = new phpbb_mock_extension_manager($phpbb_root_path); +		$module_manager = new \phpbb\module\module_manager($cache, $this->db, $phpbb_extension_manager, MODULES_TABLE, $phpbb_root_path, $phpEx); + +		$this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $module_manager, $phpbb_root_path, $phpEx, 'phpbb_modules');  	}  	public function exists_data() diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 2d673864f7..bfb2e07080 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -34,7 +34,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case  		parent::setup();  		$db = $this->db = $this->new_dbal(); -		$cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); +		$cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);  		$this->auth = new \phpbb\auth\auth();  		$this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); | 
