diff options
Diffstat (limited to 'tests')
94 files changed, 4040 insertions, 673 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index f89c1fefeb..f2688ab675 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -50,9 +50,11 @@ Database Tests  By default all tests requiring a database connection will use sqlite. If you  do not have sqlite installed the tests will be skipped. If you wish to run the  tests on a different database you have to create a test_config.php file within -your tests directory following the same format as phpBB's config.php. An -example for mysqli can be found below. More information on configuration -options can be found on the wiki (see below). +your tests directory following the same format as phpBB's config.php. Testing +makes use of a seperate database defined in this config file and before running +the tests each time this database is deleted. An example for mysqli can be +found below. More information on configuration options can be found on the +wiki (see below).      <?php      $dbms = 'phpbb_db_driver_mysqli'; @@ -132,8 +134,36 @@ only want the slow tests, run:      $ phpBB/vendor/bin/phpunit --group slow +Functional tests +----------------- + +Functional tests test software the way a user would. They simulate a user +browsing the website, but they do these steps in an automated way. +phpBB allows you to write such tests. + +Running +======= + +Running the tests requires your phpBB3 repository to be accessible through a +local web server. You will need to supply the URL to the webserver in +the 'tests/test_config.php' file. This is as simple as defining the +'$phpbb_functional_url' variable, which contains the URL for the directory containing +the board. Make sure you include the trailing slash. Note that without extensive +changes to the test framework, you cannot use a board outside of the repository +on which to run tests. + +    $phpbb_functional_url = 'http://localhost/phpBB3/'; + +To then run the tests, you run PHPUnit, but use the phpunit.xml.functional +config file instead of the default one. Specify this through the "-c" option: + +    $ phpBB/vendor/bin/phpunit -c phpunit.xml.functional + +This will change your board's config.php file, but it makes a backup at +config_dev.php, so you can restore it after the test run is complete. +  More Information  ================  Further information is available on phpbb wiki: -http://wiki.phpbb.com/Unit_Tests +http://wiki.phpbb.com/Automated_Tests diff --git a/tests/acp_board/auth_provider/invalid.php b/tests/acp_board/auth_provider/invalid.php new file mode 100644 index 0000000000..c12851afe6 --- /dev/null +++ b/tests/acp_board/auth_provider/invalid.php @@ -0,0 +1,13 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_auth_provider_acp_board_invalid +{ + +} diff --git a/tests/acp_board/auth_provider/valid.php b/tests/acp_board/auth_provider/valid.php new file mode 100644 index 0000000000..42b14cb0af --- /dev/null +++ b/tests/acp_board/auth_provider/valid.php @@ -0,0 +1,16 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_auth_provider_acp_board_valid extends phpbb_auth_provider_base +{ +	public function login($username, $password) +	{ +		return; +	} +} diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php new file mode 100644 index 0000000000..91aa5d1232 --- /dev/null +++ b/tests/acp_board/select_auth_method_test.php @@ -0,0 +1,48 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_board.php'; +require_once dirname(__FILE__) . '/auth_provider/invalid.php'; +require_once dirname(__FILE__) . '/auth_provider/valid.php'; + +class phpbb_acp_board_select_auth_method_test extends phpbb_test_case +{ +	protected $acp_board; + +	public static function select_auth_method_data() +	{ +		return array( +			array('acp_board_valid', '<option value="acp_board_valid" selected="selected">Acp_board_valid</option>'), +			array('acp_board_invalid', '<option value="acp_board_valid">Acp_board_valid</option>'), +		); +	} + +	public function setUp() +	{ +		parent::setUp(); + +		global $phpbb_container; +		$phpbb_container = new phpbb_mock_container_builder(); + +		$phpbb_container->set('auth.provider_collection', array( +				'auth.provider.acp_board_valid'		=> new phpbb_auth_provider_acp_board_valid, +				'auth.provider.acp_board_invalid'	=> new phpbb_auth_provider_acp_board_invalid, +		)); + +		$this->acp_board = new acp_board(); +	} + +	/** +	* @dataProvider select_auth_method_data +	*/ +	public function test_select_auth_method($selected, $expected) +	{ +		$this->assertEquals($expected, $this->acp_board->select_auth_method($selected)); +	} +} diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml new file mode 100644 index 0000000000..34584babbf --- /dev/null +++ b/tests/auth/fixtures/user.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_password</column> +		<column>user_passchg</column> +		<column>user_pass_convert</column> +		<column>user_email</column> +		<column>user_type</column> +		<column>user_login_attempts</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>1</value> +			<value>foobar</value> +			<value>foobar</value> +			<value>$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/</value> +			<value>0</value> +			<value>0</value> +			<value>example@example.com</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php new file mode 100644 index 0000000000..0ca6ef763e --- /dev/null +++ b/tests/auth/provider_apache_test.php @@ -0,0 +1,206 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; + +class phpbb_auth_provider_apache_test extends phpbb_database_test_case +{ +	protected $provider; +	protected $user; +	protected $request; + +	protected function setup() +	{ +		parent::setUp(); + +		global $phpbb_root_path, $phpEx; + +		$db = $this->new_dbal(); +		$config = new phpbb_config(array()); +		$this->request = $this->getMock('phpbb_request'); +		$this->user = $this->getMock('phpbb_user'); + +		$this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); +	} + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); +	} + +	/** +	 * Test to see if a user is identified to Apache. Expects false if they are. +	 */ +	public function test_init() +	{ +		$this->user->data['username'] = 'foobar'; +		$this->request->expects($this->once()) +			->method('is_set') +			->with('PHP_AUTH_USER', +				phpbb_request_interface::SERVER) +			->will($this->returnValue(true)); +		$this->request->expects($this->once()) +			->method('server') +			->with('PHP_AUTH_USER') +			->will($this->returnValue('foobar')); + +		$this->assertFalse($this->provider->init()); +	} + +	public function test_login() +	{ +		$username = 'foobar'; +		$password = 'example'; + +		$this->request->expects($this->once()) +			->method('is_set') +			->with('PHP_AUTH_USER', +				phpbb_request_interface::SERVER) +			->will($this->returnValue(true)); +		$this->request->expects($this->at(1)) +			->method('server') +			->with('PHP_AUTH_USER') +			->will($this->returnValue('foobar')); +		$this->request->expects($this->at(2)) +			->method('server') +			->with('PHP_AUTH_PW') +			->will($this->returnValue('example')); + +		$expected = array( +			'status'		=> LOGIN_SUCCESS, +			'error_msg'		=> false, +			'user_row'		=> array( +				'user_id' 				=> '1', +				'username' 				=> 'foobar', +				'user_password'			=> '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', +				'user_passchg' 			=> '0', +				'user_email' 			=> 'example@example.com', +				'user_type' 			=> '0', +				), +		); + +		$this->assertEquals($expected, $this->provider->login($username, $password)); +	} + +	public function test_autologin() +	{ +		$this->request->expects($this->once()) +			->method('is_set') +			->with('PHP_AUTH_USER', +				phpbb_request_interface::SERVER) +			->will($this->returnValue(true)); +		$this->request->expects($this->at(1)) +			->method('server') +			->with('PHP_AUTH_USER') +			->will($this->returnValue('foobar')); +		$this->request->expects($this->at(2)) +			->method('server') +			->with('PHP_AUTH_PW') +			->will($this->returnValue('example')); + +		$expected = array( +			'user_id' => '1', +			'user_type' => '0', +			'group_id' => '3', +			'user_permissions' => '', +			'user_perm_from' => '0', +			'user_ip' => '', +			'user_regdate' => '0', +			'username' => 'foobar', +			'username_clean' => 'foobar', +			'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', +			'user_passchg' => '0', +			'user_pass_convert' => '0', +			'user_email' => 'example@example.com', +			'user_email_hash' => '0', +			'user_birthday' => '', +			'user_lastvisit' => '0', +			'user_lastmark' => '0', +			'user_lastpost_time' => '0', +			'user_lastpage' => '', +			'user_last_confirm_key' => '', +			'user_last_search' => '0', +			'user_warnings' => '0', +			'user_last_warning' => '0', +			'user_login_attempts' => '0', +			'user_inactive_reason' => '0', +			'user_inactive_time' => '0', +			'user_posts' => '0', +			'user_lang' => '', +			'user_timezone' => 'UTC', +			'user_dateformat' => 'd M Y H:i', +			'user_style' => '0', +			'user_rank' => '0', +			'user_colour' => '', +			'user_new_privmsg' => '0', +			'user_unread_privmsg' => '0', +			'user_last_privmsg' => '0', +			'user_message_rules' => '0', +			'user_full_folder' => '-3', +			'user_emailtime' => '0', +			'user_topic_show_days' => '0', +			'user_topic_sortby_type' => 't', +			'user_topic_sortby_dir' => 'd', +			'user_post_show_days' => '0', +			'user_post_sortby_type' => 't', +			'user_post_sortby_dir' => 'a', +			'user_notify' => '0', +			'user_notify_pm' => '1', +			'user_notify_type' => '0', +			'user_allow_pm' => '1', +			'user_allow_viewonline' => '1', +			'user_allow_viewemail' => '1', +			'user_allow_massemail' => '1', +			'user_options' => '230271', +			'user_avatar' => '', +			'user_avatar_type' => '', +			'user_avatar_width' => '0', +			'user_avatar_height' => '0', +			'user_sig' => '', +			'user_sig_bbcode_uid' => '', +			'user_sig_bbcode_bitfield' => '', +			'user_from' => '', +			'user_icq' => '', +			'user_aim' => '', +			'user_yim' => '', +			'user_msnm' => '', +			'user_jabber' => '', +			'user_website' => '', +			'user_occ' => '', +			'user_interests' => '', +			'user_actkey' => '', +			'user_newpasswd' => '', +			'user_form_salt' => '', +			'user_new' => '1', +			'user_reminded' => '0', +			'user_reminded_time' => '0', +		); + +		$this->assertEquals($expected, $this->provider->autologin()); +	} + +	public function test_validate_session() +	{ +		$user = array( +			'username'	=> 'foobar', +			'user_type' +			); +		$this->request->expects($this->once()) +			->method('is_set') +			->with('PHP_AUTH_USER', +				phpbb_request_interface::SERVER) +			->will($this->returnValue(true)); +		$this->request->expects($this->once()) +			->method('server') +			->with('PHP_AUTH_USER') +			->will($this->returnValue('foobar')); + +		$this->assertTrue($this->provider->validate_session($user)); +	} +} diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php new file mode 100644 index 0000000000..d876683f84 --- /dev/null +++ b/tests/auth/provider_db_test.php @@ -0,0 +1,50 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; + +class phpbb_auth_provider_db_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); +	} + +	public function test_login() +	{ +		global $phpbb_root_path, $phpEx; + +		$db = $this->new_dbal(); +		$config = new phpbb_config(array( +			'ip_login_limit_max'			=> 0, +			'ip_login_limit_use_forwarded' 	=> 0, +			'max_login_attempts' 			=> 0, +			)); +		$request = $this->getMock('phpbb_request'); +		$user = $this->getMock('phpbb_user'); +		$provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + +		$expected = array( +			'status'		=> LOGIN_SUCCESS, +			'error_msg'		=> false, +			'user_row'		=> array( +				'user_id' 				=> '1', +				'username' 				=> 'foobar', +				'user_password'			=> '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', +				'user_passchg' 			=> '0', +				'user_pass_convert' 	=> '0', +				'user_email' 			=> 'example@example.com', +				'user_type' 			=> '0', +				'user_login_attempts' 	=> '0', +				), +		); + +		$this->assertEquals($expected, $provider->login('foobar', 'example')); +	} +} diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index cb895b521a..4ebe79c9cd 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -19,24 +19,35 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase  		$this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');  		$this->phpbb_container->expects($this->any())  			->method('get') -			->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); +			->will($this->returnArgument(0));  		// Prepare dependencies for avatar manager and driver  		$config = new phpbb_config(array());  		$request = $this->getMock('phpbb_request');  		$cache = $this->getMock('phpbb_cache_driver_interface'); +		// $this->avatar_foobar will be needed later on  		$this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache));  		$this->avatar_foobar->expects($this->any()) -            ->method('get_name') -            ->will($this->returnValue('avatar.driver.foobar')); +			->method('get_name') +			->will($this->returnValue('avatar.driver.foobar')); +		// barfoo driver can't be mocked with constructor arguments  		$this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name'));  		$this->avatar_barfoo->expects($this->any()) -            ->method('get_name') -            ->will($this->returnValue('avatar.driver.barfoo')); - +			->method('get_name') +			->will($this->returnValue('avatar.driver.barfoo'));  		$avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); +		foreach ($this->avatar_drivers() as $driver) +		{ +			$cur_avatar = $this->getMock('phpbb_avatar_driver_' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); +			$cur_avatar->expects($this->any()) +				->method('get_name') +				->will($this->returnValue('avatar.driver.' . $driver)); +			$config['allow_avatar_' . get_class($cur_avatar)] = false; +			$avatar_drivers[] = $cur_avatar; +		} +  		$config['allow_avatar_' . get_class($this->avatar_foobar)] = true;  		$config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; @@ -44,28 +55,27 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase  		$this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container);  	} -	public function test_get_driver() +	protected function avatar_drivers()  	{ -		$driver = $this->manager->get_driver('avatar.driver.foobar', false); -		$this->assertEquals('avatar.driver.foobar', $driver); - -		$driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); -		$this->assertNull($driver); - -		$driver = $this->manager->get_driver('avatar.driver.foobar'); -		$this->assertEquals('avatar.driver.foobar', $driver); - -		$driver = $this->manager->get_driver('avatar.driver.foo_wrong'); -		$this->assertNull($driver); +		return array( +			'local', +			'upload', +			'remote', +			'gravatar', +		);  	}  	public function test_get_all_drivers()  	{  		$drivers = $this->manager->get_all_drivers(); -		$this->assertArrayHasKey('avatar.driver.foobar', $drivers); -		$this->assertArrayHasKey('avatar.driver.barfoo', $drivers); -		$this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); -		$this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']); +		$this->assertEquals(array( +			'avatar.driver.barfoo' => 'avatar.driver.barfoo', +			'avatar.driver.foobar' => 'avatar.driver.foobar', +			'avatar.driver.local' => 'avatar.driver.local', +			'avatar.driver.remote' => 'avatar.driver.remote', +			'avatar.driver.upload' => 'avatar.driver.upload', +			'avatar.driver.gravatar' => 'avatar.driver.gravatar', +		), $drivers);  	}  	public function test_get_enabled_drivers() @@ -76,6 +86,48 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase  		$this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);  	} +	public function get_driver_data_enabled() +	{ +		return array( +			array('avatar.driver.foobar', 'avatar.driver.foobar'), +			array('avatar.driver.foo_wrong', null), +			array('avatar.driver.local', null), +			array(AVATAR_GALLERY, null), +			array(AVATAR_UPLOAD, null), +			array(AVATAR_REMOTE, null), +		); +	} + +	/** +	* @dataProvider get_driver_data_enabled +	*/ +	public function test_get_driver_enabled($driver_name, $expected) +	{ +		$driver = $this->manager->get_driver($driver_name); +		$this->assertEquals($expected, $driver); +	} + +	public function get_driver_data_all() +	{ +		return array( +			array('avatar.driver.foobar', 'avatar.driver.foobar'), +			array('avatar.driver.foo_wrong', null), +			array('avatar.driver.local', 'avatar.driver.local'), +			array(AVATAR_GALLERY, 'avatar.driver.local'), +			array(AVATAR_UPLOAD, 'avatar.driver.upload'), +			array(AVATAR_REMOTE, 'avatar.driver.remote'), +		); +	} + +	/** +	* @dataProvider get_driver_data_all +	*/ +	public function test_get_driver_all($driver_name, $expected) +	{ +		$driver = $this->manager->get_driver($driver_name, false); +		$this->assertEquals($expected, $driver); +	} +  	public function test_get_avatar_settings()  	{  		$avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); @@ -157,4 +209,38 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase  			$this->assertArrayHasKey($key, $cleaned_row);  		}  	} + +	public function test_clean_driver_name() +	{ +		$this->assertEquals('avatar.driver.local', $this->manager->clean_driver_name('avatar_driver_local')); +	} + +	public function test_prepare_driver_name() +	{ +		$this->assertEquals('avatar_driver_local', $this->manager->prepare_driver_name('avatar.driver.local')); +	} + +	public function test_localize_errors() +	{ +		$user = $this->getMock('phpbb_user'); +		$lang_array = array( +			array('FOOBAR_OFF', 'foobar_off'), +			array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'), +		); +		$user->expects($this->any()) +			->method('lang') +			->will($this->returnValueMap($lang_array)); + +		// Pass error as string +		$this->assertEquals(array('foobar_off'), $this->manager->localize_errors($user, array('FOOBAR_OFF'))); + +		// Pass error as array for vsprintf() +		$this->assertEquals(array('FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(array('FOOBAR_EXPLAIN', 'foo')))); + +		// Pass both types +		$this->assertEquals(array('foobar_off', 'FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array( +			'FOOBAR_OFF', +			array('FOOBAR_EXPLAIN', 'foo'), +		))); +	}  } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a38740c82d..68cbb64c03 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,13 +14,13 @@ require_once $phpbb_root_path . 'includes/startup.php';  $table_prefix = 'phpbb_';  require_once $phpbb_root_path . 'includes/constants.php'; -require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; +require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx;  $phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php");  $phpbb_class_loader_mock->register();  $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', "php");  $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', "php"); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'phpbb/', "php");  $phpbb_class_loader->register();  require_once 'test_framework/phpbb_test_case_helpers.php'; diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index bf27c7c217..2b55c1ff8d 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -30,9 +30,9 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase  	public function test_resolve_path()  	{  		$prefix = dirname(__FILE__) . '/'; -		$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/'); +		$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/'); -		$prefix .= 'includes/'; +		$prefix .= 'phpbb/';  		$this->assertEquals(  			'', @@ -71,10 +71,10 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase  		$cache = new phpbb_mock_cache($cache_map);  		$prefix = dirname(__FILE__) . '/'; -		$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', 'php', $cache); -		$class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', 'php', $cache); +		$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/', 'php', $cache); +		$class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'phpbb/', 'php', $cache); -		$prefix .= 'includes/'; +		$prefix .= 'phpbb/';  		$this->assertEquals(  			$prefix . 'dir/class_name.php', diff --git a/tests/class_loader/includes/class_name.php b/tests/class_loader/phpbb/class_name.php index e941173cdd..e941173cdd 100644 --- a/tests/class_loader/includes/class_name.php +++ b/tests/class_loader/phpbb/class_name.php diff --git a/tests/class_loader/includes/dir.php b/tests/class_loader/phpbb/dir.php index 1c8930d8e7..1c8930d8e7 100644 --- a/tests/class_loader/includes/dir.php +++ b/tests/class_loader/phpbb/dir.php diff --git a/tests/class_loader/includes/dir/class_name.php b/tests/class_loader/phpbb/dir/class_name.php index 0675aa8fc5..0675aa8fc5 100644 --- a/tests/class_loader/includes/dir/class_name.php +++ b/tests/class_loader/phpbb/dir/class_name.php diff --git a/tests/class_loader/includes/dir/subdir/class_name.php b/tests/class_loader/phpbb/dir/subdir/class_name.php index 7321a609cc..7321a609cc 100644 --- a/tests/class_loader/includes/dir/subdir/class_name.php +++ b/tests/class_loader/phpbb/dir/subdir/class_name.php diff --git a/tests/class_loader/includes/dir2/dir2.php b/tests/class_loader/phpbb/dir2/dir2.php index 01cf4086ff..01cf4086ff 100644 --- a/tests/class_loader/includes/dir2/dir2.php +++ b/tests/class_loader/phpbb/dir2/dir2.php diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php new file mode 100644 index 0000000000..6234aac9ad --- /dev/null +++ b/tests/content_visibility/delete_post_test.php @@ -0,0 +1,310 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../mock/search.php'; + +class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_post.xml'); +	} + +	public function delete_post_data() +	{ +		$info_data = array( +			'topic_first_post_id'	=> 1, +			'topic_last_post_id'	=> 3, +			'topic_posts_approved'		=> 3, +			'topic_posts_unapproved'	=> 0, +			'topic_posts_softdeleted'	=> 0, +			'topic_visibility'		=> ITEM_APPROVED, +			'post_time'				=> 2, +			'post_visibility'		=> ITEM_APPROVED, +			'post_postcount'		=> true, +			'poster_id'				=> 1, +			'post_reported'			=> false, +		); + +		return array( +			array( +				1, 1, 2, +				array_merge($info_data, array( +					'post_time'				=> 2, +				)), +				false, 'harddelete', +				array( +					array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					//array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 1, +						'topic_last_post_id'	=> 3, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 0, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), +				), +			), +			array( +				1, 1, 1, +				array_merge($info_data, array( +					'post_time'				=> 1, +				)), +				false, 'harddelete', +				array( +					//array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 2, +						'topic_last_post_id'	=> 3, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 0, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), +				), +			), +			array( +				1, 1, 3, +				array_merge($info_data, array( +					'post_time'				=> 3, +				)), +				false, 'harddelete', +				array( +					array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					//array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 1, +						'topic_last_post_id'	=> 2, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 0, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), +				), +			), +			array( +				1, 1, 2, +				array_merge($info_data, array( +					'post_time'				=> 2, +				)), +				true, 'soft delete', +				array( +					array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), +					array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 1, +						'topic_last_post_id'	=> 3, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 1, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), +				), +			), +			array( +				1, 1, 1, +				array_merge($info_data, array( +					'post_time'				=> 1, +				)), +				true, 'soft delete', +				array( +					array('post_id' => 1, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), +					array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 2, +						'topic_last_post_id'	=> 3, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 1, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), +				), +			), +			array( +				1, 1, 3, +				array_merge($info_data, array( +					'post_time'				=> 3, +				)), +				true, 'soft delete', +				array( +					array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_APPROVED, +						'topic_first_post_id'	=> 1, +						'topic_last_post_id'	=> 2, +						'topic_posts_approved'		=> 2, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 1, +						'topic_delete_reason'	=> '', +					), +				), +				array( +					array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), +				), +			), + +			array( +				2, 2, 4, +				array( +					'topic_first_post_id'	=> 4, +					'topic_last_post_id'	=> 4, +					'topic_posts_approved'		=> 1, +					'topic_posts_unapproved'	=> 0, +					'topic_posts_softdeleted'	=> 0, +					'topic_visibility'		=> ITEM_APPROVED, +					'post_time'				=> 4, +					'post_visibility'		=> ITEM_APPROVED, +					'post_postcount'		=> true, +					'poster_id'				=> 1, +					'post_reported'			=> false, +				), +				false, 'harddelete', +				array( +				), +				array( +				), +				array( +					array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 0), +				), +			), + +			array( +				2, 2, 4, +				array( +					'topic_first_post_id'	=> 4, +					'topic_last_post_id'	=> 4, +					'topic_posts_approved'		=> 1, +					'topic_posts_unapproved'	=> 0, +					'topic_posts_softdeleted'	=> 0, +					'topic_visibility'		=> ITEM_APPROVED, +					'post_time'				=> 4, +					'post_visibility'		=> ITEM_APPROVED, +					'post_postcount'		=> true, +					'poster_id'				=> 1, +					'post_reported'			=> false, +				), +				true, 'soft delete', +				array( +					array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''), +				), +				array( +					array( +						'topic_visibility'		=> ITEM_DELETED, +						'topic_first_post_id'	=> 4, +						'topic_last_post_id'	=> 4, +						'topic_posts_approved'		=> 0, +						'topic_posts_unapproved'	=> 0, +						'topic_posts_softdeleted'	=> 1, +						'topic_delete_reason'	=> 'soft delete', +					), +				), +				array( +					array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0), +				), +			), +		); +	} + +	/** +	* @dataProvider delete_post_data +	*/ +	public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) +	{ +		global $auth, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx; + +		$config['search_type'] = 'phpbb_mock_search'; +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); +		set_config_count(null, null, null, new phpbb_config(array('num_posts' => 3, 'num_topics' => 1))); + +		// Create auth mock +		$auth = $this->getMock('phpbb_auth'); +		$auth->expects($this->any()) +			->method('acl_get') +			->with($this->stringContains('_'), $this->anything()) +			->will($this->returnValueMap(array( +				array('m_approve', 1, true), +			))); +		$user = $this->getMock('phpbb_user'); + +		$phpbb_container = new phpbb_mock_container_builder(); +		$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); +		$phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + +		delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); + +		$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason +			FROM phpbb_posts +			WHERE topic_id = ' . $topic_id . ' +			ORDER BY post_id ASC'); + +		$this->assertEquals($expected_posts, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); + +		$result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_delete_reason +			FROM phpbb_topics +			WHERE topic_id = ' . $topic_id); + +		$this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); + +		$result = $db->sql_query('SELECT forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id +			FROM phpbb_forums +			WHERE forum_id = ' . $forum_id); + +		$this->assertEquals($expected_forum, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); +	} +} diff --git a/tests/content_visibility/fixtures/delete_post.xml b/tests/content_visibility/fixtures/delete_post.xml new file mode 100644 index 0000000000..deca9c74b6 --- /dev/null +++ b/tests/content_visibility/fixtures/delete_post.xml @@ -0,0 +1,167 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_forums"> +		<column>forum_id</column> +		<column>forum_posts_approved</column> +		<column>forum_posts_unapproved</column> +		<column>forum_posts_softdeleted</column> +		<column>forum_topics_approved</column> +		<column>forum_topics_unapproved</column> +		<column>forum_topics_softdeleted</column> +		<column>forum_last_post_id</column> +		<column>forum_parents</column> +		<column>forum_desc</column> +		<column>forum_rules</column> + +		<row> +			<value>1</value> +			<value>3</value> +			<value>0</value> +			<value>0</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value>3</value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value>4</value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<column>topic_first_post_id</column> +		<column>topic_last_post_id</column> +		<column>topic_delete_user</column> +		<column>topic_delete_time</column> +		<column>topic_delete_reason</column> +		<column>topic_posts_approved</column> +		<column>topic_posts_unapproved</column> +		<column>topic_posts_softdeleted</column> + +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +			<value>1</value> +			<value>3</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value>3</value> +			<value>0</value> +			<value>0</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>Approved</value> +			<value>4</value> +			<value>4</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>poster_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_time</column> +		<column>post_text</column> +		<column>post_delete_user</column> +		<column>post_delete_time</column> +		<column>post_delete_reason</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>2</value> +			<value>Approved</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>3</value> +			<value>Approved</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> + +		<row> +			<value>4</value> +			<value>1</value> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>4</value> +			<value>Approved</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>user_posts</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>1</value> +			<value>4</value> +			<value>user 1</value> +			<value>user 1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml new file mode 100644 index 0000000000..658d34398f --- /dev/null +++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>6</value> +			<value>2</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>7</value> +			<value>3</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>8</value> +			<value>3</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>9</value> +			<value>3</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_text</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>4</value> +			<value>4</value> +			<value>2</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>5</value> +			<value>5</value> +			<value>2</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>6</value> +			<value>6</value> +			<value>2</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>7</value> +			<value>7</value> +			<value>3</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>8</value> +			<value>8</value> +			<value>3</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>9</value> +			<value>9</value> +			<value>3</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml new file mode 100644 index 0000000000..146244263e --- /dev/null +++ b/tests/content_visibility/fixtures/get_visibility_sql.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_text</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/fixtures/set_post_visibility.xml b/tests/content_visibility/fixtures/set_post_visibility.xml new file mode 100644 index 0000000000..722525deaa --- /dev/null +++ b/tests/content_visibility/fixtures/set_post_visibility.xml @@ -0,0 +1,162 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<column>topic_first_post_id</column> +		<column>topic_last_post_id</column> +		<column>topic_posts_approved</column> +		<column>topic_posts_softdeleted</column> +		<column>topic_posts_unapproved</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +		</row> + +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>2 Approved posts</value> +			<value>5</value> +			<value>6</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +		</row> + +		<row> +			<value>3</value> +			<value>1</value> +			<value>1</value> +			<value>Only 1 Approved posts</value> +			<value>8</value> +			<value>8</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>poster_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_text</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>1</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> + +		<row> +			<value>4</value> +			<value>1</value> +			<value>2</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +		<row> +			<value>6</value> +			<value>2</value> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>Approved 2</value> +		</row> +		<row> +			<value>7</value> +			<value>3</value> +			<value>2</value> +			<value>1</value> +			<value>2</value> +			<value>Softdeleted</value> +		</row> +		<row> +			<value>8</value> +			<value>1</value> +			<value>3</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +		</row> +	</table> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>user_posts</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>user 1</value> +			<value>user 1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>user 2</value> +			<value>user 2</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>user 3</value> +			<value>user 3</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/fixtures/set_topic_visibility.xml b/tests/content_visibility/fixtures/set_topic_visibility.xml new file mode 100644 index 0000000000..a875012d4f --- /dev/null +++ b/tests/content_visibility/fixtures/set_topic_visibility.xml @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>topic_visibility</column> +		<column>topic_title</column> +		<column>topic_first_post_id</column> +		<column>topic_last_post_id</column> +		<column>topic_delete_user</column> +		<column>topic_delete_time</column> +		<column>topic_delete_reason</column> + +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> + +		<row> +			<value>2</value> +			<value>1</value> +			<value>2</value> +			<value>Soft deleted</value> +			<value>4</value> +			<value>5</value> +			<value>2</value> +			<value>123</value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>poster_id</column> +		<column>topic_id</column> +		<column>forum_id</column> +		<column>post_visibility</column> +		<column>post_text</column> +		<column>post_delete_user</column> +		<column>post_delete_time</column> +		<column>post_delete_reason</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>Approved</value> +			<value>2</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>2</value> +			<value>Soft deleted</value> +			<value>2</value> +			<value>123</value> +			<value>manually</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> + +		<row> +			<value>4</value> +			<value>1</value> +			<value>2</value> +			<value>1</value> +			<value>2</value> +			<value>Soft deleted by topic soft delete</value> +			<value>2</value> +			<value>123</value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>1</value> +			<value>2</value> +			<value>1</value> +			<value>2</value> +			<value>Soft deleted before the topic was soft deleted</value> +			<value>2</value> +			<value>120</value> +			<value>manually</value> +		</row> +		<row> +			<value>6</value> +			<value>1</value> +			<value>2</value> +			<value>1</value> +			<value>0</value> +			<value>Unapproved before the topic was soft deleted</value> +			<value>0</value> +			<value>0</value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>user_posts</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>1</value> +			<value>6</value> +			<value>user 1</value> +			<value>user 1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php new file mode 100644 index 0000000000..aa44fa4013 --- /dev/null +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); +	} + +	public function get_forums_visibility_sql_data() +	{ +		return array( +			array( +				'phpbb_topics', +				'topic', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +					array('topic_id' => 7), +					array('topic_id' => 8), +					array('topic_id' => 9), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(1, 2), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(2 => true)), +				), +				array( +					array('topic_id' => 2), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +					array('topic_id' => 8), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +					array('post_id' => 7), +					array('post_id' => 8), +					array('post_id' => 9), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +				), +			), +			array( +				'phpbb_posts', +				'post', array(1, 2, 3), '', +				array( +					array('m_approve', true, array(2 => true)), +				), +				array( +					array('post_id' => 2), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +					array('post_id' => 8), +				), +			), +		); +	} + +	/** +	* @dataProvider get_forums_visibility_sql_data +	*/ +	public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) +	{ +		global $cache, $db, $auth, $phpbb_root_path, $phpEx; + +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); + +		// Create auth mock +		$auth = $this->getMock('phpbb_auth'); +		$auth->expects($this->any()) +			->method('acl_getf') +			->with($this->stringContains('_'), $this->anything()) +			->will($this->returnValueMap($permissions)); +		$user = $this->getMock('phpbb_user'); +		$content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + +		$result = $db->sql_query('SELECT ' . $mode . '_id +			FROM ' . $table . ' +			WHERE ' . $content_visibility->get_forums_visibility_sql($mode, $forum_ids, $table_alias) . ' +			ORDER BY ' . $mode . '_id ASC'); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); +	} +} diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php new file mode 100644 index 0000000000..0f019ffa50 --- /dev/null +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); +	} + +	public function get_global_visibility_sql_data() +	{ +		return array( +			array( +				'phpbb_topics', +				'topic', array(), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +					array('topic_id' => 7), +					array('topic_id' => 8), +					array('topic_id' => 9), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +				), +			), +			array( +				'phpbb_topics', +				'topic', array(), '', +				array( +					array('m_approve', true, array(2 => true)), +				), +				array( +					array('topic_id' => 2), +					array('topic_id' => 4), +					array('topic_id' => 5), +					array('topic_id' => 6), +					array('topic_id' => 8), +				), +			), +			array( +				'phpbb_posts', +				'post', array(), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +					array('post_id' => 7), +					array('post_id' => 8), +					array('post_id' => 9), +				), +			), +			array( +				'phpbb_posts', +				'post', array(3), '', +				array( +					array('m_approve', true, array(1 => true, 2 => true, 3 => true)), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +				), +			), +			array( +				'phpbb_posts', +				'post', array(), '', +				array( +					array('m_approve', true, array(2 => true)), +				), +				array( +					array('post_id' => 2), +					array('post_id' => 4), +					array('post_id' => 5), +					array('post_id' => 6), +					array('post_id' => 8), +				), +			), +		); +	} + +	/** +	* @dataProvider get_global_visibility_sql_data +	*/ +	public function test_get_global_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) +	{ +		global $cache, $db, $auth, $phpbb_root_path, $phpEx; + +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); + +		// Create auth mock +		$auth = $this->getMock('phpbb_auth'); +		$auth->expects($this->any()) +			->method('acl_getf') +			->with($this->stringContains('_'), $this->anything()) +			->will($this->returnValueMap($permissions)); +		$user = $this->getMock('phpbb_user'); +		$content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + +		$result = $db->sql_query('SELECT ' . $mode . '_id +			FROM ' . $table . ' +			WHERE ' . $content_visibility->get_global_visibility_sql($mode, $forum_ids, $table_alias) . ' +			ORDER BY ' . $mode . '_id ASC'); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); +	} +} diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php new file mode 100644 index 0000000000..cc6c10c649 --- /dev/null +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -0,0 +1,90 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml'); +	} + +	public function get_visibility_sql_data() +	{ +		return array( +			array( +				'phpbb_posts', +				'post', 1, '', +				array( +					array('m_approve', 1, true), +				), +				array( +					array('post_id' => 1), +					array('post_id' => 2), +					array('post_id' => 3), +				), +			), +			array( +				'phpbb_posts', +				'post', 1, '', +				array( +				), +				array( +					array('post_id' => 2), +				), +			), +			array( +				'phpbb_topics', +				'topic', 1, '', +				array( +					array('m_approve', 1, true), +				), +				array( +					array('topic_id' => 1), +					array('topic_id' => 2), +					array('topic_id' => 3), +				), +			), +			array( +				'phpbb_topics', +				'topic', 1, '', +				array(), +				array( +					array('topic_id' => 2), +				), +			), +		); +	} + +	/** +	* @dataProvider get_visibility_sql_data +	*/ +	public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected) +	{ +		global $cache, $db, $auth, $phpbb_root_path, $phpEx; + +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); + +		// Create auth mock +		$auth = $this->getMock('phpbb_auth'); +		$auth->expects($this->any()) +			->method('acl_get') +			->with($this->stringContains('_'), $this->anything()) +			->will($this->returnValueMap($permissions)); +		$user = $this->getMock('phpbb_user'); +		$content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + +		$result = $db->sql_query('SELECT ' . $mode . '_id +			FROM ' . $table . ' +			WHERE ' . $content_visibility->get_visibility_sql($mode, $forum_id, $table_alias) . ' +			ORDER BY ' . $mode . '_id ASC'); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); +	} +} diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php new file mode 100644 index 0000000000..81abf56c75 --- /dev/null +++ b/tests/content_visibility/set_post_visibility_test.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_post_visibility.xml'); +	} + +	public function set_post_visibility_data() +	{ +		return array( +			array( +				ITEM_APPROVED, +				1, 1, 1, +				2, time(), 'approve', +				true, false, +				array( +					array('post_id' => 1, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), +					array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 1, 'topic_last_post_id' => 2), +				), +			), +			array( +				ITEM_APPROVED, +				3, 1, 1, +				2, time(), 'approve', +				false, true, +				array( +					array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3), +				), +			), +			array( +				ITEM_DELETED, +				2, 1, 1, +				2, time(), 'deleted', +				true, true, +				array( +					array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), +					array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3), +				), +			), +			array( +				ITEM_DELETED, +				5, 2, 1, +				2, time(), 'deleted', +				true, false, +				array( +					array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), +					array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), +					array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6), +				), +			), +			array( +				ITEM_DELETED, +				6, 2, 1, +				2, time(), 'deleted', +				false, true, +				array( +					array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), +					array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 6, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), +					array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5), +				), +			), +			array( +				ITEM_DELETED, +				8, 3, 1, +				2, time(), 'deleted', +				true, true, +				array( +					array('post_id' => 8, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), +				), +				array( +					array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8), +				), +			), +		); +	} + +	/** +	* @dataProvider set_post_visibility_data +	*/ +	public function test_set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected, $expected_topic) +	{ +		global $cache, $db, $auth, $phpbb_root_path, $phpEx; + +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); +		$auth = $this->getMock('phpbb_auth'); +		$user = $this->getMock('phpbb_user'); +		$content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + +		$content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest); + +		$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason +			FROM phpbb_posts +			WHERE topic_id = ' . $topic_id . ' +			ORDER BY post_id ASC'); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); + +		$result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id +			FROM phpbb_topics +			WHERE topic_id = ' . $topic_id); + +		$this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); +	} +} diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php new file mode 100644 index 0000000000..6b5d884a2b --- /dev/null +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -0,0 +1,107 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_topic_visibility.xml'); +	} + +	public function set_topic_visibility_data() +	{ +		return array( +			array( +				ITEM_DELETED, 1, 1, +				2, time(), 'delete', false, +				array( +					array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), +					array('post_id' => 3, 'post_visibility' => 0, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete'), +				), +			), +			array( +				ITEM_DELETED, 1, 1, +				2, time(), 'delete-forced', true, +				array( +					array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), +					array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => ''), +					array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete-forced'), +				), +			), +			array( +				ITEM_APPROVED, 2, 1, +				2, time(), 'approved', false, +				array( +					array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), +					array('post_id' => 6, 'post_visibility' => 0, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 4, 'topic_delete_reason' => 'approved'), +				), +			), +			array( +				ITEM_APPROVED, 2, 1, +				2, time(), 'approved-forced', true, +				array( +					array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), +					array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), +				), +				array( +					array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 6, 'topic_delete_reason' => 'approved-forced'), +				), +			), +		); +	} + +	/** +	* @dataProvider set_topic_visibility_data +	*/ +	public function test_set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all, $expected_posts, $expected_topic) +	{ +		global $cache, $db, $auth, $phpbb_root_path, $phpEx; + +		$cache = new phpbb_mock_cache; +		$db = $this->new_dbal(); +		$auth = $this->getMock('phpbb_auth'); +		$user = $this->getMock('phpbb_user'); +		$content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + +		$content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all); + +		$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason +			FROM phpbb_posts +			WHERE topic_id = ' . $topic_id . ' +			ORDER BY post_id ASC'); + +		$this->assertEquals($expected_posts, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); + +		$result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_delete_reason +			FROM phpbb_topics +			WHERE topic_id = ' . $topic_id); + +		$this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); +		$db->sql_freeresult($result); +	} +} diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index c06bf7d548..dfc4f80469 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -59,7 +59,7 @@ class phpbb_controller_controller_test extends phpbb_test_case  		}  		if (!class_exists('phpbb_controller_foo'))  		{ -			include(__DIR__.'/includes/controller/foo.php'); +			include(__DIR__.'/phpbb/controller/foo.php');  		}  		$resolver = new phpbb_controller_resolver(new phpbb_user, $container); diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 2c22700ca6..6686b77e8f 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -45,15 +45,17 @@ class phpbb_controller_helper_url_test extends phpbb_test_case  	*/  	public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description)  	{ -		global $phpbb_dispatcher; +		global $phpbb_dispatcher, $phpbb_root_path, $phpEx;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher;  		$this->style_resource_locator = new phpbb_style_resource_locator();  		$this->user = $this->getMock('phpbb_user'); -		$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context()); +		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); +		$this->style_resource_locator = new phpbb_style_resource_locator(); +		$this->style_provider = new phpbb_style_path_provider(); +		$this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template);  		$helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');  		$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);  	}  } - diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/phpbb/controller/foo.php index 04576e16c4..04576e16c4 100644 --- a/tests/controller/includes/controller/foo.php +++ b/tests/controller/phpbb/controller/foo.php diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index c28925272e..2d97672878 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -7,9 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/user.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/datetime.php';  require_once dirname(__FILE__) . '/../mock/lang.php';  class phpbb_datetime_from_format_test extends phpbb_test_case diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index e87fc1c6bd..077bfad933 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -8,7 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';  class phpbb_dbal_auto_increment_test extends phpbb_database_test_case  { diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index c20e46011f..7bdbc696e7 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -8,7 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';  class phpbb_dbal_db_tools_test extends phpbb_database_test_case  { diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 1e40c9c6d6..9e55e4dd35 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -8,10 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; -  require_once dirname(__FILE__) . '/migration/dummy.php';  require_once dirname(__FILE__) . '/migration/unfulfillable.php';  require_once dirname(__FILE__) . '/migration/if.php'; diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 7d582f230b..b82d1ef48d 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -7,9 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; -  class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case  {  	public function setup() diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 3303086b26..828fb76c65 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -8,8 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';  class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case  { diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 438ab2b28e..79d9db66da 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -8,8 +8,6 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';  class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case  { diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index 84d454742f..d826765681 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -18,6 +18,11 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case  	{  		$db = $this->new_dbal(); +		if (strpos($db->sql_layer, 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>=')) +		{ +			$this->markTestSkipped('MySQL 5.6 fails to order things correctly. See also: http://tracker.phpbb.com/browse/PHPBB3-11571 http://bugs.mysql.com/bug.php?id=69005'); +		} +  		// http://tracker.phpbb.com/browse/PHPBB3-10507  		// Test ORDER BY LOWER(style_name)  		$db->sql_return_on_error(true); @@ -58,7 +63,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case  					'style_parent_id'	=> 0,  					'style_parent_tree'	=> '',  				) -			),  +			),  			$db->sql_fetchrowset($result)  		);  	} diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index d6a5ec823b..c570f19ebd 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -40,11 +40,12 @@ class phpbb_di_container_test extends phpbb_test_case      public function test_phpbb_create_compiled_container()      {          $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($extensions, array(), $phpbb_root_path, 'php'); +        $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php');          $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);          $this->assertTrue($container->isFrozen()); diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index d67dea3719..fceb8aa3d8 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -8,7 +8,6 @@  */  require_once dirname(__FILE__) . '/../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../phpBB/includes/error_collector.php';  class phpbb_error_collector_test extends phpbb_test_case  { diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 6f3cebbd7c..3bf2c42573 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -36,7 +36,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  	public function test_suffix_get_classes()  	{  		$classes = $this->finder -			->core_path('includes/default/') +			->core_path('phpbb/default/')  			->extension_suffix('_class')  			->get_classes(); @@ -81,7 +81,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  	public function test_prefix_get_classes()  	{  		$classes = $this->finder -			->core_path('includes/default/') +			->core_path('phpbb/default/')  			->extension_prefix('hidden_')  			->get_classes(); @@ -98,7 +98,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  	public function test_directory_get_classes()  	{  		$classes = $this->finder -			->core_path('includes/default/') +			->core_path('phpbb/default/')  			->extension_directory('type')  			->get_classes(); @@ -209,7 +209,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  	public function test_cached_get_files()  	{  		$query = array( -			'core_path' => 'includes/foo', +			'core_path' => 'phpbb/foo',  			'core_suffix' => false,  			'core_prefix' => false,  			'core_directory' => 'bar', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index d410333f09..e5bd29092e 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; -  class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  {  	protected $class_loader; @@ -42,12 +40,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		$this->user = new phpbb_user();  		$this->table_prefix = 'phpbb_'; -		$this->template = new phpbb_template( +		$this->template = new phpbb_template_twig(  			$this->phpbb_root_path,  			$this->phpEx,  			$this->config,  			$this->user, -			new phpbb_style_resource_locator(),  			new phpbb_template_context()  		); diff --git a/tests/extension/includes/default/implementation.php b/tests/extension/phpbb/default/implementation.php index 91d5f8aa2f..91d5f8aa2f 100644 --- a/tests/extension/includes/default/implementation.php +++ b/tests/extension/phpbb/default/implementation.php diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index ff4d3ced5c..cfd85571b7 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -39,7 +39,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case  		// logout  		$crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); -		$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());  		// look for a register link, which should be visible only when logged out  		$crawler = self::request('GET', 'index.php'); diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 8c014aebed..6c6572af62 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -36,6 +36,26 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test  		$this->add_lang(array('ucp', 'acp/groups'));  	} +	// Enable all avatars in the ACP +	protected function enable_all_avatars() +	{ +		$this->add_lang('acp/board'); + +		$crawler = self::request('GET', 'adm/index.php?i=board&mode=avatar&sid=' . $this->sid); +		// Check the default entries we should have +		$this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text()); +		$this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text()); +		$this->assertContains($this->lang('ALLOW_LOCAL'), $crawler->text()); + +		// Now start setting the needed settings +		$form = $crawler->selectButton($this->lang('SUBMIT'))->form(); +		$form['config[allow_avatar_local]']->select(1); +		$form['config[allow_avatar_remote]']->select(1); +		$form['config[allow_avatar_remote_upload]']->select(1); +		$crawler = self::submit($form); +		$this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->text()); +	} +  	public function groups_manage_test_data()  	{  		return array( @@ -60,4 +80,34 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test  		$crawler = self::submit($form);  		$this->assertContains($this->lang($expected), $crawler->text());  	} + +	public function group_avatar_min_max_data() +	{ +		return array( +			array('avatar_driver_upload', 'avatar_upload_url', 'foo', 'AVATAR_URL_INVALID'), +			array('avatar_driver_upload', 'avatar_upload_url', 'foobar', 'AVATAR_URL_INVALID'), +			array('avatar_driver_upload', 'avatar_upload_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), +			array('avatar_driver_remote', 'avatar_remote_url', 'foo', 'AVATAR_URL_INVALID'), +			array('avatar_driver_remote', 'avatar_remote_url', 'foobar', 'AVATAR_URL_INVALID'), +			array('avatar_driver_remote', 'avatar_remote_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), +		); +	} + +	/** +	* @dataProvider group_avatar_min_max_data +	*/ +	public function test_group_avatar_min_max($avatar_type, $form_name, $input, $expected) +	{ +		$this->login(); +		$this->admin_login(); +		$this->add_lang(array('ucp', 'acp/groups')); +		$this->enable_all_avatars(); + +		$crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); +		$form = $crawler->selectButton($this->lang('SUBMIT'))->form(); +		$form['avatar_driver']->setValue($avatar_type); +		$form[$form_name]->setValue($input); +		$crawler = self::submit($form); +		$this->assertContains($this->lang($expected), $crawler->text()); +	}  } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 9ddf1e3e5c..7d29f0000c 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -6,7 +6,6 @@  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';  /**  * @group functional diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index c573ea5410..c31a892ce9 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -6,8 +6,6 @@  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ - -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php';  /** diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php new file mode 100644 index 0000000000..59f7341eb6 --- /dev/null +++ b/tests/functional/forum_style_test.php @@ -0,0 +1,45 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_forum_style_test extends phpbb_functional_test_case +{ +	public function test_default_forum_style() +	{ +		$crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); +		$this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + +		$crawler = self::request('GET', 'viewtopic.php?t=1'); +		$this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + +		$crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); +		$this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); +	} + +	public function test_custom_forum_style() +	{ +		$db = $this->get_db(); +		$this->add_style(2, 'test_style'); +		$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2'); + +		$crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); +		$this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + +		$crawler = self::request('GET', 'viewtopic.php?t=1'); +		$this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + +		$crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); +		$this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + +		$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2'); +		$this->delete_style(2, 'test_style'); +	} +} diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index c55e7373ea..651c99a99d 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -7,8 +7,6 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; -  /**  * @group functional  */ diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php new file mode 100644 index 0000000000..d5adc6ad0a --- /dev/null +++ b/tests/functional/paging_test.php @@ -0,0 +1,39 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_paging_test extends phpbb_functional_test_case +{ + +	public function test_pagination() +	{ +		$this->login(); + +		$post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); +		for ($post_id = 1; $post_id < 20; $post_id++) +		{ +			$this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.'); +		} +		$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); +		$this->assertContains('post no9', $crawler->text()); +		$this->assertNotContains('post no19', $crawler->text()); + +		$next_link = $crawler->filter('#viewtopic > fieldset > a.arrow-right')->attr('href'); +		$crawler = self::request('GET', $next_link); +		$this->assertContains('post no19', $crawler->text()); +		$this->assertNotContains('post no9', $crawler->text()); + +		$prev_link = $crawler->filter('#viewtopic > fieldset > a.arrow-left')->attr('href'); +		$crawler = self::request('GET', $prev_link); +		$this->assertContains('post no9', $crawler->text()); +		$this->assertNotContains('post no19', $crawler->text()); +	} +} diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 9bcfcc2fda..7fd1e4fdcf 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -32,105 +32,4 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case  		$crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");  		$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());  	} - -	/** -	* Creates a topic -	*  -	* Be sure to login before creating -	*  -	* @param int $forum_id -	* @param string $subject -	* @param string $message -	* @param array $additional_form_data Any additional form data to be sent in the request -	* @return array post_id, topic_id -	*/ -	public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) -	{ -		$posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; - -		$form_data = array_merge(array( -			'subject'		=> $subject, -			'message'		=> $message, -			'post'			=> true, -		), $additional_form_data); - -		return self::submit_post($posting_url, 'POST_TOPIC', $form_data); -	} - -	/** -	* Creates a post -	*  -	* Be sure to login before creating -	*  -	* @param int $forum_id -	* @param string $subject -	* @param string $message -	* @param array $additional_form_data Any additional form data to be sent in the request -	* @return array post_id, topic_id -	*/ -	public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) -	{ -		$posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - -		$form_data = array_merge(array( -			'subject'		=> $subject, -			'message'		=> $message, -			'post'			=> true, -		), $additional_form_data); - -		return self::submit_post($posting_url, 'POST_REPLY', $form_data); -	} -	 -	/** -	* Helper for submitting posts -	*  -	* @param string $posting_url -	* @param string $posting_contains -	* @param array $form_data -	* @return array post_id, topic_id -	*/ -	protected function submit_post($posting_url, $posting_contains, $form_data) -	{ -		$this->add_lang('posting'); - -		$crawler = self::request('GET', $posting_url); -		$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); - -		$hidden_fields = array( -			$crawler->filter('[type="hidden"]')->each(function ($node, $i) { -				return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); -			}), -		); - -		foreach ($hidden_fields as $fields) -		{ -			foreach($fields as $field) -			{ -				$form_data[$field['name']] = $field['value']; -			} -		} - -		// Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) -		// is not at least 2 seconds before submission, cancel the form -		$form_data['lastclick'] = 0; - -		// I use a request because the form submission method does not allow you to send data that is not -		// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) -		// Instead, I send it as a request with the submit button "post" set to true. -		$crawler = self::request('POST', $posting_url, $form_data); -		$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - -		$url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); -		 -		$matches = $topic_id = $post_id = false; -		preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); -		 -		$topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; -		$post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - -		return array( -			'topic_id'	=> $topic_id, -			'post_id'	=> $post_id, -		); -	}  } diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php new file mode 100644 index 0000000000..af713775c5 --- /dev/null +++ b/tests/functional/report_post_captcha.php @@ -0,0 +1,61 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * @group functional + */ +class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_case +{ +	public function test_user_report_post() +	{ +		$this->login(); +		$crawler = self::request('GET', 'report.php?f=2&p=1'); +		$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); +	} + +	public function test_guest_report_post() +	{ +		$crawler = self::request('GET', 'report.php?f=2&p=1'); +		$this->add_lang('mcp'); +		$this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text()); + +		$this->set_reporting_guest(1); +		$crawler = self::request('GET', 'report.php?f=2&p=1'); +		$this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); +		$this->set_reporting_guest(-1); +	} + +	protected function set_reporting_guest($report_post_allowed) +	{ +		$this->login(); +		$this->admin_login(); + +		$crawler = self::request('GET', 'adm/index.php?i=permissions&icat=12&mode=setting_group_local&sid=' . $this->sid); +		$form = $crawler->selectButton('Submit')->form(); +		$values = $form->getValues(); +		$values["group_id[0]"] = 1; +		$form->setValues($values); +		$crawler = self::submit($form); + +		$form = $crawler->selectButton('Submit')->form(); +		$values = $form->getValues(); +		$values["forum_id"] = 2; +		$form->setValues($values); +		$crawler = self::submit($form); + +		$this->add_lang('acp/permissions'); +		$form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); +		$values = $form->getValues(); +		$values["setting[1][2][f_report]"] = $report_post_allowed; +		$form->setValues($values); +		$crawler = self::submit($form); + +		$crawler = self::request('GET', 'ucp.php?mode=logout&sid=' . $this->sid); +	} +} diff --git a/tests/functional/softdelete_test.php b/tests/functional/softdelete_test.php new file mode 100644 index 0000000000..bd4d34cf99 --- /dev/null +++ b/tests/functional/softdelete_test.php @@ -0,0 +1,761 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_softdelete_test extends phpbb_functional_test_case +{ +	protected $data = array(); + +	public function test_setup_forums() +	{ +		$this->login(); +		$this->admin_login(); + +		$crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); +		$form = $crawler->selectButton('addforum')->form(array( +			'forum_name'	=> 'Soft Delete #1', +		)); +		$crawler = self::submit($form); +		$form = $crawler->selectButton('update')->form(array( +			'forum_perm_from'	=> 2, +		)); +		$crawler = self::submit($form); + +		$crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); +		$form = $crawler->selectButton('addforum')->form(array( +			'forum_name'	=> 'Soft Delete #2', +		)); +		$crawler = self::submit($form); +		$form = $crawler->selectButton('update')->form(array( +			'forum_perm_from'	=> 2, +		)); +		$crawler = self::submit($form); +	} + +	public function test_create_post() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'initial comparison'); + +		// Test creating topic +		$post = $this->create_topic($this->data['forums']['Soft Delete #1'], 'Soft Delete Topic #1', 'This is a test topic posted by the testing framework.'); +		$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('html')->text()); +		$this->data['topics']['Soft Delete Topic #1'] = (int) $post['topic_id']; +		$this->data['posts']['Soft Delete Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after creating topic #1'); + +		// Test creating a reply +		$post2 = $this->create_post($this->data['forums']['Soft Delete #1'], $post['topic_id'], 'Re: Soft Delete Topic #1-#2', 'This is a test post posted by the testing framework.'); +		$crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + +		$this->assertContains('Re: Soft Delete Topic #1-#2', $crawler->filter('html')->text()); +		$this->data['posts']['Re: Soft Delete Topic #1-#2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 2, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Re: Soft Delete Topic #1-#2'], +		), 'after replying'); +	} + +	public function test_softdelete_post() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 2, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Re: Soft Delete Topic #1-#2'], +		), 'before softdelete'); + +		$this->add_lang('posting'); +		$crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Soft Delete #1']}&p={$this->data['posts']['Re: Soft Delete Topic #1-#2']}&sid={$this->sid}"); +		$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('POST_DELETED', $crawler->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after softdelete'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); +	} + +	public function test_move_softdeleted_post() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'before moving #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before moving #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$form = $crawler->selectButton('Go')->eq(2)->form(); +		$form['action']->select('move'); +		$crawler = self::submit($form); +		$this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Yes')->form(); +		$form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); +		$crawler = self::submit($form); +		$this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'after moving #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after moving #2'); +	} + +	public function test_softdelete_topic() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before softdeleting #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'before softdeleting #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$this->add_lang('posting'); +		$form = $crawler->selectButton('Go')->eq(2)->form(); +		$form['action']->select('delete_topic'); +		$crawler = self::submit($form); +		$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'after moving #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 2, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> 0, +		), 'after moving #2'); +	} + +	public function test_move_softdeleted_topic() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before moving #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 2, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> 0, +		), 'before moving #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$form = $crawler->selectButton('Go')->eq(2)->form(); +		$form['action']->select('move'); +		$crawler = self::submit($form); +		$this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Yes')->form(); +		$form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); +		$crawler = self::submit($form); +		$this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 2, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> 0, +		), 'after moving #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'after moving #2'); +	} + +	public function test_restore_post() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 2, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> 0, +		), 'before restoring #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before restoring #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton($this->lang('RESTORE'))->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('RESTORE_POST', $crawler->text()); + +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('POST_RESTORED_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after restoring #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'after restoring #2'); +	} + +	public function test_split_topic() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'before splitting #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before splitting #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Go')->eq(2)->form(); +		$form['action']->select('split'); +		$crawler = self::submit($form); +		$this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text()); + +		$form = $crawler->selectButton('Submit')->form(array( +			'subject'			=> 'Soft Delete Topic #2', +		)); +		$form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); +		$form['post_id_list'][1]->tick(); +		$crawler = self::submit($form); + +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('TOPIC_SPLIT_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); +		$this->assertNotContains('Re: Soft Delete Topic #1-#2', $crawler->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after restoring #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> 0, +		), 'after restoring #2'); +	} + +	public function test_move_topic_back() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +				'Soft Delete Topic #2', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + +		$form = $crawler->selectButton('Go')->eq(1)->form(); +		$form['action']->select('move'); +		$crawler = self::submit($form); + +		$form = $crawler->selectButton('Yes')->form(); +		$form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); +		$crawler = self::submit($form); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after moving back'); +	} + +	public function test_merge_topics() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +				'Soft Delete Topic #2', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 1, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'before merging #1'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Go')->eq(1)->form(); +		$form['action']->select('merge_topic'); +		$crawler = self::submit($form); +		$this->assertContainsLang('SELECT_MERGE', $crawler->text()); + +		$crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}"); +		$this->assertContainsLang('MERGE_TOPICS_CONFIRM', $crawler->text()); + +		$form = $crawler->selectButton('Yes')->form(); +		$crawler = self::submit($form); +		$this->assertContainsLang('POSTS_MERGED_SUCCESS', $crawler->text()); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); +		$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); +		$this->assertContainsLang('POST_DELETED', $crawler->filter('body')->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after merging #1'); +	} + +	public function test_fork_topic() +	{ +		$this->login(); +		$this->load_ids(array( +			'forums' => array( +				'Soft Delete #1', +				'Soft Delete #2', +			), +			'topics' => array( +				'Soft Delete Topic #1', +			), +			'posts' => array( +				'Soft Delete Topic #1', +				'Re: Soft Delete Topic #1-#2', +			), +		)); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'before forking #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 0, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 0, +			'forum_topics_approved'		=> 0, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> 0, +		), 'before forking #2'); + +		$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + +		$this->add_lang('mcp'); +		$form = $crawler->selectButton('Go')->eq(2)->form(); +		$form['action']->select('fork'); +		$crawler = self::submit($form); +		$this->assertContainsLang('FORK_TOPIC', $crawler->text()); + +		$form = $crawler->selectButton('Yes')->form(); +		$form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); +		$crawler = self::submit($form); +		$this->assertContainsLang('TOPIC_FORKED_SUCCESS', $crawler->text()); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'], +		), 'after forking #1'); + +		$this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( +			'forum_posts_approved'		=> 1, +			'forum_posts_unapproved'	=> 0, +			'forum_posts_softdeleted'	=> 1, +			'forum_topics_approved'		=> 1, +			'forum_topics_unapproved'	=> 0, +			'forum_topics_softdeleted'	=> 0, +			'forum_last_post_id'		=> $this->data['posts']['Soft Delete Topic #1'] + 2, +		), 'after forking #2'); +	} + +	public function assert_forum_details($forum_id, $details, $additional_error_message = '') +	{ +		$this->db = $this->get_db(); + +		$sql = 'SELECT ' . implode(', ', array_keys($details)) . ' +			FROM phpbb_forums +			WHERE forum_id = ' . (int) $forum_id; +		$result = $this->db->sql_query($sql); +		$data = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		$this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); +	} + +	public function load_ids($data) +	{ +		$this->db = $this->get_db(); + +		if (!empty($data['forums'])) +		{ +			$sql = 'SELECT * +				FROM phpbb_forums +				WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); +			$result = $this->db->sql_query($sql); +			while ($row = $this->db->sql_fetchrow($result)) +			{ +				if (in_array($row['forum_name'], $data['forums'])) +				{ +					$this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; +				} +			} +			$this->db->sql_freeresult($result); +		} + +		if (!empty($data['topics'])) +		{ +			$sql = 'SELECT * +				FROM phpbb_topics +				WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); +			$result = $this->db->sql_query($sql); +			while ($row = $this->db->sql_fetchrow($result)) +			{ +				if (in_array($row['topic_title'], $data['topics'])) +				{ +					$this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; +				} +			} +			$this->db->sql_freeresult($result); +		} + +		if (!empty($data['posts'])) +		{ +			$sql = 'SELECT * +				FROM phpbb_posts +				WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); +			$result = $this->db->sql_query($sql); +			while ($row = $this->db->sql_fetchrow($result)) +			{ +				if (in_array($row['post_subject'], $data['posts'])) +				{ +					$this->data['posts'][$row['post_subject']] = (int) $row['post_id']; +				} +			} +			$this->db->sql_freeresult($result); +		} +	} +} diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php new file mode 100644 index 0000000000..4032ca5b58 --- /dev/null +++ b/tests/functions/get_remote_file_test.php @@ -0,0 +1,75 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; + +/** +* @group slow +*/ +class phpbb_functions_get_remote_file extends phpbb_test_case +{ +	public function test_version_phpbb_com() +	{ +		$hostname = 'version.phpbb.com'; + +		if (!phpbb_checkdnsrr($hostname, 'A')) +		{ +			$this->markTestSkipped(sprintf( +				'Could not find a DNS record for hostname %s. ' . +				'Assuming network is down.', +				$hostname +			)); +		} + +		$errstr = $errno = null; +		$file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); + +		$this->assertNotEquals( +			0, +			strlen($file), +			'Failed asserting that the response is not empty.' +		); + +		$this->assertSame( +			'', +			$errstr, +			'Failed asserting that the error string is empty.' +		); + +		$this->assertSame( +			0, +			$errno, +			'Failed asserting that the error number is 0 (i.e. no error occurred).' +		); + +		$lines = explode("\n", $file); + +		$this->assertGreaterThanOrEqual( +			2, +			sizeof($lines), +			'Failed asserting that the version file has at least two lines.' +		); + +		$this->assertStringStartsWith( +			'3.', +			$lines[0], +			"Failed asserting that the first line of the version file starts with '3.'" +		); + +		$this->assertNotSame( +			false, +			filter_var($lines[1], FILTER_VALIDATE_URL), +			'Failed asserting that the second line of the version file is a valid URL.' +		); + +		$this->assertContains('http', $lines[1]); +		$this->assertContains('phpbb.com', $lines[1], '', true); +	} +} diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 1ab9488568..6827aaa1b6 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -11,7 +11,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';  require_once dirname(__FILE__) . '/../mock/user.php';  require_once dirname(__FILE__) . '/../mock/cache.php'; diff --git a/tests/mock/search.php b/tests/mock/search.php new file mode 100644 index 0000000000..6739719216 --- /dev/null +++ b/tests/mock/search.php @@ -0,0 +1,23 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +*/ +class phpbb_mock_search +{ + +	public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) +	{ +	} + +	public function index_remove($post_ids, $poster_ids, $forum_ids) +	{ +	} +} + diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php new file mode 100644 index 0000000000..ba09aa8d7f --- /dev/null +++ b/tests/mock/sql_insert_buffer.php @@ -0,0 +1,21 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_sql_insert_buffer extends phpbb_db_sql_insert_buffer +{ +	public function flush() +	{ +		return (sizeof($this->buffer)) ? true : false; +	} + +	public function get_buffer() +	{ +		return $this->buffer; +	} +} diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php new file mode 100644 index 0000000000..c038020385 --- /dev/null +++ b/tests/notification/convert_test.php @@ -0,0 +1,108 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +require_once dirname(__FILE__) . '/../mock/sql_insert_buffer.php'; + +class phpbb_notification_convert_test extends phpbb_database_test_case +{ +	protected $notifications, $db, $container, $user, $config, $auth, $cache; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml'); +	} + +	protected function setUp() +	{ +		parent::setUp(); + +		global $phpbb_root_path, $phpEx; + +		$this->db = $this->new_dbal(); + +		$this->migration = new phpbb_db_migration_data_310_notification_options_reconvert( +			new phpbb_config(array()), +			$this->db, +			new phpbb_db_tools($this->db), +			$phpbb_root_path, +			$phpEx, +			'phpbb_' +		); +	} + +	public function test_convert() +	{ +		$buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); +		$this->migration->perform_conversion($buffer, 'phpbb_user_notifications'); + +		$expected = array_merge( +			$this->create_expected('post', 1, 'email'), +			$this->create_expected('topic', 1, 'email'), + +			$this->create_expected('post', 2, 'email'), +			$this->create_expected('topic', 2, 'email'), +			$this->create_expected('pm', 2, 'email'), + +			$this->create_expected('post', 3, 'jabber'), +			$this->create_expected('topic', 3, 'jabber'), + +			$this->create_expected('post', 4, 'jabber'), +			$this->create_expected('topic', 4, 'jabber'), +			$this->create_expected('pm', 4, 'jabber'), + +			$this->create_expected('post', 5, 'both'), +			$this->create_expected('topic', 5, 'both'), + +			$this->create_expected('post', 6, 'both'), +			$this->create_expected('topic', 6, 'both'), +			$this->create_expected('pm', 6, 'both') +		); + +		$this->assertEquals($expected, $buffer->get_buffer()); +	} + +	protected function create_expected($type, $user_id, $method = '') +	{ +		$return = array(); + +		if ($method !== '') +		{ +			$return[] = array( +				'item_type'		=> $type, +				'item_id'		=> 0, +				'user_id'		=> $user_id, +				'method'		=> '', +				'notify'		=> 1, +			); +		} + +		if ($method === 'email' || $method === 'both') +		{ +			$return[] = array( +				'item_type'		=> $type, +				'item_id'		=> 0, +				'user_id'		=> $user_id, +				'method'		=> 'email', +				'notify'		=> 1, +			); +		} + +		if ($method === 'jabber' || $method === 'both') +		{ +			$return[] = array( +				'item_type'		=> $type, +				'item_id'		=> 0, +				'user_id'		=> $user_id, +				'method'		=> 'jabber', +				'notify'		=> 1, +			); +		} + +		return $return; +	} +} diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml new file mode 100644 index 0000000000..3f0a065cc4 --- /dev/null +++ b/tests/notification/fixtures/convert.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_notify_type</column> +		<column>user_notify_pm</column> +		<column>user_permissions</column> +		<column>user_sig</column> +		<column>user_occ</column> +		<column>user_interests</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>2</value> +			<value>0</value> +			<value>1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>3</value> +			<value>1</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>4</value> +			<value>4</value> +			<value>1</value> +			<value>1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>5</value> +			<value>5</value> +			<value>2</value> +			<value>0</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>6</value> +			<value>6</value> +			<value>6</value> +			<value>2</value> +			<value>1</value> +			<value></value> +			<value></value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 59daf6c9cb..4e564ce23c 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -96,6 +96,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case  		// Container  		$phpbb_container = new phpbb_mock_container_builder(); +		$phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));  		$user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index ad78d92299..e5a7f7a4a1 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -53,7 +53,20 @@ class phpbb_session_continue_test extends phpbb_database_test_case  	*/  	public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message)  	{ +		global $phpbb_container, $phpbb_root_path, $phpEx; +  		$db = $this->new_dbal(); +		$config = new phpbb_config(array()); +		$request = $this->getMock('phpbb_request'); +		$user = $this->getMock('phpbb_user'); + +		$auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); +		$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); +		$phpbb_container->expects($this->any()) +			->method('get') +			->with('auth.provider.db') +			->will($this->returnValue($auth_provider)); +  		$session_factory = new phpbb_session_testable_factory;  		$session_factory->set_cookies(array(  			'_sid' => $session_id, diff --git a/tests/session/init_test.php b/tests/session/creation_test.php index 830de34ed0..fde76d6b06 100644 --- a/tests/session/init_test.php +++ b/tests/session/creation_test.php @@ -9,7 +9,7 @@  require_once dirname(__FILE__) . '/testable_factory.php'; -class phpbb_session_init_test extends phpbb_database_test_case +class phpbb_session_creation_test extends phpbb_database_test_case  {  	public function getDataSet()  	{ @@ -20,7 +20,20 @@ class phpbb_session_init_test extends phpbb_database_test_case  	public function test_login_session_create()  	{ +		global $phpbb_container, $phpbb_root_path, $phpEx; +  		$db = $this->new_dbal(); +		$config = new phpbb_config(array()); +		$request = $this->getMock('phpbb_request'); +		$user = $this->getMock('phpbb_user'); + +		$auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); +		$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); +		$phpbb_container->expects($this->any()) +			->method('get') +			->with('auth.provider.db') +			->will($this->returnValue($auth_provider)); +  		$session_factory = new phpbb_session_testable_factory;  		$session = $session_factory->get_session($db); @@ -34,10 +47,11 @@ class phpbb_session_init_test extends phpbb_database_test_case  		$this->assertSqlResultEquals(  			array(array('session_user_id' => 3)),  			$sql, -			'Check if exacly one session for user id 3 was created' +			'Check if exactly one session for user id 3 was created'  		); -		$cookie_expire = $session->time_now + 31536000; // default is one year +		$one_year_in_seconds = 365 * 24 * 60 * 60; +		$cookie_expire = $session->time_now + $one_year_in_seconds;  		$session->check_cookies($this, array(  			'u' => array(null, $cookie_expire), diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index f1012b6939..ff7b890d11 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -15,9 +15,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case  	{  		$this->setup_engine(array('tpl_allow_php' => true)); -		$cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - -		$this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); +		$this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");  		$this->template->set_filenames(array('test' => 'includephp_relative.html'));  		$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -27,9 +25,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case  	{  		$this->setup_engine(array('tpl_allow_php' => true)); -		$cache_file = $this->template->cachepath . 'includephp_variables.html.php'; - -		$this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file); +		$this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php");  		$this->template->set_filenames(array('test' => 'includephp_variables.html'));  		$this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -37,11 +33,13 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case  	public function test_includephp_absolute()  	{ -		$path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; +		global $phpbb_root_path; + +		$path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc';  		$this->assertTrue(phpbb_is_absolute($path_to_php));  		$template_text = "Path is absolute.\n<!-- INCLUDEPHP $path_to_php -->"; -		$cache_dir = dirname($this->template->cachepath) . '/'; +		$cache_dir = $phpbb_root_path . 'cache/';  		$fp = fopen($cache_dir . 'includephp_absolute.html', 'w');  		fputs($fp, $template_text);  		fclose($fp); @@ -49,9 +47,8 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case  		$this->setup_engine(array('tpl_allow_php' => true));  		$this->style->set_custom_style('tests', $cache_dir, array(), ''); -		$cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; -		$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); +		$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");  		$this->template->set_filenames(array('test' => 'includephp_absolute.html'));  		$this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php deleted file mode 100644 index 19d192b8b6..0000000000 --- a/tests/template/invalid_constructs_test.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -require_once dirname(__FILE__) . '/template_test_case.php'; - -class phpbb_template_invalid_constructs_test extends phpbb_template_template_test_case -{ -	public function template_data() -	{ -		return array( -			array( -				'Unknown tag', -				'invalid/unknown_tag.html', -				array(), -				array(), -				array(), -				'invalid/output/unknown_tag.html', -			), -			/* -			* Produces a parse error which is fatal, therefore -			* destroying the test suite. -			array( -				'ENDIF without IF', -				'invalid/endif_without_if.html', -				array(), -				array(), -				array(), -				'invalid/output/endif_without_if.html', -			), -			*/ -		); -	} - -	public function template_data_error() -	{ -		return array( -			array( -				'Include a nonexistent file', -				'invalid/include_nonexistent_file.html', -				array(), -				array(), -				array(), -				E_USER_ERROR, -				'invalid/output/include_nonexistent_file.html', -			), -		); -	} - -	/** -	* @dataProvider template_data -	*/ -	public function test_template($description, $file, $vars, $block_vars, $destroy, $expected) -	{ -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - -		$this->assertFileNotExists($cache_file); - -		$expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); -		// apparently the template engine does not put -		// the trailing newline into compiled templates -		$expected = trim($expected); -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); -	} - -	/** -	* @dataProvider template_data_error -	*/ -	public function test_template_error($description, $file, $vars, $block_vars, $destroy, $error, $expected) -	{ -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - -		$this->assertFileNotExists($cache_file); - -		$expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); -		// apparently the template engine does not put -		// the trailing newline into compiled templates -		$expected = trim($expected); -		$this->setExpectedTriggerError($error, $expected); -		$this->run_template($file, $vars, $block_vars, $destroy, '', $cache_file); -	} -} diff --git a/tests/template/parent_templates/parent_only.css b/tests/template/parent_templates/parent_only.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/template/parent_templates/parent_only.css diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php deleted file mode 100644 index 7ebb8b9bda..0000000000 --- a/tests/template/renderer_eval_test.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -class phpbb_template_renderer_eval_test extends phpbb_test_case -{ -	public function test_eval() -	{ -		$compiled_code = '<a href="<?php echo \'Test\'; ?>">'; -		$valid_code = '<a href="Test">'; -		$context = new phpbb_template_context(); -		$template = new phpbb_template_renderer_eval($compiled_code, NULL); -		ob_start(); -		try -		{ -			$template->render($context, array()); -		} -		catch (Exception $exception) -		{ -			ob_end_clean(); -			throw $exception; -		} -		$output = ob_get_clean(); -		$this->assertEquals($valid_code, $output); -	} -} diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php index 517cb85a30..6f9bc1efa6 100644 --- a/tests/template/subdir/includephp_from_subdir_test.php +++ b/tests/template/subdir/includephp_from_subdir_test.php @@ -19,9 +19,7 @@ class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_t  	{  		$this->setup_engine(array('tpl_allow_php' => true)); -		$cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - -		$this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); +		$this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");  		$this->template->set_filenames(array('test' => 'includephp_relative.html'));  		$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php deleted file mode 100644 index 7393fc1747..0000000000 --- a/tests/template/template_compile_test.php +++ /dev/null @@ -1,31 +0,0 @@ -<?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__) . '/../../phpBB/includes/functions.php'; - -class phpbb_template_template_compile_test extends phpbb_test_case -{ -	private $template_compile; -	private $template_path; - -	protected function setUp() -	{ -		$this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, ''); -		$this->template_path = dirname(__FILE__) . '/templates'; -	} - -	public function test_in_phpbb() -	{ -		$output = $this->template_compile->compile_file($this->template_path . '/trivial.html'); -		$this->assertTrue(strlen($output) > 0); -		$statements = explode(';', $output); -		$first_statement = $statements[0]; -		$this->assertTrue(!!preg_match('#if.*defined.*IN_PHPBB.*exit#', $first_statement)); -	} -} diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 0ac50c7f2b..f7bcd2dcc6 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -54,11 +54,9 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c  				array(),  				array(),  				array(), -'Kappa test event in all -Omega test event in all -Zeta test event in all -Kappa test event in silver -Omega test event in silver', +'Kappa test event in silver +Omega test event in silver +Zeta test event in all',  			),  			array(  				'Template event with inheritance - child', @@ -68,10 +66,9 @@ Omega test event in silver',  				array(),  				array(),  				array(), -'Kappa test event in all -Omega test event in all -Zeta test event in all -Kappa test event in silver_inherit', +'Kappa test event in silver_inherit +Omega test event in silver +Zeta test event in all',  			),  			array(  				'Definition in parent style', @@ -95,8 +92,7 @@ Kappa test event in silver_inherit',  		$this->setup_engine_for_events($dataset, $style_names);  		// Run test -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); +		$this->run_template($file, $vars, $block_vars, $destroy, $expected);  	}  	protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) @@ -111,7 +107,7 @@ Kappa test event in silver_inherit',  		$this->extension_manager = new phpbb_mock_filesystem_extension_manager(  			dirname(__FILE__) . "/datasets/$dataset/"  		); -		$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); +		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager);  		$this->style_provider = new phpbb_style_path_provider();  		$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);  		$this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php new file mode 100644 index 0000000000..f8999ad1a9 --- /dev/null +++ b/tests/template/template_includecss_test.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; + +class phpbb_template_template_includecss_test extends phpbb_template_template_test_case_with_tree +{ +	public function test_includecss_compilation() +	{ +		// Reset the engine state +		$this->setup_engine(array('assets_version' => 1)); + +		// Prepare correct result +		$scripts = array( +			'<link href="' . $this->test_path . '/templates/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', +			'<link href="' . $this->test_path . '/parent_templates/parent_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', +		); + +		// Run test +		$this->run_template('includecss.html', array(), array(), array(), implode('', $scripts)); +	} +} diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 22b020208b..b67fa123a1 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -11,23 +11,93 @@ require_once dirname(__FILE__) . '/template_test_case_with_tree.php';  class phpbb_template_template_includejs_test extends phpbb_template_template_test_case_with_tree  { -	public function test_includejs_compilation() +	public function template_data() +	{ +		return array( +			/* +			array( +				// vars +				// expected +			), +			*/ +			array( +				array('TEST' => 1), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 2), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=0"></script>', +			), +			array( +				array('TEST' => 3), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&assets_version=0"></script>', +			), +			array( +				array('TEST' => 4), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&assets_version=0"></script>', +			), +			array( +				array('TEST' => 6), +				'<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 7), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 8), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 9), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 10), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', +			), +			array( +				array('TEST' => 11), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/child_only.js?test1=1&test2=2&assets_version=1#test3"></script>', +			), +			array( +				array('TEST' => 12), +				'<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?test1=1&test2=2&assets_version=1#test3"></script>', +			), +			array( +				array('TEST' => 14), +				'<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?test1="&assets_version=1#test3"></script>', +			), +			array( +				array('TEST' => 15), +				'<script type="text/javascript" src="http://phpbb.com/b.js?c=d#f"></script>', +			), +			array( +				array('TEST' => 16), +				'<script type="text/javascript" src="http://phpbb.com/b.js?c=d&assets_version=2#f"></script>', +			), +			array( +				array('TEST' => 17), +				'<script type="text/javascript" src="//phpbb.com/b.js"></script>', +			), +			array( +				array('TEST' => 18), +				'<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&test2=0&assets_version=1"></script>', +			), +		); +	} + +	/** +	* @dataProvider template_data +	*/ +	public function test_includejs_compilation($vars, $expected)  	{  		// Reset the engine state  		$this->setup_engine(array('assets_version' => 1)); -		// Prepare correct result -		$scripts = array( -			'<script src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>', -			'<script src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>', -			'<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>', -			'<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', -			'<script src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>', -			'<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', -		); +		$this->template->assign_vars($vars);  		// Run test -		$cache_file = $this->template->cachepath . 'includejs.html.php'; -		$this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file); +		$this->run_template('includejs.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected);  	}  } diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index febfed9ef0..cc71ff99e0 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -50,15 +50,6 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t  	*/  	public function test_template($name, $file, array $vars, array $block_vars, array $destroy, $expected)  	{ -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - -		$this->assertFileNotExists($cache_file); - -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - -		// Reset the engine state -		$this->setup_engine(); - -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); +		$this->run_template($file, $vars, $block_vars, $destroy, $expected);  	}  } diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php deleted file mode 100644 index 851dcae8ea..0000000000 --- a/tests/template/template_locate_test.php +++ /dev/null @@ -1,68 +0,0 @@ -<?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__) . '/template_test_case_with_tree.php'; - -class phpbb_template_template_locate_test extends phpbb_template_template_test_case_with_tree -{ -	public function template_data() -	{ -		return array( -			// First element of the array is test name - keep them distinct -			array( -				'simple inheritance - only parent template exists', -				$this->test_path . '/parent_templates/parent_only.html', -				'parent_only.html', -				false, -				true, -			), -			array( -				'simple inheritance - only child template exists', -				$this->test_path . '/templates/child_only.html', -				'child_only.html', -				false, -				true, -			), -			array( -				'simple inheritance - both parent and child templates exist', -				$this->test_path . '/templates/parent_and_child.html', -				'parent_and_child.html', -				false, -				true, -			), -			array( -				'find first template - only child template exists in main style', -				'child_only.html', -				array('parent_only.html', 'child_only.html'), -				false, -				false, -			), -			array( -				'find first template - both templates exist in main style', -				'parent_and_child.html', -				array('parent_and_child.html', 'child_only.html'), -				false, -				false, -			), -		); -	} - -	/** -	* @dataProvider template_data -	*/ -	public function test_template($name, $expected, $files, $return_default, $return_full_path) -	{ -		// Reset the engine state -		$this->setup_engine(); - -		// Locate template -		$result = $this->style_resource_locator->get_first_template_location($files, $return_default, $return_full_path); -		$this->assertSame($expected, $result); -	} -} diff --git a/tests/template/template_parser_test.php b/tests/template/template_parser_test.php new file mode 100644 index 0000000000..c200770adf --- /dev/null +++ b/tests/template/template_parser_test.php @@ -0,0 +1,29 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/template_test_case.php'; + +class phpbb_template_template_parser_test extends phpbb_template_template_test_case +{ +	public function test_set_filenames() +	{ +		$this->template->set_filenames(array( +			'basic'	=> 'basic.html', +		)); + +		$this->assertEquals("passpasspass<!-- DUMMY var -->", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic'))); + +		$this->template->set_filenames(array( +			'basic'	=> 'if.html', +		)); + +		$this->assertEquals("03!false", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic'))); +	} +} diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php deleted file mode 100644 index 83f8711b38..0000000000 --- a/tests/template/template_spacing_test.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -require_once dirname(__FILE__) . '/template_test_case.php'; - -class phpbb_template_template_spacing_test extends phpbb_template_template_test_case -{ -	public function template_data() -	{ -		return array( -			/* -			array( -				'', // Description -				'', // dataset -				array(), // style names -				'', // file -				array(), // vars -				array(), // block vars -				array(), // destroy -				'', // expected result -			), -			*/ -			array( -				'Spacing in templates', -				'ext_trivial', -				array(), -				'variable_spacing.html', -				array( -					'VARIABLE'	=> '{}', -				), -				array(), -				array(), -				'|{}| -{}|{}| -|{} -<div class="{}">test</div>', -			), -		); -	} - -	/** -	* @dataProvider template_data -	*/ -	public function test_template($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) -	{ -		// Run test -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); -	} - -	/** -	* @dataProvider template_data -	*/ -	public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) -	{ -		// Reset the engine state -		$this->setup_engine_for_events($dataset, $style_names); - -		// Run test -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); -	} - -	protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) -	{ -		global $phpbb_root_path, $phpEx, $user; - -		$defaults = $this->config_defaults(); -		$config = new phpbb_config(array_merge($defaults, $new_config)); - -		$this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; -		$this->style_resource_locator = new phpbb_style_resource_locator(); -		$this->extension_manager = new phpbb_mock_filesystem_extension_manager( -			dirname(__FILE__) . "/datasets/$dataset/" -		); -		$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); -		$this->style_provider = new phpbb_style_path_provider(); -		$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); -		$this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); -	} -} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index a3c0b69123..802f0c19ba 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -46,28 +46,42 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array(),  				array(), -				'03', +				'03!false',  			),  			array(  				'if.html',  				array('S_VALUE' => true),  				array(),  				array(), -				'1', +				'1!false',  			),  			array(  				'if.html',  				array('S_VALUE' => true, 'S_OTHER_VALUE' => true),  				array(),  				array(), -				'1', +				'1!false',  			),  			array(  				'if.html',  				array('S_VALUE' => false, 'S_OTHER_VALUE' => true),  				array(),  				array(), -				'2', +				'2!false', +			), +			array( +				'if.html', +				array('S_TEST' => false), +				array(), +				array(), +				'03false', +			), +			array( +				'if.html', +				array('S_TEST' => 0), +				array(), +				array(), +				'03!false',  			),  			array(  				'loop.html', @@ -116,7 +130,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),  				array(), -				"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner\ninner loop", +				"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner",  			),  			array(  				'loop_advanced.html', @@ -126,6 +140,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561",  			),  			array( +				'loop_nested2.html', +				array(), +				array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())), +				array(), +				"o0o1m01m11", +			), +			array(  				'define.html',  				array(),  				array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), @@ -140,13 +161,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"abc\nzxc\ncde\nbcd",  			),  			array( -				'define_unclosed.html', -				array(), -				array(), -				array(), -				"test", -			), -			array(  				'expressions.html',  				array(),  				array(), @@ -247,21 +261,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array(),  				array(), -				"{ VARIABLE }\n{ 1_VARIABLE }\n{ VARIABLE }\n{ 1_VARIABLE }", +				"VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE",  			),  			array(  				'lang.html', -				array('L_VARIABLE' => "Value'", 'L_1_VARIABLE' => "1 O'Clock"),  				array(),  				array(), -				"Value'\n1 O'Clock\nValue\'\n1 O\'Clock", -			), -			array( -				'lang.html', -				array('LA_VARIABLE' => "Value'", 'LA_1_VARIABLE' => "1 O'Clock"), -				array(),  				array(), -				"{ VARIABLE }\n{ 1_VARIABLE }\nValue'\n1 O'Clock", +				"Value'\n1 O'Clock\nValue\'\n1 O\'Clock", +				array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),  			),  			array(  				'loop_nested_multilevel_ref.html', @@ -275,7 +283,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),  				array(), -				// I don't completely understand this output, hopefully it's correct  				"top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz",  			),  			array( @@ -283,7 +290,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),  				array(), -				// I don't completely understand this output, hopefully it's correct  				"top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz",  			),  			array( @@ -303,6 +309,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"a\nb\nc\nd",  			),  			*/ +			array( +				'twig.html', +				array('VARIABLE' => 'FOObar',), +				array(), +				array(), +				"13FOOBAR|foobar", +			),  		);  	} @@ -313,24 +326,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  		$this->template->set_filenames(array('test' => $filename));  		$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); -		$expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', $this->test_path . '/templates/' . $filename); -		$this->setExpectedTriggerError(E_USER_ERROR, $expecting); +		$this->setExpectedException('Twig_Error_Loader');  		$this->display('test');  	} -	public function test_empty_file() -	{ -		$expecting = 'style resource locator: set_filenames: Empty filename specified for test'; - -		$this->setExpectedTriggerError(E_USER_ERROR, $expecting); -		$this->template->set_filenames(array('test' => '')); -	}  	public function test_invalid_handle()  	{ -		$expecting = 'No file specified for handle test'; -		$this->setExpectedTriggerError(E_USER_ERROR, $expecting); +		$this->setExpectedException('Twig_Error_Loader');  		$this->display('test');  	} @@ -338,49 +342,23 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  	/**  	* @dataProvider template_data  	*/ -	public function test_template($file, array $vars, array $block_vars, array $destroy, $expected) +	public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())  	{ -		$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - -		$this->assertFileNotExists($cache_file); - -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - -		// Reset the engine state -		$this->setup_engine(); - -		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); +		$this->run_template($file, $vars, $block_vars, $destroy, $expected, $lang_vars);  	} -	/** -	* @dataProvider template_data -	*/ -	public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected) +	public function test_assign_display()  	{ +		$this->run_template('basic.html', array(), array(), array(), "pass\npass\npass\n<!-- DUMMY var -->"); +  		$this->template->set_filenames(array( -			'test' => $file, -			'container' => 'variable.html', +			'test'		=> 'basic.html', +			'container'	=> 'variable.html',  		)); -		$this->template->assign_vars($vars); - -		foreach ($block_vars as $block => $loops) -		{ -			foreach ($loops as $_vars) -			{ -				$this->template->assign_block_vars($block, $_vars); -			} -		} - -		foreach ($destroy as $block) -		{ -			$this->template->destroy_block_vars($block); -		} - -		$this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)");  		$this->template->assign_display('test', 'VARIABLE', false); -		$this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); +		$this->assertEquals("pass\npass\npass\n<!-- DUMMY var -->", $this->display('container'), "Testing assign_display($file)");  	}  	public function test_append_var_without_assign_var() @@ -391,7 +369,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  		$items = array('This ', 'is ', 'a ', 'test');  		$expecting = implode('', $items); -		 +  		foreach ($items as $word)  		{  			$this->template->append_var('VARIABLE', $word); @@ -409,7 +387,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  		$start = 'This ';  		$items = array('is ', 'a ', 'test');  		$expecting = $start . implode('', $items); -		 +  		$this->template->assign_var('VARIABLE', $start);  		foreach ($items as $word)  		{ @@ -421,13 +399,20 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  	public function test_php()  	{ -		$this->setup_engine(array('tpl_allow_php' => true)); +		global $phpbb_root_path; -		$cache_file = $this->template->cachepath . 'php.html.php'; +		$template_text = '<!-- PHP -->echo "test";<!-- ENDPHP -->'; -		$this->assertFileNotExists($cache_file); +		$cache_dir = $phpbb_root_path . 'cache/'; +		$fp = fopen($cache_dir . 'php.html', 'w'); +		fputs($fp, $template_text); +		fclose($fp); -		$this->run_template('php.html', array(), array(), array(), 'test', $cache_file); +		$this->setup_engine(array('tpl_allow_php' => true)); + +		$this->style->set_custom_style('tests', $cache_dir, array(), ''); + +		$this->run_template('php.html', array(), array(), array(), 'test');  	}  	public function alter_block_array_data() @@ -533,10 +518,40 @@ EOT  		$this->template->assign_block_vars('outer.middle', array());  		$this->template->assign_block_vars('outer.middle', array()); -		$this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification'); +		$this->assertEquals("outer - 0middle - 0middle - 1outer - 1middle - 0middle - 1outer - 2middle - 0middle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');  		$this->template->alter_block_array($alter_block, $vararray, $key, $mode); -		$this->assertEquals($expect, $this->display('test'), $description); +		$this->assertEquals(str_replace(array("\n", "\r", "\t"), '', $expect), str_replace(array("\n", "\r", "\t"), '', $this->display('test')), $description);  	} +	public function test_more_alter_block_array() +	{ +		$this->template->set_filenames(array('test' => 'loop_nested.html')); + +		$this->template->assign_var('TEST_MORE', true); + +		// @todo Change this +		$this->template->assign_block_vars('outer', array()); +		$this->template->assign_block_vars('outer.middle', array()); +		$this->template->assign_block_vars('outer', array()); +		$this->template->assign_block_vars('outer.middle', array()); +		$this->template->assign_block_vars('outer.middle', array()); +		$this->template->assign_block_vars('outer', array()); +		$this->template->assign_block_vars('outer.middle', array()); +		$this->template->assign_block_vars('outer.middle', array()); +		$this->template->assign_block_vars('outer.middle', array()); + +		$expect = 'outer - 0[outer|3]middle - 0[middle|1]outer - 1[outer|3]middle - 0[middle|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; +		$this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + +		$this->template->alter_block_array('outer', array()); + +		$expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; +		$this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion'); + +		$this->template->alter_block_array('outer', array('VARIABLE' => 'test'), 2, 'change'); + +		$expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; +		$this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); +	}  } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 3c997cb00e..6d87e5ebc0 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -16,6 +16,7 @@ class phpbb_template_template_test_case extends phpbb_test_case  	protected $template_path;  	protected $style_resource_locator;  	protected $style_provider; +	protected $user;  	protected $test_path = 'tests/template'; @@ -28,11 +29,11 @@ class phpbb_template_template_test_case extends phpbb_test_case  		try  		{ -			$this->assertTrue($this->template->display($handle, false)); +			$this->template->display($handle, false);  		}  		catch (Exception $exception)  		{ -			// reset output buffering even when an error occured +			// reset output buffering even when an error occurred  			// PHPUnit turns trigger_error into exceptions as well  			ob_end_clean();  			throw $exception; @@ -59,16 +60,17 @@ class phpbb_template_template_test_case extends phpbb_test_case  	protected function setup_engine(array $new_config = array())  	{ -		global $phpbb_root_path, $phpEx, $user; +		global $phpbb_root_path, $phpEx;  		$defaults = $this->config_defaults();  		$config = new phpbb_config(array_merge($defaults, $new_config)); +		$this->user = new phpbb_user;  		$this->template_path = $this->test_path . '/templates';  		$this->style_resource_locator = new phpbb_style_resource_locator();  		$this->style_provider = new phpbb_style_path_provider(); -		$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); -		$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); +		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); +		$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template);  		$this->style->set_custom_style('tests', $this->template_path, array(), '');  	} @@ -77,32 +79,18 @@ class phpbb_template_template_test_case extends phpbb_test_case  		// Test the engine can be used  		$this->setup_engine(); -		$template_cache_dir = dirname($this->template->cachepath); -		if (!is_writable($template_cache_dir)) -		{ -			$this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable."); -		} - -		foreach (glob($this->template->cachepath . '*') as $file) -		{ -			unlink($file); -		} - -		$this->setup_engine(); +		$this->template->clear_cache();  	}  	protected function tearDown()  	{ -		if (is_object($this->template)) +		if ($this->template)  		{ -			foreach (glob($this->template->cachepath . '*') as $file) -			{ -				unlink($file); -			} +			$this->template->clear_cache();  		}  	} -	protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file) +	protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())  	{  		$this->template->set_filenames(array('test' => $file));  		$this->template->assign_vars($vars); @@ -120,25 +108,17 @@ class phpbb_template_template_test_case extends phpbb_test_case  			$this->template->destroy_block_vars($block);  		} -		try +		// Previous functionality was $cachefile (string), which was removed, check to prevent errors +		if (is_array($lang_vars))  		{ -			$this->assertEquals($expected, $this->display('test'), "Testing $file"); -			$this->assertFileExists($cache_file); -		} -		catch (ErrorException $e) -		{ -			if (file_exists($cache_file)) +			foreach ($lang_vars as $name => $value)  			{ -				copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); +				$this->user->lang[$name] = $value;  			} -			throw $e;  		} -		// For debugging. -		// When testing eval path the cache file may not exist. -		if (self::PRESERVE_CACHE && file_exists($cache_file)) -		{ -			copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); -		} +		$expected = str_replace(array("\n", "\r", "\t"), '', $expected); +		$output = str_replace(array("\n", "\r", "\t"), '', $this->display('test')); +		$this->assertEquals($expected, $output, "Testing $file");  	}  } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 7585be5728..4b8cbada45 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat  		$this->parent_template_path = $this->test_path . '/parent_templates';  		$this->style_resource_locator = new phpbb_style_resource_locator();  		$this->style_provider = new phpbb_style_path_provider(); -		$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); +		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());  		$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);  		$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');  	} diff --git a/tests/template/templates/child_only.css b/tests/template/templates/child_only.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/template/templates/child_only.css diff --git a/tests/template/templates/define_unclosed.html b/tests/template/templates/define_unclosed.html deleted file mode 100644 index 1c975eab2b..0000000000 --- a/tests/template/templates/define_unclosed.html +++ /dev/null @@ -1,2 +0,0 @@ -<!-- DEFINE $VALUE --> -test diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index eed431019e..c010aff7fa 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -9,3 +9,11 @@  <!-- IF S_VALUE and S_OTHER_VALUE and (S_VALUE > S_OTHER_VALUE) -->  04  <!-- ENDIF --> + +<!-- IF S_TEST === false --> +false +<!-- ENDIF --> + +<!-- IF S_TEST !== false --> +!false +<!-- ENDIF --> diff --git a/tests/template/templates/includecss.html b/tests/template/templates/includecss.html new file mode 100644 index 0000000000..a09e44f240 --- /dev/null +++ b/tests/template/templates/includecss.html @@ -0,0 +1,3 @@ +<!-- INCLUDECSS child_only.css --> +<!-- INCLUDECSS parent_only.css --> +{$STYLESHEETS} diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index ef73700eeb..0bcdf1a815 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -1,8 +1,36 @@ -<!-- INCLUDEJS parent_and_child.js --> -<!-- INCLUDEJS {PARENT} --> -<!-- DEFINE $TEST = 'child_only.js' --> -<!-- INCLUDEJS {$TEST} --> -<!-- INCLUDEJS subdir/{PARENT} --> -<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} --> -<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} --> -{SCRIPTS} +<!-- IF TEST === 1 --> +	<!-- INCLUDEJS parent_and_child.js --> +<!-- ELSEIF TEST === 2 --> +	<!-- INCLUDEJS parent_and_child.js?assets_version=0 --> +<!-- ELSEIF TEST === 3 --> +	<!-- INCLUDEJS parent_and_child.js?test=1&assets_version=0 --> +<!-- ELSEIF TEST === 4 --> +	<!-- INCLUDEJS parent_and_child.js?test=1&assets_version=0 --> +<!-- ELSEIF TEST === 6 --> +	<!-- INCLUDEJS {PARENT} --> +<!-- ELSEIF TEST === 7 --> +	<!-- DEFINE $TEST = 'child_only.js' --> +	<!-- INCLUDEJS {$TEST} --> +<!-- ELSEIF TEST === 8 --> +	<!-- INCLUDEJS subdir/{PARENT} --> +<!-- ELSEIF TEST === 9 --> +	<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} --> +<!-- ELSEIF TEST === 10 --> +	<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} --> +<!-- ELSEIF TEST === 11 --> +	<!-- DEFINE $TEST = 'child_only.js?test1=1&test2=2#test3' --> +	<!-- INCLUDEJS {$TEST} --> +<!-- ELSEIF TEST === 12 --> +	<!-- INCLUDEJS parent_only.js?test1=1&test2=2#test3 --> +<!-- ELSEIF TEST === 14 --> +	<!-- INCLUDEJS parent_only.js?test1="#test3 --> +<!-- ELSEIF TEST === 15 --> +	<!-- INCLUDEJS http://phpbb.com/b.js?c=d#f --> +<!-- ELSEIF TEST === 16 --> +	<!-- INCLUDEJS http://phpbb.com/b.js?c=d&assets_version=2#f --> +<!-- ELSEIF TEST === 17 --> +	<!-- INCLUDEJS //phpbb.com/b.js --> +<!-- ELSEIF TEST === 18 --> +	<!-- INCLUDEJS parent_and_child.js?test=1&test2=0 --> +<!-- ENDIF --> +{$SCRIPTS} diff --git a/tests/template/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html deleted file mode 100644 index 617d2fdaaa..0000000000 --- a/tests/template/templates/invalid/include_nonexistent_file.html +++ /dev/null @@ -1 +0,0 @@ -<!-- INCLUDE nonexistent.html --> diff --git a/tests/template/templates/invalid/unknown_tag.html b/tests/template/templates/invalid/unknown_tag.html deleted file mode 100644 index 1489e5e31a..0000000000 --- a/tests/template/templates/invalid/unknown_tag.html +++ /dev/null @@ -1 +0,0 @@ -<!-- UNKNOWNTAG variable.html --> diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html index 45b1ef85d4..cf099ecc15 100644 --- a/tests/template/templates/loop_nested.html +++ b/tests/template/templates/loop_nested.html @@ -1,6 +1,6 @@  <!-- BEGIN outer --> -	outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF --> -	<!-- BEGIN middle --> -		middle - {middle.S_ROW_COUNT}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF --> -	<!-- END middle --> +outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF --><!-- IF TEST_MORE -->[{outer.S_BLOCK_NAME}|{outer.S_NUM_ROWS}]<!-- ENDIF --> +<!-- BEGIN middle --> +middle - {outer.middle.S_ROW_COUNT}<!-- IF outer.middle.VARIABLE --> - {outer.middle.VARIABLE}<!-- ENDIF --><!-- IF TEST_MORE -->[{outer.middle.S_BLOCK_NAME}|{outer.middle.S_NUM_ROWS}]<!-- ENDIF --> +<!-- END middle -->  <!-- END outer --> diff --git a/tests/template/templates/loop_nested2.html b/tests/template/templates/loop_nested2.html new file mode 100644 index 0000000000..3eeeb5e36a --- /dev/null +++ b/tests/template/templates/loop_nested2.html @@ -0,0 +1,6 @@ +<!-- BEGIN outer --> +o{outer.S_ROW_COUNT} +<!-- BEGIN middle --> +m{outer.middle.S_ROW_COUNT}{outer.S_ROW_COUNT} +<!-- END middle --> +<!-- END outer --> diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html index f1938441df..8f581cef10 100644 --- a/tests/template/templates/loop_size.html +++ b/tests/template/templates/loop_size.html @@ -36,4 +36,4 @@  <!-- BEGIN loop -->  	in loop -<!-- END --> +<!-- END loop --> diff --git a/tests/template/templates/loop_underscore.html b/tests/template/templates/loop_underscore.html index dafce5dea6..4001007868 100644 --- a/tests/template/templates/loop_underscore.html +++ b/tests/template/templates/loop_underscore.html @@ -2,7 +2,7 @@  loop  <!-- BEGINELSE -->  noloop -<!-- END loop --> +<!-- END _underscore_loop -->  <!-- IF ._underscore_loop -->  loop diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html index d94a0ae0f7..7d86d4b7b6 100644 --- a/tests/template/templates/loop_vars.html +++ b/tests/template/templates/loop_vars.html @@ -11,4 +11,3 @@ last  <!-- IF inner.S_LAST_ROW and inner.S_ROW_COUNT and inner.S_NUM_ROWS -->last inner<!-- ENDIF -->  <!-- END inner -->  <!-- END loop --> -<!-- IF .loop.inner -->inner loop<!-- ENDIF --> diff --git a/tests/template/templates/twig.html b/tests/template/templates/twig.html new file mode 100644 index 0000000000..17b94ad8d4 --- /dev/null +++ b/tests/template/templates/twig.html @@ -0,0 +1,6 @@ +<!-- EXTENDS "twig_parent.html" --> + +<!-- BLOCK overwritten --> +3{VARIABLE|upper}|{VARIABLE|lower} +<!-- ENDBLOCK --> + diff --git a/tests/template/templates/twig_parent.html b/tests/template/templates/twig_parent.html new file mode 100644 index 0000000000..e9863221e1 --- /dev/null +++ b/tests/template/templates/twig_parent.html @@ -0,0 +1,7 @@ +<!-- BLOCK notoverwritten --> +1 +<!-- ENDBLOCK --> + +<!-- BLOCK overwritten --> +2 +<!-- ENDBLOCK --> diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 97fe147d8e..ed307c3ce2 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -219,15 +219,19 @@ class phpbb_functional_test_case extends phpbb_test_case  		self::recreate_database(self::$config); -		if (file_exists($phpbb_root_path . "config.$phpEx")) +		$config_file = $phpbb_root_path . "config.$phpEx"; +		$config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; +		$config_file_test = $phpbb_root_path . "config_test.$phpEx"; + +		if (file_exists($config_file))  		{ -			if (!file_exists($phpbb_root_path . "config_dev.$phpEx")) +			if (!file_exists($config_file_dev))  			{ -				rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); +				rename($config_file, $config_file_dev);  			}  			else  			{ -				unlink($phpbb_root_path . "config.$phpEx"); +				unlink($config_file);  			}  		} @@ -251,10 +255,12 @@ class phpbb_functional_test_case extends phpbb_test_case  		self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(); +		// install/index.php?mode=install&sub=requirements  		$crawler = self::submit($form);  		self::assertContains('Installation compatibility', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(); +		// install/index.php?mode=install&sub=database  		$crawler = self::submit($form);  		self::assertContains('Database configuration', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(array( @@ -268,10 +274,12 @@ class phpbb_functional_test_case extends phpbb_test_case  			'table_prefix'	=> self::$config['table_prefix'],  		)); +		// install/index.php?mode=install&sub=database  		$crawler = self::submit($form);  		self::assertContains('Successful connection', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(); +		// install/index.php?mode=install&sub=administrator  		$crawler = self::submit($form);  		self::assertContains('Administrator configuration', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(array( @@ -282,16 +290,38 @@ class phpbb_functional_test_case extends phpbb_test_case  			'board_email'	=> 'nobody@example.com',  		)); +		// install/index.php?mode=install&sub=administrator  		$crawler = self::submit($form);  		self::assertContains('Tests passed', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(); -		$crawler = self::submit($form); -		self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); -		file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true)); -		$form = $crawler->selectButton('submit')->form(); +		// We have to skip install/index.php?mode=install&sub=config_file +		// because that step will create a config.php file if phpBB has the +		// permission to do so. We have to create the config file on our own +		// in order to get the DEBUG constants defined. +		$config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true); +		$config_created = file_put_contents($config_file, $config_php_data) !== false; +		if (!$config_created) +		{ +			self::markTestSkipped("Could not write $config_file file."); +		} -		$crawler = self::submit($form); +		// We also have to create a install lock that is normally created by +		// the installer. The file will be removed by the final step of the +		// installer. +		$install_lock_file = $phpbb_root_path . 'cache/install_lock'; +		$lock_created = file_put_contents($install_lock_file, '') !== false; +		if (!$lock_created) +		{ +			self::markTestSkipped("Could not create $lock_created file."); +		} +		@chmod($install_lock_file, 0666); + +		// install/index.php?mode=install&sub=advanced +		$form_data = $form->getValues(); +		unset($form_data['submit']); + +		$crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data);  		self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(array(  			'email_enable'		=> true, @@ -308,14 +338,17 @@ class phpbb_functional_test_case extends phpbb_test_case  			'script_path'		=> $parseURL['path'],  		)); +		// install/index.php?mode=install&sub=create_table  		$crawler = self::submit($form);  		self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text());  		self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text());  		$form = $crawler->selectButton('submit')->form(); +		// install/index.php?mode=install&sub=final  		$crawler = self::submit($form);  		self::assertContains('You have successfully installed', $crawler->text()); -		copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + +		copy($config_file, $config_file_test);  	}  	static private function recreate_database($config) @@ -325,6 +358,109 @@ class phpbb_functional_test_case extends phpbb_test_case  	}  	/** +	* Creates a new style +	* +	* @param string $style_id Style ID +	* @param string $style_path Style directory +	* @param string $parent_style_id Parent style id. Default = 1 +	* @param string $parent_style_path Parent style directory. Default = 'prosilver' +	*/ +	protected function add_style($style_id, $style_path, $parent_style_id = 1, $parent_style_path = 'prosilver') +	{ +		global $phpbb_root_path; + +		$db = $this->get_db(); +		if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) +		{ +			$sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( +				'style_id' => $style_id, +				'style_name' => $style_path, +				'style_copyright' => '', +				'style_active' => 1, +				'template_id' => $style_id, +				'theme_id' => $style_id, +				'imageset_id' => $style_id, +			)); +			$db->sql_query($sql); + +			$sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( +				'imageset_id' => $style_id, +				'imageset_name' => $style_path, +				'imageset_copyright' => '', +				'imageset_path' => $style_path, +			)); +			$db->sql_query($sql); + +			$sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( +				'template_id' => $style_id, +				'template_name' => $style_path, +				'template_copyright' => '', +				'template_path' => $style_path, +				'bbcode_bitfield' => 'kNg=', +				'template_inherits_id' => $parent_style_id, +				'template_inherit_path' => $parent_style_path, +			)); +			$db->sql_query($sql); + +			$sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( +				'theme_id' => $style_id, +				'theme_name' => $style_path, +				'theme_copyright' => '', +				'theme_path' => $style_path, +				'theme_storedb' => 0, +				'theme_mtime' => 0, +				'theme_data' => '', +			)); +			$db->sql_query($sql); + +			if ($style_path != 'prosilver' && $style_path != 'subsilver2') +			{ +				@mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); +				@mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); +			} +		} +		else +		{ +			$db->sql_multi_insert(STYLES_TABLE, array( +				'style_id' => $style_id, +				'style_name' => $style_path, +				'style_copyright' => '', +				'style_active' => 1, +				'style_path' => $style_path, +				'bbcode_bitfield' => 'kNg=', +				'style_parent_id' => $parent_style_id, +				'style_parent_tree' => $parent_style_path, +			)); +		} +	} + +	/** +	* Remove temporary style created by add_style() +	* +	* @param string $style_id Style ID +	* @param string $style_path Style directory +	*/ +	protected function delete_style($style_id, $style_path) +	{ +		global $phpbb_root_path; + +		$db = $this->get_db(); +		$db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); +		if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) +		{ +			$db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); +			$db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); +			$db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + +			if ($style_path != 'prosilver' && $style_path != 'subsilver2') +			{ +				@rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); +				@rmdir($phpbb_root_path . 'styles/' . $style_path); +			} +		} +	} + +	/**  	* Creates a new user with limited permissions  	*  	* @param string $username Also doubles up as the user's password @@ -474,7 +610,7 @@ class phpbb_functional_test_case extends phpbb_test_case  		$form = $crawler->selectButton($this->lang('LOGIN'))->form();  		$crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); -		$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); +		$this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text());  		$cookies = self::$cookieJar->all(); @@ -493,7 +629,7 @@ class phpbb_functional_test_case extends phpbb_test_case  		$this->add_lang('ucp');  		$crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); -		$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); +		$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());  		unset($this->sid);  	} @@ -523,7 +659,7 @@ class phpbb_functional_test_case extends phpbb_test_case  			if (strpos($field, 'password_') === 0)  			{  				$crawler = self::submit($form, array('username' => $username, $field => $username . $username)); -				$this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); +				$this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());  				$cookies = self::$cookieJar->all(); @@ -607,6 +743,7 @@ class phpbb_functional_test_case extends phpbb_test_case  		// Any output before the doc type means there was an error  		$content = self::$client->getResponse()->getContent(); +		self::assertNotContains('[phpBB Debug]', $content);  		self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');  	} @@ -703,4 +840,135 @@ class phpbb_functional_test_case extends phpbb_test_case  		return $result;  	} + +	/** +	* Creates a topic +	* +	* Be sure to login before creating +	* +	* @param int $forum_id +	* @param string $subject +	* @param string $message +	* @param array $additional_form_data Any additional form data to be sent in the request +	* @return array post_id, topic_id +	*/ +	public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) +	{ +		$posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + +		$form_data = array_merge(array( +			'subject'		=> $subject, +			'message'		=> $message, +			'post'			=> true, +		), $additional_form_data); + +		return self::submit_post($posting_url, 'POST_TOPIC', $form_data); +	} + +	/** +	* Creates a post +	* +	* Be sure to login before creating +	* +	* @param int $forum_id +	* @param int $topic_id +	* @param string $subject +	* @param string $message +	* @param array $additional_form_data Any additional form data to be sent in the request +	* @return array post_id, topic_id +	*/ +	public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) +	{ +		$posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + +		$form_data = array_merge(array( +			'subject'		=> $subject, +			'message'		=> $message, +			'post'			=> true, +		), $additional_form_data); + +		return self::submit_post($posting_url, 'POST_REPLY', $form_data); +	} + +	/** +	* Helper for submitting posts +	* +	* @param string $posting_url +	* @param string $posting_contains +	* @param array $form_data +	* @return array post_id, topic_id +	*/ +	protected function submit_post($posting_url, $posting_contains, $form_data) +	{ +		$this->add_lang('posting'); + +		$crawler = self::request('GET', $posting_url); +		$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + +		$hidden_fields = array( +			$crawler->filter('[type="hidden"]')->each(function ($node, $i) { +				return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); +			}), +		); + +		foreach ($hidden_fields as $fields) +		{ +			foreach($fields as $field) +			{ +				$form_data[$field['name']] = $field['value']; +			} +		} + +		// Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) +		// is not at least 2 seconds before submission, cancel the form +		$form_data['lastclick'] = 0; + +		// I use a request because the form submission method does not allow you to send data that is not +		// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) +		// Instead, I send it as a request with the submit button "post" set to true. +		$crawler = self::request('POST', $posting_url, $form_data); +		$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); +		$url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + +		return array( +			'topic_id'	=> $this->get_parameter_from_link($url, 't'), +			'post_id'	=> $this->get_parameter_from_link($url, 'p'), +		); +	} + +	/* +	* Returns the requested parameter from a URL +	* +	* @param	string	$url +	* @param	string	$parameter +	* @return		string	Value of the parameter in the URL, null if not set +	*/ +	public function get_parameter_from_link($url, $parameter) +	{ +		if (strpos($url, '?') === false) +		{ +			return null; +		} + +		$url_parts = explode('?', $url); +		if (isset($url_parts[1])) +		{ +			$url_parameters = $url_parts[1]; +			if (strpos($url_parameters, '#') !== false) +			{ +				$url_parameters = explode('#', $url_parameters); +				$url_parameters = $url_parameters[0]; +			} + +			foreach (explode('&', $url_parameters) as $url_param) +			{ +				list($param, $value) = explode('=', $url_param); +				if ($param == $parameter) +				{ +					return $value; +				} +			} +		} +		return null; +	}  } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 50b2bf03ec..3d9cd10f32 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -94,6 +94,9 @@ class phpbb_test_case_helpers  	public function makedirs($path)  	{ +		// PHP bug #55124 (fixed in 5.4.0) +		$path = str_replace('/./', '/', $path); +  		mkdir($path, 0777, true);  	} diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 1665c493be..8b9df33a63 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -10,6 +10,7 @@  require_once __DIR__ . '/../../phpBB/includes/functions.php';  require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';  require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; +require_once __DIR__ . '/../mock/filespec.php';  class phpbb_fileupload_test extends phpbb_test_case  {  | 
