From 986dffdae45402b9642f51565c608cb7d85ac817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 10 Aug 2017 11:21:43 +0200 Subject: [PATCH] Split updateStylesheet tests for success and error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a preparatory step for a following commit in which the properties present in the response will change depending on whether the request was successful or not. Signed-off-by: Daniel Calviño Sánchez --- .../Controller/ThemingControllerTest.php | 68 ++++++++++++++----- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index a5a8798217..960ce03b13 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -102,33 +102,26 @@ class ThemingControllerTest extends TestCase { return parent::setUp(); } - public function dataUpdateStylesheet() { + public function dataUpdateStylesheetSuccess() { return [ - ['name', str_repeat('a', 250), 'success', 'Saved'], - ['name', str_repeat('a', 251), 'error', 'The given name is too long'], - ['url', str_repeat('a', 500), 'success', 'Saved'], - ['url', str_repeat('a', 501), 'error', 'The given web address is too long'], - ['slogan', str_repeat('a', 500), 'success', 'Saved'], - ['slogan', str_repeat('a', 501), 'error', 'The given slogan is too long'], - ['color', '#0082c9', 'success', 'Saved'], - ['color', '#0082C9', 'success', 'Saved'], - ['color', '0082C9', 'error', 'The given color is invalid'], - ['color', '#0082Z9', 'error', 'The given color is invalid'], - ['color', 'Nextcloud', 'error', 'The given color is invalid'], + ['name', str_repeat('a', 250), 'Saved'], + ['url', str_repeat('a', 500), 'Saved'], + ['slogan', str_repeat('a', 500), 'Saved'], + ['color', '#0082c9', 'Saved'], + ['color', '#0082C9', 'Saved'], ]; } /** - * @dataProvider dataUpdateStylesheet + * @dataProvider dataUpdateStylesheetSuccess * * @param string $setting * @param string $value - * @param string $status * @param string $message */ - public function testUpdateStylesheet($setting, $value, $status, $message) { + public function testUpdateStylesheetSuccess($setting, $value, $message) { $this->themingDefaults - ->expects($status === 'success' ? $this->once() : $this->never()) + ->expects($this->once()) ->method('set') ->with($setting, $value); $this->l10n @@ -143,7 +136,48 @@ class ThemingControllerTest extends TestCase { [ 'message' => $message, ], - 'status' => $status, + 'status' => 'success', + ] + ); + $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value)); + } + + public function dataUpdateStylesheetError() { + return [ + ['name', str_repeat('a', 251), 'The given name is too long'], + ['url', str_repeat('a', 501), 'The given web address is too long'], + ['slogan', str_repeat('a', 501), 'The given slogan is too long'], + ['color', '0082C9', 'The given color is invalid'], + ['color', '#0082Z9', 'The given color is invalid'], + ['color', 'Nextcloud', 'The given color is invalid'], + ]; + } + + /** + * @dataProvider dataUpdateStylesheetError + * + * @param string $setting + * @param string $value + * @param string $message + */ + public function testUpdateStylesheetError($setting, $value, $message) { + $this->themingDefaults + ->expects($this->never()) + ->method('set') + ->with($setting, $value); + $this->l10n + ->expects($this->once()) + ->method('t') + ->with($message) + ->willReturn($message); + + $expected = new DataResponse( + [ + 'data' => + [ + 'message' => $message, + ], + 'status' => 'error', ] ); $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));