Code Duplication    Length = 11-12 lines in 14 locations

tests/php/controller/settingscontrollerTest.php 14 locations

@@ 96-107 (lines=12) @@
93
		$this->assertEquals(422, $actual->getStatus());
94
	}
95
96
	public function testSetViewWithConfigException() {
97
		$this->config->expects($this->once())
98
			->method('setUserValue')
99
			->with('user123', $this->appName, 'currentView', 'month')
100
			->will($this->throwException(new \Exception));
101
102
		$actual = $this->controller->setConfig('view', 'month');
103
104
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
105
		$this->assertEquals([], $actual->getData());
106
		$this->assertEquals(500, $actual->getStatus());
107
	}
108
109
	public function testGetView() {
110
		$this->config->expects($this->once())
@@ 109-120 (lines=12) @@
106
		$this->assertEquals(500, $actual->getStatus());
107
	}
108
109
	public function testGetView() {
110
		$this->config->expects($this->once())
111
			->method('getUserValue')
112
			->with('user123', $this->appName, 'currentView', 'month')
113
			->will($this->returnValue('agendaWeek'));
114
115
		$actual = $this->controller->getConfig('view');
116
117
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
118
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
119
		$this->assertEquals(200, $actual->getStatus());
120
	}
121
122
	public function testGetViewWithConfigException() {
123
		$this->config->expects($this->once())
@@ 122-133 (lines=12) @@
119
		$this->assertEquals(200, $actual->getStatus());
120
	}
121
122
	public function testGetViewWithConfigException() {
123
		$this->config->expects($this->once())
124
			->method('getUserValue')
125
			->with('user123', $this->appName, 'currentView', 'month')
126
			->will($this->throwException(new \Exception));
127
128
		$actual = $this->controller->getConfig('view');
129
130
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
131
		$this->assertEquals([], $actual->getData());
132
		$this->assertEquals(500, $actual->getStatus());
133
	}
134
135
	/**
136
	 * @dataProvider setPopoverWithAllowedValueDataProvider
@@ 165-176 (lines=12) @@
162
		$this->assertEquals(422, $actual->getStatus());
163
	}
164
165
	public function testSetPopoverWithConfigException() {
166
		$this->config->expects($this->once())
167
			->method('setUserValue')
168
			->with('user123', $this->appName, 'skipPopover', 'no')
169
			->will($this->throwException(new \Exception));
170
171
		$actual = $this->controller->setConfig('skipPopover', 'no');
172
173
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
174
		$this->assertEquals([], $actual->getData());
175
		$this->assertEquals(500, $actual->getStatus());
176
	}
177
178
	public function testGetPopover() {
179
		$this->config->expects($this->once())
@@ 178-189 (lines=12) @@
175
		$this->assertEquals(500, $actual->getStatus());
176
	}
177
178
	public function testGetPopover() {
179
		$this->config->expects($this->once())
180
			->method('getUserValue')
181
			->with('user123', $this->appName, 'skipPopover', 'no')
182
			->will($this->returnValue('agendaWeek'));
183
184
		$actual = $this->controller->getConfig('skipPopover');
185
186
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
187
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
188
		$this->assertEquals(200, $actual->getStatus());
189
	}
190
191
	public function testGetPopoverWithConfigException() {
192
		$this->config->expects($this->once())
@@ 191-202 (lines=12) @@
188
		$this->assertEquals(200, $actual->getStatus());
189
	}
190
191
	public function testGetPopoverWithConfigException() {
192
		$this->config->expects($this->once())
193
			->method('getUserValue')
194
			->with('user123', $this->appName, 'skipPopover', 'no')
195
			->will($this->throwException(new \Exception));
196
197
		$actual = $this->controller->getConfig('skipPopover');
198
199
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
200
		$this->assertEquals([], $actual->getData());
201
		$this->assertEquals(500, $actual->getStatus());
202
	}
203
204
	public function testSetFirstRun() {
205
		$this->config->expects($this->once())
@@ 204-214 (lines=11) @@
201
		$this->assertEquals(500, $actual->getStatus());
202
	}
203
204
	public function testSetFirstRun() {
205
		$this->config->expects($this->once())
206
			->method('setUserValue')
207
			->with('user123', $this->appName, 'firstRun', 'no');
208
209
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
210
211
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
212
		$this->assertEquals([], $actual->getData());
213
		$this->assertEquals(200, $actual->getStatus());
214
	}
215
216
	public function testSetFirstRunWithException() {
217
		$this->config->expects($this->once())
@@ 216-227 (lines=12) @@
213
		$this->assertEquals(200, $actual->getStatus());
214
	}
215
216
	public function testSetFirstRunWithException() {
217
		$this->config->expects($this->once())
218
			->method('setUserValue')
219
			->with('user123', $this->appName, 'firstRun', 'no')
220
			->will($this->throwException(new \Exception));
221
222
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
223
224
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
225
		$this->assertEquals([], $actual->getData());
226
		$this->assertEquals(500, $actual->getStatus());
227
	}
228
229
	public function testGetFirstRun() {
230
		$this->config->expects($this->once())
@@ 229-240 (lines=12) @@
226
		$this->assertEquals(500, $actual->getStatus());
227
	}
228
229
	public function testGetFirstRun() {
230
		$this->config->expects($this->once())
231
			->method('getUserValue')
232
			->with('user123', $this->appName, 'firstRun', 'yes')
233
			->will($this->returnValue('no'));
234
235
		$actual = $this->controller->getConfig('firstRun');
236
237
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
238
		$this->assertEquals(['value' => 'no'], $actual->getData());
239
		$this->assertEquals(200, $actual->getStatus());
240
	}
241
242
	public function testGetFirstRunWithException() {
243
		$this->config->expects($this->once())
@@ 242-253 (lines=12) @@
239
		$this->assertEquals(200, $actual->getStatus());
240
	}
241
242
	public function testGetFirstRunWithException() {
243
		$this->config->expects($this->once())
244
			->method('getUserValue')
245
			->with('user123', $this->appName, 'firstRun', 'yes')
246
			->will($this->throwException(new \Exception));
247
248
		$actual = $this->controller->getConfig('firstRun');
249
250
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
251
		$this->assertEquals([], $actual->getData());
252
		$this->assertEquals(500, $actual->getStatus());
253
	}
254
255
	public function testSetTimezone() {
256
		$this->config->expects($this->once())
@@ 255-265 (lines=11) @@
252
		$this->assertEquals(500, $actual->getStatus());
253
	}
254
255
	public function testSetTimezone() {
256
		$this->config->expects($this->once())
257
			->method('setUserValue')
258
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin');
259
260
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
261
262
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
263
		$this->assertEquals([], $actual->getData());
264
		$this->assertEquals(200, $actual->getStatus());
265
	}
266
267
	public function testSetTimezoneWithException() {
268
		$this->config->expects($this->once())
@@ 267-278 (lines=12) @@
264
		$this->assertEquals(200, $actual->getStatus());
265
	}
266
267
	public function testSetTimezoneWithException() {
268
		$this->config->expects($this->once())
269
			->method('setUserValue')
270
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin')
271
			->will($this->throwException(new \Exception));
272
273
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
274
275
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
276
		$this->assertEquals([], $actual->getData());
277
		$this->assertEquals(500, $actual->getStatus());
278
	}
279
280
	public function testGetTimezone() {
281
		$this->config->expects($this->once())
@@ 280-291 (lines=12) @@
277
		$this->assertEquals(500, $actual->getStatus());
278
	}
279
280
	public function testGetTimezone() {
281
		$this->config->expects($this->once())
282
			->method('getUserValue')
283
			->with('user123', $this->appName, 'timezone', 'automatic')
284
			->will($this->returnValue('Europe/Berlin'));
285
286
		$actual = $this->controller->getConfig('timezone');
287
288
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
289
		$this->assertEquals(['value' => 'Europe/Berlin'], $actual->getData());
290
		$this->assertEquals(200, $actual->getStatus());
291
	}
292
293
	public function testGetTimezoneWithException() {
294
		$this->config->expects($this->once())
@@ 293-304 (lines=12) @@
290
		$this->assertEquals(200, $actual->getStatus());
291
	}
292
293
	public function testGetTimezoneWithException() {
294
		$this->config->expects($this->once())
295
			->method('getUserValue')
296
			->with('user123', $this->appName, 'timezone', 'automatic')
297
			->will($this->throwException(new \Exception));
298
299
		$actual = $this->controller->getConfig('timezone');
300
301
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
302
		$this->assertEquals([], $actual->getData());
303
		$this->assertEquals(500, $actual->getStatus());
304
	}
305
306
	public function testGetNotExistingConfig() {
307
		$actual = $this->controller->getConfig('foo');