summaryrefslogtreecommitdiffstats
path: root/apps/theming/tests
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-09-21 11:36:27 +0200
committerJulius Härtl <jus@bitgrid.net>2017-10-03 15:34:44 +0200
commitf15e85c4f50b6c9e77742e15f8291a8628a28ef7 (patch)
tree6c295017a74b581e6377a16de92a103fbc78b601 /apps/theming/tests
parent9651c1abffa0134b11b7637de76ceb4e3ffae79e (diff)
downloadnextcloud-server-f15e85c4f50b6c9e77742e15f8291a8628a28ef7.tar.gz
nextcloud-server-f15e85c4f50b6c9e77742e15f8291a8628a28ef7.zip
Theming: Add tests for mimetype and upload error checks
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/tests')
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php162
1 files changed, 158 insertions, 4 deletions
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index 96a742cfa37..e964e886e5c 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -229,6 +229,56 @@ class ThemingControllerTest extends TestCase {
[
'message' => 'No file uploaded',
],
+ 'status' => 'failure',
+ ],
+ Http::STATUS_UNPROCESSABLE_ENTITY
+ );
+
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
+ public function testUpdateLogoInvalidMimeType() {
+ $this->request
+ ->expects($this->at(0))
+ ->method('getParam')
+ ->with('backgroundColor')
+ ->willReturn(false);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn([
+ 'tmp_name' => 'logo.pdf',
+ 'type' => 'application/pdf',
+ 'name' => 'logo.pdf',
+ 'error' => 0,
+ ]);
+ $this->request
+ ->expects($this->at(2))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn(null);
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($str) {
+ return $str;
+ }));
+
+ $folder = $this->createMock(ISimpleFolder::class);
+ $this->appData
+ ->expects($this->once())
+ ->method('getFolder')
+ ->with('images')
+ ->willReturn($folder);
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => 'Unsupported image type',
+ ],
+ 'status' => 'failure'
],
Http::STATUS_UNPROCESSABLE_ENTITY
);
@@ -261,13 +311,17 @@ class ThemingControllerTest extends TestCase {
public function dataUpdateImages() {
return [
- [false],
- [true]
+ ['image/jpeg', false],
+ ['image/jpeg', true],
+ ['image/gif'],
+ ['image/png'],
+ ['image/svg+xml'],
+ ['text/svg'],
];
}
/** @dataProvider dataUpdateImages */
- public function testUpdateLogoNormalLogoUpload($folderExists) {
+ public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists=true) {
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
$destination = \OC::$server->getTempManager()->getTemporaryFolder();
@@ -283,7 +337,7 @@ class ThemingControllerTest extends TestCase {
->with('uploadlogo')
->willReturn([
'tmp_name' => $tmpLogo,
- 'type' => 'text/svg',
+ 'type' => $mimeType,
'name' => 'logo.svg',
'error' => 0,
]);
@@ -461,6 +515,106 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->updateLogo());
}
+ public function dataPhpUploadErrors() {
+ return [
+ [UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'],
+ [UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'],
+ [UPLOAD_ERR_PARTIAL, 'The uploaded file was only partially uploaded'],
+ [UPLOAD_ERR_NO_FILE, 'No file was uploaded'],
+ [UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder'],
+ [UPLOAD_ERR_CANT_WRITE, 'Failed to write file to disk.'],
+ [UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload.'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataPhpUploadErrors
+ */
+ public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
+ $this->request
+ ->expects($this->at(0))
+ ->method('getParam')
+ ->with('backgroundColor')
+ ->willReturn(false);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn(null);
+ $this->request
+ ->expects($this->at(2))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn([
+ 'tmp_name' => '',
+ 'type' => 'text/svg',
+ 'name' => 'logo.svg',
+ 'error' => $error,
+ ]);
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($str) {
+ return $str;
+ }));
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => $expectedErrorMessage,
+ ],
+ 'status' => 'failure'
+ ],
+ Http::STATUS_UNPROCESSABLE_ENTITY
+ );
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
+ /**
+ * @dataProvider dataPhpUploadErrors
+ */
+ public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
+ $this->request
+ ->expects($this->at(0))
+ ->method('getParam')
+ ->with('backgroundColor')
+ ->willReturn(false);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn([
+ 'tmp_name' => '',
+ 'type' => 'text/svg',
+ 'name' => 'logo.svg',
+ 'error' => $error,
+ ]);
+ $this->request
+ ->expects($this->at(2))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn(null);
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($str) {
+ return $str;
+ }));
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => $expectedErrorMessage
+ ],
+ 'status' => 'failure'
+ ],
+ Http::STATUS_UNPROCESSABLE_ENTITY
+ );
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
public function testUndo() {
$this->l10n
->expects($this->once())