diff options
Diffstat (limited to 'tests/console')
| -rw-r--r-- | tests/console/cache/purge_test.php | 9 | ||||
| -rw-r--r-- | tests/console/config/config_test.php | 7 | ||||
| -rw-r--r-- | tests/console/cron/cron_list_test.php | 7 | ||||
| -rw-r--r-- | tests/console/cron/run_test.php | 15 | ||||
| -rw-r--r-- | tests/console/fixtures/png.png | bin | 0 -> 129 bytes | |||
| -rw-r--r-- | tests/console/fixtures/thumbnail.xml | 40 | ||||
| -rw-r--r-- | tests/console/fixtures/txt.txt | 2 | ||||
| -rw-r--r-- | tests/console/thumbnail_test.php | 122 | ||||
| -rw-r--r-- | tests/console/user/activate_test.php | 86 | ||||
| -rw-r--r-- | tests/console/user/add_test.php | 92 | ||||
| -rw-r--r-- | tests/console/user/base.php | 121 | ||||
| -rw-r--r-- | tests/console/user/delete_test.php | 93 | ||||
| -rw-r--r-- | tests/console/user/fixtures/config.xml | 63 | ||||
| -rw-r--r-- | tests/console/user/reclean_test.php | 49 | 
14 files changed, 699 insertions, 7 deletions
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..b4a0203325 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -16,7 +16,6 @@ use Symfony\Component\Console\Tester\CommandTester;  use phpbb\console\command\cron\run;  require_once dirname(__FILE__) . '/tasks/simple.php'; -require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php';  class phpbb_console_command_cron_run_test extends phpbb_database_test_case  { @@ -39,10 +38,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(); @@ -76,6 +77,10 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case  		$this->assertSame(false, $this->lock->owns_lock());  	} +	/** +	 * @expectedException \phpbb\exception\runtime_exception +	 * @expectedExceptionMessage CRON_LOCK_ERROR +	 */  	public function test_error_lock()  	{  		$this->lock->acquire(); @@ -124,6 +129,10 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case  		$this->assertSame(false, $this->lock->owns_lock());  	} +	/** +	 * @expectedException \phpbb\exception\runtime_exception +	 * @expectedExceptionMessage CRON_NO_SUCH_TASK +	 */  	public function test_arg_invalid()  	{  		$command_tester = $this->get_command_tester(); diff --git a/tests/console/fixtures/png.png b/tests/console/fixtures/png.png Binary files differnew file mode 100644 index 0000000000..c143a26a06 --- /dev/null +++ b/tests/console/fixtures/png.png diff --git a/tests/console/fixtures/thumbnail.xml b/tests/console/fixtures/thumbnail.xml new file mode 100644 index 0000000000..8037523633 --- /dev/null +++ b/tests/console/fixtures/thumbnail.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_attachments"> +		<column>attach_id</column> +		<column>physical_filename</column> +		<column>real_filename</column> +		<column>thumbnail</column> +		<column>extension</column> +		<column>mimetype</column> +		<column>attach_comment</column> + +		<row> +			<value>1</value> +			<value>test_png_1</value> +			<value>real_test.png</value> +			<value>0</value> +			<value>png</value> +			<value>image/png</value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>test_png_2</value> +			<value>real_test.png</value> +			<value>1</value> +			<value>png</value> +			<value>image/png</value> +			<value></value> +		</row> +		<row> +			<value>10</value> +			<value>test_txt</value> +			<value>real_test.txt</value> +			<value>0</value> +			<value>txt</value> +			<value>text/plain</value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/console/fixtures/txt.txt b/tests/console/fixtures/txt.txt new file mode 100644 index 0000000000..a78c858f5c --- /dev/null +++ b/tests/console/fixtures/txt.txt @@ -0,0 +1,2 @@ +<HTML>mime trigger</HTML> +The HTML tags should remain uppercase so that case-insensitivity can be checked. diff --git a/tests/console/thumbnail_test.php b/tests/console/thumbnail_test.php new file mode 100644 index 0000000000..439e3623fa --- /dev/null +++ b/tests/console/thumbnail_test.php @@ -0,0 +1,122 @@ +<?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\thumbnail\generate; +use phpbb\console\command\thumbnail\delete; +use phpbb\console\command\thumbnail\recreate; + +class phpbb_console_command_thumbnail_test extends phpbb_database_test_case +{ +	protected $db; +	protected $config; +	protected $cache; +	protected $user; +	protected $phpEx; +	protected $phpbb_root_path; +	protected $application; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/thumbnail.xml'); +	} + +	public function setUp() +	{ +		global $config, $phpbb_root_path, $phpEx, $phpbb_filesystem; + +		if (!@extension_loaded('gd')) +		{ +			$this->markTestSkipped('Thumbnail tests require gd extension.'); +		} + +		parent::setUp(); + +		$config = $this->config = new \phpbb\config\config(array( +			'img_min_thumb_filesize' => 2, +			'img_max_thumb_width' => 2, +			'img_imagick' => '', +		)); + +		$this->db = $this->db = $this->new_dbal(); +		$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->phpbb_root_path = $phpbb_root_path; +		$this->phpEx = $phpEx; + +		$this->cache = $this->getMock('\phpbb\cache\service', array(), array(new phpbb_mock_cache(), $this->config, $this->db, $this->phpbb_root_path, $this->phpEx)); +		$this->cache->expects(self::any())->method('obtain_attach_extensions')->will(self::returnValue(array( +			'png' => array('display_cat' => ATTACHMENT_CATEGORY_IMAGE), +			'txt' => array('display_cat' => ATTACHMENT_CATEGORY_NONE), +		))); + +		$this->application = new Application(); +		$this->application->add(new generate($this->user, $this->db, $this->cache, $this->phpbb_root_path, $this->phpEx)); +		$this->application->add(new delete($this->user, $this->db, $this->phpbb_root_path)); +		$this->application->add(new recreate($this->user)); + +		$phpbb_filesystem = new \phpbb\filesystem\filesystem(); + +		copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1'); +		copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2'); +		copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/thumb_test_png_2'); +		copy(dirname(__FILE__) . '/fixtures/txt.txt', $this->phpbb_root_path . 'files/test_txt'); +	} + +	protected function tearDown() +	{ +		parent::tearDown(); + +		unlink($this->phpbb_root_path . 'files/test_png_1'); +		unlink($this->phpbb_root_path . 'files/test_png_2'); +		unlink($this->phpbb_root_path . 'files/test_txt'); +		unlink($this->phpbb_root_path . 'files/thumb_test_png_1'); +		unlink($this->phpbb_root_path . 'files/thumb_test_png_2'); +	} + +	public function test_thumbnails() +	{ +		$command_tester = $this->get_command_tester('thumbnail:generate'); +		$exit_status = $command_tester->execute(array('command' => 'thumbnail:generate')); + +		self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); +		self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); +		self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); +		self::assertSame(0, $exit_status); + +		$command_tester = $this->get_command_tester('thumbnail:delete'); +		$exit_status = $command_tester->execute(array('command' => 'thumbnail:delete')); + +		self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); +		self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); +		self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); +		self::assertSame(0, $exit_status); + +		$command_tester = $this->get_command_tester('thumbnail:recreate'); +		$exit_status = $command_tester->execute(array('command' => 'thumbnail:recreate')); + +		self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); +		self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); +		self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); +		self::assertSame(0, $exit_status); +	} + +	public function get_command_tester($command_name) +	{ +		$command = $this->application->find($command_name); +		return new CommandTester($command); +	} +} diff --git a/tests/console/user/activate_test.php b/tests/console/user/activate_test.php new file mode 100644 index 0000000000..1588a76e47 --- /dev/null +++ b/tests/console/user/activate_test.php @@ -0,0 +1,86 @@ +<?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\activate; + +require_once dirname(__FILE__) . '/base.php'; + +class phpbb_console_user_activate_test extends phpbb_console_user_base +{ +	protected $notifications; + +	public function setUp() +	{ +		parent::setUp(); + +		$this->notifications = $this->getMockBuilder('\phpbb\notification\manager') +			->disableOriginalConstructor() +			->getMock(); +	} + +	public function get_command_tester() +	{ +		$application = new Application(); +		$application->add(new activate( +			$this->user, +			$this->db, +			$this->config, +			$this->language, +			$this->log, +			$this->notifications, +			$this->user_loader, +			$this->phpbb_root_path, +			$this->php_ext +		)); + +		$command = $application->find('user:activate'); +		$this->command_name = $command->getName(); + +		return new CommandTester($command); +	} + +	public function activate_test_data() +	{ +		return array( +			// Test an inactive user +			array('Test', false, 'USER_ADMIN_ACTIVATED'), +			array('Test', true, 'CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE'), + +			// Test an active user +			array('Test 2', false, 'CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE'), +			array('Test 2', true, 'USER_ADMIN_DEACTIVED'), + +			// Test a non existent user +			array('Foo', false, 'NO_USER'), +			array('Foo', true, 'NO_USER'), +		); +	} + +	/** +	 * @dataProvider activate_test_data +	 */ +	public function test_activate($username, $deactivate, $expected) +	{ +		$command_tester = $this->get_command_tester(); + +		$command_tester->execute(array( +			'command'		=> $this->command_name, +			'username'		=> $username, +			'--deactivate'	=> $deactivate, +		)); + +		$this->assertContains($expected, $command_tester->getDisplay()); +	} +} diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php new file mode 100644 index 0000000000..8641bf87b6 --- /dev/null +++ b/tests/console/user/add_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. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\user\add; + +require_once dirname(__FILE__) . '/base.php'; + +class phpbb_console_user_add_test extends phpbb_console_user_base +{ +	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 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()); +	} +} diff --git a/tests/console/user/base.php b/tests/console/user/base.php new file mode 100644 index 0000000000..b84c0bb267 --- /dev/null +++ b/tests/console/user/base.php @@ -0,0 +1,121 @@ +<?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. +* +*/ + +abstract class phpbb_console_user_base extends phpbb_database_test_case +{ +	protected $db; +	protected $config; +	protected $user; +	protected $language; +	protected $log; +	protected $passwords_manager; +	protected $command_name; +	protected $question; +	protected $user_loader; +	protected $phpbb_root_path; +	protected $php_ext; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); +	} + +	public function setUp() +	{ +		global $auth, $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()); + +		$auth = $this->getMock('\phpbb\auth\auth'); + +		$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' +		)); + +		$this->user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); + +		$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; + +		$this->log = $this->getMockBuilder('\phpbb\log\log') +			->disableOriginalConstructor() +			->getMock(); + +		$phpbb_container->set('auth.provider.db', new phpbb_mock_auth_provider()); +		$provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config); +		$provider_collection->add('auth.provider.db'); +		$phpbb_container->set( +			'auth.provider_collection', +			$provider_collection +		); + +		parent::setUp(); +	} + +	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/delete_test.php b/tests/console/user/delete_test.php new file mode 100644 index 0000000000..88f91afab1 --- /dev/null +++ b/tests/console/user/delete_test.php @@ -0,0 +1,93 @@ +<?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\delete; + +require_once dirname(__FILE__) . '/base.php'; + +class phpbb_console_user_delete_test extends phpbb_console_user_base +{ +	public function get_command_tester() +	{ +		$application = new Application(); +		$application->add(new delete( +			$this->user, +			$this->db, +			$this->language, +			$this->log, +			$this->user_loader, +			$this->phpbb_root_path, +			$this->php_ext +		)); + +		$command = $application->find('user:delete'); +		$this->command_name = $command->getName(); +		$this->question = $command->getHelper('question'); + +		return new CommandTester($command); +	} + +	public function test_delete() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertEquals(3, $this->get_user_id('Test')); + +		$this->question->setInputStream($this->getInputStream("yes\n")); + +		$command_tester->execute(array( +			'command'			=> $this->command_name, +			'username'			=> 'Test', +			'--delete-posts'	=> false, +		)); + +		$this->assertNull($this->get_user_id('Test')); +		$this->assertContains('USER_DELETED', $command_tester->getDisplay()); +	} + +	public function test_delete_non_user() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertNull($this->get_user_id('Foo')); + +		$this->question->setInputStream($this->getInputStream("yes\n")); + +		$command_tester->execute(array( +			'command'			=> $this->command_name, +			'username'			=> 'Foo', +			'--delete-posts'	=> false, +		)); + +		$this->assertContains('NO_USER', $command_tester->getDisplay()); +	} + +	public function test_delete_cancel() +	{ +		$command_tester = $this->get_command_tester(); + +		$this->assertEquals(3, $this->get_user_id('Test')); + +		$this->question->setInputStream($this->getInputStream("no\n")); + +		$command_tester->execute(array( +			'command'			=> $this->command_name, +			'username'			=> 'Test', +			'--delete-posts'	=> false, +		)); + +		$this->assertNotNull($this->get_user_id('Test')); +	} +} diff --git a/tests/console/user/fixtures/config.xml b/tests/console/user/fixtures/config.xml new file mode 100644 index 0000000000..a988ba463f --- /dev/null +++ b/tests/console/user/fixtures/config.xml @@ -0,0 +1,63 @@ +<?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> +		<column>user_type</column> +		<row> +			<value>1</value> +			<value></value> +			<value>Guest</value> +			<value>guest</value> +			<value></value> +			<value>0</value> +		</row> +		<row> +			<value>2</value> +			<value></value> +			<value>Admin</value> +			<value>admin</value> +			<value></value> +			<value>3</value> +		</row> +		<row> +			<value>3</value> +			<value></value> +			<value>Test</value> +			<value>test</value> +			<value></value> +			<value>1</value> +		</row> +		<row> +			<value>4</value> +			<value></value> +			<value>Test 2</value> +			<value>test 2</value> +			<value></value> +			<value>0</value> +		</row> +		<row> +			<value>5</value> +			<value></value> +			<value>Test Unclean</value> +			<value>Test Unclean</value> +			<value></value> +			<value>0</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/console/user/reclean_test.php b/tests/console/user/reclean_test.php new file mode 100644 index 0000000000..1bf0b8ef5a --- /dev/null +++ b/tests/console/user/reclean_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 Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\user\reclean; + +require_once dirname(__FILE__) . '/base.php'; + +class phpbb_console_user_reclean_test extends phpbb_console_user_base +{ +	public function get_command_tester() +	{ +		$application = new Application(); +		$application->add(new reclean( +			$this->user, +			$this->db, +			$this->language +		)); + +		$command = $application->find('user:reclean'); +		$this->command_name = $command->getName(); + +		return new CommandTester($command); +	} + +	public function test_reclean() +	{ +		$command_tester = $this->get_command_tester(); + +		$exit_status = $command_tester->execute(array('command' => $this->command_name)); +		$this->assertSame(0, $exit_status); + +		$result = $this->db->sql_query('SELECT user_id FROM ' . USERS_TABLE . " WHERE username_clean = 'test unclean'"); +		$row = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); +		$this->assertNotNull($row['user_id']); +	} +}  | 
