diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-05-01 12:55:00 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-01 12:55:00 -0300 |
commit | dba55f950a21802052698baa63713c2693078aa7 (patch) | |
tree | cb95f33972f5596d07c67a787250e9499e98c47a /apps | |
parent | 3eba37ac14dd24bcfe855800b9ec90c3e65e521c (diff) | |
parent | 7c69c117e20940747744bcc0172898df40484e1f (diff) | |
download | nextcloud-server-dba55f950a21802052698baa63713c2693078aa7.tar.gz nextcloud-server-dba55f950a21802052698baa63713c2693078aa7.zip |
Merge pull request #4594 from nextcloud/theming-image-default
Delete theming images when logo/background is reset to default
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 19 | ||||
-rw-r--r-- | apps/theming/tests/Controller/ThemingControllerTest.php | 50 |
2 files changed, 69 insertions, 0 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index cffc628e9b9..faaff1f2174 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -40,6 +40,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\File; use OCP\Files\IAppData; use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -265,6 +266,24 @@ class ThemingController extends Controller { $value = $this->themingDefaults->undo($setting); // reprocess server scss for preview $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core'); + + if($setting === 'logoMime') { + try { + $file = $this->appData->getFolder('images')->getFile('logo'); + $file->delete(); + } catch (NotFoundException $e) { + } catch (NotPermittedException $e) { + } + } + if($setting === 'backgroundMime') { + try { + $file = $this->appData->getFolder('images')->getFile('background'); + $file->delete(); + } catch (NotFoundException $e) { + } catch (NotPermittedException $e) { + } + } + return new DataResponse( [ 'data' => diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 0aa9ead3742..f22c317d73d 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -385,6 +385,56 @@ class ThemingControllerTest extends TestCase { $this->assertEquals($expected, $this->themingController->undo('MySetting')); } + public function dataUndoDelete() { + return [ + [ 'backgroundMime', 'background' ], + [ 'logoMime', 'logo' ] + ]; + } + + /** @dataProvider dataUndoDelete */ + public function testUndoDelete($value, $filename) { + $this->l10n + ->expects($this->once()) + ->method('t') + ->with('Saved') + ->willReturn('Saved'); + $this->themingDefaults + ->expects($this->once()) + ->method('undo') + ->with($value) + ->willReturn($value); + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willReturn($folder); + $folder + ->expects($this->once()) + ->method('getFile') + ->with($filename) + ->willReturn($file); + $file + ->expects($this->once()) + ->method('delete'); + + $expected = new DataResponse( + [ + 'data' => + [ + 'value' => $value, + 'message' => 'Saved', + ], + 'status' => 'success' + ] + ); + $this->assertEquals($expected, $this->themingController->undo($value)); + } + + + public function testGetLogoNotExistent() { $this->appData->method('getFolder') ->with($this->equalTo('images')) |