diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/console/user/add_test.php | 185 | ||||
| -rw-r--r-- | tests/console/user/fixtures/config.xml | 43 | ||||
| -rw-r--r-- | tests/controller/common_helper_route.php | 2 | ||||
| -rw-r--r-- | tests/controller/controller_test.php | 2 | ||||
| -rw-r--r-- | tests/functional/visit_installer_test.php | 30 | ||||
| -rw-r--r-- | tests/pagination/pagination_test.php | 2 | ||||
| -rw-r--r-- | tests/session/testable_factory.php | 3 | ||||
| -rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 3 | ||||
| -rw-r--r-- | tests/text_processing/decode_message_test.php | 17 | ||||
| -rw-r--r-- | tests/text_reparser/base_test.php | 70 | ||||
| -rw-r--r-- | tests/text_reparser/fixtures/base.xml | 19 | 
11 files changed, 371 insertions, 5 deletions
diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php new file mode 100644 index 0000000000..00134c18cd --- /dev/null +++ b/tests/console/user/add_test.php @@ -0,0 +1,185 @@ +<?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 Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\user\add; + +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_console_command_user_add_test extends phpbb_database_test_case +{ +	protected $db; +	protected $config; +	protected $user; +	protected $language; +	protected $passwords_manager; +	protected $command_name; +	protected $question; +	protected $phpbb_root_path; +	protected $php_ext; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); +	} + +	public function setUp() +	{ +		global $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx; + +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); +		$phpbb_container = new phpbb_mock_container_builder(); +		$phpbb_container->set('cache.driver', new phpbb_mock_cache()); +		$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + +		$cache = $phpbb_container->get('cache.driver'); + +		$config = $this->config = new \phpbb\config\config(array( +			'board_timezone'	=> 'UTC', +			'default_lang'		=> 'en', +			'email_enable'		=> false, +			'min_name_chars'	=> 3, +			'max_name_chars'	=> 10, +			'min_pass_chars'	=> 3, +			'max_pass_chars'	=> 10, +			'pass_complex'		=> 'PASS_TYPE_ANY', +		)); + +		$db = $this->db = $this->new_dbal(); + +		$this->language = $this->getMockBuilder('\phpbb\language\language') +			->disableOriginalConstructor() +			->getMock(); +		$this->language->expects($this->any()) +			->method('lang') +			->will($this->returnArgument(0)); +		$user = $this->user = $this->getMock('\phpbb\user', array(), array( +			$this->language, +			'\phpbb\datetime' +		)); + +		$driver_helper = new \phpbb\passwords\driver\helper($this->config); +		$passwords_drivers = array( +			'passwords.driver.bcrypt_2y'	=> new \phpbb\passwords\driver\bcrypt_2y($this->config, $driver_helper), +			'passwords.driver.bcrypt'		=> new \phpbb\passwords\driver\bcrypt($this->config, $driver_helper), +			'passwords.driver.salted_md5'	=> new \phpbb\passwords\driver\salted_md5($this->config, $driver_helper), +			'passwords.driver.phpass'		=> new \phpbb\passwords\driver\phpass($this->config, $driver_helper), +		); + +		$passwords_helper = new \phpbb\passwords\helper; +		$this->passwords_manager = new \phpbb\passwords\manager($this->config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); + +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $phpEx; + +		parent::setUp(); +	} + +	public function test_add_no_dialog() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertEquals(2, $this->get_user_id('Admin')); + +		$command_tester->execute(array( +			'command'		=> $this->command_name, +			'--username'	=> 'foo', +			'--password'	=> 'bar', +			'--email'		=> 'foo@test.com' +		)); + +		$this->assertNotEquals(null, $this->get_user_id('foo')); +		$this->assertContains('CLI_USER_ADD_SUCCESS', $command_tester->getDisplay()); +	} + +	public function test_add_dialog() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertEquals(2, $this->get_user_id('Admin')); + +		$this->question->setInputStream($this->getInputStream("bar\npassword\npassword\nbar@test.com\n")); + +		$command_tester->execute(array( +			'command'		=> $this->command_name, +		)); + +		$this->assertNotEquals(null, $this->get_user_id('bar')); +		$this->assertContains('CLI_USER_ADD_SUCCESS', $command_tester->getDisplay()); + +	} + +	public function test_add_no_dialog_invalid() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertEquals(3, $this->get_user_id('Test')); + +		$command_tester->execute(array( +			'command'		=> $this->command_name, +			'--username'	=> 'Test', +			'--password'	=> '1', +			'--email'		=> 'foo' +		)); + +		$this->assertContains('USERNAME_TAKEN', $command_tester->getDisplay()); +		$this->assertContains('TOO_SHORT', $command_tester->getDisplay()); +		$this->assertContains('EMAIL_INVALID', $command_tester->getDisplay()); +	} + +	public function get_command_tester() +	{ +		$application = new Application(); +		$application->add(new add( +			$this->user, +			$this->db, +			$this->config, +			$this->language, +			$this->passwords_manager, +			$this->phpbb_root_path, +			$this->php_ext +		)); + +		$command = $application->find('user:add'); +		$this->command_name = $command->getName(); +		$this->question = $command->getHelper('question'); +		return new CommandTester($command); +	} + +	public function get_user_id($username) +	{ +		$sql = 'SELECT user_id +			FROM ' . USERS_TABLE . ' +			WHERE ' . 'username = ' . "'" . $username . "'"; + +		$result = $this->db->sql_query($sql); + +		$row = $this->db->sql_fetchrow($result); + +		$this->db->sql_freeresult($result); + +		return $row['user_id']; +	} + +	public function getInputStream($input) +	{ +		$stream = fopen('php://memory', 'r+', false); +		fputs($stream, $input); +		rewind($stream); + +		return $stream; +	} +} diff --git a/tests/console/user/fixtures/config.xml b/tests/console/user/fixtures/config.xml new file mode 100644 index 0000000000..fed30dc20d --- /dev/null +++ b/tests/console/user/fixtures/config.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>user_permissions</column> +		<column>username</column> +		<column>username_clean</column> +		<column>user_sig</column> +		<row> +			<value>1</value> +			<value></value> +			<value>Guest</value> +			<value>guest</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value></value> +			<value>Admin</value> +			<value>admin</value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value></value> +			<value>Test</value> +			<value>test</value> +			<value></value> +		</row> +	</table> +	<table name="phpbb_groups"> +		<column>group_id</column> +		<column>group_name</column> +		<column>group_type</column> +		<column>group_desc</column> +		<row> +			<value>1</value> +			<value>REGISTERED</value> +			<value>3</value> +			<value>foobar</value> +		</row> +	</table> +</dataset> diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 72c5328b0b..808eb684f2 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -126,7 +126,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  			new \phpbb\routing\file_locator($this->filesystem, dirname(__FILE__) . '/')  		);  		$resources_locator = new \phpbb\routing\resources_locator\default_resources_locator(dirname(__FILE__) . '/', PHPBB_ENVIRONMENT, $this->extension_manager); -		$this->router = new phpbb_mock_router($container, $resources_locator, $loader, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); +		$this->router = new phpbb_mock_router($container, $resources_locator, $loader, dirname(__FILE__) . '/', 'php');  		// Set correct current phpBB root path  		$this->root_path = $this->get_phpbb_root_path(); diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 431b26b2bc..e8af2f7485 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -47,7 +47,7 @@ class phpbb_controller_controller_test extends phpbb_test_case  			new \phpbb\routing\file_locator(new \phpbb\filesystem\filesystem(), dirname(__FILE__) . '/')  		);  		$resources_locator = new \phpbb\routing\resources_locator\default_resources_locator(dirname(__FILE__) . '/', PHPBB_ENVIRONMENT, $this->extension_manager); -		$router = new phpbb_mock_router($container, $resources_locator, $loader, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); +		$router = new phpbb_mock_router($container, $resources_locator, $loader, dirname(__FILE__) . '/', 'php');  		$routes = $router->get_routes();  		// This will need to be updated if any new routes are defined diff --git a/tests/functional/visit_installer_test.php b/tests/functional/visit_installer_test.php new file mode 100644 index 0000000000..b4a75c0b51 --- /dev/null +++ b/tests/functional/visit_installer_test.php @@ -0,0 +1,30 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_visit_installer_test extends phpbb_functional_test_case +{ +	public function test_visit_installer() +	{ +		self::request('GET', 'install/', [], false); +		$this->assertContains('<meta http-equiv="refresh" content="0; url=./app.php" />', $this->get_content()); + +		self::request('GET', 'install/index.html', [], false); +		$this->assertContains('<meta http-equiv="refresh" content="0; url=./app.php" />', $this->get_content()); + +		self::request('GET', 'install/app.php'); +		$this->assertContains('installation system', $this->get_content()); +	} +} diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 6a3b46cdae..024b6fc02d 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -46,7 +46,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case  			new \phpbb\routing\file_locator($filesystem, dirname(__FILE__) . '/')  		);  		$resources_locator = new \phpbb\routing\resources_locator\default_resources_locator(dirname(__FILE__) . '/', PHPBB_ENVIRONMENT, $manager); -		$router = new phpbb_mock_router(new phpbb_mock_container_builder(), $resources_locator, $loader, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT); +		$router = new phpbb_mock_router(new phpbb_mock_container_builder(), $resources_locator, $loader, dirname(__FILE__) . '/', 'php');  		$request = new phpbb_mock_request();  		$request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER); diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 7819063505..6f8b49122b 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -73,7 +73,7 @@ class phpbb_session_testable_factory  	public function get_session(\phpbb\db\driver\driver_interface $dbal)  	{  		// set up all the global variables used by session -		global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container; +		global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container, $phpbb_root_path;  		$request = $this->request = new phpbb_mock_request(  			array(), @@ -95,6 +95,7 @@ class phpbb_session_testable_factory  			new phpbb_mock_auth_provider()  		);  		$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT); +		$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . 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/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 53519617b3..d234642898 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -209,10 +209,11 @@ class phpbb_functional_test_case extends phpbb_test_case  	{  		if (!$this->cache)  		{ -			global $phpbb_container; +			global $phpbb_container, $phpbb_root_path;  			$phpbb_container = new phpbb_mock_container_builder();  			$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT); +			$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');  			$this->cache = new \phpbb\cache\driver\file;  		} diff --git a/tests/text_processing/decode_message_test.php b/tests/text_processing/decode_message_test.php index 7de599f2b1..fd1719fedc 100644 --- a/tests/text_processing/decode_message_test.php +++ b/tests/text_processing/decode_message_test.php @@ -16,6 +16,15 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';  class phpbb_text_processing_decode_message_test extends phpbb_test_case  { +	public function setUp() +	{ +		parent::setUp(); + +		global $phpbb_dispatcher; + +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); +	} +  	/**  	* @dataProvider get_legacy_tests  	*/ @@ -46,6 +55,14 @@ class phpbb_text_processing_decode_message_test extends phpbb_test_case  				'<!-- m --><a class="postlink" href="http://www.phpbb.com">http://www.phpbb.com</a><!-- m -->',  				'http://www.phpbb.com'  			), +			array( +				'<!-- m --><a class="postlink" href="http://www.phpbb.com">this is just text</a><!-- m -->', +				'http://www.phpbb.com' +			), +			array( +				'<!-- m --><a class="postlink" href="http://www.phpbb.com/some/more/link/that/is/shortened">http://www.phpbb.com/some/ ... /shortened</a><!-- m -->', +				'http://www.phpbb.com/some/more/link/that/is/shortened' +			),  			/**  			* Fails as per PHPBB3-8420  			* @link http://tracker.phpbb.com/browse/PHPBB3-8420 diff --git a/tests/text_reparser/base_test.php b/tests/text_reparser/base_test.php new file mode 100644 index 0000000000..2223ead9a6 --- /dev/null +++ b/tests/text_reparser/base_test.php @@ -0,0 +1,70 @@ +<?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_textreparser_base_test extends phpbb_database_test_case +{ +	protected $db; + +	public function setUp() +	{ +		global $config; +		if (!isset($config)) +		{ +			$config = new \phpbb\config\config(array()); +		} +		$this->get_test_case_helpers()->set_s9e_services(); +		$this->db = $this->new_dbal(); +		parent::setUp(); +	} + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(__DIR__ . '/fixtures/base.xml'); +	} + +	protected function get_reparser() +	{ +		return new \phpbb\textreparser\plugins\post_text($this->db, POSTS_TABLE); +	} + +	protected function get_rows(array $ids) +	{ +		$sql = 'SELECT post_id AS id, post_text AS text +			FROM ' . POSTS_TABLE . ' +			WHERE ' . $this->db->sql_in_set('post_id', $ids) . ' +			ORDER BY id'; +		$result = $this->db->sql_query($sql); +		$rows = $this->db->sql_fetchrowset($result); +		$this->db->sql_freeresult($result); + +		return $rows; +	} + +	public function test_reparse_empty() +	{ +		$this->get_reparser()->reparse_range(1, 1); + +		$this->assertEquals( +			array( +				array( +					'id'   => 1, +					'text' => '<t></t>' +				) +			), +			$this->get_rows(array(1)) +		); +	} +} diff --git a/tests/text_reparser/fixtures/base.xml b/tests/text_reparser/fixtures/base.xml new file mode 100644 index 0000000000..a4921a8823 --- /dev/null +++ b/tests/text_reparser/fixtures/base.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>enable_bbcode</column> +		<column>enable_smilies</column> +		<column>enable_magic_url</column> +		<column>post_text</column> +		<column>bbcode_uid</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value></value> +			<value>abcd1234</value> +		</row> +	</table> +</dataset>  | 
