Skip to content

Commit

Permalink
[ticket/13904] Add more tests and test cases
Browse files Browse the repository at this point in the history
PHPBB3-13904
  • Loading branch information
marc1706 committed Sep 9, 2015
1 parent 3e99816 commit 46e3d82
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/functional/fileupload_remote_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function test_successful_upload()
$file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif');
$this->assertEquals(0, sizeof($file->error));
$this->assertTrue(file_exists($file->get('filename')));
$this->assertTrue($file->is_uploaded());
}

public function test_too_large()
Expand Down
3 changes: 2 additions & 1 deletion tests/mock/fileupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class phpbb_mock_fileupload
{
public $max_filesize = 100;
public $error_prefix = '';
public $valid_dimensions = true;

public function valid_dimensions($filespec)
{
return true;
return $this->valid_dimensions;
}
}
43 changes: 43 additions & 0 deletions tests/upload/filespec_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ protected function tearDown()
}
}

public function test_empty_upload_ary()
{
$filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser);
$this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array()));
$this->assertTrue($filespec->init_error());
}

public function additional_checks_variables()
{
// False here just indicates the file is too large and fails the
Expand Down Expand Up @@ -140,6 +147,19 @@ public function test_additional_checks($filename, $expected)
$this->assertEquals($expected, $filespec->additional_checks());
}

public function test_additional_checks_dimensions()
{
$upload = new phpbb_mock_fileupload();
$filespec = $this->get_filespec();
$filespec->set_upload_namespace($upload);
$upload->valid_dimensions = false;
$filespec->file_moved = true;
$upload->max_filesize = 0;

$this->assertEquals(false, $filespec->additional_checks());
$this->assertSame(array('WRONG_SIZE'), $filespec->error);
}

public function check_content_variables()
{
// False here indicates that a file is non-binary and contains
Expand Down Expand Up @@ -388,4 +408,27 @@ public function test_uploadname($filename)

$this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->get('uploadname'));
}

public function test_is_uploaded()
{
$filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, null);
$reflection_filespec = new ReflectionClass($filespec);
$plupload_property = $reflection_filespec->getProperty('plupload');
$plupload_property->setAccessible(true);
$plupload_mock = $this->getMockBuilder('\phpbb\plupload\plupload')
->disableOriginalConstructor()
->getMock();
$plupload_mock->expects($this->any())
->method('is_active')
->will($this->returnValue(true));
$plupload_property->setValue($filespec, $plupload_mock);
$is_uploaded = $reflection_filespec->getMethod('is_uploaded');

// Plupload is active and file does not exist
$this->assertFalse($is_uploaded->invoke($filespec));

// Plupload is not active and file was not uploaded
$plupload_property->setValue($filespec, null);
$this->assertFalse($is_uploaded->invoke($filespec));
}
}
4 changes: 3 additions & 1 deletion tests/upload/fileupload_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public function test_local_upload()
copy($this->path . 'jpg', $this->path . 'jpg.jpg');
$file = $upload->handle_upload('local', $this->path . 'jpg.jpg');
$this->assertEquals(0, sizeof($file->error));
unlink($this->path . 'jpg.jpg');
$this->assertFalse($file->additional_checks());
$this->assertTrue($file->move_file('../tests/upload/fixture/copies', true));
$file->remove();
}

public function test_move_existent_file()
Expand Down

0 comments on commit 46e3d82

Please sign in to comment.