[ticket/14168] Improve code coverage in upload class

PHPBB3-14168
This commit is contained in:
Marc Alexander 2015-10-04 12:28:12 +02:00
parent 36ea105236
commit 1f1e708815

View file

@ -12,6 +12,7 @@
*/ */
require_once(dirname(__FILE__) . '/../../phpBB/includes/functions.php'); 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 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->auth = new \phpbb\auth\auth();
$this->config = new \phpbb\config\config(array( $this->config = new \phpbb\config\config(array(
'upload_path' => '../attachment/fixtures/', 'upload_path' => '',
'img_create_thumbnail' => true,
)); ));
$config = $this->config; $config = $this->config;
$this->db = $this->new_dbal(); $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.', 'The image file you tried to attach is invalid.',
), ),
'post_attach' => false, 'post_attach' => false,
'thumbnail' => 0, 'thumbnail' => 1,
) )
), ),
array('foobar', 1, true, array('foobar', 1, true,
@ -251,18 +253,89 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
), $filedata); ), $filedata);
} }
public function data_image_not_image() public function data_image_upload()
{ {
return array( return array(
array(false), array(false, false, array(),
array(true), 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', $filespec = $this->getMock('\phpbb\files\filespec',
array( array(
@ -280,13 +353,17 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
$this->mimetype_guesser, $this->mimetype_guesser,
$this->plupload $this->plupload
)); ));
foreach ($config_data as $key => $value)
{
$this->config[$key] = $value;
}
$filespec->set_upload_namespace($this->files_upload); $filespec->set_upload_namespace($this->files_upload);
$filespec->expects($this->any()) $filespec->expects($this->any())
->method('init_error') ->method('init_error')
->willReturn(false); ->willReturn(false);
$filespec->expects($this->any()) $filespec->expects($this->any())
->method('is_image') ->method('is_image')
->willReturn(false); ->willReturn($is_image);
$filespec->expects($this->any()) $filespec->expects($this->any())
->method('is_uploaded') ->method('is_uploaded')
->willReturn(true); ->willReturn(true);
@ -338,10 +415,16 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
'type' => 'jpg', 'type' => 'jpg',
'size' => 100, 'size' => 100,
)); ));
$this->assertEquals(array(
'error' => array('The image file you tried to attach is invalid.'), foreach ($expected as $key => $entry)
'post_attach' => false, {
'thumbnail' => 0, $this->assertEquals($entry, $filedata[$key]);
), $filedata); }
// Reset config data
foreach ($config_data as $key => $value)
{
$this->config->delete($key);
}
} }
} }