Code Duplication    Length = 11-12 lines in 10 locations

tests/php/controller/settingscontrollerTest.php 10 locations

@@ 94-105 (lines=12) @@
91
		$this->assertEquals(422, $actual->getStatus());
92
	}
93
94
	public function testSetViewWithConfigException() {
95
		$this->config->expects($this->once())
96
			->method('setUserValue')
97
			->with('user123', $this->appName, 'currentView', 'month')
98
			->will($this->throwException(new \Exception));
99
100
		$actual = $this->controller->setConfig('view', 'month');
101
102
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
103
		$this->assertEquals([], $actual->getData());
104
		$this->assertEquals(500, $actual->getStatus());
105
	}
106
107
	public function testGetView() {
108
		$this->config->expects($this->once())
@@ 107-118 (lines=12) @@
104
		$this->assertEquals(500, $actual->getStatus());
105
	}
106
107
	public function testGetView() {
108
		$this->config->expects($this->once())
109
			->method('getUserValue')
110
			->with('user123', $this->appName, 'currentView', 'month')
111
			->will($this->returnValue('agendaWeek'));
112
113
		$actual = $this->controller->getConfig('view');
114
115
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
116
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
117
		$this->assertEquals(200, $actual->getStatus());
118
	}
119
120
	public function testGetViewWithConfigException() {
121
		$this->config->expects($this->once())
@@ 120-131 (lines=12) @@
117
		$this->assertEquals(200, $actual->getStatus());
118
	}
119
120
	public function testGetViewWithConfigException() {
121
		$this->config->expects($this->once())
122
			->method('getUserValue')
123
			->with('user123', $this->appName, 'currentView', 'month')
124
			->will($this->throwException(new \Exception));
125
126
		$actual = $this->controller->getConfig('view');
127
128
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
129
		$this->assertEquals([], $actual->getData());
130
		$this->assertEquals(500, $actual->getStatus());
131
	}
132
133
	/**
134
	 * @dataProvider setPopoverWithAllowedValueDataProvider
@@ 163-174 (lines=12) @@
160
		$this->assertEquals(422, $actual->getStatus());
161
	}
162
163
	public function testSetPopoverWithConfigException() {
164
		$this->config->expects($this->once())
165
			->method('setUserValue')
166
			->with('user123', $this->appName, 'skipPopover', 'no')
167
			->will($this->throwException(new \Exception));
168
169
		$actual = $this->controller->setConfig('skipPopover', 'no');
170
171
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
172
		$this->assertEquals([], $actual->getData());
173
		$this->assertEquals(500, $actual->getStatus());
174
	}
175
176
	public function testGetPopover() {
177
		$this->config->expects($this->once())
@@ 176-187 (lines=12) @@
173
		$this->assertEquals(500, $actual->getStatus());
174
	}
175
176
	public function testGetPopover() {
177
		$this->config->expects($this->once())
178
			->method('getUserValue')
179
			->with('user123', $this->appName, 'skipPopover', 'no')
180
			->will($this->returnValue('agendaWeek'));
181
182
		$actual = $this->controller->getConfig('skipPopover');
183
184
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
185
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
186
		$this->assertEquals(200, $actual->getStatus());
187
	}
188
189
	public function testGetPopoverWithConfigException() {
190
		$this->config->expects($this->once())
@@ 189-200 (lines=12) @@
186
		$this->assertEquals(200, $actual->getStatus());
187
	}
188
189
	public function testGetPopoverWithConfigException() {
190
		$this->config->expects($this->once())
191
			->method('getUserValue')
192
			->with('user123', $this->appName, 'skipPopover', 'no')
193
			->will($this->throwException(new \Exception));
194
195
		$actual = $this->controller->getConfig('skipPopover');
196
197
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
198
		$this->assertEquals([], $actual->getData());
199
		$this->assertEquals(500, $actual->getStatus());
200
	}
201
202
	public function testSetFirstRun() {
203
		$this->config->expects($this->once())
@@ 202-212 (lines=11) @@
199
		$this->assertEquals(500, $actual->getStatus());
200
	}
201
202
	public function testSetFirstRun() {
203
		$this->config->expects($this->once())
204
			->method('setUserValue')
205
			->with('user123', $this->appName, 'firstRun', 'no');
206
207
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
208
209
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
210
		$this->assertEquals([], $actual->getData());
211
		$this->assertEquals(200, $actual->getStatus());
212
	}
213
214
	public function testSetFirstRunWithException() {
215
		$this->config->expects($this->once())
@@ 214-225 (lines=12) @@
211
		$this->assertEquals(200, $actual->getStatus());
212
	}
213
214
	public function testSetFirstRunWithException() {
215
		$this->config->expects($this->once())
216
			->method('setUserValue')
217
			->with('user123', $this->appName, 'firstRun', 'no')
218
			->will($this->throwException(new \Exception));
219
220
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
221
222
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
223
		$this->assertEquals([], $actual->getData());
224
		$this->assertEquals(500, $actual->getStatus());
225
	}
226
227
	public function testGetFirstRun() {
228
		$this->config->expects($this->once())
@@ 227-238 (lines=12) @@
224
		$this->assertEquals(500, $actual->getStatus());
225
	}
226
227
	public function testGetFirstRun() {
228
		$this->config->expects($this->once())
229
			->method('getUserValue')
230
			->with('user123', $this->appName, 'firstRun', 'yes')
231
			->will($this->returnValue('no'));
232
233
		$actual = $this->controller->getConfig('firstRun');
234
235
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
236
		$this->assertEquals(['value' => 'no'], $actual->getData());
237
		$this->assertEquals(200, $actual->getStatus());
238
	}
239
240
	public function testGetFirstRunWithException() {
241
		$this->config->expects($this->once())
@@ 240-251 (lines=12) @@
237
		$this->assertEquals(200, $actual->getStatus());
238
	}
239
240
	public function testGetFirstRunWithException() {
241
		$this->config->expects($this->once())
242
			->method('getUserValue')
243
			->with('user123', $this->appName, 'firstRun', 'yes')
244
			->will($this->throwException(new \Exception));
245
246
		$actual = $this->controller->getConfig('firstRun');
247
248
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
249
		$this->assertEquals([], $actual->getData());
250
		$this->assertEquals(500, $actual->getStatus());
251
	}
252
253
	public function testGetNotExistingConfig() {
254
		$actual = $this->controller->getConfig('foo');