diff options
author | Marc Alexander <admin@m-a-styles.de> | 2015-10-04 12:28:12 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2015-10-09 10:18:41 +0200 |
commit | 1f1e708815369cc25f1c59c5ed69a49f80b64318 (patch) | |
tree | c1b7eadedf3d9bf08a57d2dd2eabe1fe8c26938d /tests/attachment/upload_test.php | |
parent | 36ea105236c87e84ca2b9f0a193b5b8721e8cf97 (diff) | |
download | forums-1f1e708815369cc25f1c59c5ed69a49f80b64318.tar forums-1f1e708815369cc25f1c59c5ed69a49f80b64318.tar.gz forums-1f1e708815369cc25f1c59c5ed69a49f80b64318.tar.bz2 forums-1f1e708815369cc25f1c59c5ed69a49f80b64318.tar.xz forums-1f1e708815369cc25f1c59c5ed69a49f80b64318.zip |
[ticket/14168] Improve code coverage in upload class
PHPBB3-14168
Diffstat (limited to 'tests/attachment/upload_test.php')
-rw-r--r-- | tests/attachment/upload_test.php | 109 |
1 files changed, 96 insertions, 13 deletions
diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index d1007dbd77..295b6b15c9 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -12,6 +12,7 @@ */ 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 { @@ -75,7 +76,8 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->auth = new \phpbb\auth\auth(); $this->config = new \phpbb\config\config(array( - 'upload_path' => '../attachment/fixtures/', + 'upload_path' => '', + 'img_create_thumbnail' => true, )); $config = $this->config; $this->db = $this->new_dbal(); @@ -176,7 +178,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case 'The image file you tried to attach is invalid.', ), 'post_attach' => false, - 'thumbnail' => 0, + 'thumbnail' => 1, ) ), array('foobar', 1, true, @@ -251,18 +253,89 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case ), $filedata); } - public function data_image_not_image() + public function data_image_upload() { return array( - array(false), - array(true), + 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_not_image + * @dataProvider data_image_upload */ - public function test_image_not_image($plupload_active) + public function test_image_upload($is_image, $plupload_active, $config_data, $expected) { $filespec = $this->getMock('\phpbb\files\filespec', array( @@ -280,13 +353,17 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $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(false); + ->willReturn($is_image); $filespec->expects($this->any()) ->method('is_uploaded') ->willReturn(true); @@ -338,10 +415,16 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case 'type' => 'jpg', 'size' => 100, )); - $this->assertEquals(array( - 'error' => array('The image file you tried to attach is invalid.'), - 'post_attach' => false, - 'thumbnail' => 0, - ), $filedata); + + foreach ($expected as $key => $entry) + { + $this->assertEquals($entry, $filedata[$key]); + } + + // Reset config data + foreach ($config_data as $key => $value) + { + $this->config->delete($key); + } } } |