瀏覽代碼

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>
tags/v13.0.0beta1
Daniel Calviño Sánchez 6 年之前
父節點
當前提交
986dffdae4
共有 1 個檔案被更改,包括 51 行新增17 行删除
  1. 51
    17
      apps/theming/tests/Controller/ThemingControllerTest.php

+ 51
- 17
apps/theming/tests/Controller/ThemingControllerTest.php 查看文件

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', 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 $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')
->with($setting, $value);
$this->l10n
->expects($this->once())
->method('t')
->with($message)
->willReturn($message);

$expected = new DataResponse(
[
'data' =>
[
'message' => $message,
],
'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') ->method('set')
->with($setting, $value); ->with($setting, $value);
$this->l10n $this->l10n
[ [
'message' => $message, 'message' => $message,
], ],
'status' => $status,
'status' => 'error',
] ]
); );
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value)); $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));

Loading…
取消
儲存