diff options
Diffstat (limited to 'tests/attachment')
| -rw-r--r-- | tests/attachment/delete_test.php | 127 | ||||
| -rw-r--r-- | tests/attachment/fixtures/resync.xml | 130 | ||||
| -rw-r--r-- | tests/attachment/manager_test.php | 131 | ||||
| -rw-r--r-- | tests/attachment/resync_test.php | 74 | ||||
| -rw-r--r-- | tests/attachment/upload_test.php | 430 | 
5 files changed, 892 insertions, 0 deletions
| diff --git a/tests/attachment/delete_test.php b/tests/attachment/delete_test.php new file mode 100644 index 0000000000..f1835dd37a --- /dev/null +++ b/tests/attachment/delete_test.php @@ -0,0 +1,127 @@ +<?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_admin.php'); + +class phpbb_attachment_delete_test extends \phpbb_database_test_case +{ +	/** @var \phpbb\config\config */ +	protected $config; + +	/** @var \phpbb\db\driver\driver_interface */ +	protected $db; + +	/** @var \phpbb\filesystem\filesystem */ +	protected $filesystem; + +	/** @var \phpbb\attachment\resync */ +	protected $resync; + +	/** @var \phpbb\attachment\delete */ +	protected $attachment_delete; + +	protected $phpbb_root_path; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml'); +	} + +	public function setUp() +	{ +		global $db, $phpbb_root_path; + +		parent::setUp(); + +		$this->config = new \phpbb\config\config(array()); +		$this->db = $this->new_dbal(); +		$db = $this->db; +		$this->resync = new \phpbb\attachment\resync($this->db); +		$this->filesystem = $this->getMock('\phpbb\filesystem\filesystem', array('remove', 'exists')); +		$this->filesystem->expects($this->any()) +			->method('remove') +			->willReturn(false); +		$this->filesystem->expects($this->any()) +			->method('exists') +			->willReturn(true); +		$this->phpbb_root_path = $phpbb_root_path; +		$this->dispatcher = new \phpbb_mock_event_dispatcher(); +		$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->filesystem, $this->resync, $phpbb_root_path); +	} + +	public function data_attachment_delete() +	{ +		return array( +			array('attach', '', false, false), +			array('meh', 5, false, 0), +			array('attach', array(5), false, 0), +			array('attach', array(1,2), false, 2), +			array('attach', array(1,2), true, 2), +			array('post', 5, false, 0), +			array('topic', 5, false, 0), +			array('topic', 1, true, 3), +			array('user', 1, false, 0), +		); +	} + +	/** +	 * @dataProvider data_attachment_delete +	 */ +	public function test_attachment_delete($mode, $ids, $resync, $expected) +	{ +		// We need to reset the attachment ID sequence to properly test this +		if ($this->db->get_sql_layer() === 'postgres') +		{ +			$sql = 'ALTER SEQUENCE phpbb_attachments_seq RESTART WITH 1'; +			$this->db->sql_query($sql); +		} + +		$this->assertSame($expected, $this->attachment_delete->delete($mode, $ids, $resync)); +	} + +	public function data_attachment_unlink() +	{ +		return array( +			array(true, true, true), +			array(true, false, false), +			array(true, true, false, true), +		); +	} + +	/** +	 * @dataProvider data_attachment_unlink +	 */ +	public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false) +	{ +		$this->filesystem = $this->getMock('\phpbb\filesystem\filesystem', array('remove', 'exists')); +		if ($throw_exception) +		{ +			$this->filesystem->expects($this->any()) +				->method('remove') +				->willThrowException(new \phpbb\filesystem\exception\filesystem_exception);; +		} +		else +		{ +			$this->filesystem->expects($this->any()) +				->method('remove') +				->willReturn($remove_success); +		} + +		$this->filesystem->expects($this->any()) +			->method('exists') +			->willReturn($exists_success); + +		$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->filesystem, $this->resync, $this->phpbb_root_path); +		$this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar')); +	} +} diff --git a/tests/attachment/fixtures/resync.xml b/tests/attachment/fixtures/resync.xml new file mode 100644 index 0000000000..6e2cc62f68 --- /dev/null +++ b/tests/attachment/fixtures/resync.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +    <table name="phpbb_attachments"> +        <column>post_msg_id</column> +        <column>topic_id</column> +        <column>in_message</column> +        <column>is_orphan</column> +        <column>attach_comment</column> +        <column>physical_filename</column> +        <column>thumbnail</column> +        <row> +            <value>1</value> +            <value>1</value> +            <value>0</value> +            <value>0</value> +            <value>foo</value> +            <value>foo</value> +            <value>0</value> +        </row> +        <row> +            <value>1</value> +            <value>1</value> +            <value>1</value> +            <value>0</value> +            <value>foo2</value> +            <value>foo2</value> +            <value>0</value> +        </row> +        <row> +            <value>1</value> +            <value>1</value> +            <value>1</value> +            <value>0</value> +            <value>foo2</value> +            <value>foo2</value> +            <value>1</value> +        </row> +    </table> +    <table name="phpbb_extensions"> +        <column>extension</column> +        <column>group_id</column> +        <row> +            <value>jpg</value> +            <value>1</value> +        </row> +        <row> +            <value>png</value> +            <value>1</value> +        </row> +    </table> +    <table name="phpbb_extension_groups"> +        <column>cat_id</column> +        <column>group_id</column> +        <column>download_mode</column> +        <column>upload_icon</column> +        <column>max_filesize</column> +        <column>allow_group</column> +        <column>allow_in_pm</column> +        <column>allowed_forums</column> +        <column>group_name</column> +        <row> +            <value>1</value> +            <value>1</value> +            <value>1</value> +            <value> </value> +            <value>1000</value> +            <value>1</value> +            <value>1</value> +            <value>a:1:{i:0;i:1;}</value> +            <value>Images</value> +        </row> +    </table> +    <table name="phpbb_posts"> +        <column>post_id</column> +        <column>post_text</column> +        <column>poster_id</column> +        <column>post_attachment</column> +        <row> +            <value>1</value> +            <value>foo</value> +            <value>1</value> +            <value>1</value> +        </row> +        <row> +            <value>2</value> +            <value>foo</value> +            <value>1</value> +            <value>1</value> +        </row> +    </table> +    <table name="phpbb_privmsgs"> +        <column>msg_id</column> +        <column>message_text</column> +        <column>message_attachment</column> +        <column>to_address</column> +        <column>bcc_address</column> +        <row> +            <value>1</value> +            <value>foo</value> +            <value>1</value> +            <value>2</value> +            <value>2</value> +        </row> +        <row> +            <value>2</value> +            <value>foo</value> +            <value>1</value> +            <value>2</value> +            <value>2</value> +        </row> +    </table> +    <table name="phpbb_topics"> +        <column>topic_id</column> +        <column>forum_id</column> +        <column>topic_title</column> +        <column>topic_attachment</column> +        <row> +            <value>1</value> +            <value>1</value> +            <value>foo</value> +            <value>1</value> +        </row> +        <row> +            <value>2</value> +            <value>1</value> +            <value>bar</value> +            <value>1</value> +        </row> +    </table> +</dataset> diff --git a/tests/attachment/manager_test.php b/tests/attachment/manager_test.php new file mode 100644 index 0000000000..47d7f38b1d --- /dev/null +++ b/tests/attachment/manager_test.php @@ -0,0 +1,131 @@ +<?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_attachment_manager_test extends \phpbb_test_case +{ +	protected $delete; +	protected $resync; +	protected $upload; + +	public function setUp() +	{ +		$this->delete = $this->getMockBuilder('\phpbb\attachment\delete') +			->disableOriginalConstructor() +			->setMethods(['delete', 'unlink_attachment']) +			->getMock(); +		$this->resync = $this->getMockBuilder('\phpbb\attachment\resync') +			->disableOriginalConstructor() +			->setMethods(['resync']) +			->getMock(); +		$this->upload = $this->getMockBuilder('\phpbb\attachment\upload') +			->disableOriginalConstructor() +			->setMethods(['upload']) +			->getMock(); +	} + +	protected function get_manager() +	{ +		return new \phpbb\attachment\manager($this->delete, $this->resync, $this->upload); +	} + +	public function data_manager() +	{ +		return array( +			array( +				'delete', +				'unlink_attachment', +				'unlink', +				['foo'], +				['foo', 'file', false], +				true, +				true, +			), +			array( +				'delete', +				'unlink_attachment', +				'unlink', +				['foo', 'bar'], +				['foo', 'bar', false], +				true, +				true, +			), +			array( +				'delete', +				'unlink_attachment', +				'unlink', +				['foo', 'bar', true], +				['foo', 'bar', true], +				true, +				true, +			), +			array( +				'delete', +				'delete', +				'delete', +				['foo', [1, 2, 3]], +				['foo', [1, 2, 3], true], +				5, +				5, +			), +			array( +				'delete', +				'delete', +				'delete', +				['foo', [1, 2, 3], false], +				['foo', [1, 2, 3], false], +				2, +				2, +			), +			array( +				'resync', +				'resync', +				'resync', +				['foo', [1, 2, 3]], +				['foo', [1, 2, 3]], +				true, +				null, +			), +			array( +				'upload', +				'upload', +				'upload', +				['foo', 1], +				['foo', 1, false, '', false, []], +				true, +				true, +			), +			array( +				'upload', +				'upload', +				'upload', +				['foo', 1, true, 'bar', true, ['filename' => 'foobar']], +				['foo', 1, true, 'bar', true, ['filename' => 'foobar']], +				true, +				true, +			), +		); +	} + +	/** +	 * @dataProvider data_manager +	 */ +	public function test_manager($class, $method_class, $method_manager, $input_manager, $input_method, $return, $output) +	{ +		$mock = call_user_func_array([$this->{$class}, 'expects'], [$this->atLeastOnce()]); +		$mock = $mock->method($method_class); +		$mock = call_user_func_array([$mock, 'with'], $input_method); +		$mock->willReturn($return); +		$manager = $this->get_manager(); +		$this->assertSame($output, call_user_func_array([$manager, $method_manager], $input_manager)); +	} +} diff --git a/tests/attachment/resync_test.php b/tests/attachment/resync_test.php new file mode 100644 index 0000000000..f882af9ae5 --- /dev/null +++ b/tests/attachment/resync_test.php @@ -0,0 +1,74 @@ +<?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_attachment_resync_test extends \phpbb_database_test_case +{ +	/** @var \phpbb\db\driver\driver_interface */ +	protected $db; + +	/** @var \phpbb\attachment\resync */ +	protected $resync; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml'); +	} + +	public function setUp() +	{ +		parent::setUp(); + +		$this->db = $this->new_dbal(); +		$this->resync = new \phpbb\attachment\resync($this->db); +	} + +	public function data_resync() +	{ +		return array( +			array('', array(1), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '1')), +			array('post', array(1), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '1')), +			array('post', array(2), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '0')), +			array('topic', array(1), 'topic_id', TOPICS_TABLE, array('topic_attachment' => '1'), array('topic_attachment' => '1')), +			array('topic', array(2), 'topic_id', TOPICS_TABLE, array('topic_attachment' => '1'), array('topic_attachment' => '0')), +			array('message', array(1), 'msg_id', PRIVMSGS_TABLE, array('message_attachment' => '1'), array('message_attachment' => '1')), +			array('message', array(2), 'msg_id', PRIVMSGS_TABLE, array('message_attachment' => '1'), array('message_attachment' => '0')), +		); +	} + +	/** +	 * @dataProvider data_resync +	 */ +	public function test_resync($type, $ids, $sql_id, $exist_table, $exist_data, $resync_data) +	{ +		$sql_prefix = ($type) ?: 'post'; +		$sql = 'SELECT ' . $sql_prefix . '_attachment +			FROM ' . $exist_table . ' +			WHERE ' . $sql_id . ' = ' . $ids[0]; +		$result = $this->db->sql_query($sql); +		$data = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		$this->assertEquals($exist_data, $data); + +		$this->resync->resync($type, $ids); + +		$sql = 'SELECT ' . $sql_prefix . '_attachment +			FROM ' . $exist_table . ' +			WHERE ' . $sql_id . ' = ' . $ids[0]; +		$result = $this->db->sql_query($sql); +		$data = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		$this->assertEquals($resync_data, $data); +	} +} diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php new file mode 100644 index 0000000000..295b6b15c9 --- /dev/null +++ b/tests/attachment/upload_test.php @@ -0,0 +1,430 @@ +<?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_posting.php'); + +class phpbb_attachment_upload_test extends \phpbb_database_test_case +{ +	/** @var \phpbb\auth\auth */ +	protected $auth; + +	/** @var \phpbb\cache\service */ +	protected $cache; + +	/** @var \phpbb\config\config */ +	protected $config; + +	/** @var \phpbb\files\upload */ +	protected $files_upload; + +	/** @var \phpbb\language\language */ +	protected $language; + +	/** @var \phpbb\mimetype\guesser */ +	protected $mimetype_guesser; + +	/** @var \phpbb\event\dispatcher */ +	protected $phpbb_dispatcher; + +	/** @var \phpbb\plupload\plupload */ +	protected $plupload; + +	/** @var \phpbb\user */ +	protected $user; + +	/** @var string phpBB root path */ +	protected $phpbb_root_path; + +	/** @var \phpbb\db\driver\driver_interface */ +	protected $db; + +	/** @var \phpbb\attachment\upload */ +	protected $upload; + +	private $filesystem; + +	/** @var \Symfony\Component\DependencyInjection\ContainerInterface */ +	protected $container; + +	/** @var \phpbb\files\factory */ +	protected $factory; + +	/** @var \bantu\IniGetWrapper\IniGetWrapper */ +	protected $php_ini; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml'); +	} + +	public function setUp() +	{ +		global $config, $phpbb_root_path, $phpEx; + +		parent::setUp(); + +		$this->auth = new \phpbb\auth\auth(); +		$this->config = new \phpbb\config\config(array( +			'upload_path'	=> '', +			'img_create_thumbnail'	=> true, +		)); +		$config = $this->config; +		$this->db = $this->new_dbal(); +		$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx); +		$this->request = $this->getMock('\phpbb\request\request'); + +		$this->filesystem = new \phpbb\filesystem\filesystem(); +		$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); +		$this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; +		$guessers = array( +			new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), +			new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(), +			new \phpbb\mimetype\content_guesser(), +			new \phpbb\mimetype\extension_guesser(), +		); +		$guessers[2]->set_priority(-2); +		$guessers[3]->set_priority(-2); +		$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); +		$this->plupload = new \phpbb\plupload\plupload($phpbb_root_path, $this->config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), $this->php_ini, $this->mimetype_guesser); +		$factory_mock = $this->getMockBuilder('\phpbb\files\factory') +			->disableOriginalConstructor() +			->getMock(); +		$factory_mock->expects($this->any()) +			->method('get') +			->willReturn(new \phpbb\files\filespec( +				$this->filesystem, +				$this->language, +				$this->php_ini, +				new \FastImageSize\FastImageSize(), +				$this->phpbb_root_path, +				$this->mimetype_guesser +			)); + +		$this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); +		$this->container->set('files.filespec', new \phpbb\files\filespec( +			$this->filesystem, +			$this->language, +			$this->php_ini, +			new \FastImageSize\FastImageSize(), +			$phpbb_root_path, +			new \phpbb\mimetype\guesser(array( +				'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), +			)))); +		$this->container->set('files.types.form', new \phpbb\files\types\form( +			$factory_mock, +			$this->language, +			$this->php_ini, +			$this->plupload, +			$this->request +		)); +		$this->container->set('files.types.local', new \phpbb\files\types\local( +			$factory_mock, +			$this->language, +			$this->php_ini, +			$this->request +		)); +		$this->factory = new \phpbb\files\factory($this->container); +		$this->files_upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); +		$this->phpbb_dispatcher = new phpbb_mock_event_dispatcher(); +		$this->user = new \phpbb\user($this->language, '\phpbb\datetime'); + + +		$this->upload = new \phpbb\attachment\upload( +			$this->auth, +			$this->cache, +			$this->config, +			$this->files_upload, +			$this->language, +			$this->mimetype_guesser, +			$this->phpbb_dispatcher, +			$this->plupload, +			$this->user, +			$this->phpbb_root_path +		); +	} + +	public function data_upload() +	{ +		return array( +			array('foobar', 1, false, +				array(), +				array( +					'error' => array( +						'Upload initiated but no valid file upload form found.', +					), +					'post_attach'	=> false, +				) +			), +			array('foobar', 1, true, +				array( +					'realname'		=> 'foobar.jpg', +					'type'			=> 'jpg', +					'size'			=> 100, +				), +				array( +					'error' => array( +						'NOT_UPLOADED', +						'The image file you tried to attach is invalid.', +					), +					'post_attach'	=> false, +					'thumbnail'		=> 1, +				) +			), +			array('foobar', 1, true, +				array(), +				array( +					'error' => array( +						'NOT_UPLOADED', +					), +					'post_attach'	=> false, +					'thumbnail'		=> 0, +				) +			), +		); +	} + +	/** +	 * @dataProvider data_upload +	 */ +	public function test_upload($form_name, $forum_id, $local, $filedata, $expected) +	{ +		$filedata = $this->upload->upload($form_name, $forum_id, $local, '', false, $filedata); + +		$this->assertSame($expected, $filedata); +	} + +	public function test_init_error() +	{ +		$filespec = $this->getMockBuilder('\phpbb\files\filespec') +			->disableOriginalConstructor() +			->getMock(); +		$filespec->expects($this->any()) +			->method('init_error') +			->willReturn(true); +		$filespec->expects($this->any()) +			->method('set_upload_namespace') +			->willReturnSelf(); +		$filespec->expects($this->any()) +			->method('set_upload_ary') +			->willReturnSelf(); +		$this->container->set('files.filespec', $filespec); +		$factory_mock = $this->getMockBuilder('\phpbb\files\factory') +			->disableOriginalConstructor() +			->getMock(); +		$factory_mock->expects($this->any()) +			->method('get') +			->willReturn($filespec); +		$this->container->set('files.types.local', new \phpbb\files\types\local( +			$factory_mock, +			$this->language, +			$this->php_ini, +			$this->request +		)); + +		$this->upload = new \phpbb\attachment\upload( +			$this->auth, +			$this->cache, +			$this->config, +			$this->files_upload, +			$this->language, +			$this->mimetype_guesser, +			$this->phpbb_dispatcher, +			$this->plupload, +			$this->user, +			$this->phpbb_root_path +		); + +		$filedata = $this->upload->upload('foobar', 1, true); + +		$this->assertSame(array( +			'error'		=> array(), +			'post_attach'	=> false, +		), $filedata); +	} + +	public function data_image_upload() +	{ +		return array( +			array(false, false, array(), +				array( +					'error'			=> array('The image file you tried to attach is invalid.'), +					'post_attach'	=> false, +					'thumbnail'		=> 1, +				) +			), +			array(false, true, array(), +				array( +					'error'			=> array('The image file you tried to attach is invalid.'), +					'post_attach'	=> false, +					'thumbnail'		=> 1, +				) +			), +			array(true, false, array(), +				array( +					'error'			=> array(), +					'post_attach'	=> true, +					// thumbnail gets reset to 0 as creation was not possible +					'thumbnail'		=> 0, +					'filesize'		=> 100, +					'mimetype'		=> 'jpg', +					'extension'		=> 'jpg', +					'real_filename'	=> 'foobar.jpg', +				) +			), +			array(true, false, +				array( +					'check_attachment_content'	=> true, +					'mime_triggers'	=> '', +				), +				array( +					'error'			=> array(), +					'post_attach'	=> true, +					// thumbnail gets reset to 0 as creation was not possible +					'thumbnail'		=> 0, +					'filesize'		=> 100, +					'mimetype'		=> 'jpg', +					'extension'		=> 'jpg', +					'real_filename'	=> 'foobar.jpg', +				) +			), +			array(true, false, +				array( +					'attachment_quota'	=> 150, +				), +				array( +					'error'			=> array(), +					'post_attach'	=> true, +					// thumbnail gets reset to 0 as creation was not possible +					'thumbnail'		=> 0, +					'filesize'		=> 100, +					'mimetype'		=> 'jpg', +					'extension'		=> 'jpg', +					'real_filename'	=> 'foobar.jpg', +				) +			), +			array(true, false, +				array( +					'attachment_quota'	=> 50, +				), +				array( +					'error'			=> array( +						'ATTACH_QUOTA_REACHED', +					), +					'post_attach'	=> false, +					'thumbnail'		=> 1, +					'filesize'		=> 100, +					'mimetype'		=> 'jpg', +					'extension'		=> 'jpg', +					'real_filename'	=> 'foobar.jpg', +				) +			), +		); +	} + +	/** +	 * @dataProvider data_image_upload +	 */ +	public function test_image_upload($is_image, $plupload_active, $config_data, $expected) +	{ +		$filespec = $this->getMock('\phpbb\files\filespec', +			array( +				'init_error', +				'is_image', +				'move_file', +				'is_uploaded', +			), +			array( +				$this->filesystem, +				$this->language, +				$this->php_ini, +				new \FastImageSize\FastImageSize(), +				$this->phpbb_root_path, +				$this->mimetype_guesser, +				$this->plupload +			)); +		foreach ($config_data as $key => $value) +		{ +			$this->config[$key] = $value; +		} +		$filespec->set_upload_namespace($this->files_upload); +		$filespec->expects($this->any()) +			->method('init_error') +			->willReturn(false); +		$filespec->expects($this->any()) +			->method('is_image') +			->willReturn($is_image); +		$filespec->expects($this->any()) +			->method('is_uploaded') +			->willReturn(true); +		$filespec->expects($this->any()) +			->method('move_file') +			->willReturn(false); +		$this->container->set('files.filespec', $filespec); +		$factory_mock = $this->getMockBuilder('\phpbb\files\factory') +			->disableOriginalConstructor() +			->getMock(); +		$factory_mock->expects($this->any()) +			->method('get') +			->willReturn($filespec); +		$this->container->set('files.types.local', new \phpbb\files\types\local( +			$factory_mock, +			$this->language, +			$this->php_ini, +			$this->request +		)); + +		$plupload = $this->getMockBuilder('\phpbb\plupload\plupload') +			->disableOriginalConstructor() +			->getMock(); +		$plupload->expects($this->any()) +			->method('is_active') +			->willReturn($plupload_active); +		if ($plupload_active) +		{ +			$plupload->expects($this->once()) +				->method('emit_error') +				->with(104, 'ATTACHED_IMAGE_NOT_IMAGE') +				->willReturn(false); +		} +		$this->upload = new \phpbb\attachment\upload( +			$this->auth, +			$this->cache, +			$this->config, +			$this->files_upload, +			$this->language, +			$this->mimetype_guesser, +			$this->phpbb_dispatcher, +			$plupload, +			$this->user, +			$this->phpbb_root_path +		); + +		$filedata = $this->upload->upload('foobar', 1, true, '', false, array( +			'realname'		=> 'foobar.jpg', +			'type'			=> 'jpg', +			'size'			=> 100, +		)); + +		foreach ($expected as $key => $entry) +		{ +			$this->assertEquals($entry, $filedata[$key]); +		} + +		// Reset config data +		foreach ($config_data as $key => $value) +		{ +			$this->config->delete($key); +		} +	} +} | 
