Split updateStylesheet tests for success and error

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 <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-08-10 11:21:43 +02:00
parent 8d93a0db8a
commit e883061f58
1 changed files with 51 additions and 17 deletions

View File

@ -102,33 +102,26 @@ class ThemingControllerTest extends TestCase {
return parent::setUp(); return parent::setUp();
} }
public function dataUpdateStylesheet() { public function dataUpdateStylesheetSuccess() {
return [ return [
['name', str_repeat('a', 250), 'success', 'Saved'], ['name', str_repeat('a', 250), 'Saved'],
['name', str_repeat('a', 251), 'error', 'The given name is too long'], ['url', str_repeat('a', 500), 'Saved'],
['url', str_repeat('a', 500), 'success', 'Saved'], ['slogan', str_repeat('a', 500), 'Saved'],
['url', str_repeat('a', 501), 'error', 'The given web address is too long'], ['color', '#0082c9', 'Saved'],
['slogan', str_repeat('a', 500), 'success', 'Saved'], ['color', '#0082C9', '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'],
]; ];
} }
/** /**
* @dataProvider dataUpdateStylesheet * @dataProvider dataUpdateStylesheetSuccess
* *
* @param string $setting * @param string $setting
* @param string $value * @param string $value
* @param string $status
* @param string $message * @param string $message
*/ */
public function testUpdateStylesheet($setting, $value, $status, $message) { public function testUpdateStylesheetSuccess($setting, $value, $message) {
$this->themingDefaults $this->themingDefaults
->expects($status === 'success' ? $this->once() : $this->never()) ->expects($this->once())
->method('set') ->method('set')
->with($setting, $value); ->with($setting, $value);
$this->l10n $this->l10n
@ -143,7 +136,48 @@ class ThemingControllerTest extends TestCase {
[ [
'message' => $message, '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)); $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));