1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - Tasks |
4
|
|
|
* |
5
|
|
|
* @author Raimund Schlüßler |
6
|
|
|
* @copyright 2019 Raimund Schlüßler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Tasks\Tests\Unit\Controller; |
24
|
|
|
|
25
|
|
|
use OCA\Tasks\Controller\SettingsController; |
26
|
|
|
use OCA\Tasks\Service\SettingsService; |
27
|
|
|
use OCP\IRequest; |
28
|
|
|
|
29
|
|
|
use PHPUnit\Framework\TestCase; |
30
|
|
|
|
31
|
|
|
|
32
|
|
View Code Duplication |
class SettingsControllerTest extends TestCase { |
|
|
|
|
33
|
|
|
|
34
|
|
|
private $appName; |
35
|
|
|
private $settingsService; |
36
|
|
|
private $request; |
37
|
|
|
private $controller; |
38
|
|
|
|
39
|
|
|
use \OCA\Tasks\Controller\Response; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Gets run before each test |
43
|
|
|
*/ |
44
|
|
|
public function setUp(): void { |
45
|
|
|
$this->appName = 'tasks'; |
46
|
|
|
$this->settingsService = $this->getMockBuilder(SettingsService::class) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
$this->request = $this->getMockBuilder(IRequest::class) |
50
|
|
|
->disableOriginalConstructor() |
51
|
|
|
->getMock(); |
52
|
|
|
$this->controller = new SettingsController( |
53
|
|
|
$this->appName, |
54
|
|
|
$this->request, |
55
|
|
|
$this->settingsService |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGet() { |
60
|
|
|
$return = ['sortOrder' => 0]; |
61
|
|
|
$this->settingsService->expects($this->once()) |
62
|
|
|
->method('get') |
63
|
|
|
->will($this->returnValue($return)); |
64
|
|
|
|
65
|
|
|
$expected = $this->generateResponse(function () use ($return) { |
66
|
|
|
return ['settings' => $return]; |
67
|
|
|
}); |
68
|
|
|
$response = $this->controller->get(); |
69
|
|
|
$this->assertEquals($expected, $response); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testSet() { |
73
|
|
|
$this->settingsService->expects($this->once()) |
74
|
|
|
->method('set') |
75
|
|
|
->with( |
76
|
|
|
'sortOrder', |
77
|
|
|
$this->equalTo(0) |
78
|
|
|
) |
79
|
|
|
->will($this->returnValue(true)); |
80
|
|
|
|
81
|
|
|
$expected = $this->generateResponse(function () { |
82
|
|
|
return true; |
83
|
|
|
}); |
84
|
|
|
$response = $this->controller->set('sortOrder', 0); |
85
|
|
|
$this->assertEquals($expected, $response); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.