diff options
Diffstat (limited to 'tests')
241 files changed, 7108 insertions, 996 deletions
| diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index afd7caa709..b082197166 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -120,8 +120,9 @@ directory (above phpBB):  Slow tests  -------------- -Certain tests, such as the UTF-8 normalizer or the DNS tests tend to be slow. -Thus these tests are in the `slow` group, which is excluded by default. If you +Certain tests, such as the DNS tests tend to be slow. +Thus these tests are in the `slow` group, which is excluded by default. You can +enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you  only want the slow tests, run:      $ phpBB/vendor/bin/phpunit --group slow diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 68ad7b2c19..60423acbc1 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -28,8 +28,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$config = new \phpbb\config\config(array()); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader);  		$this->request = $this->getMock('\phpbb\request\request'); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$this->user = new \phpbb\user($lang, '\phpbb\datetime');  		$driver_helper = new \phpbb\passwords\driver\helper($config);  		$passwords_drivers = array(  			'passwords.driver.bcrypt_2y'	=> new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 09ca0816bf..38dbfa1fcb 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -38,8 +38,10 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case  			'ip_login_limit_use_forwarded' 	=> 0,  			'max_login_attempts' 			=> 0,  			)); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader);  		$request = $this->getMock('\phpbb\request\request'); -		$user = new \phpbb\user('\phpbb\datetime'); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$driver_helper = new \phpbb\passwords\driver\helper($config);  		$passwords_drivers = array(  			'passwords.driver.bcrypt_2y'	=> new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 71b49ff439..78b936ee8e 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -31,7 +31,9 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c  		global $phpbb_root_path, $phpEx;  		$this->db = $this->new_dbal(); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$this->user = new \phpbb\user($lang, '\phpbb\datetime');  		$this->service_name = 'auth.provider.oauth.service.testing';  		$this->token_storage_table = 'phpbb_oauth_tokens'; diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php index 0bf30b8a91..067bb3ef97 100644 --- a/tests/avatar/driver/barfoo.php +++ b/tests/avatar/driver/barfoo.php @@ -1,26 +1,26 @@ -<?php
 -
 -namespace phpbb\avatar\driver;
 -
 -class barfoo extends \phpbb\avatar\driver\driver
 -{
 -	public function get_data($row)
 -	{
 -		return array();
 -	}
 -
 -	public function prepare_form($request, $template, $user, $row, &$error)
 -	{
 -		return false;
 -	}
 -
 -	public function process_form($request, $template, $user, $row, &$error)
 -	{
 -		return false;
 -	}
 -
 -	public function get_template_name()
 -	{
 -		return 'barfoo.html';
 -	}
 -}
 +<?php + +namespace phpbb\avatar\driver; + +class barfoo extends \phpbb\avatar\driver\driver +{ +	public function get_data($row) +	{ +		return array(); +	} + +	public function prepare_form($request, $template, $user, $row, &$error) +	{ +		return false; +	} + +	public function process_form($request, $template, $user, $row, &$error) +	{ +		return false; +	} + +	public function get_template_name() +	{ +		return 'barfoo.html'; +	} +} diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index aabdaf5ac4..16d50ccad4 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -1,26 +1,26 @@ -<?php
 -
 -namespace phpbb\avatar\driver;
 -
 -class foobar extends \phpbb\avatar\driver\driver
 -{
 -	public function get_data($row)
 -	{
 -		return array();
 -	}
 -
 -	public function prepare_form($request, $template, $user, $row, &$error)
 -	{
 -		return false;
 -	}
 -
 -	public function process_form($request, $template, $user, $row, &$error)
 -	{
 -		return false;
 -	}
 -
 -	public function get_template_name()
 -	{
 -		return 'foobar.html';
 -	}
 -}
 +<?php + +namespace phpbb\avatar\driver; + +class foobar extends \phpbb\avatar\driver\driver +{ +	public function get_data($row) +	{ +		return array(); +	} + +	public function prepare_form($request, $template, $user, $row, &$error) +	{ +		return false; +	} + +	public function process_form($request, $template, $user, $row, &$error) +	{ +		return false; +	} + +	public function get_template_name() +	{ +		return 'foobar.html'; +	} +} diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index a109a7b5de..71f40c0b13 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -35,6 +35,8 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  			->method('get')  			->will($this->returnArgument(0)); +		$filesystem = new \phpbb\filesystem\filesystem(); +  		// Prepare dependencies for avatar manager and driver  		$this->config = new \phpbb\config\config(array());  		$cache = $this->getMock('\phpbb\cache\driver\driver_interface'); @@ -42,7 +44,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			$filesystem,  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx @@ -55,9 +57,10 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  			new \phpbb\mimetype\content_guesser,  		);  		$guesser = new \phpbb\mimetype\guesser($guessers); +		$imagesize = new \fastImageSize\fastImageSize();  		// $this->avatar_foobar will be needed later on -		$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache)); +		$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache));  		$this->avatar_foobar->expects($this->any())  			->method('get_name')  			->will($this->returnValue('avatar.driver.foobar')); @@ -72,11 +75,11 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  		{  			if ($driver !== 'upload')  			{ -				$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache)); +				$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache));  			}  			else  			{ -				$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache)); +				$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $guesser, $cache));  			}  			$cur_avatar->expects($this->any())  				->method('get_name') @@ -91,7 +94,9 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  		// Set up avatar manager  		$this->manager = new \phpbb\avatar\manager($this->config, $avatar_drivers, $phpbb_container);  		$this->db = $this->new_dbal(); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$this->user = new \phpbb\user($lang, '\phpbb\datetime');  	}  	protected function avatar_drivers() @@ -274,7 +279,12 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case  	public function test_localize_errors()  	{ -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime') +		);  		$lang_array = array(  			array('FOOBAR_OFF', 'foobar_off'),  			array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'), diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0e81f4372a..ace48ea035 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,6 +12,8 @@  */  define('IN_PHPBB', true); +define('PHPBB_ENVIRONMENT', 'test'); +  $phpbb_root_path = 'phpBB/';  $phpEx = 'php';  require_once $phpbb_root_path . 'includes/startup.php'; diff --git a/tests/cache/null_driver_test.php b/tests/cache/dummy_driver_test.php index b9f96732f5..6cb6b73729 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/dummy_driver_test.php @@ -11,7 +11,7 @@  *  */ -class phpbb_cache_null_driver_test extends phpbb_database_test_case +class phpbb_cache_dummy_driver_test extends phpbb_database_test_case  {  	protected $driver; @@ -24,7 +24,7 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case  	{  		parent::setUp(); -		$this->driver = new \phpbb\cache\driver\null; +		$this->driver = new \phpbb\cache\driver\dummy;  	}  	public function test_get_put() diff --git a/tests/captcha/qa_test.php b/tests/captcha/qa_test.php index 1f2f9f3070..4aa5e714f5 100644 --- a/tests/captcha/qa_test.php +++ b/tests/captcha/qa_test.php @@ -27,14 +27,16 @@ class phpbb_captcha_qa_test extends \phpbb_database_test_case  	public function setUp()  	{ -		global $db; +		global $db, $request, $phpbb_container;  		$db = $this->new_dbal();  		parent::setUp(); -		$this->request = new \phpbb_mock_request(); -		request_var(false, false, false, false, $this->request); +		$request = new \phpbb_mock_request(); +		$phpbb_container = new \phpbb_mock_container_builder(); +		$factory = new \phpbb\db\tools\factory(); +		$phpbb_container->set('dbal.tools', $factory->get($db));  		$this->qa = new \phpbb\captcha\plugins\qa('phpbb_captcha_questions', 'phpbb_captcha_answers', 'phpbb_qa_confirm');  	} @@ -87,7 +89,8 @@ class phpbb_captcha_qa_test extends \phpbb_database_test_case  	 */  	public function test_acp_get_question_input($value, $expected)  	{ -		$this->request->overwrite('answers', $value); +		global $request; +		$request->overwrite('answers', $value);  		$this->assertEquals($expected, $this->qa->acp_get_question_input());  	} diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index 96988c1028..6c92660580 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -32,6 +32,8 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case  	protected function setUp()  	{ +		global $phpbb_root_path, $phpEx; +  		if (file_exists($this->cache_dir))  		{  			// cache directory possibly left after aborted @@ -45,7 +47,10 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case  		$this->db = $this->getMock('\phpbb\db\driver\driver_interface');  		$this->config = new \phpbb\config\config(array('assets_version' => 1)); -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime') +		);  	}  	public function test_purge() @@ -86,7 +91,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case  	public function get_command_tester()  	{  		$application = new Application(); -		$application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config)); +		$application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\dummy(), $this->config));  		$command = $application->find('cache:purge');  		$this->command_name = $command->getName(); diff --git a/tests/console/config/config_test.php b/tests/console/config/config_test.php index 7c098af004..076316217d 100644 --- a/tests/console/config/config_test.php +++ b/tests/console/config/config_test.php @@ -22,9 +22,14 @@ class phpbb_console_command_config_test extends phpbb_test_case  	public function setUp()  	{ +		global $phpbb_root_path, $phpEx; +  		$this->config = new \phpbb\config\config(array()); -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime') +		);  		$this->user->method('lang')->will($this->returnArgument(0));  	} diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 22423304be..3bbe2078ba 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -32,7 +32,12 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case  	protected function setUp()  	{ -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$this->user->method('lang')->will($this->returnArgument(0));  	} diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index f76e967484..51ea49b282 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -39,10 +39,12 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case  		$db = $this->db = $this->new_dbal();  		$config = $this->config = new \phpbb\config\config(array('cron_lock' => '0')); -		set_config(null, null, null, $this->config);  		$this->lock = new \phpbb\lock\db('cron_lock', $this->config, $this->db); -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$this->user->method('lang')->will($this->returnArgument(0));  		$this->task = new phpbb_cron_task_simple(); diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index 6ad6351a0c..b59b6493d4 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -292,12 +292,14 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case  	{  		global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; -		$config['search_type'] = 'phpbb_mock_search'; +		$config = new \phpbb\config\config(array( +			'num_posts' => 3, +			'num_topics' => 1, +			'search_type' => 'phpbb_mock_search', +		));  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$phpbb_config = new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1));  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		set_config_count(null, null, null, $phpbb_config);  		// Create auth mock  		$auth = $this->getMock('\phpbb\auth\auth'); @@ -307,13 +309,15 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case  			->will($this->returnValueMap(array(  				array('m_approve', 1, true),  			))); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$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, $phpbb_config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); +		$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $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); diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php index 28e463ecb5..6c5066119e 100644 --- a/tests/content_visibility/get_forums_visibility_sql_test.php +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -134,7 +134,9 @@ class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_data  			->method('acl_getf')  			->with($this->stringContains('_'), $this->anything())  			->will($this->returnValueMap($permissions)); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php index 586bae8668..9ae4182673 100644 --- a/tests/content_visibility/get_global_visibility_sql_test.php +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -134,7 +134,9 @@ class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_data  			->method('acl_getf')  			->with($this->stringContains('_'), $this->anything())  			->will($this->returnValueMap($permissions)); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php index 9ae2d2fdc4..aaaf64330e 100644 --- a/tests/content_visibility/get_visibility_sql_test.php +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -81,7 +81,9 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te  			->method('acl_get')  			->with($this->stringContains('_'), $this->anything())  			->will($this->returnValueMap($permissions)); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php index 36ebf58374..6375ce8f6d 100644 --- a/tests/content_visibility/set_post_visibility_test.php +++ b/tests/content_visibility/set_post_visibility_test.php @@ -124,7 +124,9 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal();  		$auth = $this->getMock('\phpbb\auth\auth'); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); @@ -175,7 +177,9 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal();  		$auth = $this->getMock('\phpbb\auth\auth'); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php index 6c34f42167..f4d65f9ce3 100644 --- a/tests/content_visibility/set_topic_visibility_test.php +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -88,7 +88,9 @@ class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal();  		$auth = $this->getMock('\phpbb\auth\auth'); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$config = new phpbb\config\config(array());  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index ff1af8119b..3c74c16bae 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -35,10 +35,6 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  		);  		$this->generate_route_objects();  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; -		$this->user = new \phpbb\user('\phpbb\datetime'); - -		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); -		$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context());  	}  	protected function get_phpbb_root_path() @@ -78,7 +74,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  		$this->symfony_request = new \phpbb\symfony_request(  			$this->request  		); -		$this->filesystem = new \phpbb\filesystem(); +		$this->filesystem = new \phpbb\filesystem\filesystem();  		$this->phpbb_path_helper = new \phpbb\path_helper(  			$this->symfony_request,  			$this->filesystem, @@ -87,15 +83,48 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			$phpEx  		); -		$finder = new \phpbb\finder( -			new \phpbb\filesystem(), +		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$this->user = new \phpbb\user($lang, '\phpbb\datetime');; + +		$container = new phpbb_mock_container_builder(); +		$container->setParameter('core.environment', PHPBB_ENVIRONMENT); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader($this->filesystem, ''); +		$twig = new \phpbb\template\twig\environment( +			$this->config, +			$this->filesystem, +			$this->phpbb_path_helper, +			$container, +			$cache_path, +			null, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		); +		$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + +		$this->extension_manager = new phpbb_mock_extension_manager(  			dirname(__FILE__) . '/', -			new phpbb_mock_cache() +			array( +				'vendor2/foo' => array( +					'ext_name' => 'vendor2/foo', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/foo/', +				), +			)  		); -		$finder->set_extensions(array_keys($this->extension_manager->all_enabled())); -		$this->provider = new \phpbb\controller\provider(); -		$this->provider->find_routing_files($finder); -		$this->provider->find(dirname(__FILE__) . '/'); + +		$this->router = new phpbb_mock_router($container, $this->filesystem, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT, $this->extension_manager); +		$this->router->find_routing_files($this->extension_manager->all_enabled(false)); +		$this->router->find(dirname(__FILE__) . '/');  		// Set correct current phpBB root path  		$this->root_path = $this->get_phpbb_root_path();  	} @@ -127,6 +156,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, '/' . $this->path_to_app() . 'app.php/foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -135,8 +167,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	*/  	public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)  	{ -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); +		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);  	}  	public function helper_url_data_with_rewrite() @@ -166,6 +199,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, '/' . $this->path_to_app() . 'foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -175,8 +211,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);  	}  	public function helper_url_data_absolute() @@ -206,6 +242,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -215,8 +254,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);  	}  	public function helper_url_data_relative_path() @@ -246,6 +285,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, 'app.php/foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, 'app.php/foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, 'app.php/foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false,  'app.php/foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -255,8 +297,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);  	}  	public function helper_url_data_network() @@ -286,6 +328,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -295,10 +340,10 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);  	} -//TODO +  	public function helper_url_data_absolute_with_rewrite()  	{  		return array( @@ -326,6 +371,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -335,8 +383,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);  	}  	public function helper_url_data_relative_path_with_rewrite() @@ -375,8 +423,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);  	}  	public function helper_url_data_network_with_rewrite() @@ -406,6 +454,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),  			array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + +			// Resolves DI parameters +			array('controller4', array(), true, false, '//localhost/' . $this->path_to_app() . 'foo/' . PHPBB_ENVIRONMENT, 'di parameter'),  		);  	} @@ -415,7 +466,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  	public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)  	{  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); -		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); +		$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);  	}  } diff --git a/tests/controller/config/routing.yml b/tests/controller/config/test/routing/environment.yml index 1e7df02684..1e7df02684 100644 --- a/tests/controller/config/routing.yml +++ b/tests/controller/config/test/routing/environment.yml diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 62feee3fed..d0295d66bc 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -30,14 +30,22 @@ class phpbb_controller_controller_test extends phpbb_test_case  					'ext_active' => '1',  					'ext_path' => 'ext/vendor2/foo/',  				), +				'vendor2/bar' => array( +					'ext_name' => 'vendor2/bar', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/bar/', +				),  			));  	} -	public function test_provider() +	public function test_router_find_files()  	{ -		$provider = new \phpbb\controller\provider(); -		$provider->find_routing_files($this->extension_manager->get_finder()); -		$routes = $provider->find(__DIR__)->get_routes(); +		$container = new phpbb_mock_container_builder(); +		$container->setParameter('core.environment', PHPBB_ENVIRONMENT); + +		$router = new \phpbb\routing\router($container, new \phpbb\filesystem\filesystem(), dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT, $this->extension_manager); +		$router->find_routing_files($this->extension_manager->all_enabled(false)); +		$routes = $router->find(__DIR__)->get_routes();  		// This will need to be updated if any new routes are defined  		$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller')); @@ -49,6 +57,9 @@ class phpbb_controller_controller_test extends phpbb_test_case  		$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2'));  		$this->assertEquals('/foo/bar', $routes->get('controller2')->getPath()); +		$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller3')); +		$this->assertEquals('/bar', $routes->get('controller3')->getPath()); +  		$this->assertNull($routes->get('controller_noroute'));  	} @@ -74,7 +85,7 @@ class phpbb_controller_controller_test extends phpbb_test_case  			include(__DIR__.'/phpbb/controller/foo.php');  		} -		$resolver = new \phpbb\controller\resolver(new \phpbb\user('\phpbb\datetime'), $container, dirname(__FILE__) . '/'); +		$resolver = new \phpbb\controller\resolver($container, dirname(__FILE__) . '/');  		$symfony_request = new Request();  		$symfony_request->attributes->set('_controller', 'foo.controller:handle'); diff --git a/tests/controller/ext/vendor2/bar/config/services.yml b/tests/controller/ext/vendor2/bar/config/services.yml new file mode 100644 index 0000000000..05a8a1994d --- /dev/null +++ b/tests/controller/ext/vendor2/bar/config/services.yml @@ -0,0 +1,3 @@ +services: +    bar.controller: +        class: bar\controller diff --git a/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml new file mode 100644 index 0000000000..5696ecb180 --- /dev/null +++ b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml @@ -0,0 +1,3 @@ +controller3: +    path: /bar +    defaults: { _controller: bar.controller:handle } diff --git a/tests/controller/ext/vendor2/bar/controller.php b/tests/controller/ext/vendor2/bar/controller.php new file mode 100644 index 0000000000..ad35f5a051 --- /dev/null +++ b/tests/controller/ext/vendor2/bar/controller.php @@ -0,0 +1,18 @@ +<?php + +namespace bar; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ +	/** +	* Handle method +	* +	* @return null +	*/ +	public function handle() +	{ +		return new Response('Test', 200); +	} +} diff --git a/tests/controller/ext/vendor2/foo/config/routing.yml b/tests/controller/ext/vendor2/foo/config/routing.yml index e3e8ee5f98..7d4ac7be93 100644 --- a/tests/controller/ext/vendor2/foo/config/routing.yml +++ b/tests/controller/ext/vendor2/foo/config/routing.yml @@ -5,3 +5,7 @@ controller1:  include_controller2:      resource: "routing_2.yml"      prefix:   /foo + +controller4: +    path: /foo/%core.environment% +    defaults: { _controller: foo.controller:handle } diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index 8968619bb5..7ecb546768 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -37,7 +37,11 @@ class phpbb_datetime_from_format_test extends phpbb_test_case  	*/  	public function test_from_format($timezone, $format, $expected)  	{ -		$user = new \phpbb\user('\phpbb\datetime'); +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->timezone = new DateTimeZone($timezone);  		$user->lang['datetime'] = array(  			'TODAY'		=> 'Today', @@ -107,7 +111,11 @@ class phpbb_datetime_from_format_test extends phpbb_test_case  	 */  	public function test_relative_format_date($timestamp, $forcedate, $expected)  	{ -		$user = new \phpbb\user('\phpbb\datetime'); +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->timezone = new DateTimeZone('UTC');  		$user->lang['datetime'] = array(  			'TODAY'		=> 'Today', diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index 1ed8ea29e3..39eb6835ff 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -30,7 +30,8 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->tools = $factory->get($this->db);  		$this->table_data = array(  			'COLUMNS'		=> array( diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 1ae34bd2b6..edf57189cb 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -22,7 +22,9 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case  	public function test_failing_connect()  	{ -		global $phpbb_root_path, $phpEx; +		global $phpbb_root_path, $phpEx, $phpbb_filesystem; + +		$phpbb_filesystem = new phpbb\filesystem\filesystem();  		$config = $this->get_database_config(); diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 5832b966d8..aa0b6ccf48 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  {  	/** @var \phpbb\db\driver\driver_interface */  	protected $db; -	/** @var \phpbb\db\tools */ +	/** @var \phpbb\db\tools\tools_interface */  	protected $tools;  	protected $table_exists;  	protected $table_data; @@ -32,7 +32,8 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->tools = $factory->get($this->db);  		$this->table_data = array(  			'COLUMNS'		=> array( @@ -340,7 +341,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  	public function test_perform_schema_changes_drop_tables()  	{ -		$db_tools = $this->getMock('\phpbb\db\tools', array( +		$db_tools = $this->getMock('\phpbb\db\tools\tools', array(  			'sql_table_exists',  			'sql_table_drop',  		), array(&$this->db)); @@ -366,7 +367,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case  	public function test_perform_schema_changes_drop_columns()  	{ -		$db_tools = $this->getMock('\phpbb\db\tools', array( +		$db_tools = $this->getMock('\phpbb\db\tools\tools', array(  			'sql_column_exists',  			'sql_column_remove',  		), array(&$this->db)); diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4c4306888c..f52e6ea63d 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -38,7 +38,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case  		parent::setUp();  		$this->db = $this->new_dbal(); -		$this->db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->db_tools = $factory->get($this->db);  		$this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); @@ -62,14 +63,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case  		);  		$container->set('migrator', $this->migrator);  		$container->set('dispatcher', new phpbb_mock_event_dispatcher()); -		$user = new \phpbb\user('\phpbb\datetime');  		$this->extension_manager = new \phpbb\extension\manager(  			$container,  			$this->db,  			$this->config, -			new phpbb\filesystem(), -			$user, +			new phpbb\filesystem\filesystem(),  			'phpbb_ext',  			dirname(__FILE__) . '/../../phpBB/',  			'php', diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 08c3e979b8..a71334f23f 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -27,19 +27,24 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case  		parent::setup(); -		// Force add_log function to not be used +		// Disable the logs  		$skip_add_log = true;  		$db = $this->db = $this->new_dbal(); -		$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); -		$user = $this->user = new \phpbb\user('\phpbb\user'); +		$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = $this->user = new \phpbb\user($lang, '\phpbb\datetime');  		$cache = new phpbb_mock_cache;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$auth = $this->getMock('\phpbb\auth\auth');  		$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); -		$this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); +		$phpbb_extension_manager = new phpbb_mock_extension_manager($phpbb_root_path); +		$module_manager = new \phpbb\module\module_manager($cache, $this->db, $phpbb_extension_manager, MODULES_TABLE, $phpbb_root_path, $phpEx); + +		$this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $module_manager, $phpbb_root_path, $phpEx, 'phpbb_modules');  	}  	public function exists_data() diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 4453fbf123..3d190e7a11 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -28,7 +28,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case  		parent::setup();  		$db = $this->db = $this->new_dbal(); -		$cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); +		$cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);  		$this->auth = new \phpbb\auth\auth();  		$this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 4ae6017989..2d94f1d778 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -14,6 +14,7 @@  namespace  {  	require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +	require_once dirname(__FILE__) . '/fixtures/ext/vendor/enabled_4/di/extension.php';  	class phpbb_di_container_test extends \phpbb_test_case  	{ @@ -30,7 +31,8 @@ namespace  		{  			$this->phpbb_root_path = dirname(__FILE__) . '/';  			$this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php'); -			$this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php'); +			$this->builder = new phpbb_mock_phpbb_di_container_builder($this->phpbb_root_path . 'fixtures/', 'php'); +			$this->builder->with_config($this->config_php);  			$this->filename = $this->phpbb_root_path . '../tmp/container.php';  			if (is_file($this->filename)) @@ -57,6 +59,9 @@ namespace  			// Checks use_extensions  			$this->assertTrue($container->hasParameter('enabled')); +			$this->assertTrue($container->hasParameter('enabled_2')); +			$this->assertTrue($container->hasParameter('enabled_3')); +			$this->assertTrue($container->hasParameter('enabled_4'));  			$this->assertFalse($container->hasParameter('disabled'));  			$this->assertFalse($container->hasParameter('available')); @@ -74,9 +79,9 @@ namespace  			$this->assertTrue($container->isFrozen());  		} -		public function test_dump_container() +		public function test_without_cache()  		{ -			$this->builder->set_dump_container(false); +			$this->builder->without_cache();  			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); @@ -90,9 +95,9 @@ namespace  			$this->assertTrue($container->isFrozen());  		} -		public function test_use_extensions() +		public function test_without_extensions()  		{ -			$this->builder->set_use_extensions(false); +			$this->builder->without_extensions();  			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); @@ -105,9 +110,9 @@ namespace  			$this->assertFalse($container->hasParameter('available'));  		} -		public function test_compile_container() +		public function test_without_compiled_container()  		{ -			$this->builder->set_compile_container(false); +			$this->builder->without_compiled_container();  			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); @@ -115,19 +120,9 @@ namespace  			$this->assertFalse($container->isFrozen());  		} -		public function test_inject_config() +		public function test_with_config_path()  		{ -			$this->builder->set_inject_config(false); -			$container = $this->builder->get_container(); -			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); - -			// Checks inject_config -			$this->assertFalse($container->hasParameter('dbal.dbhost')); -		} - -		public function test_set_config_path() -		{ -			$this->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/'); +			$this->builder->with_config_path($this->phpbb_root_path . 'fixtures/other_config/');  			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); @@ -135,70 +130,32 @@ namespace  			$this->assertFalse($container->hasParameter('core'));  		} -		public function test_set_custom_parameters() +		public function test_with_custom_parameters()  		{ -			$this->builder->set_custom_parameters(array('my_parameter' => true)); +			$this->builder->with_custom_parameters(array('my_parameter' => true));  			$container = $this->builder->get_container();  			$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);  			$this->assertTrue($container->hasParameter('my_parameter')); -			$this->assertFalse($container->hasParameter('core.root_path'));  		}  	}  } -namespace phpbb\db\driver +namespace phpbb\extension  { -	class container_mock extends \phpbb\db\driver\driver +	class manager_mock extends \phpbb\extension\manager  	{ -		public function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) -		{ -		} - -		public function sql_query($query = '', $cache_ttl = 0) -		{ -		} - -		public function sql_fetchrow($query_id = false) -		{ -		} - -		public function sql_freeresult($query_id = false) -		{ -		} - -		function sql_server_info($raw = false, $use_cache = true) -		{ -		} - -		function sql_affectedrows() -		{ -		} - -		function sql_rowseek($rownum, &$query_id) -		{ -		} - -		function sql_nextid() -		{ -		} - -		function sql_escape($msg) -		{ -		} - -		function sql_like_expression($expression) -		{ -		} - -		function sql_not_like_expression($expression) +		public function __construct()  		{  		} -		function sql_fetchrowset($query_id = false) +		public function all_enabled($phpbb_relative = true)  		{  			return array( -				array('ext_name' => 'vendor/enabled'), +				'vendor/enabled' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled/', +				'vendor/enabled-2' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled-2/', +				'vendor/enabled-3' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled-3/', +				'vendor/enabled_4' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled_4/',  			);  		}  	} diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php index 04e20f63d8..1e9207d924 100644 --- a/tests/di/fixtures/config.php +++ b/tests/di/fixtures/config.php @@ -1,11 +1,11 @@  <?php  // phpBB 3.1.x auto-generated configuration file  // Do not change anything in this file! -$dbms = 'container_mock'; +$dbms = 'mysql';  $dbhost = '127.0.0.1';  $dbport = '';  $dbname = 'phpbb';  $dbuser = 'root';  $dbpasswd = '';  $table_prefix = 'phpbb_'; -$acm_type = '\phpbb\cache\driver\null'; +$acm_type = '\phpbb\cache\driver\dummy'; diff --git a/tests/di/fixtures/config/production/config.yml b/tests/di/fixtures/config/production/config.yml new file mode 100644 index 0000000000..fcfa84f68b --- /dev/null +++ b/tests/di/fixtures/config/production/config.yml @@ -0,0 +1,2 @@ +core: +    require_dev_dependencies: true diff --git a/tests/di/fixtures/config/production/container/environment.yml b/tests/di/fixtures/config/production/container/environment.yml new file mode 100644 index 0000000000..9dcf11d865 --- /dev/null +++ b/tests/di/fixtures/config/production/container/environment.yml @@ -0,0 +1,29 @@ +parameters: +    core: true + +services: +    config.php: +        synthetic: true + +    dbal.conn: +        class: phpbb\db\driver\factory +        arguments: +            - @service_container + +    dispatcher: +        class: phpbb\db\driver\container_mock + +    ext.manager: +        class: phpbb\extension\manager_mock + +    template.twig.environment: +        class: Exception +        arguments: +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - [] diff --git a/tests/di/fixtures/config/test/config.yml b/tests/di/fixtures/config/test/config.yml new file mode 100644 index 0000000000..fcfa84f68b --- /dev/null +++ b/tests/di/fixtures/config/test/config.yml @@ -0,0 +1,2 @@ +core: +    require_dev_dependencies: true diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/test/container/environment.yml index f2a22ae109..14c986d123 100644 --- a/tests/di/fixtures/config/services.yml +++ b/tests/di/fixtures/config/test/container/environment.yml @@ -12,3 +12,15 @@ services:      dispatcher:          class: phpbb\db\driver\container_mock + +    template.twig.environment: +        class: Exception +        arguments: +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - [] diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml index 31ada384bf..31ada384bf 100644 --- a/tests/di/fixtures/ext/vendor/disabled/config/services.yml +++ b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml diff --git a/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml new file mode 100644 index 0000000000..feeb5a7a2d --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml @@ -0,0 +1,2 @@ +parameters: +    enabled_2: true diff --git a/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml new file mode 100644 index 0000000000..0dae35d2bd --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml @@ -0,0 +1,2 @@ +parameters: +    enabled_3: true diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml index 88a7919ed1..88a7919ed1 100644 --- a/tests/di/fixtures/ext/vendor/enabled/config/services.yml +++ b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml diff --git a/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php new file mode 100644 index 0000000000..8e5ed6c52c --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php @@ -0,0 +1,32 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace vendor\enabled_4\di; + +use phpbb\extension\di\extension_base; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +/** +* Container core extension +*/ +class extension extends extension_base +{ +	protected function load_services(ContainerBuilder $container) +	{ +		$filesystem = new \phpbb\filesystem\filesystem(); +		$loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($this->ext_path))); +		$loader->load('environment.yml'); +	} +} diff --git a/tests/di/fixtures/ext/vendor/enabled_4/environment.yml b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml new file mode 100644 index 0000000000..d0affe4fd6 --- /dev/null +++ b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml @@ -0,0 +1,2 @@ +parameters: +    enabled_4: true diff --git a/tests/di/fixtures/other_config/test/config.yml b/tests/di/fixtures/other_config/test/config.yml new file mode 100644 index 0000000000..fcfa84f68b --- /dev/null +++ b/tests/di/fixtures/other_config/test/config.yml @@ -0,0 +1,2 @@ +core: +    require_dev_dependencies: true diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/test/container/environment.yml index c299bfc648..e285b1b781 100644 --- a/tests/di/fixtures/other_config/services.yml +++ b/tests/di/fixtures/other_config/test/container/environment.yml @@ -12,3 +12,15 @@ services:      dispatcher:          class: phpbb\db\driver\container_mock + +    template.twig.environment: +        class: Exception +        arguments: +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - ~ +            - [] diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index b92c4fa6bb..ddbe2e3af1 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -15,6 +15,15 @@ require_once dirname(__FILE__) . '/../phpBB/includes/functions.php';  class phpbb_error_collector_test extends phpbb_test_case  { +	public function setUp() +	{ +		parent::setUp(); + +		global $phpbb_filesystem; + +		$phpbb_filesystem = new \phpbb\filesystem\filesystem(); +	} +  	public function test_collection()  	{  		$collector = new \phpbb\error_collector(E_ALL | E_STRICT); // php set_error_handler() default diff --git a/tests/event/exception_listener_test.php b/tests/event/exception_listener_test.php index 4d3453cd83..608cde4f9b 100644 --- a/tests/event/exception_listener_test.php +++ b/tests/event/exception_listener_test.php @@ -79,7 +79,11 @@ class exception_listener extends phpbb_test_case  			->disableOriginalConstructor()  			->getMock(); -		$user = new \phpbb\user('\phpbb\datetime'); +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->add_lang('common');  		$exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $user); diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php index 1a51204cbe..a6c1dc78de 100644 --- a/tests/event/md_exporter_test.php +++ b/tests/event/md_exporter_test.php @@ -23,7 +23,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  					'event' => 'acp_bbcodes_actions_append',  					'files' => array(  						'prosilver' => array(), -						'subsilver2' => array(),  						'adm' => array('acp_bbcodes.html'),  					),  					'since' => '3.1.0-a3', @@ -36,7 +35,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  					'event' => 'acp_bbcodes_actions_prepend',  					'files' => array(  						'prosilver' => array(), -						'subsilver2' => array(),  						'adm' => array('acp_bbcodes.html'),  					),  					'since' => '3.1.0-a5', @@ -47,7 +45,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  					'event' => 'acp_bbcodes_actions_prepend2',  					'files' => array(  						'prosilver' => array(), -						'subsilver2' => array(),  						'adm' => array('acp_bbcodes.html'),  					),  					'since' => '3.1.0-a4', @@ -63,7 +60,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  					'event' => 'acp_bbcodes_actions_prepend',  					'files' => array(  						'prosilver' => array(), -						'subsilver2' => array(),  						'adm' => array('acp_bbcodes.html'),  					),  					'since' => '3.1.0-a5', @@ -74,7 +70,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  					'event' => 'acp_bbcodes_actions_prepend2',  					'files' => array(  						'prosilver' => array(), -						'subsilver2' => array(),  						'adm' => array('acp_bbcodes.html'),  					),  					'since' => '3.1.0-a4', @@ -130,7 +125,6 @@ class phpbb_event_md_exporter_test extends phpbb_test_case  		$styles = array(  			'adm/style/' => 'adm',  			'styles/prosilver/template/' => 'styles', -			'styles/subsilver2/template/' => 'styles',  		);  		foreach ($styles as $path => $filter)  		{ diff --git a/tests/extension/ext/vendor2/bar/acp/a_info.php b/tests/extension/ext/vendor2/bar/acp/a_info.php index 8132df587f..8268006f9f 100644 --- a/tests/extension/ext/vendor2/bar/acp/a_info.php +++ b/tests/extension/ext/vendor2/bar/acp/a_info.php @@ -9,7 +9,6 @@ class a_info  		return array(  			'filename'	=> 'vendor2\\bar\\acp\\a_module',  			'title'		=> 'Bar', -			'version'	=> '3.1.0-dev',  			'modes'		=> array(  				'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')),  			), diff --git a/tests/extension/ext/vendor2/foo/acp/a_info.php b/tests/extension/ext/vendor2/foo/acp/a_info.php index e1eaa340b7..48ab4cf8e7 100644 --- a/tests/extension/ext/vendor2/foo/acp/a_info.php +++ b/tests/extension/ext/vendor2/foo/acp/a_info.php @@ -9,7 +9,6 @@ class a_info  		return array(  			'filename'	=> 'vendor2\\foo\\acp\\a_module',  			'title'		=> 'Foobar', -			'version'	=> '3.1.0-dev',  			'modes'		=> array(  				'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),  			), diff --git a/tests/extension/ext/vendor2/foo/acp/fail_info.php b/tests/extension/ext/vendor2/foo/acp/fail_info.php index d9b4353957..78479fee70 100644 --- a/tests/extension/ext/vendor2/foo/acp/fail_info.php +++ b/tests/extension/ext/vendor2/foo/acp/fail_info.php @@ -13,7 +13,6 @@ class foo_info  		return array(  			'filename'	=> 'vendor2\foo\acp\fail_module',  			'title'		=> 'Foobar', -			'version'	=> '3.1.0-dev',  			'modes'		=> array(  				'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')),  			), diff --git a/tests/extension/ext/vendor2/foo/mcp/a_info.php b/tests/extension/ext/vendor2/foo/mcp/a_info.php index b5599fde65..2532e44b12 100644 --- a/tests/extension/ext/vendor2/foo/mcp/a_info.php +++ b/tests/extension/ext/vendor2/foo/mcp/a_info.php @@ -9,7 +9,6 @@ class a_info  		return array(  			'filename'	=> 'vendor2\\foo\\mcp\\a_module',  			'title'		=> 'Foobar', -			'version'	=> '3.1.0-dev',  			'modes'		=> array(  				'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('MCP_MAIN')),  			), diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 2116cc057b..463b69e9a9 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -244,7 +244,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  	public function test_get_classes_create_cache()  	{  		$cache = new phpbb_mock_cache; -		$finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); +		$finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name');  		$finder->set_extensions(array_keys($this->extension_manager->all_enabled()));  		$files = $finder->suffix('_class.php')->get_files(); @@ -284,7 +284,7 @@ class phpbb_extension_finder_test extends phpbb_test_case  		);  		$finder = new \phpbb\finder( -			new \phpbb\filesystem(), +			new \phpbb\filesystem\filesystem(),  			dirname(__FILE__) . '/',  			new phpbb_mock_cache(array(  				'_ext_finder' => array( diff --git a/tests/extension/includes/acp/info/acp_foobar.php b/tests/extension/includes/acp/info/acp_foobar.php index 870225ba4f..8ca1afa1c6 100644 --- a/tests/extension/includes/acp/info/acp_foobar.php +++ b/tests/extension/includes/acp/info/acp_foobar.php @@ -18,7 +18,6 @@ class acp_foobar_info  		return array(  			'filename'	=> 'acp_foobar',  			'title'		=> 'ACP Foobar', -			'version'	=> '3.1.0-dev',  			'modes'		=> array(  				'test'		=> array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),  			), diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 0eeb060936..a24b0cf178 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -150,11 +150,11 @@ class phpbb_extension_manager_test extends phpbb_database_test_case  		$config = new \phpbb\config\config(array('version' => PHPBB_VERSION));  		$db = $this->new_dbal(); -		$db_tools = new \phpbb\db\tools($db); +		$factory = new \phpbb\db\tools\factory(); +		$db_tools = $factory->get($db);  		$phpbb_root_path = __DIR__ . './../../phpBB/';  		$php_ext = 'php';  		$table_prefix = 'phpbb_'; -		$user = new \phpbb\user('\phpbb\user');  		$container = new phpbb_mock_container_builder(); @@ -176,8 +176,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case  			$container,  			$db,  			$config, -			new \phpbb\filesystem(), -			$user, +			new \phpbb\filesystem\filesystem(),  			'phpbb_ext',  			dirname(__FILE__) . '/',  			$php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 2a746d3792..53bd3d109b 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -41,25 +41,40 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			'version'		=> '3.1.0',  		));  		$this->db = $this->new_dbal(); -		$this->db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->db_tools = $factory->get($this->db);  		$this->phpbb_root_path = dirname(__FILE__) . '/';  		$this->phpEx = 'php'; -		$this->user = new \phpbb\user('\phpbb\datetime');  		$this->table_prefix = 'phpbb_'; -		$this->template = new \phpbb\template\twig\twig( -			new \phpbb\path_helper( -				new \phpbb\symfony_request( -					new phpbb_mock_request() -				), -				new \phpbb\filesystem(), -				$this->getMock('\phpbb\request\request'), -				$this->phpbb_root_path, -				$this->phpEx +		$container = new phpbb_mock_container_builder(); +		$cache_path = $this->phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$filesystem = new \phpbb\filesystem\filesystem(); +		$phpbb_path_helper = new \phpbb\path_helper( +			new \phpbb\symfony_request( +				new phpbb_mock_request()  			), +			$filesystem, +			$this->getMock('\phpbb\request\request'), +			$this->phpbb_root_path, +			$this->phpEx +		); +		$twig = new \phpbb\template\twig\environment(  			$this->config, -			$this->user, -			new \phpbb\template\context() +			$filesystem, +			$phpbb_path_helper, +			$container, +			$cache_path, +			null, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			)  		);  		$container = new phpbb_mock_container_builder(); @@ -82,13 +97,22 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$container,  			$this->db,  			$this->config, -			new \phpbb\filesystem(), -			$this->user, +			new \phpbb\filesystem\filesystem(),  			'phpbb_ext',  			$this->phpbb_root_path,  			$this->phpEx,  			$this->cache  		); + +		global $phpbb_root_path; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $this->phpEx); +		$lang_loader->set_extension_manager($this->extension_manager); +		$lang = new \phpbb\language\language($lang_loader); +		$this->user = new \phpbb\user($lang, '\phpbb\datetime'); + +		$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));  	}  	// Should fail from missing composer.json @@ -104,7 +128,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch (\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json')); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->assertEquals($message, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'));  		}  	} @@ -121,7 +146,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch (\phpbb\extension\exception $e)  		{ -			$this->fail($e); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->fail($message);  		}  		$json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/vendor2/foo/composer.json'), true); @@ -151,9 +177,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$manager->validate($field_name);  			$this->fail('Exception not triggered');  		} -		catch(\phpbb\extension\exception $e) +		catch (\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', $field_name)); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', $field_name));  		}  	} @@ -167,7 +194,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch (\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors')); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', 'authors'));  		}  		$manager->merge_metadata(array( @@ -183,7 +211,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch (\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name')); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', 'author name'));  		}  	} @@ -214,9 +243,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$manager->validate($field_name);  			$this->fail('Exception not triggered');  		} -		catch(\phpbb\extension\exception $e) +		catch (\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name)); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); +			$this->assertEquals($message, $this->user->lang('META_FIELD_INVALID', $field_name));  		}  	} @@ -238,9 +268,9 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		{  			$this->assertEquals(true, $manager->validate('enable'));  		} -		catch(\phpbb\extension\exception $e) +		catch (\phpbb\extension\exception $e)  		{ -			$this->fail($e); +			$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));  		}  	} @@ -336,7 +366,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$this->config,  			$this->extension_manager,  			$this->template, -			$this->user,  			$this->phpbb_root_path  		);  	} diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index 21f1c6aca5..88634bc6ba 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -22,6 +22,7 @@ class phpbb_extension_modules_test extends phpbb_test_case  {  	protected $extension_manager;  	protected $finder; +	protected $module_manager;  	public function setUp()  	{ @@ -43,7 +44,14 @@ class phpbb_extension_modules_test extends phpbb_test_case  			));  		$phpbb_extension_manager = $this->extension_manager; -		$this->acp_modules = new acp_modules(); +		$this->module_manager = new \phpbb\module\module_manager( +			new \phpbb\cache\driver\dummy(), +			$this->getMock('\phpbb\db\driver\driver_interface'), +			$this->extension_manager, +			MODULES_TABLE, +			dirname(__FILE__) . '/', +			'php' +		);  	}  	public function test_get_module_infos() @@ -56,13 +64,11 @@ class phpbb_extension_modules_test extends phpbb_test_case  		$phpbb_root_path = dirname(__FILE__) . '/';  		// Find acp module info files -		$this->acp_modules->module_class = 'acp'; -		$acp_modules = $this->acp_modules->get_module_infos(); +		$acp_modules = $this->module_manager->get_module_infos('acp');  		$this->assertEquals(array(  				'vendor2\\foo\\acp\\a_module' => array(  					'filename'	=> 'vendor2\\foo\\acp\\a_module',  					'title'		=> 'Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),  					), @@ -70,7 +76,6 @@ class phpbb_extension_modules_test extends phpbb_test_case  				'acp_foobar' => array(  					'filename'	=> 'acp_foobar',  					'title'		=> 'ACP Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'test'		=> array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),  					), @@ -78,13 +83,11 @@ class phpbb_extension_modules_test extends phpbb_test_case  			), $acp_modules);  		// Find mcp module info files -		$this->acp_modules->module_class = 'mcp'; -		$acp_modules = $this->acp_modules->get_module_infos(); +		$acp_modules = $this->module_manager->get_module_infos('mcp');  		$this->assertEquals(array(  				'vendor2\\foo\\mcp\\a_module' => array(  					'filename'	=> 'vendor2\\foo\\mcp\\a_module',  					'title'		=> 'Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('MCP_MAIN')),  					), @@ -92,27 +95,11 @@ class phpbb_extension_modules_test extends phpbb_test_case  			), $acp_modules);  		// Find a specific module info file (mcp_a_module) -		$this->acp_modules->module_class = 'mcp'; -		$acp_modules = $this->acp_modules->get_module_infos('mcp_a_module'); -		$this->assertEquals(array( -				'vendor2\\foo\\mcp\\a_module' => array( -					'filename'	=> 'vendor2\\foo\\mcp\\a_module', -					'title'		=> 'Foobar', -					'version'	=> '3.1.0-dev', -					'modes'		=> array( -						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('MCP_MAIN')), -					), -				), -			), $acp_modules); - -		// Find a specific module info file (mcp_a_module) with passing the module_class -		$this->acp_modules->module_class = ''; -		$acp_modules = $this->acp_modules->get_module_infos('mcp_a_module', 'mcp'); +		$acp_modules = $this->module_manager->get_module_infos('mcp', 'mcp_a_module');  		$this->assertEquals(array(  				'vendor2\\foo\\mcp\\a_module' => array(  					'filename'	=> 'vendor2\\foo\\mcp\\a_module',  					'title'		=> 'Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('MCP_MAIN')),  					), @@ -120,23 +107,19 @@ class phpbb_extension_modules_test extends phpbb_test_case  			), $acp_modules);  		// The mcp module info file we're looking for shouldn't exist -		$this->acp_modules->module_class = 'mcp'; -		$acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail'); +		$acp_modules = $this->module_manager->get_module_infos('mcp', 'mcp_a_fail');  		$this->assertEquals(array(), $acp_modules);  		// As there are no ucp modules we shouldn't find any -		$this->acp_modules->module_class = 'ucp'; -		$acp_modules = $this->acp_modules->get_module_infos(); +		$acp_modules = $this->module_manager->get_module_infos('ucp');  		$this->assertEquals(array(), $acp_modules);  		// Get module info of specified extension module -		$this->acp_modules->module_class = 'acp'; -		$acp_modules = $this->acp_modules->get_module_infos('foo_acp_a_module'); +		$acp_modules = $this->module_manager->get_module_infos('acp', 'foo_acp_a_module');  		$this->assertEquals(array(  				'vendor2\\foo\\acp\\a_module' => array (  					'filename' => 'vendor2\\foo\\acp\\a_module',  					'title' => 'Foobar', -					'version' => '3.1.0-dev',  					'modes' => array (  						'config'		=> array ('title' => 'Config', 'auth' => 'ext_vendor2/foo', 'cat' => array ('ACP_MODS')),  					), @@ -144,23 +127,20 @@ class phpbb_extension_modules_test extends phpbb_test_case  			), $acp_modules);  		// No specific module and module class set to an incorrect name -		$acp_modules = $this->acp_modules->get_module_infos('', 'wcp', true); +		$acp_modules = $this->module_manager->get_module_infos('wcp', '', true);  		$this->assertEquals(array(), $acp_modules);  		// No specific module, no module_class set in the function parameter, and an incorrect module class -		$this->acp_modules->module_class = 'wcp'; -		$acp_modules = $this->acp_modules->get_module_infos(); +		$acp_modules = $this->module_manager->get_module_infos('wcp');  		$this->assertEquals(array(), $acp_modules);  		// No specific module, module class set to false (will default to the above acp)  		// Setting $use_all_available will cause get_module_infos() to also load not enabled extensions (vendor2/bar) -		$this->acp_modules->module_class = 'acp'; -		$acp_modules = $this->acp_modules->get_module_infos('', false, true); +		$acp_modules = $this->module_manager->get_module_infos('acp', '', true);  		$this->assertEquals(array(  				'vendor2\\foo\\acp\\a_module' => array(  					'filename'	=> 'vendor2\\foo\\acp\\a_module',  					'title'		=> 'Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),  					), @@ -168,7 +148,6 @@ class phpbb_extension_modules_test extends phpbb_test_case  				'acp_foobar' => array(  					'filename'	=> 'acp_foobar',  					'title'		=> 'ACP Foobar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'test'		=> array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),  					), @@ -176,7 +155,6 @@ class phpbb_extension_modules_test extends phpbb_test_case  				'vendor2\\bar\\acp\\a_module' => array(  					'filename'	=> 'vendor2\\bar\\acp\\a_module',  					'title'		=> 'Bar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')),  					), @@ -184,12 +162,11 @@ class phpbb_extension_modules_test extends phpbb_test_case  			), $acp_modules);  		// Specific module set to disabled extension -		$acp_modules = $this->acp_modules->get_module_infos('vendor2_bar_acp_a_module', 'acp', true); +		$acp_modules = $this->module_manager->get_module_infos('acp', 'vendor2_bar_acp_a_module', true);  		$this->assertEquals(array(  				'vendor2\\bar\\acp\\a_module' => array(  					'filename'	=> 'vendor2\\bar\\acp\\a_module',  					'title'		=> 'Bar', -					'version'	=> '3.1.0-dev',  					'modes'		=> array(  						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')),  					), diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index c585b17155..d2dec424b4 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -18,7 +18,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case  	public function setUp()  	{  		parent::setUp(); -		$this->filesystem = new \phpbb\filesystem(); +		$this->filesystem = new \phpbb\filesystem\filesystem();  	}  	public function clean_path_data() diff --git a/tests/functions/is_absolute_test.php b/tests/filesystem/is_absolute_test.php index afa4b9b59f..7a50989b74 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/filesystem/is_absolute_test.php @@ -1,20 +1,28 @@  <?php  /** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_functions_is_absolute_test extends phpbb_test_case + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_filesystem_is_absolute_test extends phpbb_test_case  { +	/** @var \phpbb\filesystem\filesystem_interface */ +	protected $filesystem; + +	public function setUp() +	{ +		parent::setUp(); + +		$this->filesystem = new \phpbb\filesystem\filesystem(); +	} +  	static public function is_absolute_data()  	{  		return array( @@ -51,10 +59,10 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case  	}  	/** -	* @dataProvider is_absolute_data -	*/ +	 * @dataProvider is_absolute_data +	 */  	public function test_is_absolute($path, $expected)  	{ -		$this->assertEquals($expected, phpbb_is_absolute($path)); +		$this->assertEquals($expected, $this->filesystem->is_absolute_path($path));  	}  } diff --git a/tests/filesystem/realpath_test.php b/tests/filesystem/realpath_test.php new file mode 100644 index 0000000000..d994935f94 --- /dev/null +++ b/tests/filesystem/realpath_test.php @@ -0,0 +1,90 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_filesystem_realpath_test extends phpbb_test_case +{ +	static protected $filesystem_own_realpath; + +	/** @var \phpbb\filesystem\filesystem_interface */ +	protected $filesystem; + +	static public function setUpBeforeClass() +	{ +		parent::setUpBeforeClass(); + +		$reflection_class = new ReflectionClass('\phpbb\filesystem\filesystem'); +		self::$filesystem_own_realpath = $reflection_class->getMethod('phpbb_own_realpath'); +		self::$filesystem_own_realpath->setAccessible(true); +	} + +	public function setUp() +	{ +		parent::setUp(); + +		$this->filesystem = new \phpbb\filesystem\filesystem(); +	} + +	public function realpath_resolve_absolute_without_symlinks_data() +	{ +		return array( +			// Constant data +			array(__DIR__, __DIR__), +			array(__DIR__ . '/../filesystem/../filesystem', __DIR__), +			array(__DIR__ . '/././', __DIR__), +			array(__DIR__ . '/non_existent', false), + +			array(__FILE__, __FILE__), +			array(__FILE__ . '../', false), +		); +	} + +	public function realpath_resolve_relative_without_symlinks_data() +	{ +		if (!function_exists('getcwd')) +		{ +			return array(); +		} + +		$filesystem = new \phpbb\filesystem\filesystem(); +		$relative_path = $filesystem->make_path_relative(__DIR__, getcwd()); + +		return array( +			array($relative_path, __DIR__), +			array($relative_path . '../filesystem/../filesystem', __DIR__), +			array($relative_path . '././', __DIR__), + +			array($relative_path . 'realpath_test.php', __FILE__), +		); +	} + +	/** +	 * @dataProvider realpath_resolve_absolute_without_symlinks_data +	 */ +	public function test_realpath_absolute_without_links($path, $expected) +	{ +		$this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path)); +	} + +	/** +	 * @dataProvider realpath_resolve_relative_without_symlinks_data +	 */ +	public function test_realpath_relative_without_links($path, $expected) +	{ +		if (!function_exists('getcwd')) +		{ +			$this->markTestSkipped('phpbb_own_realpath() cannot be tested with relative paths: getcwd is not available.'); +		} + +		$this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path)); +	} +} diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index b9e74a280f..4f28879687 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -34,6 +34,18 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case  		$this->assertGreaterThan(0, $crawler->filter('.postbody')->count());  	} +	public function test_help_faq() +	{ +		$crawler = self::request('GET', 'app.php/help/faq'); +		$this->assertGreaterThan(0, $crawler->filter('h2.faq-title')->count()); +	} + +	public function test_help_bbcode() +	{ +		$crawler = self::request('GET', 'app.php/help/bbcode'); +		$this->assertGreaterThan(0, $crawler->filter('h2.faq-title')->count()); +	} +  	public function test_feed()  	{  		$crawler = self::request('GET', 'feed.php', array(), false); diff --git a/tests/functional/controllers_compatibility_test.php b/tests/functional/controllers_compatibility_test.php new file mode 100644 index 0000000000..7ba0b0d991 --- /dev/null +++ b/tests/functional/controllers_compatibility_test.php @@ -0,0 +1,43 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ + +class phpbb_functional_controllers_compatibility_test extends phpbb_functional_test_case +{ +	public function test_report_compatibility() +	{ +		$this->assert301('report.php?f=1&p=1', 'app.php/post/1/report'); +		$this->assert301('report.php?p=1', 'app.php/post/1/report'); +		$this->assert301('report.php?pm=1', 'app.php/pm/1/report'); +	} + +	protected function assert301($from, $to) +	{ +		self::$client->followRedirects(false); +		self::request('GET', $from, array(), false); + +		// Fix sid issues +		$location = self::$client->getResponse()->getHeader('Location'); +		$location = preg_replace('#sid=[^&]+(&(amp;)?)?#', '', $location); +		if (substr($location, -1) === '?') +		{ +			$location = substr($location, 0, -1); +		} + +		$this->assertEquals(301, self::$client->getResponse()->getStatus()); +		$this->assertStringEndsWith($to, $location); +	} +} diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index ee084720e4..95107665cd 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -49,8 +49,9 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case  		$this->phpbb_extension_manager = $this->get_extension_manager();  		$this->phpbb_extension_manager->enable('foo/bar'); -		$modules = new acp_modules();  		$db = $this->get_db(); +		$cache = $this->get_cache_driver(); +		$modules = new \phpbb\module\module_manager($cache, $db, $this->phpbb_extension_manager, MODULES_TABLE, dirname(__FILE__) . '/../../phpBB/', 'php');  		$sql = 'SELECT module_id  			FROM ' . MODULES_TABLE . " @@ -70,7 +71,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case  			'module_mode'		=> '',  			'module_auth'		=> '',  		); -		$modules->update_module_data($parent_data, true); +		$modules->update_module_data($parent_data);  		$module_data = array(  			'module_basename'	=> 'foo\\bar\\acp\\main_module', @@ -82,7 +83,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case  			'module_mode'		=> 'mode',  			'module_auth'		=> '',  		); -		$modules->update_module_data($module_data, true); +		$modules->update_module_data($module_data);  		$parent_data = array(  			'module_basename'	=> '', @@ -94,7 +95,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case  			'module_mode'		=> '',  			'module_auth'		=> '',  		); -		$modules->update_module_data($parent_data, true); +		$modules->update_module_data($parent_data);  		$module_data = array(  			'module_basename'	=> 'foo\\bar\\ucp\\main_module', @@ -106,7 +107,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case  			'module_mode'		=> 'mode',  			'module_auth'		=> '',  		); -		$modules->update_module_data($module_data, true); +		$modules->update_module_data($module_data);  		$this->purge_cache();  	} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 6ece150b23..4aa1a83b30 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -18,6 +18,8 @@ require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';   */  class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case  { +	protected $filesystem; +  	public function setUp()  	{  		parent::setUp(); @@ -38,6 +40,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case  		$user = new phpbb_mock_user();  		$user->lang = new phpbb_mock_lang(); +		$this->filesystem = new \phpbb\filesystem\filesystem();  	}  	public function tearDown() @@ -49,21 +52,21 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case  	public function test_invalid_extension()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $upload->remote_upload(self::$root_url . 'develop/blank.gif');  		$this->assertEquals('URL_INVALID', $file->error[0]);  	}  	public function test_empty_file()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg');  		$this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);  	}  	public function test_successful_upload()  	{ -		$upload = new fileupload('', array('gif'), 1000); +		$upload = new fileupload($this->filesystem, '', array('gif'), 1000);  		$file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif');  		$this->assertEquals(0, sizeof($file->error));  		$this->assertTrue(file_exists($file->filename)); @@ -71,7 +74,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case  	public function test_too_large()  	{ -		$upload = new fileupload('', array('gif'), 100); +		$upload = new fileupload($this->filesystem, '', array('gif'), 100);  		$file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif');  		$this->assertEquals(1, sizeof($file->error));  		$this->assertEquals('WRONG_FILESIZE', $file->error[0]); diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php index ec378e0e75..371ab7c967 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -28,7 +28,6 @@ class main_info  		return array(  			'filename'	=> 'foo\bar\acp\main_module',  			'title'		=> 'ACP_FOOBAR_TITLE', -			'version'	=> '1.0.0',  			'modes'		=> array(  				'mode'		=> array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')),  			), diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php index d34244f800..4c74442639 100644 --- a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php @@ -20,7 +20,6 @@ class main_info  		return array(  			'filename'	=> '\foo\bar\ucp\main_module',  			'title'		=> 'ACP_FOOBAR_TITLE', -			'version'	=> '1.0.0',  			'modes'		=> array(  				'mode'		=> array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')),  			), diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index fd802eed45..49f0c1d749 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -45,18 +45,139 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case  		self::create_post(2,  			1, -			'Unsupported characters', -			"This is a test with these weird characters: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", -			array(), -			'Your message contains the following unsupported characters' -		); - -		self::create_post(2, -			1,  			"Unsupported: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6",  			'This is a test with emoji characters in the topic title.',  			array(),  			'Your subject contains the following unsupported characters'  		);  	} + +	public function test_supported_unicode_characters() +	{ +		$this->login(); + +		$post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); +		$this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', "This is a test with these weird characters: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6"); +		$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); +		$this->assertContains("\xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", $crawler->text()); +	} + +	public function test_html_entities() +	{ +		$this->login(); + +		$post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); +		$this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', '😀'); +		$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); +		$this->assertContains('😀', $crawler->text()); +	} + +	public function test_quote() +	{ +		$text     = 'Test post </textarea>"\' &&amp;'; +		$expected = '[quote="admin"]' . $text . '[/quote]'; + +		$this->login(); +		$topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); +		$post  = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); + +		$crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}"); + +		$this->assertContains($expected, $crawler->filter('textarea#message')->text()); +	} + +	/** +	* @testdox max_quote_depth is applied to the text populating the posting form +	*/ +	public function test_quote_depth_form() +	{ +		$text = '0[quote]1[quote]2[/quote]1[/quote]0'; +		$expected = array( +			0 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]', +			1 => '[quote="admin"]00[/quote]', +			2 => '[quote="admin"]0[quote]11[/quote]0[/quote]', +			3 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]', +		); + +		$this->login(); +		$topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); +		$post  = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); +		$quote_url = "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}"; + +		$this->admin_login(); +		foreach ($expected as $quote_depth => $expected_text) +		{ +			$this->set_quote_depth($quote_depth); +			$crawler = self::request('GET', $quote_url); +			$this->assertContains($expected_text, $crawler->filter('textarea#message')->text()); +		} +	} + +	/** +	* @testdox max_quote_depth is applied to the submitted text +	*/ +	public function test_quote_depth_submit() +	{ +		$text = 'depth:0[quote]depth:1[quote]depth:2[quote]depth:3[/quote][/quote][/quote]'; +		$contains = array( +			0 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'), +			1 => array('depth:0', 'depth:1'), +			2 => array('depth:0', 'depth:1', 'depth:2'), +			3 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'), +		); +		$not_contains = array( +			0 => array(), +			1 => array('depth:2', 'depth:3'), +			2 => array('depth:3'), +			3 => array(), +		); + +		$this->login(); +		$this->admin_login(); +		$topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); + +		for ($quote_depth = 0; $quote_depth <= 2; ++$quote_depth) +		{ +			$this->set_quote_depth($quote_depth); + +			$post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); +			$url  = "viewtopic.php?p={$post['post_id']}&sid={$this->sid}"; + +			$crawler = self::request('GET', $url); +			$text_content = $crawler->filter('#p' . $post['post_id'])->text(); +			foreach ($contains[$quote_depth] as $contains_text) +			{ +				$this->assertContains($contains_text, $text_content); +			} +			foreach ($not_contains[$quote_depth] as $not_contains_text) +			{ +				$this->assertNotContains($not_contains_text, $text_content); +			} +		} +	} + +	protected function set_quote_depth($depth) +	{ +		$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); +		$form = $crawler->selectButton('Submit')->form(); +		$values = $form->getValues(); +		$values['config[max_quote_depth]'] = $depth; +		$form->setValues($values); +		$crawler = self::submit($form); +		$this->assertEquals(1, $crawler->filter('.successbox')->count()); +	} + +	public function test_ticket_8420() +	{ +		$text = '[b][url=http://example.org] :arrow: here[/url][/b]'; + +		$this->login(); +		$crawler = self::request('GET', 'posting.php?mode=post&f=2'); +		$form = $crawler->selectButton('Preview')->form(array( +			'subject' => 'Test subject', +			'message' => $text +		)); +		$crawler = self::submit($form); +		$this->assertEquals($text, $crawler->filter('#message')->text()); +	}  } diff --git a/tests/functional/private_messages_test.php b/tests/functional/private_messages_test.php index 1f6dc3a979..3f602d62fb 100644 --- a/tests/functional/private_messages_test.php +++ b/tests/functional/private_messages_test.php @@ -66,4 +66,31 @@ class phpbb_functional_private_messages_test extends phpbb_functional_test_case  		$crawler = self::submit($form);  		$this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());  	} + +	public function test_quote_post() +	{ +		$text     = 'Test post'; +		$expected = '[quote="admin"]' . $text . '[/quote]'; + +		$this->login(); +		$topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); +		$post  = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); + +		$crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=quotepost&p=' . $post['post_id'] . '&sid=' . $this->sid); + +		$this->assertContains($expected, $crawler->filter('textarea#message')->text()); +	} + +	public function test_quote_forward() +	{ +		$text     = 'This is a test private message sent by the testing framework.'; +		$expected = '[quote="admin"]' . $text . '[/quote]'; + +		$this->login(); +		$message_id = $this->create_private_message('Test', $text, array(2)); + +		$crawler = self::request('GET', 'ucp.php?i=pm&mode=compose&action=forward&f=0&p=' . $message_id . '&sid=' . $this->sid); + +		$this->assertContains($expected, $crawler->filter('textarea#message')->text()); +	}  } diff --git a/tests/functional/report_post_captcha_test.php b/tests/functional/report_post_captcha_test.php index 93a03bd931..36a1a9ee4d 100644 --- a/tests/functional/report_post_captcha_test.php +++ b/tests/functional/report_post_captcha_test.php @@ -18,12 +18,13 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca  {  	public function test_guest_report_post()  	{ -		$crawler = self::request('GET', 'report.php?f=2&p=1'); +		$crawler = self::request('GET', 'app.php/post/1/report', array(), false); +		$this->assert_response_html(403);  		$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'); +		$crawler = self::request('GET', 'app.php/post/1/report');  		$this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());  		$this->set_reporting_guest(-1);  	} @@ -31,7 +32,7 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca  	public function test_user_report_post()  	{  		$this->login(); -		$crawler = self::request('GET', 'report.php?f=2&p=1'); +		$crawler = self::request('GET', 'app.php/post/1/report');  		$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());  		$this->add_lang('mcp'); diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php index a59b94c744..3e19b51f02 100644 --- a/tests/functions/build_url_test.php +++ b/tests/functions/build_url_test.php @@ -29,7 +29,7 @@ class phpbb_build_url_test extends phpbb_test_case  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			new \phpbb\filesystem\filesystem(),  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			'php' diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php index cd1e37618a..bcf0c09fe4 100644 --- a/tests/functions/generate_string_list.php +++ b/tests/functions/generate_string_list.php @@ -22,7 +22,12 @@ class phpbb_generate_string_list_test extends phpbb_test_case  	{  		parent::setUp(); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$this->user = $user;  		$this->user->data = array('user_lang' => 'en');  		$this->user->add_lang('common');  	} @@ -36,7 +41,7 @@ class phpbb_generate_string_list_test extends phpbb_test_case  			),  			array(  				array('A'), -				'A',	 +				'A',  			),  			array(  				array(2 => 'A', 3 => 'B'), diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php index 612d82273e..781a73a462 100644 --- a/tests/functions/get_remote_file_test.php +++ b/tests/functions/get_remote_file_test.php @@ -12,7 +12,7 @@  */  require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compatibility.php';  /**  * @group slow diff --git a/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml b/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml new file mode 100644 index 0000000000..c78d63f7cb --- /dev/null +++ b/tests/functions_privmsgs/fixtures/get_max_setting_from_group.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_groups"> +		<column>group_id</column> +		<column>group_desc</column> +		<column>group_message_limit</column> +		<column>group_max_recipients</column> +		<row> +			<value>1</value> +			<value></value> +			<value>1</value> +			<value>3</value> +		</row> +		<row> +			<value>2</value> +			<value></value> +			<value>2</value> +			<value>4</value> +		</row> +		<row> +			<value>3</value> +			<value></value> +			<value>0</value> +			<value>0</value> +		</row> +		<row> +			<value>4</value> +			<value></value> +			<value>0</value> +			<value>5</value> +		</row> +	</table> +	<table name="phpbb_user_group"> +		<column>user_id</column> +		<column>group_id</column> +		<column>user_pending</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>0</value> +		</row> +		<row> +			<value>1</value> +			<value>2</value> +			<value>0</value> +		</row> +		<row> +			<value>1</value> +			<value>3</value> +			<value>0</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>0</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value>0</value> +		</row> +		<row> +			<value>3</value> +			<value>3</value> +			<value>0</value> +		</row> +		<row> +			<value>4</value> +			<value>4</value> +			<value>0</value> +		</row> +		<row> +			<value>5</value> +			<value>3</value> +			<value>1</value> +		</row> +		<row> +			<value>5</value> +			<value>2</value> +			<value>0</value> +		</row> +	</table> +</dataset> diff --git a/tests/functions_privmsgs/get_max_setting_from_group_test.php b/tests/functions_privmsgs/get_max_setting_from_group_test.php new file mode 100644 index 0000000000..3eb7866802 --- /dev/null +++ b/tests/functions_privmsgs/get_max_setting_from_group_test.php @@ -0,0 +1,64 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_privmsgs.php'; + +class phpbb_functions_privmsgs_get_max_setting_from_group_test extends phpbb_database_test_case +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/get_max_setting_from_group.xml'); +	} + +	/** @var \phpbb\db\driver\driver_interface */ +	protected $db; + +	protected function setUp() +	{ +		parent::setUp(); + +		$this->db = $this->new_dbal(); +	} + +	static public function get_max_setting_from_group_data() +	{ +		return array( +			array(1, 0, 'message_limit'), +			array(2, 2, 'message_limit'), +			array(3, 0, 'message_limit'), +			array(4, 0, 'message_limit'), +			array(5, 2, 'message_limit'), +			array(1, 0, 'max_recipients'), +			array(2, 4, 'max_recipients'), +			array(3, 0, 'max_recipients'), +			array(4, 5, 'max_recipients'), +			array(5, 4, 'max_recipients'), +		); +	} + +	/** +	* @dataProvider get_max_setting_from_group_data +	*/ +	public function test_get_max_setting_from_group($user_id, $expected, $setting) +	{ +		$this->assertEquals($expected, phpbb_get_max_setting_from_group($this->db, $user_id, $setting)); +	} + +	/** +	 * @expectedException InvalidArgumentException +	 */ +	public function test_get_max_setting_from_group_throws() +	{ +		phpbb_get_max_setting_from_group($this->db, ANONYMOUS, 'not_a_setting'); +	} +} diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 7db69e332c..9e2caf9d21 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -32,8 +32,6 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case  			'load_online_time'	=> 5,  			'search_type'		=> '\phpbb\search\fulltext_mysql',  		)); -		set_config(false, false, false, $config); -		set_config_count(false, false, false, $config);  		$cache = new phpbb_mock_null_cache();  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$phpbb_container = new phpbb_mock_container_builder(); diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php index 99a15b32bf..6ccada44f8 100644 --- a/tests/functions_user/group_user_attributes_test.php +++ b/tests/functions_user/group_user_attributes_test.php @@ -139,7 +139,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes  		$auth = $this->getMock('\phpbb\auth\auth');  		$auth->expects($this->any())  			->method('acl_clear_prefetch'); -		$cache_driver = new \phpbb\cache\driver\null(); +		$cache_driver = new \phpbb\cache\driver\dummy();  		$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');  		$phpbb_container  			->expects($this->any()) diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index fe003e93a7..566a8a2935 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -33,11 +33,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_get_group_value($group_id, $expected, $throws_exception)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		if ($throws_exception) @@ -51,11 +53,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	public function test_get_group_count()  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); @@ -91,11 +95,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_add_group($group_id, $expected_added, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); @@ -179,11 +185,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); @@ -234,11 +242,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_move_up($group_id, $excepted_moved, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); @@ -289,11 +299,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_move_down($group_id, $excepted_moved, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); @@ -387,11 +399,13 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case  	*/  	public function test_move($group_id, $increment, $excepted_moved, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\legend($db, $user); diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 1e61e3ebfb..dff52f7a43 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -35,11 +35,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_get_group_value($group_id, $expected, $throws_exception)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		if ($throws_exception) @@ -53,11 +55,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	public function test_get_group_count()  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -137,11 +141,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_add_group_teampage($group_id, $parent_id, $expected_added, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -180,11 +186,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_add_category_teampage($group_name, $expected_added, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -247,11 +255,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_delete_group($group_id, $expected_deleted, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -299,11 +309,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_delete_teampage($teampage_id, $expected_deleted, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -462,11 +474,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_move($group_id, $move_delta, $excepted_moved, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -625,11 +639,13 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case  	*/  	public function test_move_teampage($teampage_id, $move_delta, $excepted_moved, $expected)  	{ -		global $cache; +		global $cache, $phpbb_root_path, $phpEx;  		$cache = new phpbb_mock_cache;  		$db = $this->new_dbal(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = array();  		$test_class = new \phpbb\groupposition\teampage($db, $user, $cache); diff --git a/tests/help/manager_test.php b/tests/help/manager_test.php new file mode 100644 index 0000000000..68534d9a32 --- /dev/null +++ b/tests/help/manager_test.php @@ -0,0 +1,184 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_help_manager_test extends phpbb_test_case +{ +	/** @var \phpbb\help\manager */ +	protected $manager; +	/** @var \phpbb\template\template */ +	protected $template; +	/** @var \phpbb\language\language */ +	protected $language; + +	public function setUp() +	{ +		$this->template = $this->getMockBuilder('\phpbb\template\template') +			->disableOriginalConstructor() +			->getMock(); +		$this->language = $this->getMockBuilder('\phpbb\language\language') +			->disableOriginalConstructor() +			->getMock(); + +		$this->manager = new \phpbb\help\manager( +			new \phpbb_mock_event_dispatcher(), +			$this->language, +			$this->template +		); +	} + +	public function add_block_data() +	{ +		return array( +			array('abc', false, array(), false), +			array('def', true, array(), true), +			array( +				'abc', +				false, +				array( +					'question1' => 'answer1', +					'question2' => 'answer2', +					'question3' => 'answer3', +				), +				false +			), +		); +	} + +	/** +	 * @dataProvider add_block_data +	 * +	 * @param string $block_name +	 * @param bool $switch +	 * @param array $questions +	 * @param bool $switch_expected +	 */ +	public function test_add_block($block_name, $switch, $questions, $switch_expected) +	{ +		$this->language->expects($this->at(0)) +			->method('lang') +			->with($block_name) +			->willReturn(strtoupper($block_name)); +		$lang_call_count = 1; +		foreach ($questions as $question => $answer) +		{ +			$this->language->expects($this->at($lang_call_count)) +				->method('lang') +				->with($question) +				->willReturn(strtoupper($question)); +			$lang_call_count++; + +			$this->language->expects($this->at($lang_call_count)) +				->method('lang') +				->with($answer) +				->willReturn(strtoupper($answer)); +			$lang_call_count++; +		} + +		$this->template->expects($this->at(0)) +			->method('assign_block_vars') +			->with('faq_block', array( +				'BLOCK_TITLE' => strtoupper($block_name), +				'SWITCH_COLUMN' => $switch_expected, +			)); +		$template_call_count = 1; +		foreach ($questions as $question => $answer) +		{ +			$this->template->expects($this->at($template_call_count)) +				->method('assign_block_vars') +				->with('faq_block.faq_row', array( +					'FAQ_QUESTION' => strtoupper($question), +					'FAQ_ANSWER' => strtoupper($answer), +				)); +			$template_call_count++; +		} + +		$this->manager->add_block($block_name, $switch, $questions); + +		$this->assertEquals($switch_expected, $this->manager->switched_column()); +	} + +	public function add_question_data() +	{ +		return array( +			array('abc', false, false), +			array('def', true, true), +		); +	} + +	/** +	 * @dataProvider add_question_data +	 * +	 * @param string $question +	 * @param string $answer +	 */ +	public function test_add_question($question, $answer) +	{ +		$this->language->expects($this->at(0)) +			->method('lang') +			->with($question) +			->willReturn(strtoupper($question)); +		$this->language->expects($this->at(1)) +			->method('lang') +			->with($answer) +			->willReturn(strtoupper($answer)); + +		$this->template->expects($this->once()) +			->method('assign_block_vars') +			->with('faq_block.faq_row', array( +				'FAQ_QUESTION' => strtoupper($question), +				'FAQ_ANSWER' => strtoupper($answer), +			)); + +		$this->manager->add_question($question, $answer); +	} + +	public function test_add_block_double_switch() +	{ +		$block_name = 'abc'; +		$switch_expected = true; + +		$this->language->expects($this->at(0)) +			->method('lang') +			->with($block_name) +			->willReturn(strtoupper($block_name)); + +		$this->template->expects($this->at(0)) +			->method('assign_block_vars') +			->with('faq_block', array( +				'BLOCK_TITLE' => strtoupper($block_name), +				'SWITCH_COLUMN' => $switch_expected, +			)); + +		$this->manager->add_block($block_name, true); +		$this->assertTrue($this->manager->switched_column()); + +		// Add a second block with switch +		$block_name = 'def'; +		$switch_expected = false; + +		$this->language->expects($this->at(0)) +			->method('lang') +			->with($block_name) +			->willReturn(strtoupper($block_name)); + +		$this->template->expects($this->at(0)) +			->method('assign_block_vars') +			->with('faq_block', array( +				'BLOCK_TITLE' => strtoupper($block_name), +				'SWITCH_COLUMN' => $switch_expected, +			)); + +		$this->manager->add_block($block_name, true); +		$this->assertTrue($this->manager->switched_column()); +	} +} diff --git a/tests/language/language_test.php b/tests/language/language_test.php new file mode 100644 index 0000000000..95de403bd4 --- /dev/null +++ b/tests/language/language_test.php @@ -0,0 +1,210 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_language_test extends phpbb_test_case +{ +	/** @var \phpbb\language\language */ +	protected $lang; + +	public function setUp() +	{ +		global $phpbb_root_path, $phpEx; + +		// Set up language service +		$this->lang = new \phpbb\language\language( +			new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) +		); + +		// Set up language data for testing +		$reflection_class = new ReflectionClass('\phpbb\language\language'); + +		// Set default language files loaded flag to true +		$loaded_flag = $reflection_class->getProperty('common_language_files_loaded'); +		$loaded_flag->setAccessible(true); +		$loaded_flag->setValue($this->lang, true); + +		// Set up test language data +		$lang_array = $reflection_class->getProperty('lang'); +		$lang_array->setAccessible(true); +		$lang_array->setValue($this->lang, $this->get_test_data_set()); +	} + +	public function test_lang() +	{ +		// No param +		$this->assertEquals($this->lang->lang('FOO'), 'BAR'); +		$this->assertEquals($this->lang->lang('EMPTY'), ''); +		$this->assertEquals($this->lang->lang('ZERO'), '0'); + +		// Invalid index +		$this->assertEquals($this->lang->lang('VOID'), 'VOID'); + +		// Unnecessary param +		$this->assertEquals($this->lang->lang('FOO', 2), 'BAR'); +		$this->assertEquals($this->lang->lang('FOO', 2, 3), 'BAR'); +		$this->assertEquals($this->lang->lang('FOO', 2, 3, 'BARZ'), 'BAR'); + +		// String +		$this->assertEquals($this->lang->lang('STR', 24, 'x', 42), '24 x, 42 topics'); +		$this->assertEquals($this->lang->lang('STR2', 64), '64 foos'); + +		// Array +		$this->assertEquals($this->lang->lang('ARRY', 0), 'No posts'); +		$this->assertEquals($this->lang->lang('ARRY', 1), '1 post'); +		$this->assertEquals($this->lang->lang('ARRY', 2), '2 posts'); +		$this->assertEquals($this->lang->lang('ARRY', 123), '123 posts'); + +		// Empty array returns the language key +		$this->assertEquals($this->lang->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY'); + +		// No 0 key defined +		$this->assertEquals($this->lang->lang('ARRY_NO_ZERO', 0), '0 posts'); +		$this->assertEquals($this->lang->lang('ARRY_NO_ZERO', 1), '1 post'); +		$this->assertEquals($this->lang->lang('ARRY_NO_ZERO', 2), '2 posts'); + +		// Array with missing keys +		$this->assertEquals($this->lang->lang('ARRY_MISSING', 2), '2 post'); + +		// Floats as array key +		$this->assertEquals($this->lang->lang('ARRY_FLOAT', 1.3), '1 post'); +		$this->assertEquals($this->lang->lang('ARRY_FLOAT', 2.0), '2.0 posts'); +		$this->assertEquals($this->lang->lang('ARRY_FLOAT', 2.51), '2.5 posts'); + +		// Use sub key, if first paramenter is an array +		$this->assertEquals($this->lang->lang(array('dateformat', 'AGO'), 2), '2 seconds'); + +		// ticket PHPBB3-9949 - use first int to determinate the plural-form to use +		$this->assertEquals($this->lang->lang('ARRY', 1, 2), '1 post'); +		$this->assertEquals($this->lang->lang('ARRY', 1, 's', 2), '1 post'); +	} + +	public function test_lang_plural_rules() +	{ +		$this->assertEquals($this->lang->lang('PLURAL_ARRY', 0), '0 is 0'); +		$this->assertEquals($this->lang->lang('PLURAL_ARRY', 1), '1 is 1'); +		$this->assertEquals($this->lang->lang('PLURAL_ARRY', 103), '103 ends with 01-10'); +		$this->assertEquals($this->lang->lang('PLURAL_ARRY', 15), '15 ends with 11-19'); +		$this->assertEquals($this->lang->lang('PLURAL_ARRY', 300), '300 is part of the last rule'); +	} + +	public function test_lang_bc() +	{ +		$user = new \phpbb\user($this->lang, '\phpbb\datetime'); + +		// Test lang array access +		$this->assertEquals($user->lang['FOO'], 'BAR'); + +		// No param +		$this->assertEquals($user->lang('FOO'), 'BAR'); +		$this->assertEquals($user->lang('EMPTY'), ''); +		$this->assertEquals($user->lang('ZERO'), '0'); + +		// Invalid index +		$this->assertEquals($user->lang('VOID'), 'VOID'); + +		// Unnecessary param +		$this->assertEquals($user->lang('FOO', 2), 'BAR'); +		$this->assertEquals($user->lang('FOO', 2, 3), 'BAR'); +		$this->assertEquals($user->lang('FOO', 2, 3, 'BARZ'), 'BAR'); + +		// String +		$this->assertEquals($user->lang('STR', 24, 'x', 42), '24 x, 42 topics'); +		$this->assertEquals($user->lang('STR2', 64), '64 foos'); + +		// Array +		$this->assertEquals($user->lang('ARRY', 0), 'No posts'); +		$this->assertEquals($user->lang('ARRY', 1), '1 post'); +		$this->assertEquals($user->lang('ARRY', 2), '2 posts'); +		$this->assertEquals($user->lang('ARRY', 123), '123 posts'); + +		// Empty array returns the language key +		$this->assertEquals($user->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY'); + +		// No 0 key defined +		$this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts'); +		$this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post'); +		$this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts'); + +		// Array with missing keys +		$this->assertEquals($user->lang('ARRY_MISSING', 2), '2 post'); + +		// Floats as array key +		$this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post'); +		$this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts'); +		$this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts'); + +		// Use sub key, if first paramenter is an array +		$this->assertEquals($user->lang(array('dateformat', 'AGO'), 2), '2 seconds'); + +		// ticket PHPBB3-9949 - use first int to determinate the plural-form to use +		$this->assertEquals($user->lang('ARRY', 1, 2), '1 post'); +		$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post'); +	} + +	public function test_lang_plural_rules_bc() +	{ +		$user = new \phpbb\user($this->lang, '\phpbb\datetime'); + +		// ticket PHPBB3-10345 - different plural rules, not just 0/1/2+ +		$this->assertEquals($user->lang('PLURAL_ARRY', 0), '0 is 0'); +		$this->assertEquals($user->lang('PLURAL_ARRY', 1), '1 is 1'); +		$this->assertEquals($user->lang('PLURAL_ARRY', 103), '103 ends with 01-10'); +		$this->assertEquals($user->lang('PLURAL_ARRY', 15), '15 ends with 11-19'); +		$this->assertEquals($user->lang('PLURAL_ARRY', 300), '300 is part of the last rule'); +	} + +	protected function get_test_data_set() +	{ +		return array( +			'FOO'		=> 'BAR', +			'BARZ'		=> 'PENG', +			'EMPTY'		=> '', +			'ZERO'		=> '0', +			'STR'		=> '%d %s, %d topics', +			'STR2'		=> '%d foos', +			'ARRY'		=> array( +				0		=> 'No posts',		// 0 +				1		=> '1 post',		// 1 +				2		=> '%d posts',		// 2+ +			), +			'ARRY_NO_ZERO'	=> array( +				1		=> '1 post',		// 1 +				2		=> '%d posts',		// 0, 2+ +			), +			'ARRY_MISSING'	=> array( +				1		=> '%d post',		// 1 +				//Missing second plural +			), +			'ARRY_FLOAT'	=> array( +				1		=> '1 post',		// 1.x +				2		=> '%1$.1f posts',	// 0.x, 2+.x +			), +			'ARRY_EMPTY'	=> array( +			), +			'dateformat'	=> array( +				'AGO'	=> array( +					1	=> '%d second', +					2	=> '%d seconds', +				), +			), +			'PLURAL_RULE' => 13, +			'PLURAL_ARRY' => array( +				0		=> '%d is 0',						// 0 +				1		=> '%d is 1',						// 1 +				2		=> '%d ends with 01-10',			// ending with 01-10 +				3		=> '%d ends with 11-19',			// ending with 11-19 +				4		=> '%d is part of the last rule',	// everything else +			), +		); +	} +} diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php index 6fc813cb38..389eab4152 100644 --- a/tests/lock/db_test.php +++ b/tests/lock/db_test.php @@ -30,7 +30,6 @@ class phpbb_lock_db_test extends phpbb_database_test_case  		$db = $this->db = $this->new_dbal();  		$config = $this->config = new \phpbb\config\config(array('rand_seed' => '', 'rand_seed_last_update' => '0')); -		set_config(null, null, null, $this->config);  		$this->lock = new \phpbb\lock\db('test_lock', $this->config, $this->db);  	} diff --git a/tests/log/add_test.php b/tests/log/add_test.php index bacc0c76f7..cfc592a464 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -27,7 +27,9 @@ class phpbb_log_add_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$cache = new phpbb_mock_cache;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$auth = $this->getMock('\phpbb\auth\auth');  		$log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); @@ -56,7 +58,9 @@ class phpbb_log_add_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$cache = new phpbb_mock_cache;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$auth = $this->getMock('\phpbb\auth\auth');  		$log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php index ec43182a0c..fe4c3835cb 100644 --- a/tests/log/delete_test.php +++ b/tests/log/delete_test.php @@ -30,7 +30,9 @@ class phpbb_log_delete_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->data['user_id'] = 1;  		$auth = $this->getMock('\phpbb\auth\auth'); diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 63e468498e..cdfeb52996 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -11,7 +11,7 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compatibility.php';  class phpbb_log_function_add_log_test extends phpbb_database_test_case  { @@ -161,7 +161,10 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$cache = new phpbb_mock_cache;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$auth = $this->getMock('\phpbb\auth\auth');  		$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); diff --git a/tests/migrator/convert_timezones_test.php b/tests/migrator/convert_timezones_test.php index 7501ed2ed0..f8d780da0c 100644 --- a/tests/migrator/convert_timezones_test.php +++ b/tests/migrator/convert_timezones_test.php @@ -18,7 +18,8 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case  	public function getDataSet()  	{  		$this->db = $this->new_dbal(); -		$db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$db_tools = $factory->get($this->db);  		// user_dst doesn't exist anymore, must re-add it to test this  		$db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1)); @@ -55,11 +56,12 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case  		global $phpbb_root_path, $phpEx;  		$this->db = $this->new_dbal(); +		$factory = new \phpbb\db\tools\factory();  		$this->migration = new \phpbb\db\migration\data\v310\timezone(  			new \phpbb\config\config(array()),  			$this->db, -			new \phpbb\db\tools($this->db), +			$factory->get($this->db),  			$phpbb_root_path,  			$phpEx,  			'phpbb_' @@ -90,7 +92,8 @@ class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case  		}  		$this->db->sql_freeresult($result); -		$db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$db_tools = $factory->get($this->db);  		// Remove the user_dst field again  		$db_tools->sql_column_remove('phpbb_users', 'user_dst'); diff --git a/tests/migrator/schema_generator_test.php b/tests/migrator/schema_generator_test.php index 9adf518a5d..40a8343e22 100644 --- a/tests/migrator/schema_generator_test.php +++ b/tests/migrator/schema_generator_test.php @@ -30,7 +30,8 @@ class schema_generator_test extends phpbb_test_case  		$this->config = new \phpbb\config\config(array());  		$this->db = new \phpbb\db\driver\sqlite(); -		$this->db_tools = new \phpbb\db\tools($this->db); +		$factory = new \phpbb\db\tools\factory(); +		$this->db_tools = $factory->get($this->db);  		$this->table_prefix = 'phpbb_';  	} diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php index ae3e7bf432..1d9f5dc5bf 100644 --- a/tests/mock/controller_helper.php +++ b/tests/mock/controller_helper.php @@ -13,7 +13,7 @@  class phpbb_mock_controller_helper extends \phpbb\controller\helper  { -	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext) +	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext)  	{  		$this->template = $template;  		$this->user = $user; @@ -23,8 +23,7 @@ class phpbb_mock_controller_helper extends \phpbb\controller\helper  		$this->filesystem = $filesystem;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; -		$provider->find_routing_files($manager->get_finder()); -		$this->route_collection = $provider->find($phpbb_root_path_ext)->get_routes(); +		$this->router = $router;  	}  	public function get_current_url() diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 3b759fbbc2..2ce61c5149 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -18,7 +18,7 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = 'php';  		$this->extensions = $extensions; -		$this->filesystem = new \phpbb\filesystem(); +		$this->filesystem = new \phpbb\filesystem\filesystem();  		$this->container = $container;  	}  } diff --git a/tests/mock/router.php b/tests/mock/router.php new file mode 100644 index 0000000000..01faa338c5 --- /dev/null +++ b/tests/mock/router.php @@ -0,0 +1,27 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_mock_router extends \phpbb\routing\router +{ +	public function get_matcher() +	{ +		$this->create_new_url_matcher(); +		return parent::get_matcher(); +	} + +	public function get_generator() +	{ +		$this->create_new_url_generator(); +		return parent::get_generator(); +	} +} diff --git a/tests/notification/base.php b/tests/notification/base.php index 162feae557..45b0b6f179 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -56,17 +56,20 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case  			'allow_topic_notify'	=> true,  			'allow_forum_notify'	=> true,  		)); -		$user = $this->user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$this->user = $user;  		$this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');  		$auth = $this->auth = new phpbb_mock_notifications_auth();  		$cache = $this->cache = new \phpbb\cache\service( -			new \phpbb\cache\driver\null(), +			new \phpbb\cache\driver\dummy(),  			$this->config,  			$this->db,  			$phpbb_root_path,  			$phpEx  		); -		 +  		$this->phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$phpbb_container = $this->container = new phpbb_mock_container_builder(); @@ -113,7 +116,14 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case  	{  		global $phpbb_root_path, $phpEx; -		return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); +		$instance = new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + +		if ($type === 'phpbb\\notification\\type\\quote') +		{ +			$instance->set_utils(new \phpbb\textformatter\s9e\utils); +		} + +		return $instance;  	}  	protected function assert_notifications($expected, $options = array()) diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index 32ab34c9bc..4a7fd89409 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -28,11 +28,12 @@ class phpbb_notification_convert_test extends phpbb_database_test_case  		global $phpbb_root_path, $phpEx;  		$this->db = $this->new_dbal(); +		$factory = new \phpbb\db\tools\factory();  		$this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert(  			new \phpbb\config\config(array()),  			$this->db, -			new \phpbb\db\tools($this->db), +			$factory->get($this->db),  			$phpbb_root_path,  			$phpEx,  			'phpbb_' diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 0d1bda95ce..a24808fbbd 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -40,8 +40,6 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas  		include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);  		include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx); -		set_config(false, false, false, $this->config); -  		$this->container->set('groupposition.legend', new \phpbb\groupposition\legend(  			$this->db,  			$this->user @@ -52,7 +50,8 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas  			$this->cache->get_driver()  		));  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; -		$phpbb_log = new \phpbb\log\null(); +		$phpbb_log = new \phpbb\log\dummy(); +		$this->get_test_case_helpers()->set_s9e_services();  		// Now on to the actual test diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php index 75b7275d3a..48bf5b177b 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -48,6 +48,11 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager  		$item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); +		if ($item_type === 'phpbb\\notification\\type\\quote') +		{ +			$item->set_utils(new \phpbb\textformatter\s9e\utils); +		} +  		$item->set_notification_manager($this);  		$item->set_initial_data($data); diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 5e770f71c9..04fb6658c3 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -70,11 +70,9 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c  		// Config  		$config = new \phpbb\config\config(array('num_topics' => 1,'num_posts' => 1,)); -		set_config(null, null, null, $config); -		set_config_count(null, null, null, $config);  		$cache = new \phpbb\cache\service( -			new \phpbb\cache\driver\null(), +			new \phpbb\cache\driver\dummy(),  			$config,  			$db,  			$phpbb_root_path, @@ -85,7 +83,10 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		// User -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$user->ip = '';  		$user->data = array(  			'user_id'		=> 2, @@ -116,6 +117,11 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c  				$phpbb_root_path, $phpEx,  				NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); +			if ($type === 'quote') +			{ +				$class->set_utils(new \phpbb\textformatter\s9e\utils); +			} +  			$phpbb_container->set('notification.type.' . $type, $class);  			$notification_types_array['notification.type.' . $type] = $class; diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 61e3840773..8ad6a62b09 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -51,6 +51,8 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_  	*/  	public function submit_post_data()  	{ +		$parser = $this->get_test_case_helpers()->set_s9e_services()->get('text_formatter.parser'); +  		return array(  			/**  			* Normal post @@ -65,15 +67,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_  			*/  			array(  				array( -					'message'			=> implode(' ', array( -						'[quote="poster":uid]poster should not be notified[/quote:uid]', -						'[quote="test":uid]test should be notified[/quote:uid]', -						'[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', -						'[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', -						'[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', -						'[quote="default":uid]option set to default, should receive a notification[/quote:uid]', -						'[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', -					)), +					'message'			=> $parser->parse(implode(' ', array( +						'[quote="poster"]poster should not be notified[/quote]', +						'[quote="test"]test should be notified[/quote]', +						'[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]', +						'[quote="notified"]already notified, should not receive a new notification[/quote]', +						'[quote="disabled"]option disabled, should not receive a notification[/quote]', +						'[quote="default"]option set to default, should receive a notification[/quote]', +						'[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]', +					))),  					'bbcode_uid'		=> 'uid',  				),  				array( @@ -94,15 +96,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_  			*/  			array(  				array( -					'message'			=> implode(' ', array( -						'[quote="poster":uid]poster should not be notified[/quote:uid]', -						'[quote="test":uid]test should be notified[/quote:uid]', -						'[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', -						'[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', -						'[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', -						'[quote="default":uid]option set to default, should receive a notification[/quote:uid]', -						'[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', -					)), +					'message'			=> $parser->parse(implode(' ', array( +						'[quote="poster"]poster should not be notified[/quote]', +						'[quote="test"]test should be notified[/quote]', +						'[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]', +						'[quote="notified"]already notified, should not receive a new notification[/quote]', +						'[quote="disabled"]option disabled, should not receive a notification[/quote]', +						'[quote="default"]option set to default, should receive a notification[/quote]', +						'[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]', +					))),  					'bbcode_uid'		=> 'uid',  					'force_approved_state' => false,  				), diff --git a/tests/notification/submit_post_type_topic_test.php b/tests/notification/submit_post_type_topic_test.php index c095fbc4ba..f14f305517 100644 --- a/tests/notification/submit_post_type_topic_test.php +++ b/tests/notification/submit_post_type_topic_test.php @@ -42,7 +42,7 @@ class phpbb_notification_submit_post_type_topic_test extends phpbb_notification_  				),  			))); -		$phpbb_log = $this->getMock('\phpbb\log\null'); +		$phpbb_log = $this->getMock('\phpbb\log\dummy');  	}  	/** diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php index c43eff729c..f7b4fcb215 100644 --- a/tests/notification/user_list_trim_test.php +++ b/tests/notification/user_list_trim_test.php @@ -33,11 +33,9 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  		$db = $this->new_dbal();  		$config = new \phpbb\config\config(array()); -		set_config(null, null, null, $config); -		set_config_count(null, null, null, $config);  		$cache = new \phpbb\cache\service( -			new \phpbb\cache\driver\null(), +			new \phpbb\cache\driver\dummy(),  			$config,  			$db,  			$phpbb_root_path, @@ -53,7 +51,9 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  				array('u_viewprofile', 1, false),  			))); -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->data = array('user_lang' => 'en');  		$user->add_lang('common'); @@ -73,7 +73,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  					'topic_title'	=> 'Test',  					'poster_id'		=> 2,  					'post_username'	=> 'A', -					'responders'	=> null,			 +					'responders'	=> null,  				),  				'<strong>Reply</strong> from A in topic:',  			), @@ -84,7 +84,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  					'post_username'	=> 'A',  					'responders'	=> array(  						array('username' => '', 'poster_id' => 3), -					),			 +					),  				),  				'<strong>Reply</strong> from A and <span class="username">B</span> in topic:',  			), @@ -96,7 +96,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  					'responders'	=> array(  						array('username' => '', 'poster_id' => 3),  						array('username' => '', 'poster_id' => 4), -					),			 +					),  				),  				'<strong>Reply</strong> from A, <span class="username">B</span>, and <span class="username">C</span> in topic:',  			), @@ -109,7 +109,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  						array('username' => '', 'poster_id' => 3),  						array('username' => '', 'poster_id' => 4),  						array('username' => '', 'poster_id' => 5), -					),			 +					),  				),  				'<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and <span class="username">D</span> in topic:',  			), @@ -123,7 +123,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case  						array('username' => '', 'poster_id' => 4),  						array('username' => '', 'poster_id' => 5),  						array('username' => '', 'poster_id' => 6), -					),			 +					),  				),  				'<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and 2 others in topic:',  			), diff --git a/tests/pagination/config/routing.yml b/tests/pagination/config/test/routing/environment.yml index 2ce082c9d1..2ce082c9d1 100644 --- a/tests/pagination/config/routing.yml +++ b/tests/pagination/config/test/routing/environment.yml diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index ea6dd999c3..07f9ec9c56 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -26,27 +26,24 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case  	{  		parent::setUp(); -		global $phpbb_dispatcher; +		global $phpbb_dispatcher, $phpbb_root_path, $phpEx;  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$this->user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); -		$filesystem = new \phpbb\filesystem(); +		$filesystem = new \phpbb\filesystem\filesystem();  		$manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); -		$finder = new \phpbb\finder( -			$filesystem, -			dirname(__FILE__) . '/', -			new phpbb_mock_cache() -		); -		$finder->set_extensions(array_keys($manager->all_enabled()));  		$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); -		$provider = new \phpbb\controller\provider(); -		$provider->find_routing_files($finder); -		$provider->find(dirname(__FILE__) . '/'); +		$router = new phpbb_mock_router(new phpbb_mock_container_builder(), $filesystem, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT, $manager); +		$router->find_routing_files($manager->all_enabled(false)); +		$router->find(dirname(__FILE__) . '/');  		$request = new phpbb_mock_request();  		$request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER); @@ -57,7 +54,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case  			$request  		); -		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/'); +		$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $router, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/');  		$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher);  	} diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 73f0e6bafc..007441bc92 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -21,14 +21,14 @@ class phpbb_path_helper_test extends phpbb_test_case  	{  		parent::setUp(); -		$filesystem = new \phpbb\filesystem(); +		$filesystem = new \phpbb\filesystem\filesystem();  		$this->set_phpbb_root_path($filesystem);  		$this->path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			new \phpbb\filesystem\filesystem(),  			$this->getMock('\phpbb\request\request'),  			$this->phpbb_root_path,  			'php' @@ -56,7 +56,7 @@ class phpbb_path_helper_test extends phpbb_test_case  	public function basic_update_web_root_path_data()  	{ -		$filesystem = new \phpbb\filesystem(); +		$filesystem = new \phpbb\filesystem\filesystem();  		$this->set_phpbb_root_path($filesystem);  		return array( @@ -90,7 +90,7 @@ class phpbb_path_helper_test extends phpbb_test_case  	public function update_web_root_path_data()  	{ -		$this->set_phpbb_root_path(new \phpbb\filesystem()); +		$this->set_phpbb_root_path(new \phpbb\filesystem\filesystem());  		return array(  			array( @@ -158,7 +158,7 @@ class phpbb_path_helper_test extends phpbb_test_case  		$path_helper = new \phpbb\path_helper(  			$symfony_request, -			new \phpbb\filesystem(), +			new \phpbb\filesystem\filesystem(),  			$this->getMock('\phpbb\request\request'),  			$this->phpbb_root_path,  			'php' diff --git a/tests/plupload/plupload_test.php b/tests/plupload/plupload_test.php index 2f47bf2b39..aa7793567d 100644 --- a/tests/plupload/plupload_test.php +++ b/tests/plupload/plupload_test.php @@ -34,6 +34,10 @@ class phpbb_plupload_test extends phpbb_test_case  	*/  	public function test_generate_resize_string($config_width, $config_height, $expected)  	{ +		global $phpbb_root_path, $phpEx; + +		$lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); +  		$config = new \phpbb\config\config(array(  			'img_max_width'		=> $config_width,  			'img_max_height'	=> $config_height, @@ -43,7 +47,7 @@ class phpbb_plupload_test extends phpbb_test_case  			'',  			$config,  			new phpbb_mock_request, -			new \phpbb\user('\phpbb\datetime'), +			new \phpbb\user($lang, '\phpbb\datetime'),  			new \phpbb\php\ini,  			new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser))  		); diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index 41c40ddb4b..10239172c3 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -25,7 +25,12 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 123955198e..e0807b2f9b 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -25,7 +25,12 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$this->user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$this->user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 3845a8e96b..ab02353fb9 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -25,7 +25,12 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php index f3db6ef01f..6faf939231 100644 --- a/tests/profilefields/type_googleplus_test.php +++ b/tests/profilefields/type_googleplus_test.php @@ -21,7 +21,11 @@ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case  	{  		parent::setUp(); -		$user = new \phpbb\user('\phpbb\datetime'); +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->add_lang('ucp');  		$request = $this->getMock('\phpbb\request\request');  		$template = $this->getMock('\phpbb\template\template'); diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 07b22525e2..33f3f575c8 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -24,7 +24,12 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 0417afbfab..447ab32a00 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -28,9 +28,12 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		global $request, $user, $cache; +		global $request, $user, $cache, $phpbb_root_path, $phpEx; -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$cache = new phpbb_mock_cache;  		$user->expects($this->any())  			->method('lang') diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index cc37f04f30..a0f93fe1f6 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -26,7 +26,12 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case  	*/  	public function setUp()  	{ -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		global $phpbb_root_path, $phpEx; + +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$user->expects($this->any())  			->method('lang')  			->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/regex/censor_test.php b/tests/regex/censor_test.php index 50c6778c8c..5625b0020b 100644 --- a/tests/regex/censor_test.php +++ b/tests/regex/censor_test.php @@ -37,17 +37,7 @@ class phpbb_regex_censor_test extends phpbb_test_case  	*/  	public function test_censor_unicode($pattern, $subject)  	{ -		$regex = get_censor_preg_expression($pattern, true); - -		$this->assertRegExp($regex, $subject); -	} - -	/** -	* @dataProvider censor_test_data -	*/ -	public function test_censor_no_unicode($pattern, $subject) -	{ -		$regex = get_censor_preg_expression($pattern, false); +		$regex = get_censor_preg_expression($pattern);  		$this->assertRegExp($regex, $subject);  	} diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index 67712eb6c8..b409e5ef25 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -11,7 +11,7 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compatibility.php';  require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';  class phpbb_request_var_test extends phpbb_test_case diff --git a/tests/security/base.php b/tests/security/base.php index 330408b448..d2abdbc362 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -46,10 +46,12 @@ abstract class phpbb_security_test_base extends phpbb_test_case  		$request = new phpbb_mock_request(array(), array(), array(), $this->server);  		$symfony_request = new \phpbb\symfony_request($request); -		$phpbb_filesystem = new \phpbb\filesystem(); +		$phpbb_filesystem = new \phpbb\filesystem\filesystem();  		// Set no user and trick a bit to circumvent errors -		$user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->lang = true;  		$user->browser				= $this->server['HTTP_USER_AGENT'];  		$user->referer				= ''; diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index a88fc63858..62781f3ee6 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -67,7 +67,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base  				new \phpbb\symfony_request(  					new phpbb_mock_request()  				), -				new \phpbb\filesystem(), +				new \phpbb\filesystem\filesystem(),  				$this->getMock('\phpbb\request\request'),  				$this->phpbb_root_path,  				'php' diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php index 561b7faf49..04da5f08b9 100644 --- a/tests/session/check_ban_test.php +++ b/tests/session/check_ban_test.php @@ -42,7 +42,10 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case  		parent::setUp();  		// Get session here so that config is mocked correctly  		$this->session = $this->session_factory->get_session($this->db); -		global $cache, $config, $phpbb_root_path, $phpEx; +		global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_filesystem; + +		$phpbb_filesystem = new \phpbb\filesystem\filesystem(); +  		$this->backup_cache = $cache;  		// Change the global cache object for this test because  		// the mock cache object does not hit the database as is needed diff --git a/tests/session/extract_page_test.php b/tests/session/extract_page_test.php index f0d1cdb60e..96445ef9b3 100644 --- a/tests/session/extract_page_test.php +++ b/tests/session/extract_page_test.php @@ -145,7 +145,7 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case  	{  		global $symfony_request, $request, $phpbb_filesystem; -		$phpbb_filesystem = new \phpbb\filesystem(); +		$phpbb_filesystem = new \phpbb\filesystem\filesystem();  		$server['HTTP_HOST']			= 'localhost';  		$server['SERVER_NAME']			= 'localhost'; diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 3e25286480..7819063505 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -81,10 +81,8 @@ class phpbb_session_testable_factory  			$this->cookies,  			$this->server_data  		); -		request_var(null, null, null, null, $request);  		$config = $this->config = new \phpbb\config\config($this->get_config_data()); -		set_config(null, null, null, $config);  		$db = $dbal; @@ -96,6 +94,7 @@ class phpbb_session_testable_factory  			'auth.provider.db',  			new phpbb_mock_auth_provider()  		); +		$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT);  		$provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);  		$provider_collection->add('auth.provider.db');  		$phpbb_container->set( diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php new file mode 100644 index 0000000000..3d2fdd8959 --- /dev/null +++ b/tests/template/asset_test.php @@ -0,0 +1,49 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use phpbb\template\asset; + +class phpbb_template_asset_test extends phpbb_test_case +{ +	public function set_path_data() +	{ +		return array( +			// array(phpbb_root_path, given path, expected path), +			array('.', 'foo/bar', 'foo/bar'), +			array('../', 'foo/bar', 'foo/bar'), +			array('./phpBB/', 'foo/bar', 'foo/bar'), +			array('../', __DIR__ . '/foo/bar', '../' . basename(dirname(dirname(__DIR__))) . '/tests/template/foo/bar'), +			array('./', __DIR__ . '/foo/bar', './tests/template/foo/bar'), +			array('./phpBB/', __DIR__ . '/foo/bar', 'tests/template/foo/bar'), +		); +	} + +	/** +	 * @dataProvider set_path_data +	 */ +	public function test_set_path($phpbb_root_path, $path, $expected) +	{ +		$path_helper = $this->getMockBuilder('\phpbb\path_helper') +			->disableOriginalConstructor() +			->setMethods(array()) +			->getMock(); + +		$path_helper->method('get_phpbb_root_path') +			->willReturn($phpbb_root_path); + +		$asset = new asset('', $path_helper, new phpbb\filesystem\filesystem()); + +		$asset->set_path($path, true); +		$this->assertEquals($expected, $asset->get_path()); +	} +} diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index fdddbef4f2..722e10e42d 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -39,8 +39,9 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case  	{  		global $phpbb_root_path; +		$filesystem = new \phpbb\filesystem\filesystem();  		$path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc'; -		$this->assertTrue(phpbb_is_absolute($path_to_php)); +		$this->assertTrue($filesystem->is_absolute_path($path_to_php));  		$template_text = "Path is absolute.\n<!-- INCLUDEPHP $path_to_php -->";  		$cache_dir = $phpbb_root_path . 'cache/'; diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index b4ad84e9c3..9a0f1f512e 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -28,13 +28,18 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case  		$defaults = $this->config_defaults();  		$config = new \phpbb\config\config(array_merge($defaults, $new_config)); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$this->user = $user; + +		$filesystem = new \phpbb\filesystem\filesystem();  		$path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			$filesystem,  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx @@ -51,9 +56,30 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case  			)  		); +		$container = new phpbb_mock_container_builder(); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$twig = new \phpbb\template\twig\environment( +			$config, +			$filesystem, +			$path_helper, +			$container, +			$cache_path, +			$this->extension_manager, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		); +		$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); +  		$this->template_path = $this->test_path . '/templates';  		$this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template'; -		$this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context(), $this->extension_manager);  		$this->template->set_custom_style('all', array($this->template_path, $this->ext_template_path));  	}  } diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index c415c969fe..54e08652a1 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -138,16 +138,40 @@ Zeta test event in all',  		$this->extension_manager = new phpbb_mock_filesystem_extension_manager(  			dirname(__FILE__) . "/datasets/$dataset/"  		); + +		$filesystem = new \phpbb\filesystem\filesystem();  		$path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			new \phpbb\filesystem\filesystem(),  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx  		); -		$this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, new \phpbb\template\context, $this->extension_manager); + +		$container = new phpbb_mock_container_builder(); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$twig = new \phpbb\template\twig\environment( +			$config, +			$filesystem, +			$path_helper, +			$container, +			$cache_path, +			$this->extension_manager, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		); +		$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); +  		$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));  	}  } diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 49bd9dec8b..062fc9493b 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -15,6 +15,12 @@ require_once dirname(__FILE__) . '/template_test_case_with_tree.php';  class phpbb_template_template_includecss_test extends phpbb_template_template_test_case_with_tree  { +	/** @var \phpbb\path_helper */ +	protected $phpbb_path_helper; + +	/** @var string */ +	protected $parent_template_path; +  	protected function setup_engine(array $new_config = array())  	{  		global $phpbb_root_path, $phpEx, $user; @@ -22,11 +28,13 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te  		$defaults = $this->config_defaults();  		$config = new \phpbb\config\config(array_merge($defaults, $new_config)); +		$filesystem = new \phpbb\filesystem\filesystem(); +  		$this->phpbb_path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			$filesystem,  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx @@ -34,11 +42,33 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te  		$this->template_path = $this->test_path . '/templates';  		$this->parent_template_path = $this->test_path . '/parent_templates'; +		$container = new phpbb_mock_container_builder(); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$twig = new \phpbb\template\twig\environment( +			$config, +			$filesystem, +			$this->phpbb_path_helper, +			$container, +			$cache_path, +			null, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		);  		$this->template = new phpbb\template\twig\twig(  			$this->phpbb_path_helper,  			$config, -			$user, -			new phpbb\template\context(), +			$context, +			$twig, +			$cache_path, +			$this->user, +			array(new \phpbb\template\twig\extension($context, $this->user)),  			new phpbb_mock_extension_manager(  				dirname(__FILE__) . '/',  				array( @@ -50,18 +80,12 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te  				)  			)  		); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));  		$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));  	}  	public function template_data()  	{ -		$url_base = explode('/', dirname(__FILE__)); -		foreach ($url_base as &$dir) -		{ -			$dir = rawurlencode($dir); -		} -		$url_base = implode('/', $url_base); -  		return array(  			/*  			array( @@ -79,11 +103,11 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te  			),  			array(  				array('TEST' => 3), -				'<link href="' . $url_base . '/ext/include/css/styles/all/theme/test.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', +				'<link href="tests/template/ext/include/css/styles/all/theme/test.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />',  			),  			array(  				array('TEST' => 4), -				'<link href="' . $url_base . '/ext/include/css/styles/all/theme/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', +				'<link href="tests/template/ext/include/css/styles/all/theme/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />',  			),  		);  	} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..33dc4ca551 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -130,6 +130,34 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1",  			),  			array( +				'loop_twig.html', +				array(), +				array(), +				array(), +				"noloop\nnoloop", +			), +			array( +				'loop_twig.html', +				array(), +				array('test_loop' => array(array())), +				array(), +				"loop\nloop", +			), +			array( +				'loop_twig.html', +				array(), +				array('test_loop' => array(array(), array()), 'test_loop.block' => array(array())), +				array(), +				"loop\nloop\nloop\nloop", +			), +			array( +				'loop_twig.html', +				array(), +				array('test_loop' => array(array(), array()), 'test_loop.block' => array(array()), 'block' => array(array(), array())), +				array(), +				"loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", +			), +			array(  				'loop_vars.html',  				array(),  				array('test_loop' => array(array('VARIABLE' => 'x'))), @@ -151,6 +179,27 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner",  			),  			array( +				'loop_vars_twig.html', +				array(), +				array('test_loop' => array(array('VARIABLE' => 'x'))), +				array(), +				"first\n0 - a\nx - b\nset\nlast", +			), +			array( +				'loop_vars_twig.html', +				array(), +				array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), +				array(), +				"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast", +			), +			array( +				'loop_vars_twig.html', +				array(), +				array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), +				array(), +				"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner", +			), +			array(  				'loop_advanced.html',  				array(),  				array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())), @@ -158,6 +207,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_advanced_twig.html', +				array(), +				array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())), +				array(), +				"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())), @@ -165,6 +221,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"o0o1m01m11",  			),  			array( +				'loop_nested2_twig.html', +				array(), +				array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())), +				array(), +				"o0o1m01m11", +			), +			array(  				'define.html',  				array(),  				array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), @@ -244,6 +307,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				'',  			),  			array( +				'loop_vars_twig.html', +				array(), +				array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), +				array('test_loop'), +				'', +			), +			array(  				'include_define_variable.html',  				array('VARIABLE' => 'variable.html'),  				array(), @@ -275,6 +345,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"noloop\nnoloop",  			),  			array( +				// Just like a regular loop but the name begins +				// with an underscore +				'loop_underscore_twig.html', +				array(), +				array(), +				array(), +				"noloop\nnoloop", +			), +			array(  				'lang.html',  				array(),  				array(), @@ -286,7 +365,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				array(),  				array(), -				"Value'\n1 O'Clock\nValue\'\n1 O\'Clock", +				"Value'\n1 O'Clock\nValue\\x27\n1\\x20O\\x27Clock",  				array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),  			),  			array( @@ -297,6 +376,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"top-level content",  			),  			array( +				'loop_nested_multilevel_ref_twig.html', +				array(), +				array(), +				array(), +				"top-level content", +			), +			array(  				'loop_nested_multilevel_ref.html',  				array(),  				array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), @@ -304,6 +390,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz",  			),  			array( +				'loop_nested_multilevel_ref_twig.html', +				array(), +				array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), +				array(), +				"top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz", +			), +			array(  				'loop_nested_deep_multilevel_ref.html',  				array(),  				array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), @@ -311,6 +404,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz",  			),  			array( +				'loop_nested_deep_multilevel_ref_twig.html', +				array(), +				array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), +				array(), +				"top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz", +			), +			array(  				'loop_size.html',  				array(),  				array('test_loop' => array(array()), 'empty_loop' => array()), @@ -318,6 +418,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop",  			),  			array( +				'loop_size_twig.html', +				array(), +				array('test_loop' => array(array()), 'empty_loop' => array()), +				array(), +				"nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", +			), +			array(  				'loop_include.html',  				array(),  				array('test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1'))), @@ -325,6 +432,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"barbarbar1bar1",  			),  			array( +				'loop_include_twig.html', +				array(), +				array('test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1'))), +				array(), +				"barbarbar1bar1", +			), +			array(  				'loop_nested_include.html',  				array(),  				array( @@ -335,6 +449,17 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				"[bar|[bar|]][bar1|[bar1|[bar1|works]]]",  				array(),  			), +			array( +				'loop_nested_include_twig.html', +				array(), +				array( +					'test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1')), +					'test_loop.inner' => array(array('myinner' => 'works')), +				), +				array(), +				"[bar|[bar|]][bar1|[bar1|[bar1|works]]]", +				array(), +			),  			/* Does not pass with the current implementation.  			array(  				'loop_reuse.html', @@ -343,8 +468,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				// Not entirely sure what should be outputted but the current output of "a" is most certainly wrong  				"a\nb\nc\nd", +			),*/ +			array( +				'loop_reuse_twig.html', +				array(), +				array('one' => array(array('VAR' => 'a'), array('VAR' => 'b')), 'one.one' => array(array('VAR' => 'c'), array('VAR' => 'd'))), +				array(), +				// Not entirely sure what should be outputted but the current output of "a" is most certainly wrong +				"a\nb\nc\nd",  			), -			*/  			array(  				'twig.html',  				array('VARIABLE' => 'FOObar',), @@ -359,6 +491,27 @@ class phpbb_template_template_test extends phpbb_template_template_test_case  				array(),  				'inner_value',  			), +			array( +				'loop_expressions.html', +				array(), +				array('loop' => array(array(),array(),array(),array(),array(),array()),), +				array(), +				'yesnononoyesnoyesnonoyesnono', +			), +			array( +				'loop_expressions_twig.html', +				array(), +				array('loop' => array(array(),array(),array(),array(),array(),array()),), +				array(), +				'yesnononoyesnoyesnonoyesnono', +			), +			array( +				'loop_expressions_twig2.html', +				array('loop' => array(array(),array(),array(),array(),array(),array()),), +				array(), +				array(), +				'yesnononoyesnoyesnonoyesnono', +			),  		);  	} diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 1250397401..62eea0d361 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  class phpbb_template_template_test_case extends phpbb_test_case  { +	protected $lang;  	protected $template;  	protected $template_path;  	protected $user; @@ -24,6 +25,17 @@ class phpbb_template_template_test_case extends phpbb_test_case  	// Keep the contents of the cache for debugging?  	const PRESERVE_CACHE = true; +	static protected $language_reflection_lang; + +	static public function setUpBeforeClass() +	{ +		parent::setUpBeforeClass(); + +		$reflection = new ReflectionClass('\phpbb\language\language'); +		self::$language_reflection_lang = $reflection->getProperty('lang'); +		self::$language_reflection_lang->setAccessible(true); +	} +  	protected function display($handle)  	{  		ob_start(); @@ -65,20 +77,46 @@ class phpbb_template_template_test_case extends phpbb_test_case  		$defaults = $this->config_defaults();  		$config = new \phpbb\config\config(array_merge($defaults, $new_config)); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$this->lang = $lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$this->user = $user; + +		$filesystem = new \phpbb\filesystem\filesystem();  		$path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			$filesystem,  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx  		);  		$this->template_path = $this->test_path . '/templates'; -		$this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context()); + +		$container = new phpbb_mock_container_builder(); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$twig = new \phpbb\template\twig\environment( +			$config, +			$filesystem, +			$path_helper, +			$container, +			$cache_path, +			null, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		); +		$this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));  		$this->template->set_custom_style('tests', $this->template_path);  	} @@ -88,6 +126,10 @@ class phpbb_template_template_test_case extends phpbb_test_case  		$this->setup_engine();  		$this->template->clear_cache(); + +		global $phpbb_filesystem; + +		$phpbb_filesystem = new \phpbb\filesystem\filesystem();  	}  	protected function tearDown() @@ -121,7 +163,10 @@ class phpbb_template_template_test_case extends phpbb_test_case  		{  			foreach ($lang_vars as $name => $value)  			{ -				$this->user->lang[$name] = $value; +				self::$language_reflection_lang->setValue($this->lang, array_merge( +					self::$language_reflection_lang->getValue($this->lang), +					array($name => $value) +				));  			}  		} diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 68ecc4b706..bf5de6b85e 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,11 +22,13 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat  		$defaults = $this->config_defaults();  		$config = new \phpbb\config\config(array_merge($defaults, $new_config)); +		$filesystem = new \phpbb\filesystem\filesystem(); +  		$this->phpbb_path_helper = new \phpbb\path_helper(  			new \phpbb\symfony_request(  				new phpbb_mock_request()  			), -			new \phpbb\filesystem(), +			$filesystem,  			$this->getMock('\phpbb\request\request'),  			$phpbb_root_path,  			$phpEx @@ -34,7 +36,28 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat  		$this->template_path = $this->test_path . '/templates';  		$this->parent_template_path = $this->test_path . '/parent_templates'; -		$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, new phpbb\template\context()); + +		$container = new phpbb_mock_container_builder(); +		$cache_path = $phpbb_root_path . 'cache/twig'; +		$context = new \phpbb\template\context(); +		$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); +		$twig = new \phpbb\template\twig\environment( +			$config, +			$filesystem, +			$this->phpbb_path_helper, +			$container, +			$cache_path, +			null, +			$loader, +			array( +				'cache'			=> false, +				'debug'			=> false, +				'auto_reload'	=> true, +				'autoescape'	=> false, +			) +		); +		$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); +		$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));  		$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));  	}  } diff --git a/tests/template/templates/loop_advanced_twig.html b/tests/template/templates/loop_advanced_twig.html new file mode 100644 index 0000000000..fd9fcae045 --- /dev/null +++ b/tests/template/templates/loop_advanced_twig.html @@ -0,0 +1,19 @@ +{% for test_loop_inner in test_loop %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,-1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(1,1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(2,4) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,-7) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(-2,6) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(-2,-1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} diff --git a/tests/template/templates/loop_expressions.html b/tests/template/templates/loop_expressions.html index 6bff53f388..ddb9fd52fa 100644 --- a/tests/template/templates/loop_expressions.html +++ b/tests/template/templates/loop_expressions.html @@ -1,11 +1,11 @@  <!-- BEGIN loop --> -<!-- IF loop.S_ROW_NUM is even by 4 -->on<!-- ELSE -->off<!-- ENDIF --> +<!-- IF loop.S_ROW_NUM is divisible by(4) -->yes<!-- ELSE -->no<!-- ENDIF -->  <!-- END loop -->  <!-- BEGIN loop --> -<!-- IF loop.S_ROW_NUM is odd by 3 -->on<!-- ELSE -->off<!-- ENDIF --> +<!-- IF loop.S_ROW_NUM is divisible by(3) -->yes<!-- ELSE -->no<!-- ENDIF -->  <!-- END loop --> diff --git a/tests/template/templates/loop_expressions_twig.html b/tests/template/templates/loop_expressions_twig.html new file mode 100644 index 0000000000..5ca8cc3601 --- /dev/null +++ b/tests/template/templates/loop_expressions_twig.html @@ -0,0 +1,11 @@ +{% for loop_inner in loop %} + +{% if loop_inner.S_ROW_NUM is divisible by(4) %}yes{% else %}no{% endif %} + +{% endfor %} + +{% for loop_inner in loop %} + +{% if loop_inner.S_ROW_NUM is divisible by(3) %}yes{% else %}no{% endif %} + +{% endfor %} diff --git a/tests/template/templates/loop_expressions_twig2.html b/tests/template/templates/loop_expressions_twig2.html new file mode 100644 index 0000000000..16159ead4c --- /dev/null +++ b/tests/template/templates/loop_expressions_twig2.html @@ -0,0 +1,11 @@ +{% for loop_inner in loop %} + +{% if loop.index0 is divisible by(4) %}yes{% else %}no{% endif %} + +{% endfor %} + +{% for loop_inner in loop %} + +{% if loop.index0 is divisible by(3) %}yes{% else %}no{% endif %} + +{% endfor %} diff --git a/tests/template/templates/loop_include1_twig.html b/tests/template/templates/loop_include1_twig.html new file mode 100644 index 0000000000..2ff9f61b02 --- /dev/null +++ b/tests/template/templates/loop_include1_twig.html @@ -0,0 +1 @@ +{{ test_loop_inner.foo }} diff --git a/tests/template/templates/loop_include_twig.html b/tests/template/templates/loop_include_twig.html new file mode 100644 index 0000000000..1a534e2dbc --- /dev/null +++ b/tests/template/templates/loop_include_twig.html @@ -0,0 +1,4 @@ +{% for test_loop_inner in test_loop %} +	{{ test_loop_inner.foo }} +	{% INCLUDE 'loop_include1_twig.html' %} +{% endfor %} diff --git a/tests/template/templates/loop_nested2_twig.html b/tests/template/templates/loop_nested2_twig.html new file mode 100644 index 0000000000..cf802dc69f --- /dev/null +++ b/tests/template/templates/loop_nested2_twig.html @@ -0,0 +1,6 @@ +{% for outer_inner in outer %} +	o{{ outer_inner.S_ROW_COUNT }} +	{% for middle in outer_inner.middle %} +		m{{ middle.S_ROW_COUNT }}{{ outer_inner.S_ROW_COUNT }} +	{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html b/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html new file mode 100644 index 0000000000..9bc68e6e2e --- /dev/null +++ b/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html @@ -0,0 +1,13 @@ +top-level content +{% for outer_inner in outer %} +	outer +	{% for middle in outer_inner.middle %} +		{{ middle.S_BLOCK_NAME }} +		{% for inner in middle.inner %} +			inner {{ inner.VARIABLE }} +			{% if inner.S_FIRST_ROW %} +				first row of {{ inner.S_NUM_ROWS }} in {{ inner.S_BLOCK_NAME }} +			{% endif %} +		{% endfor %} +	{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_include1_twig.html b/tests/template/templates/loop_nested_include1_twig.html new file mode 100644 index 0000000000..4c2ebb5f15 --- /dev/null +++ b/tests/template/templates/loop_nested_include1_twig.html @@ -0,0 +1,5 @@ +[{{ test_loop_inner.foo }}| +{% for inner in test_loop_inner.inner %} +	[{{ test_loop_inner.foo }}| +	{{ inner.myinner }}] +{% endfor %}] diff --git a/tests/template/templates/loop_nested_include_twig.html b/tests/template/templates/loop_nested_include_twig.html new file mode 100644 index 0000000000..c92ac922d1 --- /dev/null +++ b/tests/template/templates/loop_nested_include_twig.html @@ -0,0 +1,4 @@ +{% for test_loop_inner in test_loop %} +	[{{ test_loop_inner.foo }} +	|{% INCLUDE 'loop_nested_include1_twig.html' %}] +{% endfor %} diff --git a/tests/template/templates/loop_nested_multilevel_ref_twig.html b/tests/template/templates/loop_nested_multilevel_ref_twig.html new file mode 100644 index 0000000000..336a57d0bc --- /dev/null +++ b/tests/template/templates/loop_nested_multilevel_ref_twig.html @@ -0,0 +1,10 @@ +top-level content +{% for outer_inner in outer %} +	outer {{ outer_inner.VARIABLE }} +	{% for inner in outer_inner.inner %} +		inner {{ inner.VARIABLE }} +		{% if inner.S_FIRST_ROW %} +			first row +		{% endif %} +	{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_twig.html b/tests/template/templates/loop_nested_twig.html new file mode 100644 index 0000000000..b294226b3a --- /dev/null +++ b/tests/template/templates/loop_nested_twig.html @@ -0,0 +1,6 @@ +{% for outer_inner in outer %} +outer - {{ outer_inner.S_ROW_COUNT }}{% if outer_inner.VARIABLE %} - {{ outer_inner.VARIABLE }}{% endif %}{% if TEST_MORE %}[{{ outer_inner.S_BLOCK_NAME }}|{{ outer_inner.S_NUM_ROWS }}]{% endif %} +{% for middle in outer_inner.middle %} +middle - {{ middle.S_ROW_COUNT }}{% if middle.VARIABLE %} - {{ middle.VARIABLE }}{% endif %}{% if TEST_MORE %}[{{ middle.S_BLOCK_NAME }}|{{ middle.S_NUM_ROWS }}]{% endif %} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_reuse_twig.html b/tests/template/templates/loop_reuse_twig.html new file mode 100644 index 0000000000..67452a737f --- /dev/null +++ b/tests/template/templates/loop_reuse_twig.html @@ -0,0 +1,6 @@ +{% for one_inner in one %} +	{{ one_inner.VAR }} +	{% for one_one_inner in one_inner.one %} +		{{ one_one_inner.VAR }} +	{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_size_twig.html b/tests/template/templates/loop_size_twig.html new file mode 100644 index 0000000000..f6d2571e11 --- /dev/null +++ b/tests/template/templates/loop_size_twig.html @@ -0,0 +1,39 @@ +{% if nonexistent_loop|length %} +nonexistent +{% endif %} + +{% if nonexistent_loop|length == 0 %} +nonexistent = 0 +{% endif %} + +{% if ! nonexistent_loop|length %} +! nonexistent +{% endif %} + +{% if empty_loop|length %} +empty +{% endif %} + +{% if empty_loop|length == 0 %} +empty = 0 +{% endif %} + +{% if ! empty_loop|length %} +! empty +{% endif %} + +{% if test_loop|length %} +loop +{% endif %} + +{% if test_loop|length == 0 %} +loop = 0 +{% endif %} + +{% if ! test_loop|length %} +! loop +{% endif %} + +{% for test_loop_inner in test_loop %} +in loop +{% endfor %} diff --git a/tests/template/templates/loop_twig.html b/tests/template/templates/loop_twig.html new file mode 100644 index 0000000000..fb24f331b3 --- /dev/null +++ b/tests/template/templates/loop_twig.html @@ -0,0 +1,21 @@ +{% for test_loop_inner in test_loop %} +loop +{% else %} +noloop +{% endfor %} + +{% if test_loop|length %} +loop +{% else %} +noloop +{% endif %} + +{% if test_loop|length == 2 %} +loop +{% endif %} + +{% for test_loop_inner in test_loop %} +{% for block_inner in block %} +loop#{{ test_loop_inner.S_ROW_COUNT }}-block#{{ block_inner.S_ROW_COUNT }} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_underscore_twig.html b/tests/template/templates/loop_underscore_twig.html new file mode 100644 index 0000000000..44b095c882 --- /dev/null +++ b/tests/template/templates/loop_underscore_twig.html @@ -0,0 +1,21 @@ +{% for _underscore_loop_inner in _underscore_loop %} +loop +{% else %} +noloop +{% endfor %} + +{% if _underscore_loop|length %} +loop +{% else %} +noloop +{% endif %} + +{% if _underscore_loop|length == 2 %} +loop +{% endif %} + +{% for _underscore_loop_inner in _underscore_loop %} +{% for block_inner in block %} +loop#{{ loop.S_ROW_COUNT }}-block#{{ block_inner.S_ROW_COUNT }} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_vars_twig.html b/tests/template/templates/loop_vars_twig.html new file mode 100644 index 0000000000..af6c63d8e3 --- /dev/null +++ b/tests/template/templates/loop_vars_twig.html @@ -0,0 +1,13 @@ +{% for test_loop_inner in test_loop %} +{% if test_loop_inner.S_FIRST_ROW %}first{% endif %} +{{ test_loop_inner.S_ROW_NUM }} - a +{{ test_loop_inner.VARIABLE }} - b +{% if test_loop_inner.VARIABLE %}set{% endif %} +{% if test_loop_inner.S_LAST_ROW %} +last +{% endif %} +{% for inner_inner in test_loop_inner.inner %} +{{ inner_inner.S_ROW_NUM }} - c +{% if inner_inner.S_LAST_ROW and inner_inner.S_ROW_COUNT and inner_inner.S_NUM_ROWS %}last inner{% endif %} +{% endfor %} +{% endfor %} diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index fc1a3632f4..4d0460ebeb 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -58,7 +58,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  		$setup_extensions = static::setup_extensions(); -		$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); +		$finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);  		$finder->core_path('phpbb/db/migration/data/');  		if (!empty($setup_extensions))  		{ @@ -77,7 +77,10 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test  			global $table_prefix;  			$db = new \phpbb\db\driver\sqlite(); -			$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); +			$factory = new \phpbb\db\tools\factory(); +			$db_tools = $factory->get($db, true); + +			$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);  			file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));  		} diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 5d643e43e2..5136af5ad1 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -365,16 +365,20 @@ class phpbb_database_test_connection_manager  		{  			global $phpbb_root_path, $phpEx, $table_prefix; -			$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); +			$finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);  			$classes = $finder->core_path('phpbb/db/migration/data/')  				->get_classes();  			$db = new \phpbb\db\driver\sqlite(); -			$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); +			$factory = new \phpbb\db\tools\factory(); +			$db_tools = $factory->get($db, true); + +			$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);  			$db_table_schema = $schema_generator->get_schema();  		} -		$db_tools = new \phpbb\db\tools($db, true); +		$factory = new \phpbb\db\tools\factory(); +		$db_tools = $factory->get($db, true);  		foreach ($db_table_schema as $table_name => $table_data)  		{  			$queries = $db_tools->sql_create_table( diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 844caa8f54..0fec3c2dff 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -204,6 +204,11 @@ class phpbb_functional_test_case extends phpbb_test_case  	{  		if (!$this->cache)  		{ +			global $phpbb_container; + +			$phpbb_container = new phpbb_mock_container_builder(); +			$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT); +  			$this->cache = new \phpbb\cache\driver\file;  		} @@ -225,7 +230,8 @@ class phpbb_functional_test_case extends phpbb_test_case  		$config = new \phpbb\config\config(array());  		$db = $this->get_db(); -		$db_tools = new \phpbb\db\tools($db); +		$factory = new \phpbb\db\tools\factory(); +		$db_tools = $factory->get($db);  		$container = new phpbb_mock_container_builder();  		$migrator = new \phpbb\db\migrator( @@ -242,14 +248,12 @@ class phpbb_functional_test_case extends phpbb_test_case  		);  		$container->set('migrator', $migrator);  		$container->set('dispatcher', new phpbb_mock_event_dispatcher()); -		$user = new \phpbb\user('\phpbb\datetime');  		$extension_manager = new \phpbb\extension\manager(  			$container,  			$db,  			$config, -			new phpbb\filesystem(), -			$user, +			new phpbb\filesystem\filesystem(),  			self::$config['table_prefix'] . 'ext',  			dirname(__FILE__) . '/',  			$phpEx, @@ -489,7 +493,7 @@ class phpbb_functional_test_case extends phpbb_test_case  			));  			$db->sql_query($sql); -			if ($style_path != 'prosilver' && $style_path != 'subsilver2') +			if ($style_path != 'prosilver')  			{  				@mkdir($phpbb_root_path . 'styles/' . $style_path, 0777);  				@mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); @@ -528,7 +532,7 @@ class phpbb_functional_test_case extends phpbb_test_case  			$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') +			if ($style_path != 'prosilver')  			{  				@rmdir($phpbb_root_path . 'styles/' . $style_path . '/template');  				@rmdir($phpbb_root_path . 'styles/' . $style_path); @@ -570,7 +574,7 @@ class phpbb_functional_test_case extends phpbb_test_case  		}  		$cache = new phpbb_mock_null_cache; -		$cache_driver = new \phpbb\cache\driver\null(); +		$cache_driver = new \phpbb\cache\driver\dummy();  		$phpbb_container = new phpbb_mock_container_builder();  		$phpbb_container->set('cache.driver', $cache_driver);  		$phpbb_notifications = new phpbb_mock_notification_manager(); @@ -584,8 +588,7 @@ class phpbb_functional_test_case extends phpbb_test_case  		{  			require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');  		} -		set_config(null, null, null, $config); -		set_config_count(null, null, null, $config); +  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();  		$passwords_manager = $this->get_passwords_manager(); @@ -611,13 +614,16 @@ class phpbb_functional_test_case extends phpbb_test_case  		$db = $this->get_db();  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$auth = $this->getMock('\phpbb\auth\auth');  		$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);  		$cache = new phpbb_mock_null_cache; -		$cache_driver = new \phpbb\cache\driver\null(); +		$cache_driver = new \phpbb\cache\driver\dummy();  		$phpbb_container = new phpbb_mock_container_builder();  		$phpbb_container->set('cache.driver', $cache_driver);  		$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); @@ -650,13 +656,16 @@ class phpbb_functional_test_case extends phpbb_test_case  		$db = $this->get_db();  		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -		$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); +		$user = $this->getMock('\phpbb\user', array(), array( +			new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), +			'\phpbb\datetime' +		));  		$auth = $this->getMock('\phpbb\auth\auth');  		$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);  		$cache = new phpbb_mock_null_cache; -		$cache_driver = new \phpbb\cache\driver\null(); +		$cache_driver = new \phpbb\cache\driver\dummy();  		$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');  		$phpbb_container  			->expects($this->any()) @@ -947,8 +956,7 @@ class phpbb_functional_test_case extends phpbb_test_case  	*/  	public function assert_checkbox_is_unchecked($crawler, $name, $message = '')  	{ -		$this->assertSame( -			'', +		$this->assertNull(  			$this->assert_find_one_checkbox($crawler, $name)->attr('checked'),  			$message ?: "Failed asserting that checkbox $name is unchecked."  		); diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php index 1bf0277fe0..1c1930e88d 100644 --- a/tests/test_framework/phpbb_session_test_case.php +++ b/tests/test_framework/phpbb_session_test_case.php @@ -34,7 +34,7 @@ abstract class phpbb_session_test_case extends phpbb_database_test_case  		$symfony_request = new \phpbb\symfony_request(  			new phpbb_mock_request()  		); -		$phpbb_filesystem = new \phpbb\filesystem(); +		$phpbb_filesystem = new \phpbb\filesystem\filesystem();  		$phpbb_path_helper = new \phpbb\path_helper(  			$symfony_request,  			$phpbb_filesystem, diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index dee70ad016..210cda9a94 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -11,6 +11,8 @@  *  */ +use Symfony\Component\DependencyInjection\ContainerInterface; +  class phpbb_test_case_helpers  {  	protected $expectedTriggerError = false; @@ -298,4 +300,232 @@ class phpbb_test_case_helpers  			}  		}  	} + +	/** +	* Set working instances of the text_formatter.* services +	* +	* If no container is passed, the global $phpbb_container will be used and/or +	* created if applicable +	* +	* @param  ContainerInterface $container   Service container +	* @param  string             $fixture     Path to the XML fixture +	* @param  string             $styles_path Path to the styles dir +	* @return ContainerInterface +	*/ +	public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null) +	{ +		static $first_run; +		global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + +		$cache_dir = __DIR__ . '/../tmp/'; + +		// Remove old cache files on first run +		if (!isset($first_run)) +		{ +			$first_run = 1; + +			array_map('unlink', array_merge( +				glob($cache_dir . 'data_s9e_*'), +				glob($cache_dir . 's9e_*') +			)); +		} + +		if (!isset($container)) +		{ +			if (!isset($phpbb_container)) +			{ +				$phpbb_container = new phpbb_mock_container_builder; +			} + +			$container = $phpbb_container; +		} + +		if (!isset($fixture)) +		{ +			$fixture = __DIR__ . '/../text_formatter/s9e/fixtures/default_formatting.xml'; +		} + +		if (!isset($styles_path)) +		{ +			$styles_path = $phpbb_root_path . 'styles/'; +		} + +		$dataset = new DOMDocument; +		$dataset->load($fixture); + +		$tables = array( +			'phpbb_bbcodes' => array(), +			'phpbb_smilies' => array(), +			'phpbb_styles'  => array(), +			'phpbb_words'   => array() +		); +		foreach ($dataset->getElementsByTagName('table') as $table) +		{ +			$name = $table->getAttribute('name'); +			$columns = array(); + +			foreach ($table->getElementsByTagName('column') as $column) +			{ +				$columns[] = $column->textContent; +			} + +			foreach ($table->getElementsByTagName('row') as $row) +			{ +				$values = array(); + +				foreach ($row->getElementsByTagName('value') as $value) +				{ +					$values[] = $value->textContent; +				} + +				$tables[$name][] = array_combine($columns, $values); +			} +		} + +		// Set up a default style if there's none set +		if (empty($tables['phpbb_styles'])) +		{ +			$tables['phpbb_styles'][] = array( +				'style_id' => 1, +				'style_path' => 'prosilver', +				'bbcode_bitfield' => 'kNg=' +			); +		} + +		// Mock the DAL, make it return data from the fixture +		$mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access'); +		$mb->setMethods(array('get_bbcodes', 'get_censored_words', 'get_smilies', 'get_styles')); +		$mb->setConstructorArgs(array( +			$this->test_case->getMock('phpbb\\db\\driver\\driver'), +			'phpbb_bbcodes', +			'phpbb_smilies', +			'phpbb_styles', +			'phpbb_words', +			$styles_path +		)); + +		$dal = $mb->getMock(); +		$container->set('text_formatter.data_access', $dal); + +		$dal->expects($this->test_case->any()) +		    ->method('get_bbcodes') +		    ->will($this->test_case->returnValue($tables['phpbb_bbcodes'])); +		$dal->expects($this->test_case->any()) +		    ->method('get_smilies') +		    ->will($this->test_case->returnValue($tables['phpbb_smilies'])); +		$dal->expects($this->test_case->any()) +		    ->method('get_styles') +		    ->will($this->test_case->returnValue($tables['phpbb_styles'])); +		$dal->expects($this->test_case->any()) +		    ->method('get_censored_words') +		    ->will($this->test_case->returnValue($tables['phpbb_words'])); + +		// Cache the parser and renderer with a key based on this method's arguments +		$cache = new \phpbb\cache\driver\file($cache_dir); +		$prefix = '_s9e_' . md5(serialize(func_get_args())); +		$cache_key_parser = $prefix . '_parser'; +		$cache_key_renderer = $prefix . '_renderer'; +		$container->set('cache.driver', $cache); +		$container->setParameter('cache.dir', $cache_dir); + +		// Create a path_helper +		if (!$container->has('path_helper')) +		{ +			$container->set( +				'path_helper', +				new \phpbb\path_helper( +					new \phpbb\symfony_request( +						new phpbb_mock_request() +					), +					new \phpbb\filesystem(), +					$this->test_case->getMock('\phpbb\request\request'), +					$phpbb_root_path, +					$phpEx +				) +			); +		} + +		// Create an event dispatcher +		if ($container->has('dispatcher')) +		{ +			$dispatcher = $container->get('dispatcher'); +		} +		else if (isset($phpbb_dispatcher)) +		{ +			$dispatcher = $phpbb_dispatcher; +		} +		else +		{ +			$dispatcher = new phpbb_mock_event_dispatcher; +		} +		if (!isset($phpbb_dispatcher)) +		{ +			$phpbb_dispatcher = $dispatcher; +		} + +		// Create and register the text_formatter.s9e.factory service +		$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer); +		$container->set('text_formatter.s9e.factory', $factory); + +		// Create a user if none was provided, and add the common lang strings +		if ($container->has('user')) +		{ +			$user = $container->get('user'); +		} +		else +		{ +			$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +			$lang = new \phpbb\language\language($lang_loader); +			$user = new \phpbb\user($lang, '\phpbb\datetime'); +			$user->optionset('viewcensors', true); +			$user->optionset('viewflash', true); +			$user->optionset('viewimg', true); +			$user->optionset('viewsmilies', true); +			$container->set('user', $user); +		} +		$user->add_lang('common'); + +		if (!isset($user->style)) +		{ +			$user->style = array('style_id' => 1); +		} + +		// Create and register the text_formatter.s9e.parser service and its alias +		$parser = new \phpbb\textformatter\s9e\parser( +			$cache, +			$cache_key_parser, +			$factory, +			$dispatcher +		); +		$container->set('text_formatter.parser', $parser); +		$container->set('text_formatter.s9e.parser', $parser); + +		// Create and register the text_formatter.s9e.renderer service and its alias +		$renderer = new \phpbb\textformatter\s9e\renderer( +			$cache, +			$cache_dir, +			$cache_key_renderer, +			$factory, +			$dispatcher +		); + +		$config = ($container->has('config')) +		        ? $container->get('config') +		        : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false)); +		$auth = ($container->has('auth')) ? $container->get('auth') : new \phpbb\auth\auth; + +		// Calls configured in services.yml +		$renderer->configure_smilies_path($config, $container->get('path_helper')); +		$renderer->configure_user($user, $config, $auth); + +		$container->set('text_formatter.renderer', $renderer); +		$container->set('text_formatter.s9e.renderer', $renderer); + +		// Create and register the text_formatter.s9e.utils service and its alias +		$utils = new \phpbb\textformatter\s9e\utils; +		$container->set('text_formatter.utils', $utils); +		$container->set('text_formatter.s9e.utils', $utils); + +		return $container; +	}  } diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php new file mode 100644 index 0000000000..2aa15146aa --- /dev/null +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -0,0 +1,226 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; + +class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_default_formatting_tests +	*/ +	public function test_default_formatting($original, $expected) +	{ +		$fixture   = __DIR__ . '/fixtures/default_formatting.xml'; +		$container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); + +		$parser   = $container->get('text_formatter.parser'); +		$renderer = $container->get('text_formatter.renderer'); + +		$parsed_text = $parser->parse($original); + +		$this->assertSame($expected, $renderer->render($parsed_text)); +	} + +	public function get_default_formatting_tests() +	{ +		return array( +			array( +				'[b]bold[/b]', +				'<span style="font-weight: bold">bold</span>' +			), +			array( +				'[u]underlined[/u]', +				'<span style="text-decoration: underline">underlined</span>' +			), +			array( +				'[i]italic[/i]', +				'<span style="font-style: italic">italic</span>' +			), +			array( +				'[color=#FF0000]colored[/color]', +				'<span style="color: #FF0000">colored</span>' +			), +			array( +				'[color=red]colored[/color]', +				'<span style="color: red">colored</span>' +			), +			array( +				'[size=75]smaller[/size]', +				'<span style="font-size: 75%; line-height: normal">smaller</span>' +			), +			array( +				'[quote]quoted[/quote]', +				'<blockquote class="uncited"><div>quoted</div></blockquote>' +			), +			array( +				'[quote="username"]quoted[/quote]', +				'<blockquote><div><cite>username wrote:</cite>quoted</div></blockquote>' +			), +			array( +				'[code]unparsed code[/code]', +				'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code</code></pre></div>' +			), +			array( +				'[list]no item[/list]', +				'<ul>no item</ul>' +			), +			array( +				'[*]unparsed', +				'[*]unparsed' +			), +			array( +				'[list][*]item[/list]', +				'<ul><li>item</li></ul>' +			), +			array( +				'[list][*]item[/*][/list]', +				'<ul><li>item</li></ul>' +			), +			array( +				'[list=1][*]item[/list]', +				'<ol style="list-style-type: decimal"><li>item</li></ol>' +			), +			array( +				'[list=a][*]item[/list]', +				'<ol style="list-style-type: lower-alpha"><li>item</li></ol>' +			), +			array( +				'[list=i][*]item[/list]', +				'<ol style="list-style-type: lower-roman"><li>item</li></ol>' +			), +			array( +				'[list=I][*]item[/list]', +				'<ol style="list-style-type: upper-roman"><li>item</li></ol>' +			), +			array( +				'[list=disc][*]item[/list]', +				'<ul style="list-style-type: disc"><li>item</li></ul>' +			), +			array( +				'[list=circle][*]item[/list]', +				'<ul style="list-style-type: circle"><li>item</li></ul>' +			), +			array( +				'[list=square][*]item[/list]', +				'<ul style="list-style-type: square"><li>item</li></ul>' +			), +			array( +				'[img]https://area51.phpbb.com/images/area51.png[/img]', +				'<img src="https://area51.phpbb.com/images/area51.png" alt="Image">' +			), +			array( +				'[url]https://area51.phpbb.com/[/url]', +				'<a href="https://area51.phpbb.com/" class="postlink">https://area51.phpbb.com/</a>' +			), +			array( +				'[url=https://area51.phpbb.com/]Area51[/url]', +				'<a href="https://area51.phpbb.com/" class="postlink">Area51</a>' +			), +			array( +				'[email]bbcode-test@phpbb.com[/email]', +				'<a href="mailto:bbcode-test@phpbb.com">bbcode-test@phpbb.com</a>' +			), +			array( +				'[email=bbcode-test@phpbb.com]Email[/email]', +				'<a href="mailto:bbcode-test@phpbb.com">Email</a>' +			), +			array( +				'[attachment=0]filename[/attachment]', +				'<div class="inline-attachment"><!-- ia0 -->filename<!-- ia0 --></div>' +			), +			array( +				// PHPBB3-1401 - correct: parsed +				'[quote="[test]test"]test [ test[/quote]', +				'<blockquote><div><cite>[test]test wrote:</cite>test [ test</div></blockquote>' +			), +			array( +				// PHPBB3-6117 - correct: parsed +				'[quote]test[/quote] test ] and [ test [quote]test[/quote]', +				'<blockquote class="uncited"><div>test</div></blockquote> test ] and [ test <blockquote class="uncited"><div>test</div></blockquote>' +			), +			array( +				// PHPBB3-6200 - correct: parsed +				'[quote="["]test[/quote]', +				'<blockquote><div><cite>[ wrote:</cite>test</div></blockquote>' +			), +			array( +				// PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted +				'[quote]test[/[/b]quote] test [/quote][/quote] test', +				'<blockquote class="uncited"><div>test[/[/b]quote] test </div></blockquote>[/quote] test' +			), +			array( +				// PHPBB3-8096 - first quote tag parsed, second quote tag unparsed +				'[quote="a"]a[/quote][quote="a]a[/quote]', +				'<blockquote><div><cite>a wrote:</cite>a</div></blockquote>[quote="a]a[/quote]' +			), +			array( +				// Allow textual bbcodes in textual bbcodes +				'[b]bold [i]bold + italic[/i][/b]', +				'<span style="font-weight: bold">bold <span style="font-style: italic">bold + italic</span></span>' +			), +			array( +				// Allow textual bbcodes in url with description +				'[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', +				'<a href="https://area51.phpbb.com/" class="postlink">Area51 <span style="font-style: italic">italic</span></a>' +			), +			array( +				// Allow url with description in textual bbcodes +				'[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', +				'<span style="font-style: italic">italic <a href="https://area51.phpbb.com/" class="postlink">Area51</a></span>' +			), +			array( +				// Do not parse textual bbcodes in code +				'[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', +				'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code [b]bold [i]bold + italic[/i][/b]</code></pre></div>' +			), +			array( +				// Do not parse quote bbcodes in code +				'[code]unparsed code [quote="username"]quoted[/quote][/code]', +				'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code [quote="username"]quoted[/quote]</code></pre></div>' +			), +			array( +				// Textual bbcode nesting into textual bbcode +				'[b]bold [i]bold + italic[/b] italic[/i]', +				'<span style="font-weight: bold">bold <span style="font-style: italic">bold + italic</span></span><span style="font-style: italic"> italic</span>' +			), +			array( +				"[code]\tline1\n  line2[/code]", +				'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>' . "\tline1\n  line2</code></pre></div>" +			), +			array( +				"[code]\n\tline1\n  line2[/code]", +				'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>' . "\tline1\n  line2</code></pre></div>" +			), +			array( +				'... http://example.org ...', +				'... <a href="http://example.org" class="postlink">http://example.org</a> ...' +			), +			array( +				'... www.example.org ...', +				'... <a href="http://www.example.org" class="postlink">www.example.org</a> ...' +			), +			array( +				'[quote="[url=http://example.org]xxx[/url]"]...[/quote]', +				'<blockquote><div><cite><a href="http://example.org" class="postlink">xxx</a> wrote:</cite>...</div></blockquote>' +			), +			array( +				'[quote="[url]http://example.org[/url]"]...[/quote]', +				'<blockquote><div><cite><a href="http://example.org" class="postlink">http://example.org</a> wrote:</cite>...</div></blockquote>' +			), +			array( +				'[quote="http://example.org"]...[/quote]', +				'<blockquote><div><cite><a href="http://example.org" class="postlink">http://example.org</a> wrote:</cite>...</div></blockquote>' +			), +		); +	} +} diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php new file mode 100644 index 0000000000..8382097544 --- /dev/null +++ b/tests/text_formatter/s9e/factory_test.php @@ -0,0 +1,241 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; + +class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case +{ +	public function setUp() +	{ +		$this->cache = new phpbb_mock_cache; +		$this->dispatcher = new phpbb_mock_event_dispatcher; +		parent::setUp(); +	} + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(__DIR__ . '/fixtures/factory.xml'); +	} + +	public function get_cache_dir() +	{ +		return __DIR__ . '/../../tmp/'; +	} + +	public function get_factory() +	{ +		global $phpbb_root_path; +		$this->cache = new phpbb_mock_cache; +		$dal = new \phpbb\textformatter\data_access( +			$this->new_dbal(), +			'phpbb_bbcodes', +			'phpbb_smilies', +			'phpbb_styles', +			'phpbb_words', +			$phpbb_root_path . 'styles/' +		); +		$factory = new \phpbb\textformatter\s9e\factory( +			$dal, +			$this->cache, +			$this->dispatcher, +			$this->get_cache_dir(), +			'_foo_parser', +			'_foo_renderer' +		); + +		return $factory; +	} + +	public function test_get_configurator() +	{ +		$configurator = $this->get_factory()->get_configurator(); + +		$this->assertInstanceOf('s9e\\TextFormatter\\Configurator', $configurator); + +		$this->assertTrue(isset($configurator->plugins['Autoemail'])); +		$this->assertTrue(isset($configurator->plugins['Autolink'])); + +		$this->assertTrue(isset($configurator->BBCodes['B'])); +		$this->assertTrue(isset($configurator->BBCodes['CODE'])); +		$this->assertTrue(isset($configurator->BBCodes['COLOR'])); +		$this->assertTrue(isset($configurator->BBCodes['EMAIL'])); +		$this->assertTrue(isset($configurator->BBCodes['FLASH'])); +		$this->assertTrue(isset($configurator->BBCodes['I'])); +		$this->assertTrue(isset($configurator->BBCodes['IMG'])); +		$this->assertTrue(isset($configurator->BBCodes['LIST'])); +		$this->assertTrue(isset($configurator->BBCodes['*'])); +		$this->assertTrue(isset($configurator->BBCodes['QUOTE'])); +		$this->assertTrue(isset($configurator->BBCodes['SIZE'])); +		$this->assertTrue(isset($configurator->BBCodes['U'])); +		$this->assertTrue(isset($configurator->BBCodes['URL'])); + +		// This custom BBCode should be set +		$this->assertTrue(isset($configurator->BBCodes['CUSTOM'])); + +		$this->assertTrue(isset($configurator->Emoticons[':D'])); +	} + +	public function test_regenerate() +	{ +		extract($this->get_factory()->regenerate()); + +		$this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser); +		$this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer); + +		$renderer_data = $this->cache->get('_foo_renderer'); +		$this->assertEquals($parser, $this->cache->get('_foo_parser'), 'The parser was not cached'); +		$this->assertEquals(get_class($renderer), $renderer_data['class']); +		$this->assertInstanceOf('s9e\\TextFormatter\\Plugins\\Censor\\Helper', $renderer_data['censor']); + +		$file = $this->get_cache_dir() . get_class($renderer) . '.php'; +		$this->assertFileExists($file); +		unlink($file); +	} + +	public function test_tidy() +	{ +		$factory = $this->get_factory(); + +		// Create a fake "old" cache file +		$old_file = $this->get_cache_dir() . 's9e_foo.php'; +		touch($old_file); + +		// Create a current renderer +		extract($factory->regenerate()); +		$new_file = $this->get_cache_dir() . get_class($renderer) . '.php'; + +		// Tidy the cache +		$factory->tidy(); + +		$this->assertFileExists($new_file, 'The current renderer has been deleted'); +		$this->assertFileNotExists($old_file, 'The old renderer has not been deleted'); + +		unlink($new_file); +	} + +	public function test_local_url() +	{ +		global $config, $user, $request; +		$config = array( +			'force_server_vars' => true, +			'server_protocol' => 'http://', +			'server_name' => 'path', +			'server_port' => 80, +			'script_path' => '/to', +			'cookie_secure' => false +		); +		$user = new phpbb_mock_user; +		$request = new phpbb_mock_request; + +		$fixture = __DIR__ . '/fixtures/local_url.xml'; +		$renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer'); + +		$this->assertSame( +			'<a href="http://path/to/foo">http://path/to/foo</a>', +			$renderer->render('<r><LOCAL content="foo"><s>[local]</s>foo<e>[/local]</e></LOCAL></r>') +		); +	} + +	public function test_smilies_special_chars() +	{ +		// Use a smiley that contains every special chars in every field +		$fixture = __DIR__ . '/fixtures/smilies_special_chars.xml'; +		$renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer'); + +		$this->assertSame( +			'<img class="smilies" src="phpBB/images/smilies/%22%27%3C&%3E.png" alt=""\'<&>" title=""\'<&>">', +			$renderer->render('<r><E>"\'<&></E></r>') +		); +	} + +	/** +	* @testdox {INTTEXT} is supported in custom BBCodes +	*/ +	public function test_inttext_token() +	{ +		$fixture = __DIR__ . '/fixtures/inttext_token.xml'; +		$container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); +		$parser = $container->get('text_formatter.parser'); +		$renderer = $container->get('text_formatter.renderer'); + +		$original = '[spoiler=ɎɆS]text[/spoiler]'; +		$expected = '<div class="spoiler"><div class="title">ɎɆS</div><div class="content">text</div></div>'; +		$this->assertSame($expected, $renderer->render($parser->parse($original))); + +		$original = '[spoiler=N:O:P:E]text[/spoiler]'; +		$expected = $original; +		$this->assertSame($expected, $renderer->render($parser->parse($original))); +	} + +	/** +	* @testdox Preserves comments in custom BBCodes +	*/ +	public function test_preserve_comments() +	{ +		$fixture = __DIR__ . '/fixtures/preserve_comments.xml'; +		$container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); +		$parser = $container->get('text_formatter.parser'); +		$renderer = $container->get('text_formatter.renderer'); + +		$original = '[X]'; +		$expected = '<!-- comment -->'; +		$this->assertSame($expected, $renderer->render($parser->parse($original))); +	} + +	/** +	* @testdox Accepts unsafe custom BBCodes +	*/ +	public function test_unsafe_bbcode() +	{ +		$fixture = __DIR__ . '/fixtures/unsafe_bbcode.xml'; +		$container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); +		$parser = $container->get('text_formatter.parser'); +		$renderer = $container->get('text_formatter.renderer'); + +		$original = '[xss=javascript:alert(1)]text[/xss]'; +		$expected = '<a href="javascript:alert(1)">text</a>'; +		$this->assertSame($expected, $renderer->render($parser->parse($original))); +	} + +	/** +	* @testdox get_configurator() triggers events before and after configuration +	*/ +	public function test_configure_events() +	{ +		$this->dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); +		$this->dispatcher +			->expects($this->at(0)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_configure_before', +				$this->callback(array($this, 'configure_event_callback')) +			) +			->will($this->returnArgument(1)); +		$this->dispatcher +			->expects($this->at(1)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_configure_after', +				$this->callback(array($this, 'configure_event_callback')) +			) +			->will($this->returnArgument(1)); + +		$this->get_factory()->get_configurator(); +	} + +	public function configure_event_callback($vars) +	{ +		return isset($vars['configurator']) && $vars['configurator'] instanceof \s9e\TextFormatter\Configurator; +	} +} diff --git a/tests/text_formatter/s9e/fixtures/default_formatting.xml b/tests/text_formatter/s9e/fixtures/default_formatting.xml new file mode 100644 index 0000000000..2b7236fb30 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/default_formatting.xml @@ -0,0 +1,466 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>1</value> +			<value>:D</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>1</value> +			<value>1</value> +		</row> +		<row> +			<value>2</value> +			<value>:-D</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>2</value> +			<value>1</value> +		</row> +		<row> +			<value>3</value> +			<value>:grin:</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>3</value> +			<value>1</value> +		</row> +		<row> +			<value>4</value> +			<value>:)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>4</value> +			<value>1</value> +		</row> +		<row> +			<value>5</value> +			<value>:-)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>5</value> +			<value>1</value> +		</row> +		<row> +			<value>6</value> +			<value>:smile:</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>6</value> +			<value>1</value> +		</row> +		<row> +			<value>7</value> +			<value>;)</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>7</value> +			<value>1</value> +		</row> +		<row> +			<value>8</value> +			<value>;-)</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>8</value> +			<value>1</value> +		</row> +		<row> +			<value>9</value> +			<value>:wink:</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>9</value> +			<value>1</value> +		</row> +		<row> +			<value>10</value> +			<value>:(</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>10</value> +			<value>1</value> +		</row> +		<row> +			<value>11</value> +			<value>:-(</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>11</value> +			<value>1</value> +		</row> +		<row> +			<value>12</value> +			<value>:sad:</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>12</value> +			<value>1</value> +		</row> +		<row> +			<value>13</value> +			<value>:o</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>13</value> +			<value>1</value> +		</row> +		<row> +			<value>14</value> +			<value>:-o</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>14</value> +			<value>1</value> +		</row> +		<row> +			<value>15</value> +			<value>:eek:</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>15</value> +			<value>1</value> +		</row> +		<row> +			<value>16</value> +			<value>:shock:</value> +			<value>Shocked</value> +			<value>icon_eek.gif</value> +			<value>15</value> +			<value>17</value> +			<value>16</value> +			<value>1</value> +		</row> +		<row> +			<value>17</value> +			<value>:?</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>17</value> +			<value>1</value> +		</row> +		<row> +			<value>18</value> +			<value>:-?</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>18</value> +			<value>1</value> +		</row> +		<row> +			<value>19</value> +			<value>:???:</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>19</value> +			<value>1</value> +		</row> +		<row> +			<value>20</value> +			<value>8-)</value> +			<value>Cool</value> +			<value>icon_cool.gif</value> +			<value>15</value> +			<value>17</value> +			<value>20</value> +			<value>1</value> +		</row> +		<row> +			<value>21</value> +			<value>:cool:</value> +			<value>Cool</value> +			<value>icon_cool.gif</value> +			<value>15</value> +			<value>17</value> +			<value>21</value> +			<value>1</value> +		</row> +		<row> +			<value>22</value> +			<value>:lol:</value> +			<value>Laughing</value> +			<value>icon_lol.gif</value> +			<value>15</value> +			<value>17</value> +			<value>22</value> +			<value>1</value> +		</row> +		<row> +			<value>23</value> +			<value>:x</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>23</value> +			<value>1</value> +		</row> +		<row> +			<value>24</value> +			<value>:-x</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>24</value> +			<value>1</value> +		</row> +		<row> +			<value>25</value> +			<value>:mad:</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>25</value> +			<value>1</value> +		</row> +		<row> +			<value>26</value> +			<value>:P</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>26</value> +			<value>1</value> +		</row> +		<row> +			<value>27</value> +			<value>:-P</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>27</value> +			<value>1</value> +		</row> +		<row> +			<value>28</value> +			<value>:razz:</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>28</value> +			<value>1</value> +		</row> +		<row> +			<value>29</value> +			<value>:oops:</value> +			<value>Embarrassed</value> +			<value>icon_redface.gif</value> +			<value>15</value> +			<value>17</value> +			<value>29</value> +			<value>1</value> +		</row> +		<row> +			<value>30</value> +			<value>:cry:</value> +			<value>Crying or Very Sad</value> +			<value>icon_cry.gif</value> +			<value>15</value> +			<value>17</value> +			<value>30</value> +			<value>1</value> +		</row> +		<row> +			<value>31</value> +			<value>:evil:</value> +			<value>Evil or Very Mad</value> +			<value>icon_evil.gif</value> +			<value>15</value> +			<value>17</value> +			<value>31</value> +			<value>1</value> +		</row> +		<row> +			<value>32</value> +			<value>:twisted:</value> +			<value>Twisted Evil</value> +			<value>icon_twisted.gif</value> +			<value>15</value> +			<value>17</value> +			<value>32</value> +			<value>1</value> +		</row> +		<row> +			<value>33</value> +			<value>:roll:</value> +			<value>Rolling Eyes</value> +			<value>icon_rolleyes.gif</value> +			<value>15</value> +			<value>17</value> +			<value>33</value> +			<value>1</value> +		</row> +		<row> +			<value>34</value> +			<value>:!:</value> +			<value>Exclamation</value> +			<value>icon_exclaim.gif</value> +			<value>15</value> +			<value>17</value> +			<value>34</value> +			<value>1</value> +		</row> +		<row> +			<value>35</value> +			<value>:?:</value> +			<value>Question</value> +			<value>icon_question.gif</value> +			<value>15</value> +			<value>17</value> +			<value>35</value> +			<value>1</value> +		</row> +		<row> +			<value>36</value> +			<value>:idea:</value> +			<value>Idea</value> +			<value>icon_idea.gif</value> +			<value>15</value> +			<value>17</value> +			<value>36</value> +			<value>1</value> +		</row> +		<row> +			<value>37</value> +			<value>:arrow:</value> +			<value>Arrow</value> +			<value>icon_arrow.gif</value> +			<value>15</value> +			<value>17</value> +			<value>37</value> +			<value>1</value> +		</row> +		<row> +			<value>38</value> +			<value>:|</value> +			<value>Neutral</value> +			<value>icon_neutral.gif</value> +			<value>15</value> +			<value>17</value> +			<value>38</value> +			<value>1</value> +		</row> +		<row> +			<value>39</value> +			<value>:-|</value> +			<value>Neutral</value> +			<value>icon_neutral.gif</value> +			<value>15</value> +			<value>17</value> +			<value>39</value> +			<value>1</value> +		</row> +		<row> +			<value>40</value> +			<value>:mrgreen:</value> +			<value>Mr. Green</value> +			<value>icon_mrgreen.gif</value> +			<value>15</value> +			<value>17</value> +			<value>40</value> +			<value>1</value> +		</row> +		<row> +			<value>41</value> +			<value>:geek:</value> +			<value>Geek</value> +			<value>icon_e_geek.gif</value> +			<value>17</value> +			<value>17</value> +			<value>41</value> +			<value>1</value> +		</row> +		<row> +			<value>42</value> +			<value>:ugeek:</value> +			<value>Uber Geek</value> +			<value>icon_e_ugeek.gif</value> +			<value>17</value> +			<value>18</value> +			<value>42</value> +			<value>1</value> +		</row> +	</table> + +	<table name="phpbb_styles"> +		<column>style_id</column> +		<column>style_name</column> +		<column>style_copyright</column> +		<column>style_active</column> +		<column>style_path</column> +		<column>bbcode_bitfield</column> +		<column>style_parent_id</column> +		<column>style_parent_tree</column> +		<row> +			<value>1</value> +			<value>prosilver</value> +			<value>&copy; phpBB Group</value> +			<value>1</value> +			<value>prosilver</value> +			<value>kNg=</value> +			<value>0</value> +			<value></value> +		</row> +	</table> + +	<table name="phpbb_words"> +		<column>word_id</column> +		<column>word</column> +		<column>replacement</column> + +		<row> +			<value>1</value> +			<value>apple</value> +			<value>banana</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/default_lang.xml b/tests/text_formatter/s9e/fixtures/default_lang.xml new file mode 100644 index 0000000000..2cfde4aab2 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/default_lang.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> + +		<row> +			<value>13</value> +			<value>foo</value> +			<value></value> +			<value>1</value> +			<value>[foo]{TEXT}[/foo]</value> +			<value>{L_FOO_BAR}</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/factory.xml b/tests/text_formatter/s9e/fixtures/factory.xml new file mode 100644 index 0000000000..9ae52e9747 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/factory.xml @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>custom</value> +			<value></value> +			<value>1</value> +			<value>[custom]{TEXT}[/custom]</value> +			<value><span style="color:red">{TEXT}</span></value> +			<value>!\[custom\](.*?)\[/custom\]!ies</value> +			<value>'[custom:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/custom:$uid]'</value> +			<value>!\[custom:$uid\](.*?)\[/custom:$uid\]!s</value> +			<value><span style="color:red">${1}</span></value> +		</row> +		<row> +			<value>14</value> +			<value>unsafe</value> +			<value></value> +			<value>1</value> +			<value>[unsafe]{TEXT}[/unsafe]</value> +			<value><script>{TEXT}</script></value> +			<value>!\[unsafe\](.*?)\[/unsafe\]!ies</value> +			<value>'[unsafe:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/unsafe:$uid]'</value> +			<value>!\[unsafe:$uid\](.*?)\[/unsafe:$uid\]!s</value> +			<value><script>${1}</script></value> +		</row> +	</table> + +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>1</value> +			<value>:D</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>2</value> +			<value>1</value> +		</row> +		<row> +			<value>4</value> +			<value>:)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>4</value> +			<value>1</value> +		</row> +		<row> +			<value>10</value> +			<value>:(</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>10</value> +			<value>1</value> +		</row> +	</table> + +	<table name="phpbb_styles"> +		<column>style_id</column> +		<column>style_name</column> +		<column>style_copyright</column> +		<column>style_active</column> +		<column>style_path</column> +		<column>bbcode_bitfield</column> +		<column>style_parent_id</column> +		<column>style_parent_tree</column> + +		<row> +			<value>1</value> +			<value>prosilver</value> +			<value>&copy; phpBB Group</value> +			<value>1</value> +			<value>prosilver</value> +			<value>kNg=</value> +			<value>0</value> +			<value></value> +		</row> +	</table> + +	<table name="phpbb_words"> +		<column>word_id</column> +		<column>word</column> +		<column>replacement</column> + +		<row> +			<value>1</value> +			<value>apple</value> +			<value>banana</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/inttext_token.xml b/tests/text_formatter/s9e/fixtures/inttext_token.xml new file mode 100644 index 0000000000..30b971f315 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/inttext_token.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>spoiler=</value> +			<value></value> +			<value>1</value> +			<value>[spoiler={INTTEXT}]{TEXT}[/spoiler]</value> +			<value><![CDATA[<div class="spoiler"><div class="title">{INTTEXT}</div><div class="content">{TEXT}</div></div>]]></value> +			<value><![CDATA[!\[spoiler\=([\p{L}\p{N}\-+,_. ]+)\](.*?)\[/spoiler\]!iues]]></value> +			<value><![CDATA['[spoiler=${1}:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${2}')).'[/spoiler:$uid]']]></value> +			<value><![CDATA[!\[spoiler\=([\p{L}\p{N}\-+,_. ]+):$uid\](.*?)\[/spoiler:$uid\]!su]]></value><value><![CDATA[<div class="spoiler"><div class="title">${1}</div><div class="content">${2}</div></div>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/local_url.xml b/tests/text_formatter/s9e/fixtures/local_url.xml new file mode 100644 index 0000000000..9db2bf4710 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/local_url.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>local</value> +			<value></value> +			<value>1</value> +			<value>[local]{LOCAL_URL}[/local]</value> +			<value><![CDATA[<a href="{LOCAL_URL}">{LOCAL_URL}</a>]]></value> +			<value><*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:#(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?)\[/local\]!ie]]></value> +			<value><![CDATA['[local:$uid]'.$this->bbcode_specialchars('${1}').'[/local:$uid]']]></value> +			<value><((?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:#(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?)(?-i)\[/local:$uid\]!s]]></value> +			<value><![CDATA[<a href="http://path/to/phpBB/${1}">http://path/to/phpBB/${1}</a>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/preserve_comments.xml b/tests/text_formatter/s9e/fixtures/preserve_comments.xml new file mode 100644 index 0000000000..f81d366aad --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/preserve_comments.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>X</value> +			<value></value> +			<value>1</value> +			<value>[X][/X]</value> +			<value><![CDATA[<!-- comment -->]]></value> +			<value><![CDATA[!\[x\]\[/x\]!i]]></value> +			<value><![CDATA[[x:$uid][/x:$uid]]]></value> +			<value><![CDATA[[x:$uid][/x:$uid]]]></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml new file mode 100644 index 0000000000..d3a7cfa4f7 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>1</value> +			<value>"'<&></value> +			<value>"'<&></value> +			<value>"'<&>.png</value> +			<value>15</value> +			<value>17</value> +			<value>2</value> +			<value>1</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/style_inheritance.xml b/tests/text_formatter/s9e/fixtures/style_inheritance.xml new file mode 100644 index 0000000000..a692d0ef2d --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/style_inheritance.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_styles"> +		<column>style_id</column> +		<column>style_name</column> +		<column>style_copyright</column> +		<column>style_active</column> +		<column>style_path</column> +		<column>bbcode_bitfield</column> +		<column>style_parent_id</column> +		<column>style_parent_tree</column> + +		<row> +			<value>1</value> +			<value>foo</value> +			<value></value> +			<value>1</value> +			<value>foo</value> +			<!-- Bitfield for "b" only --> +			<value>QA==</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>fooplus</value> +			<value></value> +			<value>1</value> +			<value>fooplus</value> +			<value>QA==</value> +			<value>1</value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>fooplusplus</value> +			<value></value> +			<value>1</value> +			<value>fooplusplus</value> +			<value>QA==</value> +			<value>2</value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>bar</value> +			<value></value> +			<value>1</value> +			<value>bar</value> +			<!-- Bitfield for "b" only --> +			<value>QA==</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>barplus</value> +			<value></value> +			<value>1</value> +			<value>barplus</value> +			<value>QA==</value> +			<value>4</value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/styles.xml b/tests/text_formatter/s9e/fixtures/styles.xml new file mode 100644 index 0000000000..8004412aea --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_styles"> +		<column>style_id</column> +		<column>style_name</column> +		<column>style_copyright</column> +		<column>style_active</column> +		<column>style_path</column> +		<column>bbcode_bitfield</column> +		<column>style_parent_id</column> +		<column>style_parent_tree</column> + +		<row> +			<value>1</value> +			<value>foo</value> +			<value></value> +			<value>1</value> +			<value>foo</value> +			<!-- Bitfield for "b" only --> +			<value>QA==</value> +			<value>0</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>bar</value> +			<value></value> +			<value>1</value> +			<value>bar</value> +			<!-- Bitfield for "b" only --> +			<value>QA==</value> +			<value>0</value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html new file mode 100644 index 0000000000..a17446581a --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html @@ -0,0 +1,40 @@ +<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open --> +<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default --> +<!-- BEGIN ulist_close --></ul><!-- END ulist_close --> + +<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open --> +<!-- BEGIN olist_close --></ol><!-- END olist_close --> + +<!-- BEGIN listitem --><li><!-- END listitem --> +<!-- BEGIN listitem_close --></li><!-- END listitem_close --> + +<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open --> +<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open --> +<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close --> + +<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open --> +<!-- BEGIN code_close --></code></div><!-- END code_close --> + +<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open --> +<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close --> + +<!-- BEGIN b_open --><b><!-- END b_open --> +<!-- BEGIN b_close --></b><!-- END b_close --> + +<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open --> +<!-- BEGIN u_close --></span><!-- END u_close --> + +<!-- BEGIN i_open --><em><!-- END i_open --> +<!-- BEGIN i_close --></em><!-- END i_close --> + +<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color --> + +<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> + +<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> + +<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> + +<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email --> + +<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash --> diff --git a/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html new file mode 100644 index 0000000000..cd2f0acae3 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html @@ -0,0 +1,40 @@ +<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open --> +<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default --> +<!-- BEGIN ulist_close --></ul><!-- END ulist_close --> + +<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open --> +<!-- BEGIN olist_close --></ol><!-- END olist_close --> + +<!-- BEGIN listitem --><li><!-- END listitem --> +<!-- BEGIN listitem_close --></li><!-- END listitem_close --> + +<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open --> +<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open --> +<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close --> + +<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open --> +<!-- BEGIN code_close --></code></div><!-- END code_close --> + +<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open --> +<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close --> + +<!-- BEGIN b_open --><b class="barplus"><!-- END b_open --> +<!-- BEGIN b_close --></b><!-- END b_close --> + +<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open --> +<!-- BEGIN u_close --></span><!-- END u_close --> + +<!-- BEGIN i_open --><em><!-- END i_open --> +<!-- BEGIN i_close --></em><!-- END i_close --> + +<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color --> + +<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> + +<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> + +<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> + +<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email --> + +<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash --> diff --git a/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html new file mode 100644 index 0000000000..909c09df5a --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html @@ -0,0 +1,40 @@ +<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open --> +<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default --> +<!-- BEGIN ulist_close --></ul><!-- END ulist_close --> + +<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open --> +<!-- BEGIN olist_close --></ol><!-- END olist_close --> + +<!-- BEGIN listitem --><li><!-- END listitem --> +<!-- BEGIN listitem_close --></li><!-- END listitem_close --> + +<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open --> +<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open --> +<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close --> + +<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open --> +<!-- BEGIN code_close --></code></div><!-- END code_close --> + +<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open --> +<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close --> + +<!-- BEGIN b_open --><strong><!-- END b_open --> +<!-- BEGIN b_close --></strong><!-- END b_close --> + +<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open --> +<!-- BEGIN u_close --></span><!-- END u_close --> + +<!-- BEGIN i_open --><em><!-- END i_open --> +<!-- BEGIN i_close --></em><!-- END i_close --> + +<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color --> + +<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> + +<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> + +<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> + +<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email --> + +<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash --> diff --git a/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml b/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml new file mode 100644 index 0000000000..55a2e689b6 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>xss=</value> +			<value></value> +			<value>1</value> +			<value>[xss={TEXT1}]{TEXT2}[/xss]</value> +			<value><![CDATA[<a href="{TEXT1}">{TEXT2}</a>]]></value> +			<value><\[/xss\]!ies]]></value> +			<value><![CDATA['[xss='.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).':$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${2}')).'[/xss:$uid]']]></value> +			<value><\[/xss:$uid\]!s]]></value> +			<value><![CDATA[<a href="${1}">${2}</a>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php new file mode 100644 index 0000000000..3b72e713e1 --- /dev/null +++ b/tests/text_formatter/s9e/parser_test.php @@ -0,0 +1,260 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; + +class phpbb_textformatter_s9e_parser_test extends phpbb_test_case +{ +	public function test_load_from_cache() +	{ +		$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') +		             ->disableOriginalConstructor() +		             ->getMock(); + +		$cache = $this->getMock('phpbb_mock_cache'); +		$cache->expects($this->once()) +		      ->method('get') +		      ->with('_foo_parser') +		      ->will($this->returnValue($mock)); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); +		$factory->expects($this->never())->method('regenerate'); + +		$parser = new \phpbb\textformatter\s9e\parser( +			$cache, +			'_foo_parser', +			$factory, +			new phpbb_mock_event_dispatcher +		); +	} + +	public function test_use_from_cache() +	{ +		$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') +		             ->disableOriginalConstructor() +		             ->getMock(); + +		$mock->expects($this->once()) +		     ->method('parse') +		     ->with('test') +		     ->will($this->returnValue('<t>test</t>')); + +		$cache = new phpbb_mock_cache; +		$cache->put('_foo_parser', $mock); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); +		$factory->expects($this->never())->method('regenerate'); + +		$parser = new \phpbb\textformatter\s9e\parser( +			$cache, +			'_foo_parser', +			$factory, +			new phpbb_mock_event_dispatcher +		); + +		$this->assertSame('<t>test</t>', $parser->parse('test')); +	} + +	public function test_regenerate_on_cache_miss() +	{ +		$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') +		             ->disableOriginalConstructor() +		             ->getMock(); + +		$mock->expects($this->once()) +		     ->method('parse') +		     ->with('test') +		     ->will($this->returnValue('<t>test</t>')); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); +		$factory->expects($this->once()) +		        ->method('regenerate') +		        ->will($this->returnValue(array('parser' => $mock))); + +		$parser = new \phpbb\textformatter\s9e\parser( +			new phpbb_mock_cache, +			'_foo_parser', +			$factory, +			new phpbb_mock_event_dispatcher +		); + +		$this->assertSame('<t>test</t>', $parser->parse('test')); +	} + +	/** +	* @dataProvider get_options_tests() +	*/ +	public function test_options($adapter_method, $adapter_arg, $concrete_method, $concrete_arg) +	{ +		$mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') +		             ->setMethods(array($concrete_method)) +		             ->disableOriginalConstructor() +		             ->getMock(); +		foreach ((array) $concrete_arg as $i => $concrete_arg) +		{ +			$mock->expects($this->at($i)) +			     ->method($concrete_method) +			     ->with($concrete_arg); +		} + +		$cache = new phpbb_mock_cache; +		$cache->put('_foo_parser', $mock); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); + +		$parser = new \phpbb\textformatter\s9e\parser( +			$cache, +			'_foo_parser', +			$factory, +			new phpbb_mock_event_dispatcher +		); + +		call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg); +	} + +	public function get_options_tests() +	{ +		return array( +			array( +				'disable_bbcode', 'url', +				'disableTag',     'URL' +			), +			array( +				'disable_bbcodes', null, +				'disablePlugin',   'BBCodes' +			), +			array( +				'disable_magic_url', null, +				'disablePlugin',     array('Autoemail', 'Autolink') +			), +			array( +				'disable_smilies', null, +				'disablePlugin',   'Emoticons' +			), +			array( +				'enable_bbcode', 'url', +				'enableTag',     'URL' +			), +			array( +				'enable_bbcodes', null, +				'enablePlugin',   'BBCodes' +			), +			array( +				'enable_magic_url', null, +				'enablePlugin',     array('Autoemail', 'Autolink') +			), +			array( +				'enable_smilies', null, +				'enablePlugin',   'Emoticons' +			) +		); +	} + +	/** +	* @testdox The constructor triggers a core.text_formatter_s9e_parser_setup event +	*/ +	public function test_setup_event() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); +		$dispatcher +			->expects($this->once()) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_parser_setup', +				$this->callback(array($this, 'setup_event_callback')) +			) +			->will($this->returnArgument(1)); + +		new \phpbb\textformatter\s9e\parser( +			$container->get('cache.driver'), +			'_foo_parser', +			$container->get('text_formatter.s9e.factory'), +			$dispatcher +		); +	} + +	public function setup_event_callback($vars) +	{ +		return isset($vars['parser']) +			&& $vars['parser'] instanceof \phpbb\textformatter\s9e\parser; +	} + +	/** +	* @testdox parse() triggers a core.text_formatter_s9e_parse_before and core.text_formatter_s9e_parse_after events +	*/ +	public function test_parse_event() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); +		$dispatcher +			->expects($this->any()) +			->method('trigger_event') +			->will($this->returnArgument(1)); +		$dispatcher +			->expects($this->at(1)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_parse_before', +				$this->callback(array($this, 'parse_before_event_callback')) +			) +			->will($this->returnArgument(1)); +		$dispatcher +			->expects($this->at(2)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_parse_after', +				$this->callback(array($this, 'parse_after_event_callback')) +			) +			->will($this->returnArgument(1)); + +		$parser = new \phpbb\textformatter\s9e\parser( +			$container->get('cache.driver'), +			'_foo_parser', +			$container->get('text_formatter.s9e.factory'), +			$dispatcher +		); +		$parser->parse('...'); +	} + +	public function parse_before_event_callback($vars) +	{ +		return isset($vars['parser']) +			&& $vars['parser'] instanceof \phpbb\textformatter\s9e\parser +			&& isset($vars['text']) +			&& $vars['text'] === '...'; +	} + +	public function parse_after_event_callback($vars) +	{ +		return isset($vars['parser']) +			&& $vars['parser'] instanceof \phpbb\textformatter\s9e\parser +			&& isset($vars['xml']) +			&& $vars['xml'] === '<t>...</t>'; +	} + +	public function test_get_parser() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$parser = $container->get('text_formatter.parser'); +		$this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser->get_parser()); +	} +} diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php new file mode 100644 index 0000000000..3c0bbb96c7 --- /dev/null +++ b/tests/text_formatter/s9e/renderer_test.php @@ -0,0 +1,483 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; + +class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case +{ +	public function get_cache_dir() +	{ +		return __DIR__ . '/../../tmp/'; +	} + +	public function test_load_from_cache() +	{ +		// Save a fake renderer class in the cache dir +		file_put_contents( +			$this->get_cache_dir() . 'renderer_foo.php', +			'<?php class renderer_foo { public function setParameter() {} }' +		); + +		$cache = $this->getMock('phpbb_mock_cache'); +		$cache->expects($this->once()) +		      ->method('get') +		      ->with('_foo_renderer') +		      ->will($this->returnValue(array('class' => 'renderer_foo'))); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); +		$factory->expects($this->never())->method('regenerate'); + +		$renderer = new \phpbb\textformatter\s9e\renderer( +			$cache, +			$this->get_cache_dir(), +			'_foo_renderer', +			$factory, +			new phpbb_mock_event_dispatcher +		); +	} + +	public function test_regenerate_on_cache_miss() +	{ +		$mock = $this->getMockForAbstractClass('s9e\\TextFormatter\\Renderer'); + +		$cache = $this->getMock('phpbb_mock_cache'); +		$cache->expects($this->once()) +		      ->method('get') +		      ->with('_foo_renderer') +		      ->will($this->returnValue(false)); + +		$factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') +		                ->disableOriginalConstructor() +		                ->getMock(); +		$factory->expects($this->once()) +		        ->method('regenerate') +		        ->will($this->returnValue(array('parser' => $mock))); + +		$renderer = new \phpbb\textformatter\s9e\renderer( +			$cache, +			$this->get_cache_dir(), +			'_foo_renderer', +			$factory, +			new phpbb_mock_event_dispatcher +		); +	} + +	/** +	* @dataProvider get_options_cases +	*/ +	public function test_options($original, $expected, $calls) +	{ +		$container = new phpbb_mock_container_builder; +		$this->get_test_case_helpers()->set_s9e_services($container); + +		$renderer = $container->get('text_formatter.renderer'); + +		foreach ($calls as $method => $arg) +		{ +			$renderer->$method($arg); +		} + +		$this->assertSame($expected, $renderer->render($original)); +	} + +	public function get_options_cases() +	{ +		return array( +			array( +				'<t>apple</t>', +				'banana', +				array('set_viewcensors' => true) +			), +			array( +				'<t>apple</t>', +				'apple', +				array('set_viewcensors' => false) +			), +			array( +				'<r><FLASH height="456" url="http://example.org/foo.swf" width="123"><s>[flash=123,456]</s><URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL><e>[/flash]</e></FLASH></r>', +				'<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://example.org/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://example.org/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>', +				array('set_viewflash' => true) +			), +			array( +				'<r><IMG src="http://example.org/foo.png"><s>[img]</s>http://example.org/foo.png<e>[/img]</e></IMG></r>', +				'<img src="http://example.org/foo.png" alt="Image">', +				array('set_viewimg' => true) +			), +			array( +				'<r><E>:)</E></r>', +				'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">', +				array('set_viewsmilies' => true) +			), +			array( +				'<r><E>:)</E></r>', +				':)', +				array('set_viewsmilies' => false) +			), +		); +	} + +	/** +	* @dataProvider get_default_options_cases +	*/ +	public function test_default_options($original, $expected, $setup = null) +	{ +		$container = new phpbb_mock_container_builder; + +		if (isset($setup)) +		{ +			$setup($container, $this); +		} + +		$this->get_test_case_helpers()->set_s9e_services($container); + +		$this->assertSame($expected, $container->get('text_formatter.renderer')->render($original)); +	} + +	public function get_default_options_cases() +	{ +		return array( +			array( +				'<t>apple</t>', +				'banana' +			), +			array( +				'<t>apple</t>', +				'banana', +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewcensors', false); + +					$phpbb_container->set('user', $user); +				} +			), +			array( +				'<t>apple</t>', +				'banana', +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewcensors', false); + +					$config = new \phpbb\config\config(array('allow_nocensors' => true)); + +					$phpbb_container->set('user', $user); +					$phpbb_container->set('config', $config); +				} +			), +			array( +				'<t>apple</t>', +				'apple', +				function ($phpbb_container, $test) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewcensors', false); + +					$config = new \phpbb\config\config(array('allow_nocensors' => true)); + +					$auth = $test->getMock('phpbb\\auth\\auth'); +					$auth->expects($test->any()) +					     ->method('acl_get') +					     ->with('u_chgcensors') +					     ->will($test->returnValue(true)); + +					$phpbb_container->set('user', $user); +					$phpbb_container->set('config', $config); +					$phpbb_container->set('auth', $auth); +				} +			), +			array( +				'<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', +				'<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>' +			), +			array( +				'<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', +				'http://localhost/foo.swf', +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewflash', false); + +					$phpbb_container->set('user', $user); +				} +			), +			array( +				'<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', +				'<img src="http://localhost/mrgreen.gif" alt="Image">' +			), +			array( +				'<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', +				'<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewimg', false); + +					$phpbb_container->set('user', $user); +				} +			), +			array( +				'<r><E>:)</E></r>', +				'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">' +			), +			array( +				'<r><E>:)</E></r>', +				':)', +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('smilies', false); + +					$phpbb_container->set('user', $user); +				} +			), +		); +	} + +	public function test_default_lang() +	{ +		global $phpbb_container; +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/default_lang.xml'); + +		$renderer = $phpbb_container->get('text_formatter.renderer'); + +		$this->assertSame('FOO_BAR', $renderer->render('<r><FOO/></r>')); +	} + +	/** +	* @dataProvider get_option_names +	*/ +	public function test_get_option($option_name) +	{ +		global $phpbb_container; +		$this->get_test_case_helpers()->set_s9e_services(); + +		$renderer = $phpbb_container->get('text_formatter.renderer'); + +		$renderer->{'set_' . $option_name}(false); +		$this->assertFalse($renderer->{'get_' . $option_name}()); +		$renderer->{'set_' . $option_name}(true); +		$this->assertTrue($renderer->{'get_' . $option_name}()); +	} + +	public function get_option_names() +	{ +		return array( +			array('viewcensors'), +			array('viewflash'), +			array('viewimg'), +			array('viewsmilies') +		); +	} + +	public function test_styles() +	{ +		global $phpbb_container; + +		$tests = array( +			1 => '<strong>bold</strong>', +			2 => '<b>bold</b>' +		); + +		global $phpbb_root_path, $phpEx; + +		foreach ($tests as $style_id => $expected) +		{ +			$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +			$lang = new \phpbb\language\language($lang_loader); +			$user = new \phpbb\user($lang, '\phpbb\datetime'); +			$user->style = array('style_id' => $style_id); + +			$phpbb_container = new phpbb_mock_container_builder; +			$phpbb_container->set('user', $user); + +			$this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/styles.xml', __DIR__ . '/fixtures/styles/'); + +			$renderer = $phpbb_container->get('text_formatter.renderer'); +			$this->assertSame( +				$expected, +				$renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>') +			); +		} +	} + +	public function test_style_inheritance1() +	{ +		global $phpbb_container, $phpbb_root_path, $phpEx; + +		// Style 3 inherits from 2 which inherits from 1. Only style 1 has a bbcode.html +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$user->style = array('style_id' => 3); + +		$phpbb_container = new phpbb_mock_container_builder; +		$phpbb_container->set('user', $user); + +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/'); + +		$renderer = $phpbb_container->get('text_formatter.renderer'); +		$this->assertSame( +			'<strong>bold</strong>', +			$renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>') +		); +	} + +	public function test_style_inheritance2() +	{ +		global $phpbb_container, $phpbb_root_path, $phpEx; + +		// Style 5 inherits from 4, but both have a bbcode.html +		$tests = array( +			4 => '<b>bold</b>', +			5 => '<b class="barplus">bold</b>' +		); + +		foreach ($tests as $style_id => $expected) +		{ +			$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +			$lang = new \phpbb\language\language($lang_loader); +			$user = new \phpbb\user($lang, '\phpbb\datetime'); +			$user->style = array('style_id' => $style_id); + +			$phpbb_container = new phpbb_mock_container_builder; +			$phpbb_container->set('user', $user); + +			$this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/'); + +			$renderer = $phpbb_container->get('text_formatter.renderer'); +			$this->assertSame( +				$expected, +				$renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>') +			); +		} +	} + +	/** +	* @testdox The constructor triggers a core.text_formatter_s9e_renderer_setup event +	*/ +	public function test_setup_event() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); +		$dispatcher +			->expects($this->once()) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_renderer_setup', +				$this->callback(array($this, 'setup_event_callback')) +			) +			->will($this->returnArgument(1)); + +		new \phpbb\textformatter\s9e\renderer( +			$container->get('cache.driver'), +			$container->getParameter('cache.dir'), +			'_foo_renderer', +			$container->get('text_formatter.s9e.factory'), +			$dispatcher +		); +	} + +	public function setup_event_callback($vars) +	{ +		return isset($vars['renderer']) +			&& $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer; +	} + +	/** +	* @testdox render() triggers a core.text_formatter_s9e_render_before and core.text_formatter_s9e_render_after events +	*/ +	public function test_render_event() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); +		$dispatcher +			->expects($this->any()) +			->method('trigger_event') +			->will($this->returnArgument(1)); +		$dispatcher +			->expects($this->at(1)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_render_before', +				$this->callback(array($this, 'render_before_event_callback')) +			) +			->will($this->returnArgument(1)); +		$dispatcher +			->expects($this->at(2)) +			->method('trigger_event') +			->with( +				'core.text_formatter_s9e_render_after', +				$this->callback(array($this, 'render_after_event_callback')) +			) +			->will($this->returnArgument(1)); + +		$renderer = new \phpbb\textformatter\s9e\renderer( +			$container->get('cache.driver'), +			$container->getParameter('cache.dir'), +			'_foo_renderer', +			$container->get('text_formatter.s9e.factory'), +			$dispatcher +		); +		$renderer->render('<t>...</t>'); +	} + +	public function render_before_event_callback($vars) +	{ +		return isset($vars['renderer']) +			&& $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer +			&& isset($vars['xml']) +			&& $vars['xml'] === '<t>...</t>'; +	} + +	public function render_after_event_callback($vars) +	{ +		return isset($vars['html']) +			&& $vars['html'] === '...' +			&& isset($vars['renderer']) +			&& $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer; +	} + +	public function test_get_renderer() +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$renderer = $container->get('text_formatter.renderer'); +		$this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer->get_renderer()); +	} +} diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php new file mode 100644 index 0000000000..555f29cb38 --- /dev/null +++ b/tests/text_formatter/s9e/utils_test.php @@ -0,0 +1,221 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; + +class phpbb_textformatter_s9e_utils_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_unparse_tests +	*/ +	public function test_unparse($original, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$utils     = $container->get('text_formatter.utils'); + +		$this->assertSame($expected, $utils->unparse($original)); +	} + +	public function get_unparse_tests() +	{ +		return array( +			array( +				'<t>Plain text</t>', +				'Plain text' +			), +			array( +				"<t>Multi<br/>\nline</t>", +				"Multi\nline" +			), +			array( +				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>', +				'[b]bold[/b]' +			) +		); +	} + +	/** +	* @dataProvider get_clean_formatting_tests +	*/ +	public function test_clean_formatting($original, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$utils     = $container->get('text_formatter.utils'); + +		$this->assertSame($expected, $utils->clean_formatting($original)); +	} + +	public function get_clean_formatting_tests() +	{ +		return array( +			array( +				'<t>Plain text</t>', +				'Plain text' +			), +			array( +				"<t>Multi<br/>\nline</t>", +				"Multi\nline" +			), +			array( +				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>', +				' bold ' +			) +		); +	} + +	/** +	* @dataProvider get_outermost_quote_authors_tests +	*/ +	public function test_get_outermost_quote_authors($original, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$utils     = $container->get('text_formatter.utils'); +		$parser    = $container->get('text_formatter.parser'); + +		$this->assertSame($expected, $utils->get_outermost_quote_authors($parser->parse($original))); +	} + +	public function get_outermost_quote_authors_tests() +	{ +		return array( +			array( +				'No quotes here', +				array() +			), +			array( +				'[quote="foo"]..[/quote] [quote]..[/quote]', +				array('foo') +			), +			array( +				'[quote="foo"]..[/quote] [quote="bar"]..[/quote]', +				array('foo', 'bar') +			), +			array( +				'[quote="foo"].[quote="baz"]..[/quote].[/quote] [quote="bar"]..[/quote]', +				array('foo', 'bar') +			), +		); +	} + +	/** +	* @dataProvider get_generate_quote_tests +	*/ +	public function test_generate_quote($text, $params, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$utils     = $container->get('text_formatter.utils'); + +		$this->assertSame($expected, $utils->generate_quote($text, $params)); +	} + +	public function get_generate_quote_tests() +	{ +		return array( +			array( +				'...', +				array(), +				'[quote]...[/quote]', +			), +			array( +				'...', +				array('author' => 'Brian Kibler'), +				'[quote="Brian Kibler"]...[/quote]', +			), +			array( +				'...', +				array('author' => 'Brian "Brian Kibler" Kibler of Brian Kibler Gaming'), +				'[quote=\'Brian "Brian Kibler" Kibler of Brian Kibler Gaming\']...[/quote]', +			), +			array( +				'...', +				array('author' => "Brian Kibler Gaming's Brian Kibler"), +				'[quote="Brian Kibler Gaming\'s Brian Kibler"]...[/quote]', +			), +			array( +				'...', +				array('author' => "\\\"'"), +				'[quote="\\\\\\"\'"]...[/quote]', +			), +			array( +				'...', +				array('author' => 'Lots of doubles """ one single \' one backslash \\'), +				'[quote=\'Lots of doubles """ one single \\\' one backslash \\\\\']...[/quote]', +			), +			array( +				'...', +				array('author' => "Lots of singles ''' one double \" one backslash \\"), +				'[quote="Lots of singles \'\'\' one double \\" one backslash \\\\"]...[/quote]', +			), +			array( +				'...', +				array('author' => 'Defaults to doublequotes """\'\'\''), +				'[quote="Defaults to doublequotes \\"\\"\\"\'\'\'"]...[/quote]', +			), +			array( +				'...', +				array( +					'author'  => 'user', +					'post_id' => 123, +					'url'     => 'http://example.org' +				), +				'[quote="user" post_id="123" url="http://example.org"]...[/quote]', +			), +		); +	} + +	/** +	* @dataProvider get_remove_bbcode_tests +	*/ +	public function test_remove_bbcode($original, $name, $depth, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(); +		$parser    = $container->get('text_formatter.parser'); +		$utils     = $container->get('text_formatter.utils'); + +		$parsed = $parser->parse($original); +		$actual = $utils->unparse($utils->remove_bbcode($parsed, $name, $depth)); + +		$this->assertSame($expected, $actual); +	} + +	public function get_remove_bbcode_tests() +	{ +		return array( +			array( +				'Plain text', +				'b', +				1, +				'Plain text' +			), +			array( +				'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', +				'quote', +				0, +				'[b]bold[/b]', +			), +			array( +				'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', +				'quote', +				1, +				'[quote="u0"]q0[/quote][b]bold[/b]', +			), +			array( +				'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', +				'quote', +				2, +				'[quote="u0"][quote="u1"]q1[/quote]q0[/quote][b]bold[/b]', +			), +		); +	} +} diff --git a/tests/text_processing/decode_message_test.php b/tests/text_processing/decode_message_test.php new file mode 100644 index 0000000000..c9c1da52d5 --- /dev/null +++ b/tests/text_processing/decode_message_test.php @@ -0,0 +1,91 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; + +class phpbb_text_processing_decode_message_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_legacy_tests +	*/ +	public function test_legacy($original, $expected, $bbcode_uid = '') +	{ +		$actual = $original; +		decode_message($actual, $bbcode_uid); + +		$this->assertSame($expected, $actual); +	} + +	public function get_legacy_tests() +	{ +		return array( +			array( +				"&<>"'", +				"&<>"'" +			), +			array( +				'<!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->', +				':)' +			), +			/** +			* Fails as per PHPBB3-8420 +			* @link http://tracker.phpbb.com/browse/PHPBB3-8420 +			* +			array( +				'[url=http://example.com:2cpxwbdy]<!-- s:arrow: --><img src="{SMILIES_PATH}/icon_arrow.gif" alt=":arrow:" title="Arrow" /><!-- s:arrow: --> here[/url:2cpxwbdy]', +				'[url=http://example.com] :arrow: here[/url]', +				'2cpxwbdy' +			), +			*/ +		); +	} + +	/** +	* @dataProvider get_text_formatter_tests +	*/ +	public function test_text_formatter($original, $expected) +	{ +		$this->get_test_case_helpers()->set_s9e_services(); + +		$actual = $original; +		decode_message($actual); + +		$this->assertSame($expected, $actual); +	} + +	public function get_text_formatter_tests() +	{ +		return array( +			array( +				"<t>&<>\"'", +				"&<>"'" +			), +			array( +				'<r><E>:)</E></r>', +				':)' +			), +			array( +				"<t>a<br/>\nb</t>", +				"a\nb" +			), +			/** +			* @link http://tracker.phpbb.com/browse/PHPBB3-8420 +			*/ +			array( +				'<r><URL url="http://example.com"><s>[url=http://example.com]</s> <E>:arrow:</E> here<e>[/url]</e></URL></r>', +				'[url=http://example.com] :arrow: here[/url]' +			), +		); +	} +} diff --git a/tests/text_processing/fixtures/empty.xml b/tests/text_processing/fixtures/empty.xml new file mode 100644 index 0000000000..d8206ad124 --- /dev/null +++ b/tests/text_processing/fixtures/empty.xml @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +</dataset> diff --git a/tests/text_processing/fixtures/smilies.xml b/tests/text_processing/fixtures/smilies.xml new file mode 100644 index 0000000000..25b2e60836 --- /dev/null +++ b/tests/text_processing/fixtures/smilies.xml @@ -0,0 +1,443 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>1</value> +			<value>:D</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>1</value> +			<value>1</value> +		</row> +		<row> +			<value>2</value> +			<value>:-D</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>2</value> +			<value>1</value> +		</row> +		<row> +			<value>3</value> +			<value>:grin:</value> +			<value>Very Happy</value> +			<value>icon_e_biggrin.gif</value> +			<value>15</value> +			<value>17</value> +			<value>3</value> +			<value>1</value> +		</row> +		<row> +			<value>4</value> +			<value>:)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>4</value> +			<value>1</value> +		</row> +		<row> +			<value>5</value> +			<value>:-)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>5</value> +			<value>1</value> +		</row> +		<row> +			<value>6</value> +			<value>:smile:</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>6</value> +			<value>1</value> +		</row> +		<row> +			<value>7</value> +			<value>;)</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>7</value> +			<value>1</value> +		</row> +		<row> +			<value>8</value> +			<value>;-)</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>8</value> +			<value>1</value> +		</row> +		<row> +			<value>9</value> +			<value>:wink:</value> +			<value>Wink</value> +			<value>icon_e_wink.gif</value> +			<value>15</value> +			<value>17</value> +			<value>9</value> +			<value>1</value> +		</row> +		<row> +			<value>10</value> +			<value>:(</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>10</value> +			<value>1</value> +		</row> +		<row> +			<value>11</value> +			<value>:-(</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>11</value> +			<value>1</value> +		</row> +		<row> +			<value>12</value> +			<value>:sad:</value> +			<value>Sad</value> +			<value>icon_e_sad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>12</value> +			<value>1</value> +		</row> +		<row> +			<value>13</value> +			<value>:o</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>13</value> +			<value>1</value> +		</row> +		<row> +			<value>14</value> +			<value>:-o</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>14</value> +			<value>1</value> +		</row> +		<row> +			<value>15</value> +			<value>:eek:</value> +			<value>Surprised</value> +			<value>icon_e_surprised.gif</value> +			<value>15</value> +			<value>17</value> +			<value>15</value> +			<value>1</value> +		</row> +		<row> +			<value>16</value> +			<value>:shock:</value> +			<value>Shocked</value> +			<value>icon_eek.gif</value> +			<value>15</value> +			<value>17</value> +			<value>16</value> +			<value>1</value> +		</row> +		<row> +			<value>17</value> +			<value>:?</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>17</value> +			<value>1</value> +		</row> +		<row> +			<value>18</value> +			<value>:-?</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>18</value> +			<value>1</value> +		</row> +		<row> +			<value>19</value> +			<value>:???:</value> +			<value>Confused</value> +			<value>icon_e_confused.gif</value> +			<value>15</value> +			<value>17</value> +			<value>19</value> +			<value>1</value> +		</row> +		<row> +			<value>20</value> +			<value>8-)</value> +			<value>Cool</value> +			<value>icon_cool.gif</value> +			<value>15</value> +			<value>17</value> +			<value>20</value> +			<value>1</value> +		</row> +		<row> +			<value>21</value> +			<value>:cool:</value> +			<value>Cool</value> +			<value>icon_cool.gif</value> +			<value>15</value> +			<value>17</value> +			<value>21</value> +			<value>1</value> +		</row> +		<row> +			<value>22</value> +			<value>:lol:</value> +			<value>Laughing</value> +			<value>icon_lol.gif</value> +			<value>15</value> +			<value>17</value> +			<value>22</value> +			<value>1</value> +		</row> +		<row> +			<value>23</value> +			<value>:x</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>23</value> +			<value>1</value> +		</row> +		<row> +			<value>24</value> +			<value>:-x</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>24</value> +			<value>1</value> +		</row> +		<row> +			<value>25</value> +			<value>:mad:</value> +			<value>Mad</value> +			<value>icon_mad.gif</value> +			<value>15</value> +			<value>17</value> +			<value>25</value> +			<value>1</value> +		</row> +		<row> +			<value>26</value> +			<value>:P</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>26</value> +			<value>1</value> +		</row> +		<row> +			<value>27</value> +			<value>:-P</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>27</value> +			<value>1</value> +		</row> +		<row> +			<value>28</value> +			<value>:razz:</value> +			<value>Razz</value> +			<value>icon_razz.gif</value> +			<value>15</value> +			<value>17</value> +			<value>28</value> +			<value>1</value> +		</row> +		<row> +			<value>29</value> +			<value>:oops:</value> +			<value>Embarrassed</value> +			<value>icon_redface.gif</value> +			<value>15</value> +			<value>17</value> +			<value>29</value> +			<value>1</value> +		</row> +		<row> +			<value>30</value> +			<value>:cry:</value> +			<value>Crying or Very Sad</value> +			<value>icon_cry.gif</value> +			<value>15</value> +			<value>17</value> +			<value>30</value> +			<value>1</value> +		</row> +		<row> +			<value>31</value> +			<value>:evil:</value> +			<value>Evil or Very Mad</value> +			<value>icon_evil.gif</value> +			<value>15</value> +			<value>17</value> +			<value>31</value> +			<value>1</value> +		</row> +		<row> +			<value>32</value> +			<value>:twisted:</value> +			<value>Twisted Evil</value> +			<value>icon_twisted.gif</value> +			<value>15</value> +			<value>17</value> +			<value>32</value> +			<value>1</value> +		</row> +		<row> +			<value>33</value> +			<value>:roll:</value> +			<value>Rolling Eyes</value> +			<value>icon_rolleyes.gif</value> +			<value>15</value> +			<value>17</value> +			<value>33</value> +			<value>1</value> +		</row> +		<row> +			<value>34</value> +			<value>:!:</value> +			<value>Exclamation</value> +			<value>icon_exclaim.gif</value> +			<value>15</value> +			<value>17</value> +			<value>34</value> +			<value>1</value> +		</row> +		<row> +			<value>35</value> +			<value>:?:</value> +			<value>Question</value> +			<value>icon_question.gif</value> +			<value>15</value> +			<value>17</value> +			<value>35</value> +			<value>1</value> +		</row> +		<row> +			<value>36</value> +			<value>:idea:</value> +			<value>Idea</value> +			<value>icon_idea.gif</value> +			<value>15</value> +			<value>17</value> +			<value>36</value> +			<value>1</value> +		</row> +		<row> +			<value>37</value> +			<value>:arrow:</value> +			<value>Arrow</value> +			<value>icon_arrow.gif</value> +			<value>15</value> +			<value>17</value> +			<value>37</value> +			<value>1</value> +		</row> +		<row> +			<value>38</value> +			<value>:|</value> +			<value>Neutral</value> +			<value>icon_neutral.gif</value> +			<value>15</value> +			<value>17</value> +			<value>38</value> +			<value>1</value> +		</row> +		<row> +			<value>39</value> +			<value>:-|</value> +			<value>Neutral</value> +			<value>icon_neutral.gif</value> +			<value>15</value> +			<value>17</value> +			<value>39</value> +			<value>1</value> +		</row> +		<row> +			<value>40</value> +			<value>:mrgreen:</value> +			<value>Mr. Green</value> +			<value>icon_mrgreen.gif</value> +			<value>15</value> +			<value>17</value> +			<value>40</value> +			<value>1</value> +		</row> +		<row> +			<value>41</value> +			<value>:geek:</value> +			<value>Geek</value> +			<value>icon_e_geek.gif</value> +			<value>17</value> +			<value>17</value> +			<value>41</value> +			<value>1</value> +		</row> +		<row> +			<value>42</value> +			<value>:ugeek:</value> +			<value>Uber Geek</value> +			<value>icon_e_ugeek.gif</value> +			<value>17</value> +			<value>18</value> +			<value>42</value> +			<value>1</value> +		</row> +		<row> +			<value>43</value> +			<value>8)</value> +			<value>8)</value> +			<value>custom.gif</value> +			<value>17</value> +			<value>18</value> +			<value>42</value> +			<value>1</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index 057416da33..f2b0d6c78b 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -11,10 +11,8 @@  *  */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../mock/user.php'; -require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php';  class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case  { @@ -24,21 +22,195 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca  		parent::setUp(); +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; +		$config = new \phpbb\config\config(array()); +		set_config(null, null, null, $config); +	} + +	/** +	* @dataProvider get_legacy_tests +	*/ +	public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true) +	{ +		global $cache, $user; + +		global $phpbb_root_path, $phpEx; +  		$cache = new phpbb_mock_cache; +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime'); +		$user->optionset('viewcensors', true); +		$user->optionset('viewflash', true); +		$user->optionset('viewimg', true); +		$user->optionset('viewsmilies', true); + +		$actual = generate_text_for_display($original, $uid, $bitfield, $flags, $censor_text); + +		$this->assertSame($expected, $actual); +	} -		$user = new phpbb_mock_user; +	public function get_legacy_tests() +	{ +		return array( +			array( +				'', +				'' +			), +			array( +				'0', +				'0' +			), +		); +	} + +	public function test_censor_is_restored() +	{ +		global $phpbb_container; + +		$phpbb_container = new phpbb_mock_container_builder; + +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$user = new \phpbb\user($lang, '\phpbb\datetime');  		$user->optionset('viewcensors', false); -		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); +		$config = new \phpbb\config\config(array('allow_nocensors' => true)); + +		$auth = $this->getMock('phpbb\\auth\\auth'); +		$auth->expects($this->any()) +			 ->method('acl_get') +			 ->with('u_chgcensors') +			 ->will($this->returnValue(true)); + +		$phpbb_container->set('user', $user); +		$phpbb_container->set('config', $config); +		$phpbb_container->set('auth', $auth); + +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container); +		$renderer = $phpbb_container->get('text_formatter.renderer'); + +		$original = '<r><CENSOR with="banana">apple</CENSOR></r>'; + +		$renderer->set_viewcensors(false); +		$this->assertSame('apple', $renderer->render($original)); +		$renderer->set_viewcensors(true); +		$this->assertSame('banana', $renderer->render($original)); +		$this->assertSame('apple', generate_text_for_display($original, '', '', 0, false)); +		$this->assertSame('banana', $renderer->render($original), 'The original setting was not restored'); + +		$renderer->set_viewcensors(false); +		$this->assertSame('apple', $renderer->render($original)); +		$this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee)); +		$this->assertSame('apple', $renderer->render($original), 'The original setting was not restored');  	} -	public function test_empty_string() +	/** +	* @dataProvider get_text_formatter_tests +	*/ +	public function test_text_formatter($original, $expected, $censor_text = true, $setup = null)  	{ -		$this->assertSame('', generate_text_for_display('', '', '', 0)); +		global $phpbb_container; + +		$phpbb_container = new phpbb_mock_container_builder; + +		if (isset($setup)) +		{ +			$setup($phpbb_container, $this); +		} + +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container); + +		$this->assertSame($expected, generate_text_for_display($original, '', '', 0, $censor_text));  	} -	public function test_zero_string() +	public function get_text_formatter_tests()  	{ -		$this->assertSame('0', generate_text_for_display('0', '', '', 0)); +		return array( +			array( +				'<t>Plain text</t>', +				'Plain text' +			), +			array( +				'<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL></r>', +				'Hello <a href="http://example.org" class="postlink">world</a>' +			), +			array( +				'<t>&<>"\'</t>', +				'&<>"\'' +			), +			array( +				'<r><CENSOR with="banana">apple</CENSOR></r>', +				'banana', +				true +			), +			array( +				'<r><CENSOR with="banana">apple</CENSOR></r>', +				'apple', +				false +			), +			array( +				'<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', +				'<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>' +			), +			array( +				'<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', +				'http://localhost/foo.swf', +				true, +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewflash', false); + +					$phpbb_container->set('user', $user); +				} +			), +			array( +				'<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', +				'<img src="http://localhost/mrgreen.gif" alt="Image">' +			), +			array( +				'<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', +				'<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', +				true, +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('viewimg', false); + +					$phpbb_container->set('user', $user); +				} +			), +			array( +				'<r><E>:)</E></r>', +				'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">' +			), +			array( +				'<r><E>:)</E></r>', +				':)', +				true, +				function ($phpbb_container) +				{ +					global $phpbb_root_path, $phpEx; + +					$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +					$lang = new \phpbb\language\language($lang_loader); +					$user = new \phpbb\user($lang, '\phpbb\datetime'); +					$user->optionset('smilies', false); + +					$phpbb_container->set('user', $user); +				} +			), +		);  	}  } diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php new file mode 100644 index 0000000000..105e8da86b --- /dev/null +++ b/tests/text_processing/generate_text_for_edit_test.php @@ -0,0 +1,92 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; + +class phpbb_text_processing_generate_text_for_edit_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_legacy_tests +	*/ +	public function test_legacy($original, $expected, $uid = '', $flags = 0) +	{ +		global $cache, $user, $phpbb_dispatcher; + +		$cache = new phpbb_mock_cache; +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; + +		$user = new phpbb_mock_user; +		$user->optionset('viewcensors', false); + +		$return = generate_text_for_edit($original, $uid, $flags); + +		$this->assertSame($expected, $return['text']); +	} + +	public function get_legacy_tests() +	{ +		return array( +			array( +				'', +				'' +			), +			array( +				'0', +				'0' +			), +			array( +				'Hello [url=http://example.org:1f4coh9x]world[/url:1f4coh9x] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->', +				'Hello [url=http://example.org]world[/url] :)', +				'1f4coh9x', +				0 +			), +			array( +				"&<>"'", +				"&<>"'" +			) +		); +	} + +	/** +	* @dataProvider get_text_formatter_tests +	*/ +	public function test_text_formatter($original, $expected) +	{ +		global $phpbb_dispatcher; +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; +		$this->get_test_case_helpers()->set_s9e_services(); + +		$return = generate_text_for_edit($original, '', 0); + +		$this->assertSame($expected, $return['text']); +	} + +	public function get_text_formatter_tests() +	{ +		return array( +			array( +				'<t>Plain text</t>', +				'Plain text' +			), +			array( +				'<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL> <E>:)</E></r>', +				'Hello [url=http://example.org]world[/url] :)' +			), +			array( +				'<t>&<>"\'</t>', +				"&<>"'" +			) +		); +	} +} diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php new file mode 100644 index 0000000000..474f6d8f0f --- /dev/null +++ b/tests/text_processing/generate_text_for_storage_test.php @@ -0,0 +1,183 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_compatibility.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_case +{ +	public function setUp() +	{ +		global $config, $phpbb_container, $phpbb_dispatcher; + +		parent::setUp(); + +		$config = new \phpbb\config\config(array()); +		set_config(null, null, null, $config); + +		$phpbb_container = new phpbb_mock_container_builder; +		$phpbb_container->set('config', $config); +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container); + +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher; +	} + +	/** +	* @dataProvider get_text_formatter_tests +	*/ +	public function test_text_formatter($original, $expected, $allow_bbcode, $allow_urls, $allow_smilies, $allow_img_bbcode, $allow_flash_bbcode, $allow_quote_bbcode, $allow_url_bbcode, $setup = null) +	{ +		$actual   = $original; +		$uid      = ''; +		$bitfield = ''; +		$flags    = 0; + +		if (isset($setup)) +		{ +			$setup(); +		} + +		generate_text_for_storage($actual, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies, $allow_img_bbcode, $allow_flash_bbcode, $allow_quote_bbcode, $allow_url_bbcode); + +		$this->assertSame($expected, $actual); +	} + +	public function get_text_formatter_tests() +	{ +		return array( +			array( +				'Hello world', +				'<t>Hello world</t>', +				true, +				true, +				true, +				true, +				true, +				true, +				true, +			), +			array( +				'Hello [url=http://example.org]world[/url] :)', +				'<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL> <E>:)</E></r>', +				true, +				true, +				true, +				true, +				true, +				true, +				true, +			), +			array( +				'&<>"\'', +				'<t>&<>"\'</t>', +				true, +				true, +				true, +				true, +				true, +				true, +				true, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<t>[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]</t>', +				false, +				false, +				false, +				false, +				false, +				false, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r><B><s>[b]</s>..<e>[/b]</e></B> http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]</r>', +				true, +				false, +				false, +				false, +				false, +				false, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r>[b]..[/b] <URL url="http://example.org">http://example.org</URL> :) [img]<URL url="http://example.org/img.png">http://example.org/img.png</URL>[/img] [flash=123,123]<URL url="http://example.org/flash.swf">http://example.org/flash.swf</URL>[/flash] [quote]...[/quote] [url]<URL url="http://example.org">http://example.org</URL>[/url]</r>', +				false, +				true, +				false, +				false, +				false, +				false, +				true, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r>[b]..[/b] http://example.org <E>:)</E> [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]</r>', +				false, +				false, +				true, +				false, +				false, +				false, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r><B><s>[b]</s>..<e>[/b]</e></B> http://example.org :) <IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG> [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]</r>', +				true, +				false, +				false, +				true, +				false, +				false, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r><B><s>[b]</s>..<e>[/b]</e></B> http://example.org :) [img]http://example.org/img.png[/img] <FLASH height="123" url="http://example.org/flash.swf" width="123"><s>[flash=123,123]</s>http://example.org/flash.swf<e>[/flash]</e></FLASH> [quote]...[/quote] [url]http://example.org[/url]</r>', +				true, +				false, +				false, +				false, +				true, +				false, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r><B><s>[b]</s>..<e>[/b]</e></B> http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] <QUOTE><s>[quote]</s>...<e>[/quote]</e></QUOTE> [url]http://example.org[/url]</r>', +				true, +				false, +				false, +				false, +				false, +				true, +				false, +			), +			array( +				'[b]..[/b] http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] [url]http://example.org[/url]', +				'<r><B><s>[b]</s>..<e>[/b]</e></B> http://example.org :) [img]http://example.org/img.png[/img] [flash=123,123]http://example.org/flash.swf[/flash] [quote]...[/quote] <URL url="http://example.org"><s>[url]</s>http://example.org<e>[/url]</e></URL></r>', +				true, +				false, +				false, +				false, +				false, +				false, +				true, +			), +		); +	} +} diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php new file mode 100644 index 0000000000..bee1b3fca3 --- /dev/null +++ b/tests/text_processing/message_parser_test.php @@ -0,0 +1,543 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/bbcode.php'; +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../phpBB/includes/message_parser.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_text_processing_message_parser_test extends phpbb_test_case +{ +	public static function setUpBeforeClass() +	{ +		parent::setUpBeforeClass(); + +		// Set up an intercepting proxy for getimagesize() calls +		stream_wrapper_unregister('http'); +		stream_wrapper_register('http', __CLASS__ . '_proxy'); +	} + +	public static function tearDownAfterClass() +	{ +		parent::tearDownAfterClass(); +		stream_wrapper_restore('http'); +	} + +	protected function prepare_s9e_services($setup = null) +	{ +		global $config, $phpbb_container, $user; + +		$config = new \phpbb\config\config(array('max_poll_options' => 999)); + +		$map = array( +			array('MAX_FLASH_HEIGHT_EXCEEDED', 123, 'Your flash files may only be up to 123 pixels high.'), +			array('MAX_FLASH_WIDTH_EXCEEDED', 456, 'Your flash files may only be up to 456 pixels wide.'), +			array('MAX_FONT_SIZE_EXCEEDED', 120, 'You may only use fonts up to size 120.'), +			array('MAX_FONT_SIZE_EXCEEDED', 200, 'You may only use fonts up to size 200.'), +			array('MAX_IMG_HEIGHT_EXCEEDED', 12, 'Your images may only be up to 12 pixels high.'), +			array('MAX_IMG_WIDTH_EXCEEDED', 34, 'Your images may only be up to 34 pixels wide.'), +			array('TOO_MANY_SMILIES', 3, 'Your message contains too many smilies. The maximum number of smilies allowed is 3.'), +			array('TOO_MANY_URLS', 2, 'Your message contains too many URLs. The maximum number of URLs allowed is 2.'), +			array('UNAUTHORISED_BBCODE', '[flash]', 'You cannot use certain BBCodes: [flash].'), +			array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'), +			array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'), +			array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'), +			array('UNABLE_GET_IMAGE_SIZE', 'It was not possible to determine the dimensions of the image.'), +		); + +		$user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(); +		$user->expects($this->any()) +		     ->method('lang') +		     ->will($this->returnValueMap($map)); + +		$user->data = array( +			'is_bot' => false, +			'is_registered' => true, +			'user_id' => 2, +		); +		$user->style = array('style_id' => 1); + +		$user->lang = array( +			'NO_POLL_TITLE' => 'You have to enter a poll title.', +			'POLL_TITLE_TOO_LONG' => 'The poll title must contain fewer than 100 characters.', +			'POLL_TITLE_COMP_TOO_LONG' => 'The parsed size of your poll title is too large, consider removing BBCodes or smilies.', +			'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.', +			'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.', +			'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.', +		); + +		$phpbb_container = new phpbb_mock_container_builder; +		$phpbb_container->set('user', $user); +		$phpbb_container->set('config', $config); + +		if (isset($setup)) +		{ +			$setup($phpbb_container, $this); +		} + +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container); +	} + +	/** +	* @dataProvider get_test_polls +	*/ +	public function test_parse_poll($poll, $expected, $warn_msg = array()) +	{ +		$this->prepare_s9e_services(); + +		$message_parser = new parse_message('Me[i]s[/i]sage'); + +		// Add some default values +		$poll += array( +			'poll_length'		=> 123, +			'poll_start'		=> 123, +			'poll_last_vote'	=> 123, +			'poll_vote_change'	=> true, +			'enable_bbcode'		=> true, +			'enable_urls'		=> true, +			'enable_smilies'	=> true, +			'img_status'		=> true +		); + +		$message_parser->parse_poll($poll); +		$this->assertSame($expected, array_intersect_key($poll, $expected)); + +		$this->assertSame( +			'<r>Me<I><s>[i]</s>s<e>[/i]</e></I>sage</r>', +			$message_parser->parse(true, true, true, true, true, true, true, false) +		); + +		$this->assertSame($warn_msg, $message_parser->warn_msg); +	} + +	public function get_test_polls() +	{ +		return array( +			array( +				array( +					'poll_title' => 'foo [b]bar[/b] baz', +					'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]", +					'poll_max_options'	=> 3, +					'poll_options_size' => 3 +				), +				array( +					'poll_title' => '<r>foo <B><s>[b]</s>bar<e>[/b]</e></B> baz</r>', +					'poll_option_text' => "<r><I><s>[i]</s>foo<e>[/i]</e></I></r>\n<t>bar</t>\n<r><I><s>[i]</s>baz<e>[/i]</e></I></r>", +					'poll_options' => array( +						'<r><I><s>[i]</s>foo<e>[/i]</e></I></r>', +						'<t>bar</t>', +						'<r><I><s>[i]</s>baz<e>[/i]</e></I></r>' +					) +				) +			), +			array( +				array( +					'poll_title' => 'xxx', +					'poll_option_text' => "[quote]quote[/quote]\n:)", +					'poll_max_options'	=> 2, +					'poll_options_size' => 2 +				), +				array( +					'poll_title' => '<t>xxx</t>', +					'poll_option_text' => "<t>[quote]quote[/quote]</t>\n<r><E>:)</E></r>", +					'poll_options' => array( +						'<t>[quote]quote[/quote]</t>', +						'<r><E>:)</E></r>' +					) +				), +				array('You cannot use certain BBCodes: [quote].') +			), +			array( +				array( +					'poll_title' => 'xxx', +					'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)", +					'poll_max_options'	=> 2, +					'poll_options_size' => 2 +				), +				array( +					'poll_title' => '<t>xxx</t>', +					'poll_option_text' => "<t>[flash=12,34]http://example.org/x.swf[/flash]</t>\n<r><E>:)</E></r>", +					'poll_options' => array( +						'<t>[flash=12,34]http://example.org/x.swf[/flash]</t>', +						'<r><E>:)</E></r>' +					) +				), +				array('You cannot use certain BBCodes: [flash].') +			), +			array( +				array( +					'poll_title' => 'xxx', +					'poll_option_text' => "[b]x\ny[/b]", +					'poll_max_options'	=> 2, +					'poll_options_size' => 2 +				), +				array( +					'poll_title' => '<t>xxx</t>', +					'poll_option_text' => "<r><B><s>[b]</s>x</B></r>\n<t>y[/b]</t>", +					'poll_options' => array( +						'<r><B><s>[b]</s>x</B></r>', +						'<t>y[/b]</t>', +					) +				) +			), +		); +	} + +	/** +	* @dataProvider get_test_cases +	*/ +	public function test_options($original, $expected, array $args, $setup = null, $warn_msg = array()) +	{ +		$this->prepare_s9e_services($setup); + +		$message_parser = new parse_message($original); +		call_user_func_array(array($message_parser, 'parse'), $args); + +		$this->assertSame($expected, $message_parser->message); +		$this->assertSame($warn_msg, $message_parser->warn_msg); +	} + +	public function get_test_cases() +	{ +		return array( +			array( +				'[b]bold[/b]', +				'<r><B><s>[b]</s>bold<e>[/b]</e></B></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'[b]bold[/b]', +				'<t>[b]bold[/b]</t>', +				array(false, true, true, true, true, true, true) +			), +			array( +				'http://example.org', +				'<r><URL url="http://example.org">http://example.org</URL></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'http://example.org', +				'<t>http://example.org</t>', +				array(true, false, true, true, true, true, true) +			), +			array( +				':)', +				'<r><E>:)</E></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				':)', +				'<t>:)</t>', +				array(true, true, false, true, true, true, true) +			), +			array( +				'[url=http://example.org][img]http://example.org/img.png[/img][/url]', +				'<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'[url=http://example.org][img]http://example.org/img.png[/img][/url]', +				'<r><URL url="http://example.org"><s>[url=http://example.org]</s>[img]http://example.org/img.png[/img]<e>[/url]</e></URL></r>', +				array(true, true, true, false, true, true, true), +				null, +				array('You cannot use certain BBCodes: [img].') +			), +			array( +				'[flash=12,34]http://example.org/foo.swf[/flash]', +				'<r><FLASH height="34" url="http://example.org/foo.swf" width="12"><s>[flash=12,34]</s><URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL><e>[/flash]</e></FLASH></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'[flash=12,34]http://example.org/foo.swf[/flash]', +				'<r>[flash=12,34]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>', +				array(true, true, true, true, false, true, true), +				null, +				array('You cannot use certain BBCodes: [flash].') +			), +			array( +				'[quote="foo"]bar :)[/quote]', +				'<r><QUOTE author="foo"><s>[quote="foo"]</s>bar <E>:)</E><e>[/quote]</e></QUOTE></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'[quote="foo"]bar :)[/quote]', +				'<r>[quote="foo"]bar <E>:)</E>[/quote]</r>', +				array(true, true, true, true, true, false, true), +				null, +				array('You cannot use certain BBCodes: [quote].') +			), +			array( +				'[url=http://example.org][img]http://example.org/img.png[/img][/url]', +				'<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>', +				array(true, true, true, true, true, true, true) +			), +			array( +				'[url=http://example.org][img]http://example.org/img.png[/img][/url]', +				'<r>[url=http://example.org]<IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG>[/url]</r>', +				array(true, true, true, true, true, true, false), +				null, +				array('You cannot use certain BBCodes: [url].') +			), +			array( +				'[size=200]200[/size]', +				'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_font_size', 200); +				} +			), +			array( +				'[size=200]200[/size]', +				'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_font_size', 0); +				} +			), +			array( +				'[size=2000]2000[/size]', +				'<t>[size=2000]2000[/size]</t>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_font_size', 200); +				}, +				array('You may only use fonts up to size 200.') +			), +			array( +				'[size=0]0[/size]', +				'<t>[size=0]0[/size]</t>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_font_size', 200); +				} +			), +			array( +				'[size=200]200[/size]', +				'<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_font_size', 200); +				} +			), +			array( +				'[size=200]200[/size]', +				'<t>[size=200]200[/size]</t>', +				array(true, true, true, true, true, true, true, true, 'sig'), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_font_size', 120); +				}, +				array('You may only use fonts up to size 120.') +			), +			array( +				'[img]http://example.org/100x100.png[/img]', +				'<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_height', 12); +				}, +				array('Your images may only be up to 12 pixels high.') +			), +			array( +				'[img]http://example.org/100x100.png[/img]', +				'<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_width', 34); +				}, +				array('Your images may only be up to 34 pixels wide.') +			), +			array( +				'[img]http://example.org/100x100.png[/img]', +				'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_height', 0); +					$phpbb_container->get('config')->set('max_post_img_width', 0); +				} +			), +			array( +				'[img]http://example.org/100x100.png[/img]', +				'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_height', 100); +					$phpbb_container->get('config')->set('max_post_img_width', 100); +				} +			), +			array( +				'[img]http://example.org/100x100.png[/img]', +				'<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_img_height', 12); +					$phpbb_container->get('config')->set('max_sig_img_width', 34); +				} +			), +			array( +				'[img]http://example.org/404.png[/img]', +				'<r>[img]<URL url="http://example.org/404.png">http://example.org/404.png</URL>[/img]</r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_height', 12); +				}, +				array('It was not possible to determine the dimensions of the image.') +			), +			array( +				'[flash=999,999]http://example.org/foo.swf[/flash]', +				'<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_height', 123); +				}, +				array('Your flash files may only be up to 123 pixels high.') +			), +			array( +				'[flash=999,999]http://example.org/foo.swf[/flash]', +				'<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>', +				array(true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_img_width', 456); +				}, +				array('Your flash files may only be up to 456 pixels wide.') +			), +			array( +				':) :) :)', +				'<r><E>:)</E> <E>:)</E> <E>:)</E></r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_smilies', 3); +				} +			), +			array( +				':) :) :) :)', +				'<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_smilies', 3); +				}, +				array('Your message contains too many smilies. The maximum number of smilies allowed is 3.') +			), +			array( +				':) :) :) :)', +				'<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_smilies', 0); +				} +			), +			array( +				':) :) :) :)', +				'<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_smilies', 3); +				} +			), +			array( +				':) :) :) :)', +				'<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>', +				array(true, true, true, true, true, true, true, true, 'sig'), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_smilies', 3); +				}, +				array('Your message contains too many smilies. The maximum number of smilies allowed is 3.') +			), +			array( +				'http://example.org http://example.org http://example.org', +				'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> http://example.org</r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_urls', 2); +				}, +				array('Your message contains too many URLs. The maximum number of URLs allowed is 2.') +			), +			array( +				'http://example.org http://example.org http://example.org', +				'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_post_urls', 0); +				} +			), +			array( +				'http://example.org http://example.org http://example.org', +				'<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>', +				array(true, true, true, true, true, true, true, true), +				function ($phpbb_container) +				{ +					$phpbb_container->get('config')->set('max_sig_urls', 2); +				} +			), +		); +	} +} + +class phpbb_text_processing_message_parser_test_proxy +{ +	protected $response; + +	public function stream_open($url) +	{ +		if (strpos($url, '100x100')) +		{ +			// Return a 100 x 100 PNG image +			$this->response = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAE0lEQVR4AWOgKxgFo2AUjIJRAAAFeAABHs0ozQAAAABJRU5ErkJggg=='); +		} +		else +		{ +			$this->response = '404 not found'; +		} + +		return true; +	} + +	public function stream_stat() +	{ +		return false; +	} + +	public function stream_read($len) +	{ +		$chunk = substr($this->response, 0, $len); +		$this->response = substr($this->response, $len); + +		return $chunk; +	} + +	public function stream_eof() +	{ +		return ($this->response === false); +	} +} diff --git a/tests/text_processing/smilies_test.php b/tests/text_processing/smilies_test.php new file mode 100644 index 0000000000..3bbe065d36 --- /dev/null +++ b/tests/text_processing/smilies_test.php @@ -0,0 +1,52 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; + +class phpbb_text_processing_smilies_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_text_formatter_tests +	*/ +	public function test_text_formatter($original, $expected) +	{ +		$container = $this->get_test_case_helpers()->set_s9e_services(null, __DIR__ . '/fixtures/smilies.xml'); +		$parser = $container->get('text_formatter.parser'); +		$renderer = $container->get('text_formatter.renderer'); + +		$this->assertSame($expected, $renderer->render($parser->parse($original))); +	} + +	public function get_text_formatter_tests() +	{ +		return array( +			array( +				':) beginning', +				'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"> beginning' +			), +			array( +				'end :)', +				'end <img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">' +			), +			array( +				':)', +				'<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">' +			), +			array( +				'xx (18) 8) xx', +				'xx (18) <img class="smilies" src="phpBB/images/smilies/custom.gif" alt="8)" title="8)"> xx' +			), +		); +	} +} diff --git a/tests/text_processing/strip_bbcode_test.php b/tests/text_processing/strip_bbcode_test.php new file mode 100644 index 0000000000..827d8d4a52 --- /dev/null +++ b/tests/text_processing/strip_bbcode_test.php @@ -0,0 +1,42 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; + +class phpbb_text_processing_strip_bbcode_test extends phpbb_test_case +{ +	public function test_legacy() +	{ +		$original = '[b:20m4ill1]bold[/b:20m4ill1]'; +		$expected = ' bold '; + +		$actual = $original; +		strip_bbcode($actual); + +		$this->assertSame($expected, $actual, '20m4ill1'); +	} + +	public function test_s9e() +	{ +		$phpbb_container = $this->get_test_case_helpers()->set_s9e_services(); + +		$original = '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>'; +		$expected = ' bold '; + +		$actual = $original; +		strip_bbcode($actual); + +		$this->assertSame($expected, $actual); +	} +} diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.html b/tests/text_processing/tickets_data/PHPBB3-10002.html new file mode 100644 index 0000000000..82990b2253 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10002.html @@ -0,0 +1,2 @@ +<blockquote class="uncited"><div><ul><li>one +<blockquote class="uncited"><div><ul><li>two</li></ul></div></blockquote></li></ul></div></blockquote>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.txt b/tests/text_processing/tickets_data/PHPBB3-10002.txt new file mode 100644 index 0000000000..fe2f29073f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10002.txt @@ -0,0 +1,2 @@ +[quote][list][*]one +[quote][list][*]two[/list][/quote]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.html b/tests/text_processing/tickets_data/PHPBB3-10122.html new file mode 100644 index 0000000000..f0fb6115b2 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10122.html @@ -0,0 +1 @@ +<ul style="list-style-type: none"><li>This is my indented text</li></ul>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.txt b/tests/text_processing/tickets_data/PHPBB3-10122.txt new file mode 100644 index 0000000000..a5e059df66 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10122.txt @@ -0,0 +1 @@ +[list=none][*]This is my indented text[/list]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10268.html b/tests/text_processing/tickets_data/PHPBB3-10268.html new file mode 100644 index 0000000000..c89e63f9a3 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10268.html @@ -0,0 +1,4 @@ +<blockquote><div><cite><a href="http://phpbb.com" class="postlink">http://phpbb.com</a> wrote:</cite>...</div></blockquote> +<blockquote><div><cite><a href="http://phpbb.com" class="postlink"> http://phpbb.com</a> wrote:</cite>...</div></blockquote> +<span style="font-weight: bold"><a href="http://phpbb.com" class="postlink">http://phpbb.com</a></span><br> +<span style="font-weight: bold"> <a href="http://phpbb.com" class="postlink">http://phpbb.com</a></span><br> diff --git a/tests/text_processing/tickets_data/PHPBB3-10268.txt b/tests/text_processing/tickets_data/PHPBB3-10268.txt new file mode 100644 index 0000000000..b4e49c9454 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10268.txt @@ -0,0 +1,4 @@ +[quote="http://phpbb.com"]...[/quote] +[quote=" http://phpbb.com"]...[/quote] +[b]http://phpbb.com[/b] +[b] http://phpbb.com[/b] diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.html b/tests/text_processing/tickets_data/PHPBB3-10425.html new file mode 100644 index 0000000000..522b2f8858 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10425.html @@ -0,0 +1,3 @@ +<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br> +<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br> +<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">link</a>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.txt b/tests/text_processing/tickets_data/PHPBB3-10425.txt new file mode 100644 index 0000000000..d93c0446b6 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10425.txt @@ -0,0 +1,3 @@ +http://ar.wikipedia.org/wiki/الصفحة_الرئيسية +[url]http://ar.wikipedia.org/wiki/الصفحة_الرئيسية[/url] +[url=http://ar.wikipedia.org/wiki/الصفحة_الرئيسية]link[/url]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.html b/tests/text_processing/tickets_data/PHPBB3-10587.html new file mode 100644 index 0000000000..dd0a483244 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10587.html @@ -0,0 +1,2 @@ +<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&action=brackets" class="postlink">http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets</a><br> +<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&action=brackets" class="postlink">link</a>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.txt b/tests/text_processing/tickets_data/PHPBB3-10587.txt new file mode 100644 index 0000000000..f81a35eb5f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10587.txt @@ -0,0 +1,2 @@ +[url]http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets[/url] +[url="http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets"]link[/url]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.html b/tests/text_processing/tickets_data/PHPBB3-10922.html new file mode 100644 index 0000000000..3ff117f171 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10922.html @@ -0,0 +1,9 @@ +<a href="mailto:user@example.org">user@example.org</a><br> +<a href="mailto:user@example.org">...</a><br> +<a href="mailto:user@example.org">...</a><br> +<a href="mailto:user@example.org?subject=Hello">...</a><br> +<a href="mailto:user@example.org?subject=Hi%20there">user@example.org</a><br> +<a href="mailto:user@example.org?body=Hi%20there">user@example.org</a><br> +<a href="mailto:user@example.org?subject=Hello&body=Sent%20from%20phpBB">user@example.org</a><br> +<a href="mailto:user@example.org?subject=Hello&body=Sent%20from%20phpBB">user@example.org</a><br> +<a href="mailto:user@example.org?subject=Hello&body=Sent%20from%20phpBB">...</a><br> diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.txt b/tests/text_processing/tickets_data/PHPBB3-10922.txt new file mode 100644 index 0000000000..e533ce6ed5 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10922.txt @@ -0,0 +1,9 @@ +[email]user@example.org[/email] +[email=user@example.org]...[/email] +[email=user@example.org ]...[/email] +[email=user@example.org subject="Hello"]...[/email] +[email subject="Hi there"]user@example.org[/email] +[email body="Hi there"]user@example.org[/email] +[email subject="Hello" body="Sent from phpBB"]user@example.org[/email] +[email body="Sent from phpBB" subject="Hello"]user@example.org[/email] +[email body="Sent from phpBB" subject="Hello" email="user@example.org"]...[/email] diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.html b/tests/text_processing/tickets_data/PHPBB3-10989.html new file mode 100644 index 0000000000..f003ad3dfa --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10989.html @@ -0,0 +1,8 @@ +<blockquote><div><cite>Lorem wrote:</cite>[quote="Lorem"<blockquote class="uncited"><div> Suspendisse iaculis porta tempor. Nulla.</div></blockquote> + Nullam a tortor sit amet.</div></blockquote> + Proin ac mi eget magna. + +<blockquote><div><cite>Lorem wrote:</cite>Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.</div></blockquote> + +<br> +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.txt b/tests/text_processing/tickets_data/PHPBB3-10989.txt new file mode 100644 index 0000000000..dc2430f210 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10989.txt @@ -0,0 +1,8 @@ +[quote="Lorem"][quote="Lorem"[quote] Suspendisse iaculis porta tempor. Nulla.[/quote] + Nullam a tortor sit amet.[/quote] + Proin ac mi eget magna. + +[quote="Lorem"]Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.[/quote] + + +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.html b/tests/text_processing/tickets_data/PHPBB3-11153.html new file mode 100644 index 0000000000..0f67ac4bc0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.html @@ -0,0 +1 @@ +<a href="mailto:user@example.org">...</a>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.txt b/tests/text_processing/tickets_data/PHPBB3-11153.txt new file mode 100644 index 0000000000..d2794978d9 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.txt @@ -0,0 +1 @@ +[myemail=user@example.org]...[/myemail]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.xml b/tests/text_processing/tickets_data/PHPBB3-11153.xml new file mode 100644 index 0000000000..a7fc69520b --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>myemail</value> +			<value></value> +			<value>1</value> +			<value>[myemail={EMAIL}]{TEXT}[/myemail]</value> +			<value><![CDATA[<a href="mailto:{EMAIL}">{TEXT}</a>]]></value> +			<value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))\](.*?)\[/myemail\]!ies]]></value> +			<value><![CDATA['[myemail='.$this->bbcode_specialchars('${1}').':$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${2}')).'[/myemail:$uid]']]></value> +			<value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)):$uid\](.*?)\[/myemail:$uid\]!s]]></value> +			<value><![CDATA[<a href="mailto:${1}">${2}</a>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-11742.html b/tests/text_processing/tickets_data/PHPBB3-11742.html new file mode 100644 index 0000000000..e7890eef19 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11742.html @@ -0,0 +1 @@ +<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>	tab</code></pre></div>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11742.txt b/tests/text_processing/tickets_data/PHPBB3-11742.txt new file mode 100644 index 0000000000..db72e5dda0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11742.txt @@ -0,0 +1 @@ +[code]	tab[/code]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.html b/tests/text_processing/tickets_data/PHPBB3-12195.html new file mode 100644 index 0000000000..d8e0f8d523 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-12195.html @@ -0,0 +1 @@ +<a href="//example.org/" class="postlink"><img src="//example.org/img.png" alt="Image"></a>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.txt b/tests/text_processing/tickets_data/PHPBB3-12195.txt new file mode 100644 index 0000000000..b66dbd5d96 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-12195.txt @@ -0,0 +1 @@ +[url=//example.org/][img]//example.org/img.png[/img][/url]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13425.html b/tests/text_processing/tickets_data/PHPBB3-13425.html new file mode 100644 index 0000000000..9a042dc558 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13425.html @@ -0,0 +1 @@ +<blockquote class="uncited"><div><img class="smilies" src="phpBB/images/smilies/icon_lol.gif" alt=":lol:" title="Laughing"> starts with a smiley</div></blockquote>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13425.txt b/tests/text_processing/tickets_data/PHPBB3-13425.txt new file mode 100644 index 0000000000..8456410df5 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13425.txt @@ -0,0 +1 @@ +[quote]:lol: starts with a smiley[/quote]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13425.xml b/tests/text_processing/tickets_data/PHPBB3-13425.xml new file mode 100644 index 0000000000..cbdcaa7fb7 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13425.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>22</value> +			<value>:lol:</value> +			<value>Laughing</value> +			<value>icon_lol.gif</value> +			<value>15</value> +			<value>17</value> +			<value>22</value> +			<value>1</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.html b/tests/text_processing/tickets_data/PHPBB3-13641.html new file mode 100644 index 0000000000..1bd1c06dbb --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.html @@ -0,0 +1 @@ +<code>[color=#FF0000]</code> - <span style="color: #FF0000">red</span>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.txt b/tests/text_processing/tickets_data/PHPBB3-13641.txt new file mode 100644 index 0000000000..58f324715e --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.txt @@ -0,0 +1 @@ +[c][color=#FF0000][/c] - [color=#FF0000]red[/color]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.xml b/tests/text_processing/tickets_data/PHPBB3-13641.xml new file mode 100644 index 0000000000..451c5c69cd --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>c</value> +			<value></value> +			<value>1</value> +			<value>[c]{TEXT}[/c]</value> +			<value><![CDATA[<code>{TEXT}</code>]]></value> +			<value><\[/c\]!ies]]></value> +			<value><![CDATA['[c:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/c:$uid]']]></value> +			<value><\[/c:$uid\]!s]]></value> +			<value><![CDATA[<code>${1}</code>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.before.php b/tests/text_processing/tickets_data/PHPBB3-3981.before.php new file mode 100644 index 0000000000..1c326b52af --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.before.php @@ -0,0 +1,21 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +function before_assert_phpbb3_3981($vars) +{ +	if (!function_exists('idn_to_ascii')) +	{ +		extract($vars); +		$test->markTestSkipped('International URLs need idn_to_ascii()'); +	} +} diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.html b/tests/text_processing/tickets_data/PHPBB3-3981.html new file mode 100644 index 0000000000..e5f1b4561d --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.html @@ -0,0 +1 @@ +<a href="http://www.xn--ndaaa.com" class="postlink">http://www.ööö.com</a>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.txt b/tests/text_processing/tickets_data/PHPBB3-3981.txt new file mode 100644 index 0000000000..976823f1d1 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.txt @@ -0,0 +1 @@ +[url]http://www.ööö.com[/url]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.html b/tests/text_processing/tickets_data/PHPBB3-7187.html new file mode 100644 index 0000000000..9138779d29 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.html @@ -0,0 +1 @@ +<blockquote class="uncited"><div><img class="smilies" src="phpBB/images/smilies/icon_e_geek.gif" alt=":geek:" title="Geek"> <img class="smilies" src="phpBB/images/smilies/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek"></div></blockquote>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.txt b/tests/text_processing/tickets_data/PHPBB3-7187.txt new file mode 100644 index 0000000000..584151a083 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.txt @@ -0,0 +1 @@ +[quote]:geek: :ugeek:[/quote]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.xml b/tests/text_processing/tickets_data/PHPBB3-7187.xml new file mode 100644 index 0000000000..d270b12619 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>41</value> +			<value>:geek:</value> +			<value>Geek</value> +			<value>icon_e_geek.gif</value> +			<value>17</value> +			<value>17</value> +			<value>41</value> +			<value>1</value> +		</row> +		<row> +			<value>42</value> +			<value>:ugeek:</value> +			<value>Uber Geek</value> +			<value>icon_e_ugeek.gif</value> +			<value>17</value> +			<value>18</value> +			<value>42</value> +			<value>1</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.after.php b/tests/text_processing/tickets_data/PHPBB3-7275.after.php new file mode 100644 index 0000000000..99f41d7839 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.after.php @@ -0,0 +1,19 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +function after_assert_phpbb3_7275($vars) +{ +	extract($vars); +	decode_message($parsed_text); +	$test->assertSame($original, $parsed_text); +} diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.html b/tests/text_processing/tickets_data/PHPBB3-7275.html new file mode 100644 index 0000000000..12502833fd --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.html @@ -0,0 +1 @@ +<div align="center"><img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"></div>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.txt b/tests/text_processing/tickets_data/PHPBB3-7275.txt new file mode 100644 index 0000000000..8de97d67e0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.txt @@ -0,0 +1 @@ +[center]:)[/center]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.xml b/tests/text_processing/tickets_data/PHPBB3-7275.xml new file mode 100644 index 0000000000..9e979afffb --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>center</value> +			<value></value> +			<value>1</value> +			<value>[center]{TEXT}[/center]</value> +			<value><![CDATA[<div align="center">{TEXT}</div>]]></value> +			<value>!\[center\](.*?)\[/center\]!ies</value> +			<value><![CDATA['[center:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/center:$uid]']]></value> +			<value>!\[center:$uid\](.*?)\[/center:$uid\]!s</value> +			<value><![CDATA[<div align="center">${1}</div>]]></value> +		</row> +	</table> + +	<table name="phpbb_smilies"> +		<column>smiley_id</column> +		<column>code</column> +		<column>emotion</column> +		<column>smiley_url</column> +		<column>smiley_width</column> +		<column>smiley_height</column> +		<column>smiley_order</column> +		<column>display_on_posting</column> +		<row> +			<value>4</value> +			<value>:)</value> +			<value>Smile</value> +			<value>icon_e_smile.gif</value> +			<value>15</value> +			<value>17</value> +			<value>4</value> +			<value>1</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.html b/tests/text_processing/tickets_data/PHPBB3-8419.html new file mode 100644 index 0000000000..38df626a94 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.html @@ -0,0 +1 @@ +<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">tę </span></span></span>przykład
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.txt b/tests/text_processing/tickets_data/PHPBB3-8419.txt new file mode 100644 index 0000000000..dac47823b6 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.txt @@ -0,0 +1 @@ +[ort]tę [/ort]przykład
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.xml b/tests/text_processing/tickets_data/PHPBB3-8419.xml new file mode 100644 index 0000000000..2f1df345f9 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>myemail</value> +			<value></value> +			<value>1</value> +			<value>[ort]{TEXT}[/ort]</value> +			<value><![CDATA[<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">{TEXT}</span></span></span>]]></value> +			<value><\[/ort\]!ies]]></value> +			<value><![CDATA['[ort:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/ort:$uid]']]></value> +			<value><\[/ort:$uid\]!s]]></value> +			<value><![CDATA[<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">${1}</span></span></span>]]></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-9073.html b/tests/text_processing/tickets_data/PHPBB3-9073.html new file mode 100644 index 0000000000..ff1f9fd0ce --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9073.html @@ -0,0 +1,2 @@ +<a href="http://www.xxxx-xx-xxxx.com/" class="postlink">http://www.xxxx-xx-xxxx.com/</a><br> +<a href="http://www.xxxx-xx-xxxx.com/" class="postlink">http://www.xxxx-xx-xxxx.com/</a><br> diff --git a/tests/text_processing/tickets_data/PHPBB3-9073.txt b/tests/text_processing/tickets_data/PHPBB3-9073.txt new file mode 100644 index 0000000000..2c271173ce --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9073.txt @@ -0,0 +1,2 @@ +http://www.some-ad-site.com/ +[url]http://www.some-ad-site.com/[/url] diff --git a/tests/text_processing/tickets_data/PHPBB3-9073.xml b/tests/text_processing/tickets_data/PHPBB3-9073.xml new file mode 100644 index 0000000000..d635d51ed1 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9073.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_words"> +		<column>word_id</column> +		<column>word</column> +		<column>replacement</column> + +		<row> +			<value>1</value> +			<value>http://www.some-ad-site.com*</value> +			<value>http://www.xxxx-xx-xxxx.com</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.html b/tests/text_processing/tickets_data/PHPBB3-9377.html new file mode 100644 index 0000000000..dcfb79c173 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.html @@ -0,0 +1 @@ +<span style="color:red">red <span style="color:blue">blue</span> red</span>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.txt b/tests/text_processing/tickets_data/PHPBB3-9377.txt new file mode 100644 index 0000000000..dfd71492c5 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.txt @@ -0,0 +1 @@ +[red]red [blue]blue[/blue] red[/red]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.xml b/tests/text_processing/tickets_data/PHPBB3-9377.xml new file mode 100644 index 0000000000..1d8ee3d53f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_bbcodes"> +		<column>bbcode_id</column> +		<column>bbcode_tag</column> +		<column>bbcode_helpline</column> +		<column>display_on_posting</column> +		<column>bbcode_match</column> +		<column>bbcode_tpl</column> +		<column>first_pass_match</column> +		<column>first_pass_replace</column> +		<column>second_pass_match</column> +		<column>second_pass_replace</column> + +		<row> +			<value>13</value> +			<value>red</value> +			<value></value> +			<value>1</value> +			<value>[red]{TEXT}[/red]</value> +			<value><span style="color:red">{TEXT}</span></value> +			<value>!\[red\](.*?)\[/red\]!ies</value> +			<value>'[red:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/red:$uid]'</value> +			<value>!\[red:$uid\](.*?)\[/red:$uid\]!s</value> +			<value><span style="color:red">${1}</span></value> +		</row> + +		<row> +			<value>14</value> +			<value>blue</value> +			<value></value> +			<value>1</value> +			<value>[blue]{TEXT}[/blue]</value> +			<value><span style="color:blue">{TEXT}</span></value> +			<value>!\[blue\](.*?)\[/blue\]!ies</value> +			<value>'[blue:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/blue:$uid]'</value> +			<value>!\[blue:$uid\](.*?)\[/blue:$uid\]!s</value> +			<value><span style="color:blue">${1}</span></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_processing/tickets_test.php b/tests/text_processing/tickets_test.php new file mode 100644 index 0000000000..8c48a3f4a9 --- /dev/null +++ b/tests/text_processing/tickets_test.php @@ -0,0 +1,94 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_text_processing_tickets_test extends phpbb_test_case +{ +	/** +	* @dataProvider get_tickets_data +	*/ +	public function test_tickets($ticket_id, $original, $expected, $fixture, $before_assert, $after_assert) +	{ +		global $phpbb_container; + +		$phpbb_container = new phpbb_mock_container_builder; + +		$this->get_test_case_helpers()->set_s9e_services($phpbb_container, $fixture); + +		$parser   = $phpbb_container->get('text_formatter.parser'); +		$renderer = $phpbb_container->get('text_formatter.renderer'); + +		if (isset($before_assert)) +		{ +			$test = $this; +			$before_assert(get_defined_vars()); +		} + +		$parsed_text = $parser->parse($original); + +		$this->assertSame($expected, $renderer->render($parsed_text)); + +		if (isset($after_assert)) +		{ +			$test = $this; +			$after_assert(get_defined_vars()); +		} +	} + +	public function get_tickets_data() +	{ +		$tests = array(); + +		foreach (glob(__DIR__ . '/tickets_data/*.txt') as $txt_filename) +		{ +			$ticket_id     = basename($txt_filename, '.txt'); +			$html_filename = substr($txt_filename, 0, -3) . 'html'; +			$xml_filename  = substr($txt_filename, 0, -3) . 'xml'; +			$before_filename = substr($txt_filename, 0, -3) . 'before.php'; +			$after_filename  = substr($txt_filename, 0, -3) . 'after.php'; + +			if (!file_exists($xml_filename)) +			{ +				$xml_filename = __DIR__ . '/../fixtures/empty.xml'; +			} + +			$before_assert = null; +			if (file_exists($before_filename)) +			{ +				include($before_filename); +				$before_assert = 'before_assert_' . strtolower(str_replace('-', '_', $ticket_id)); +			} + +			$after_assert = null; +			if (file_exists($after_filename)) +			{ +				include($after_filename); +				$after_assert = 'after_assert_' . strtolower(str_replace('-', '_', $ticket_id)); +			} + +			$tests[] = array( +				$ticket_id, +				file_get_contents($txt_filename), +				file_get_contents($html_filename), +				$xml_filename, +				$before_assert, +				$after_assert +			); +		} + +		return $tests; +	} +} diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index c56be1f81e..647fcef2af 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -59,7 +59,6 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case  		global $config;  		$config = $this->config = new \phpbb\config\config(array('nestedset_forum_lock' => 0)); -		set_config(null, null, null, $this->config);  		$this->lock = new \phpbb\lock\db('nestedset_forum_lock', $this->config, $this->db);  		$this->set = new \phpbb\tree\nestedset_forum($this->db, $this->lock, 'phpbb_forums'); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index ed28bcb38f..f953970f64 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -23,6 +23,7 @@ class phpbb_filespec_test extends phpbb_test_case  	const UPLOAD_MAX_FILESIZE = 1000;  	private $config; +	private $filesystem;  	public $path;  	protected function setUp() @@ -30,7 +31,7 @@ class phpbb_filespec_test extends phpbb_test_case  		// Global $config required by unique_id  		// Global $user required by filespec::additional_checks and  		// filespec::move_file -		global $config, $user; +		global $config, $user, $phpbb_filesystem;  		if (!is_array($config))  		{ @@ -75,6 +76,8 @@ class phpbb_filespec_test extends phpbb_test_case  		$guessers[2]->set_priority(-2);  		$guessers[3]->set_priority(-2);  		$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); + +		$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem();  	}  	private function get_filespec($override = array()) @@ -88,7 +91,7 @@ class phpbb_filespec_test extends phpbb_test_case  			'error' => '',  		); -		return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser); +		return new filespec(array_merge($upload_ary, $override), null, $this->filesystem, $this->mimetype_guesser);  	}  	protected function tearDown() @@ -198,7 +201,7 @@ class phpbb_filespec_test extends phpbb_test_case  			$filespec = $this->get_filespec();  			$filespec->clean_filename('unique', self::PREFIX);  			$name = $filespec->realname; -			 +  			$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));  			$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));  			$this->assertFalse(isset($filenames[$name])); @@ -286,7 +289,7 @@ class phpbb_filespec_test extends phpbb_test_case  			array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true),  			array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true),  			array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), -			array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), +			array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH png jpg', true),  		);  	} diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index fcfb84125d..9de384b64f 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -20,12 +20,14 @@ class phpbb_fileupload_test extends phpbb_test_case  {  	private $path; +	private $filesystem; +  	protected function setUp()  	{  		// Global $config required by unique_id  		// Global $user required by several functions dealing with translations  		// Global $request required by form_upload, local_upload and is_valid -		global $config, $user, $request; +		global $config, $user, $request, $phpbb_filesystem;  		if (!is_array($config))  		{ @@ -40,6 +42,8 @@ class phpbb_fileupload_test extends phpbb_test_case  		$request = new phpbb_mock_request(); +		$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); +  		$this->path = __DIR__ . '/fixture/';  	} @@ -65,7 +69,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_invalid_extension()  	{ -		$upload = new fileupload('', array('png'), 100); +		$upload = new fileupload($this->filesystem, '', array('png'), 100);  		$file = $this->gen_valid_filespec();  		$upload->common_checks($file);  		$this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); @@ -73,7 +77,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_invalid_filename()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $this->gen_valid_filespec();  		$file->realname = 'invalid?';  		$upload->common_checks($file); @@ -82,7 +86,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_too_large()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $this->gen_valid_filespec();  		$file->filesize = 1000;  		$upload->common_checks($file); @@ -91,7 +95,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_valid_file()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		$file = $this->gen_valid_filespec();  		$upload->common_checks($file);  		$this->assertEquals(0, sizeof($file->error)); @@ -99,7 +103,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_local_upload()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		$file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -109,7 +113,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_move_existent_file()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		$file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -121,7 +125,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_move_existent_file_overwrite()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg'); @@ -134,7 +138,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_valid_dimensions()  	{ -		$upload = new fileupload('', false, false, 1, 1, 100, 100); +		$upload = new fileupload($this->filesystem, '', false, false, 1, 1, 100, 100);  		$file1 = $this->gen_valid_filespec();  		$file2 = $this->gen_valid_filespec(); diff --git a/tests/upload/fixture/bmp b/tests/upload/fixture/bmpBinary files differ new file mode 100644 index 0000000000..04bff561ab --- /dev/null +++ b/tests/upload/fixture/bmp diff --git a/tests/upload/fixture/iff b/tests/upload/fixture/iffBinary files differ new file mode 100644 index 0000000000..24eda8f593 --- /dev/null +++ b/tests/upload/fixture/iff diff --git a/tests/upload/fixture/iff_maya b/tests/upload/fixture/iff_mayaBinary files differ new file mode 100644 index 0000000000..b6fb85101b --- /dev/null +++ b/tests/upload/fixture/iff_maya diff --git a/tests/upload/fixture/jp2 b/tests/upload/fixture/jp2Binary files differ new file mode 100644 index 0000000000..adca6ecf0e --- /dev/null +++ b/tests/upload/fixture/jp2 diff --git a/tests/upload/fixture/jpx b/tests/upload/fixture/jpxBinary files differ new file mode 100644 index 0000000000..adca6ecf0e --- /dev/null +++ b/tests/upload/fixture/jpx diff --git a/tests/upload/fixture/psd b/tests/upload/fixture/psdBinary files differ new file mode 100644 index 0000000000..d1bc9a6a70 --- /dev/null +++ b/tests/upload/fixture/psd diff --git a/tests/upload/fixture/tif_compressed b/tests/upload/fixture/tif_compressedBinary files differ new file mode 100644 index 0000000000..133b50c4f0 --- /dev/null +++ b/tests/upload/fixture/tif_compressed diff --git a/tests/upload/fixture/tif_msb b/tests/upload/fixture/tif_msbBinary files differ new file mode 100644 index 0000000000..32eb8abfbb --- /dev/null +++ b/tests/upload/fixture/tif_msb diff --git a/tests/upload/fixture/wbmp b/tests/upload/fixture/wbmpBinary files differ new file mode 100644 index 0000000000..708c86ccee --- /dev/null +++ b/tests/upload/fixture/wbmp diff --git a/tests/upload/imagesize_test.php b/tests/upload/imagesize_test.php new file mode 100644 index 0000000000..bfea4b819d --- /dev/null +++ b/tests/upload/imagesize_test.php @@ -0,0 +1,99 @@ +<?php + +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once(__DIR__ . '/../../phpBB/includes/functions.php'); + +class phpbb_upload_imagesize_test extends \phpbb_test_case +{ +	/** @var \fastImageSize\fastImageSize */ +	protected $imagesize; + +	/** @var string Path to fixtures */ +	protected $path; + +	public function setUp() +	{ +		parent::setUp(); +		$this->imagesize = new \fastImageSize\fastImageSize(); +		$this->path = __DIR__ . '/fixture/'; +	} + +	public function data_get_imagesize() +	{ +		return array( +			array('foobar', 'image/bmp', false), +			array('png', 'image/png', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)), +			array('gif', 'image/png', false), +			array('png', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)), +			array('gif', 'image/gif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)), +			array('jpg', 'image/gif', false), +			array('gif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)), +			array('jpg', 'image/jpg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), +			array('jpg', 'image/jpeg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), +			array('png', 'image/jpg', false), +			array('jpg', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), +			array('psd', 'image/psd', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), +			array('psd', 'image/photoshop', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), +			array('jpg', 'image/psd', false), +			array('psd', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), +			array('bmp', 'image/bmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)), +			array('png', 'image/bmp', false), +			array('bmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)), +			array('tif', 'image/tif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), +			array('png', 'image/tif', false), +			array('tif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), +			array('tif_compressed', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), +			array('png', 'image/tiff', false), +			array('tif_compressed', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), +			array('tif_msb', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)), +			array('tif_msb', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)), +			array('wbmp', 'image/wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), +			array('wbmp', 'image/vnd.wap.wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), +			array('png', 'image/vnd.wap.wbmp', false), +			array('wbmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), +			array('iff', 'image/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), +			array('iff', 'image/x-iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), +			array('iff_maya', 'iamge/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), +			array('png', 'image/iff', false), +			array('png', 'image/x-iff', false), +			array('iff', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), +			array('iff_maya', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), +			array('jp2', 'image/jp2', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +			array('jp2', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +			array('jp2', 'image/jpm', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +			array('jpg', 'image/jp2', false), +			array('jpx', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +			array('jp2', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +			array('jpx', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), +		); +	} + +	/** +	 * @dataProvider data_get_imagesize +	 */ +	public function test_get_imagesize($file, $mime_type, $expected) +	{ +		$this->assertEquals($expected, $this->imagesize->getImageSize($this->path . $file, $mime_type)); +	} + +	public function test_get_imagesize_remote() +	{ +		$this->assertSame(array( +			'width'		=> 80, +			'height'	=> 80, +			'type'		=> IMAGETYPE_JPEG, +		), +		$this->imagesize->getImageSize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg')); +	} +} diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php deleted file mode 100644 index bb11bb63cb..0000000000 --- a/tests/user/lang_test.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_user_lang_test extends phpbb_test_case -{ -	public function test_user_lang_sprintf() -	{ -		$user = new \phpbb\user('\phpbb\datetime'); -		$user->lang = array( -			'FOO'		=> 'BAR', -			'BARZ'		=> 'PENG', -			'EMPTY'		=> '', -			'ZERO'		=> '0', -			'STR'		=> '%d %s, %d topics', -			'STR2'		=> '%d foos', -			'ARRY'		=> array( -				0		=> 'No posts',		// 0 -				1		=> '1 post',		// 1 -				2		=> '%d posts',		// 2+ -			), -			'ARRY_NO_ZERO'	=> array( -				1		=> '1 post',		// 1 -				2		=> '%d posts',		// 0, 2+ -			), -			'ARRY_MISSING'	=> array( -				1		=> '%d post',		// 1 -				//Missing second plural -			), -			'ARRY_FLOAT'	=> array( -				1		=> '1 post',		// 1.x -				2		=> '%1$.1f posts',	// 0.x, 2+.x -			), -			'ARRY_EMPTY'	=> array( -			), -			'dateformat'	=> array( -				'AGO'	=> array( -					1	=> '%d second', -					2	=> '%d seconds', -				), -			), -		); - -		// No param -		$this->assertEquals($user->lang('FOO'), 'BAR'); -		$this->assertEquals($user->lang('EMPTY'), ''); -		$this->assertEquals($user->lang('ZERO'), '0'); - -		// Invalid index -		$this->assertEquals($user->lang('VOID'), 'VOID'); - -		// Unnecessary param -		$this->assertEquals($user->lang('FOO', 2), 'BAR'); -		$this->assertEquals($user->lang('FOO', 2, 3), 'BAR'); -		$this->assertEquals($user->lang('FOO', 2, 3, 'BARZ'), 'BAR'); - -		// String -		$this->assertEquals($user->lang('STR', 24, 'x', 42), '24 x, 42 topics'); -		$this->assertEquals($user->lang('STR2', 64), '64 foos'); - -		// Array -		$this->assertEquals($user->lang('ARRY', 0), 'No posts'); -		$this->assertEquals($user->lang('ARRY', 1), '1 post'); -		$this->assertEquals($user->lang('ARRY', 2), '2 posts'); -		$this->assertEquals($user->lang('ARRY', 123), '123 posts'); - -		// Empty array returns the language key -		$this->assertEquals($user->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY'); - -		// No 0 key defined -		$this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts'); -		$this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post'); -		$this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts'); - -		// Array with missing keys -		$this->assertEquals($user->lang('ARRY_MISSING', 2), '2 post'); - -		// Floats as array key -		$this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post'); -		$this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts'); -		$this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts'); - -		// Use sub key, if first paramenter is an array -		$this->assertEquals($user->lang(array('dateformat', 'AGO'), 2), '2 seconds'); - -		// ticket PHPBB3-9949 - use first int to determinate the plural-form to use -		$this->assertEquals($user->lang('ARRY', 1, 2), '1 post'); -		$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post'); - -		// ticket PHPBB3-10345 - different plural rules, not just 0/1/2+ -		$user = new \phpbb\user('\phpbb\datetime'); -		$user->lang = array( -			'PLURAL_RULE'		=> 13, -			'ARRY'		=> array( -				0		=> '%d is 0',						// 0 -				1		=> '%d is 1',						// 1 -				2		=> '%d ends with 01-10',			// ending with 01-10 -				3		=> '%d ends with 11-19',			// ending with 11-19 -				4		=> '%d is part of the last rule',	// everything else -			), -		); -		$this->assertEquals($user->lang('ARRY', 0), '0 is 0'); -		$this->assertEquals($user->lang('ARRY', 1), '1 is 1'); -		$this->assertEquals($user->lang('ARRY', 103), '103 ends with 01-10'); -		$this->assertEquals($user->lang('ARRY', 15), '15 ends with 11-19'); -		$this->assertEquals($user->lang('ARRY', 300), '300 is part of the last rule'); -	} -} diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php deleted file mode 100644 index 50eafda859..0000000000 --- a/tests/utf/normalizer_test.php +++ /dev/null @@ -1,327 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_normalizer.php'; - -/** -* @group slow -*/ -class phpbb_utf_normalizer_test extends phpbb_test_case -{ -	static private $data_dir; - -	static public function setUpBeforeClass() -	{ -		self::$data_dir = dirname(__file__) . '/../tmp'; -		self::download('http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt', self::$data_dir); -		self::download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt', self::$data_dir); -	} - -	public function test_normalizer() -	{ -		$test_suite = array( -			/** -			* NFC -			*   c2 ==  NFC(c1) ==  NFC(c2) ==  NFC(c3) -			*   c4 ==  NFC(c4) ==  NFC(c5) -			*/ -			'NFC'	=>	array( -				'c2'	=>	array('c1', 'c2', 'c3'), -				'c4'	=>	array('c4', 'c5') -			), - -			/** -			* NFD -			*   c3 ==  NFD(c1) ==  NFD(c2) ==  NFD(c3) -			*   c5 ==  NFD(c4) ==  NFD(c5) -			*/ -			'NFD'	=>	array( -				'c3'	=>	array('c1', 'c2', 'c3'), -				'c5'	=>	array('c4', 'c5') -			), - -			/** -			* NFKC -			*   c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) -			*/ -			'NFKC'	=>	array( -				'c4'	=>	array('c1', 'c2', 'c3', 'c4', 'c5') -			), - -			/** -			* NFKD -			*   c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) -			*/ -			'NFKD'	=>	array( -				'c5'	=>	array('c1', 'c2', 'c3', 'c4', 'c5') -			) -		); - -		$tested_chars = array(); - -		$fp = fopen(self::$data_dir . '/NormalizationTest.txt', 'rb'); -		while (!feof($fp)) -		{ -			$line = fgets($fp); - -			if ($line[0] == '@') -			{ -				continue; -			} - -			if (!strpos(' 0123456789ABCDEF', $line[0])) -			{ -				continue; -			} - -			list($c1, $c2, $c3, $c4, $c5) = explode(';', $line); - -			if (!strpos($c1, ' ')) -			{ -				/** -				* We are currently testing a single character, we add it to the list of -				* characters we have processed so that we can exclude it when testing -				* for invariants -				*/ -				$tested_chars[$c1] = 1; -			} - -			foreach ($test_suite as $form => $serie) -			{ -				foreach ($serie as $expected => $tests) -				{ -					$hex_expected = ${$expected}; -					$utf_expected = $this->hexseq_to_utf($hex_expected); - -					foreach ($tests as $test) -					{ -						$utf_result = $utf_expected; -						call_user_func_array(array('utf_normalizer', $form), array(&$utf_result)); - -						$hex_result = $this->utf_to_hexseq($utf_result); -						$this->assertEquals($utf_expected, $utf_result, "$expected == $form($test) ($hex_expected != $hex_result)"); -					} -				} -			} -		} -		fclose($fp); - -		return $tested_chars; -	} - -	/** -	* @depends test_normalizer -	*/ -	public function test_invariants(array $tested_chars) -	{ -		$fp = fopen(self::$data_dir . '/UnicodeData.txt', 'rb'); - -		while (!feof($fp)) -		{ -			$line = fgets($fp, 1024); - -			if (!$pos = strpos($line, ';')) -			{ -				continue; -			} - -			$hex_tested = $hex_expected = substr($line, 0, $pos); - -			if (isset($tested_chars[$hex_tested])) -			{ -				continue; -			} - -			$utf_expected = $this->hex_to_utf($hex_expected); - -			if ($utf_expected >= UTF8_SURROGATE_FIRST -			 && $utf_expected <= UTF8_SURROGATE_LAST) -			{ -				/** -				* Surrogates are illegal on their own, we expect the normalizer -				* to return a replacement char -				*/ -				$utf_expected = UTF8_REPLACEMENT; -				$hex_expected = $this->utf_to_hexseq($utf_expected); -			} - -			foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) -			{ -				$utf_result = $utf_expected; -				call_user_func_array(array('utf_normalizer', $form), array(&$utf_result)); -				$hex_result = $this->utf_to_hexseq($utf_result); - -				$this->assertEquals($utf_expected, $utf_result, "$hex_expected == $form($hex_tested) ($hex_expected != $hex_result)"); -			} -		} -		fclose($fp); -	} - -	/** -	* Convert a UTF string to a sequence of codepoints in hexadecimal -	* -	* @param	string	$utf	UTF string -	* @return	integer			Unicode codepoints in hex -	*/ -	protected function utf_to_hexseq($str) -	{ -		$pos = 0; -		$len = strlen($str); -		$ret = array(); - -		while ($pos < $len) -		{ -			$c = $str[$pos]; -			switch ($c & "\xF0") -			{ -				case "\xC0": -				case "\xD0": -					$utf_char = substr($str, $pos, 2); -					$pos += 2; -					break; - -				case "\xE0": -					$utf_char = substr($str, $pos, 3); -					$pos += 3; -					break; - -				case "\xF0": -					$utf_char = substr($str, $pos, 4); -					$pos += 4; -					break; - -				default: -					$utf_char = $c; -					++$pos; -			} - -			$hex = dechex($this->utf_to_cp($utf_char)); - -			if (!isset($hex[3])) -			{ -				$hex = substr('000' . $hex, -4); -			} - -			$ret[] = $hex; -		} - -		return strtr(implode(' ', $ret), 'abcdef', 'ABCDEF'); -	} - -	/** -	* Convert a UTF-8 char to its codepoint -	* -	* @param	string	$utf_char	UTF-8 char -	* @return	integer				Unicode codepoint -	*/ -	protected function utf_to_cp($utf_char) -	{ -		switch (strlen($utf_char)) -		{ -			case 1: -				return ord($utf_char); - -			case 2: -				return ((ord($utf_char[0]) & 0x1F) << 6) | (ord($utf_char[1]) & 0x3F); - -			case 3: -				return ((ord($utf_char[0]) & 0x0F) << 12) | ((ord($utf_char[1]) & 0x3F) << 6) | (ord($utf_char[2]) & 0x3F); - -			case 4: -				return ((ord($utf_char[0]) & 0x07) << 18) | ((ord($utf_char[1]) & 0x3F) << 12) | ((ord($utf_char[2]) & 0x3F) << 6) | (ord($utf_char[3]) & 0x3F); - -			default: -				throw new RuntimeException('UTF-8 chars can only be 1-4 bytes long'); -		} -	} - -	/** -	* Return a UTF string formed from a sequence of codepoints in hexadecimal -	* -	* @param	string	$seq		Sequence of codepoints, separated with a space -	* @return	string				UTF-8 string -	*/ -	protected function hexseq_to_utf($seq) -	{ -		return implode('', array_map(array($this, 'hex_to_utf'), explode(' ', $seq))); -	} - -	/** -	* Convert a codepoint in hexadecimal to a UTF-8 char -	* -	* @param	string	$hex		Codepoint, in hexadecimal -	* @return	string				UTF-8 char -	*/ -	protected function hex_to_utf($hex) -	{ -		return $this->cp_to_utf(hexdec($hex)); -	} - -	/** -	* Convert a codepoint to a UTF-8 char -	* -	* @param	integer	$cp			Unicode codepoint -	* @return	string				UTF-8 string -	*/ -	protected function cp_to_utf($cp) -	{ -		if ($cp > 0xFFFF) -		{ -			return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); -		} -		else if ($cp > 0x7FF) -		{ -			return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); -		} -		else if ($cp > 0x7F) -		{ -			return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F)); -		} -		else -		{ -			return chr($cp); -		} -	} - -	// chunked download helper -	static protected function download($url, $to) -	{ -		$target = $to . '/' . basename($url); - -		if (file_exists($target)) -		{ -			return; -		} - -		if (!$fpr = fopen($url, 'rb')) -		{ -			echo "Failed to download $url\n"; -			return; -		} - -		if (!$fpw = fopen($target, 'wb')) -		{ -			echo "Failed to open $target for writing\n"; -			return; -		} - -		$chunk = 32768; - -		while (!feof($fpr)) -		{ -			fwrite($fpw, fread($fpr, $chunk)); -		} -		fclose($fpr); -		fclose($fpw); -	} -} diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php index cfc87183cf..6ecc9b7223 100644 --- a/tests/version/version_fetch_test.php +++ b/tests/version/version_fetch_test.php @@ -28,13 +28,15 @@ class phpbb_version_helper_fetch_test extends phpbb_test_case  			->disableOriginalConstructor()  			->getMock(); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +  		$this->version_helper = new \phpbb\version_helper(  			$this->cache,  			new \phpbb\config\config(array(  				'version'	=> '3.1.0',  			)),  			new \phpbb\file_downloader(), -			new \phpbb\user('\phpbb\datetime') +			new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime')  		);  	} diff --git a/tests/version/version_helper_remote_test.php b/tests/version/version_helper_remote_test.php index 65ae7646b9..724c4c970c 100644 --- a/tests/version/version_helper_remote_test.php +++ b/tests/version/version_helper_remote_test.php @@ -30,20 +30,22 @@ class version_helper_remote_test extends \phpbb_test_case  		));  		$container = new \phpbb_mock_container_builder();  		$db = new \phpbb\db\driver\factory($container); -		$this->cache = $this->getMock('\phpbb\cache\service', array('get'), array(new \phpbb\cache\driver\null(), $config, $db, '../../', 'php')); +		$this->cache = $this->getMock('\phpbb\cache\service', array('get'), array(new \phpbb\cache\driver\dummy(), $config, $db, '../../', 'php'));  		$this->cache->expects($this->any())  			->method('get')  			->with($this->anything())  			->will($this->returnValue(false));  		$this->file_downloader = new phpbb_mock_file_downloader(); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +  		$this->version_helper = new \phpbb\version_helper(  			$this->cache,  			$config,  			$this->file_downloader, -			new \phpbb\user('\phpbb\datetime') +			new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime')  		); -		$this->user = new \phpbb\user('\phpbb\datetime'); +		$this->user = new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime');  		$this->user->add_lang('acp/common');  	} diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 528f1602d6..05577f6a18 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -25,13 +25,15 @@ class phpbb_version_helper_test extends phpbb_test_case  			->disableOriginalConstructor()  			->getMock(); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +  		$this->version_helper = new \phpbb\version_helper(  			$this->cache,  			new \phpbb\config\config(array(  				'version'	=> '3.1.0',  			)),  			new \phpbb\file_downloader(), -			new \phpbb\user('\phpbb\datetime') +			new \phpbb\user(new \phpbb\language\language($lang_loader), '\phpbb\datetime')  		);  	} @@ -199,6 +201,11 @@ class phpbb_version_helper_test extends phpbb_test_case  	*/  	public function test_get_suggested_updates($current_version, $versions, $expected)  	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +  		$version_helper = $this  			->getMockBuilder('\phpbb\version_helper')  			->setMethods(array( @@ -210,7 +217,7 @@ class phpbb_version_helper_test extends phpbb_test_case  					'version'	=> $current_version,  				)),  				new \phpbb\file_downloader(), -				new \phpbb\user('\phpbb\datetime'), +				new \phpbb\user($lang, '\phpbb\datetime'),  			))  			->getMock()  		; @@ -310,6 +317,11 @@ class phpbb_version_helper_test extends phpbb_test_case  	*/  	public function test_get_latest_on_current_branch($current_version, $versions, $expected)  	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +  		$version_helper = $this  			->getMockBuilder('\phpbb\version_helper')  			->setMethods(array( @@ -321,7 +333,7 @@ class phpbb_version_helper_test extends phpbb_test_case  					'version'	=> $current_version,  				)),  				new \phpbb\file_downloader(), -				new \phpbb\user('\phpbb\datetime'), +				new \phpbb\user($lang, '\phpbb\datetime'),  			))  			->getMock()  		; diff --git a/tests/viewonline/helper_test.php b/tests/viewonline/helper_test.php index bbbed59de7..6540d33287 100644 --- a/tests/viewonline/helper_test.php +++ b/tests/viewonline/helper_test.php @@ -17,7 +17,7 @@ class phpbb_viewonline_helper_test extends phpbb_test_case  	{  		parent::setUp(); -		$this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem()); +		$this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem\filesystem());  	}  	public function session_pages_data() | 
