aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/testsrc
Commit message (Collapse)AuthorAgeFilesLines
* mavenizing weaver - wipAndy Clement2019-01-2584-9417/+0
|
* Support Java10Andy Clement2018-04-181-6/+15
|
* more generics and missing @OverridesAndy Clement2018-02-143-14/+24
|
* Basic tests for JImage accessAndy Clement2017-09-281-0/+135
|
* Optimized type lookup on Java9Andy Clement2017-09-281-0/+5
| | | | | Took the code from the patch submitted by Mario Ivankovits in bug 520597 and made some improvements to make (hopefully) better use of memory. Some basic tests added.
* various changes to make more tests pass on Java9Andy Clement2017-09-221-1/+7
|
* Fix 500796: Allow for kotlin creating 'synthetic' local variable table entriesAndy Clement2016-11-071-2/+0
|
* Upgraded to new JDT compiler - neon.1 and a bitAndy Clement2016-11-071-3/+2
|
* Fix 461323: around advice on default methodsAndy Clement2015-11-191-3/+4
|
* Do not attach INTERFACE modifier to methods from interfacesAndy Clement2015-05-121-1/+1
|
* Fix 436653: conditional aspect activation plus various polishAndy Clement2014-10-061-3/+14
| | | | | | | | | | | | | | Modified test expectation system so it is possible to say the test cares about one particular message and the rest do not matter (prefix message string with '*') - crude but quick. Polished many places to exploit generics Upgraded all the tests to work on Java8 - some serious changes regarding ajdoc on Java8. Hopefully it has stayed backwards compatible with earlier JDK versions (e.g. if using AspectJ 1.8.3+ with a JDK less than 8) but no explicit testing done for this.
* 391123: ltw cache improvementsAndy Clement2012-10-299-53/+900
|
* 386341Andy Clement2012-10-012-0/+80
|
* 389967Andy Clement2012-10-012-98/+122
|
* genericsAndy Clement2012-07-311-4/+4
|
* genericsAndy Clement2012-03-022-6/+3
|
* AspectJ Caching w/ CRC Index Filejkew2012-02-295-0/+461
| | | | Signed-off-by: Andy Clement <aclement@vmware.com>
* 239649 and primitives no longer all resolved by defaultaclement2011-08-129-615/+588
|
* trying to get these tests to pass on the build machineaclement2011-06-201-1/+1
|
* when demotion is happening we also need to put the jar on the classpath!aclement2011-06-171-47/+37
|
* formattedaclement2010-08-171-7/+7
|
* 319190: AND precedence over ORaclement2010-07-071-136/+208
|
* 312839: smaller class filesaclement2010-05-194-8/+12
|
* change all relevant DataOutputStream usage to use CompressingDataOutputStreamaclement2010-05-183-606/+507
|
* refactored generic type handlingaclement2010-04-053-110/+91
|
* removing debug and unused codeaclement2009-11-221-3/+3
|
* avoid using helpers on Member hierarchyaclement2009-11-171-1/+1
|
* move away from using helper methods on Memberaclement2009-11-171-3/+5
|
* fastmatch for execution!aclement2009-11-081-274/+302
|
* testcaseaclement2009-10-311-0/+64
|
* 291523: annotation pattern parsing changes for (@a.b.c.Foo *)aclement2009-10-061-82/+43
|
* 271201: inpath handle: can determine if class is from inpath in add method nowaclement2009-04-062-2/+2
|
* fbaclement2009-03-033-138/+102
|
* 194314: updated based on extra paramaclement2009-01-291-2/+3
|
* refactoring to make around advice lvt fixes easier to apply - and make the ↵aclement2009-01-281-4/+6
| | | | code a bit clearer
* fix for 163005aclement2008-10-303-190/+189
|
* 246125: pulled tests from weaver into matcher and created bcel subtypes of ↵aclement2008-10-2835-4036/+278
| | | | matcher tests where appropriate
* 246125: moving some very simple tests across to matcher from weaveraclement2008-10-234-300/+6
|
* 246125: promoted generic sig parsing code to utilaclement2008-10-203-50/+131
|
* 242797: latest fixes for using * rather than ? in sigsaclement2008-09-191-4/+6
|
* 246125: comment 3: reworked AnnotationX - got rid of the thingaclement2008-09-051-192/+244
|
* breaking the weaver apartaclement2008-09-046-763/+730
|
* remove unused codeaclement2008-08-311-310/+314
|
* eclipse: addressed unnecessary casts, unused code, invalid null checksaclement2008-08-2713-61/+83
|
* findbugs/eclipse warnings fixedaclement2008-08-272-2/+2
|
* trying to get 237447 to happenaclement2008-06-171-0/+10
|
* 231396: refactoring AspectJ: use getExtractableName() at new locationaclement2008-06-061-2/+2
|
* 231396: refactoring AspectJ: simplifying resolvedmember hierarchy and ↵aclement2008-06-051-0/+183
| | | | removing unused test code.
* organized importsaclement2008-06-012-4/+2
|
* 231396: mainline code moved to test areaaclement2008-05-302-19/+19
|
ble28'>backport/48205/stable28 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AllConfigTest.php
blob: ba48a07871395c668c2c8fcb0acca5ace40bb89d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace Test;

/**
 * Class AllConfigTest
 *
 * @group DB
 *
 * @package Test
 */
use OC\AllConfig;
use OC\SystemConfig;
use OCP\IDBConnection;
use OCP\PreConditionNotMetException;
use OCP\Server;

class AllConfigTest extends \Test\TestCase {
	/** @var \OCP\IDBConnection */
	protected $connection;

	protected function getConfig($systemConfig = null, $connection = null) {
		if ($this->connection === null) {
			$this->connection = Server::get(IDBConnection::class);
		}
		if ($connection === null) {
			$connection = $this->connection;
		}
		if ($systemConfig === null) {
			$systemConfig = $this->getMockBuilder('\OC\SystemConfig')
				->disableOriginalConstructor()
				->getMock();
		}
		return new AllConfig($systemConfig, $connection);
	}

	public function testDeleteUserValue(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$this->connection->executeUpdate(
			'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
			'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
			['userDelete', 'appDelete', 'keyDelete', 'valueDelete']
		);

		$config->deleteUserValue('userDelete', 'appDelete', 'keyDelete');

		$result = $this->connection->executeQuery(
			'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?',
			['userDelete']
		)->fetch();
		$actualCount = $result['count'];

		$this->assertEquals(0, $actualCount, 'There was one value in the database and after the tests there should be no entry left.');
	}

	public function testSetUserValue(): void {
		$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
		$config = $this->getConfig();

		$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet');

		$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userSet',
			'appid' => 'appSet',
			'configkey' => 'keySet',
			'configvalue' => 'valueSet'
		], $result[0]);

		// test if the method overwrites existing database entries
		$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet2');

		$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userSet',
			'appid' => 'appSet',
			'configkey' => 'keySet',
			'configvalue' => 'valueSet2'
		], $result[0]);

		// cleanup - it therefore relies on the successful execution of the previous test
		$config->deleteUserValue('userSet', 'appSet', 'keySet');
	}

	public function testSetUserValueWithPreCondition(): void {
		$config = $this->getConfig();

		$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';

		$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userPreCond',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond'
		], $result[0]);

		// test if the method overwrites existing database entries with valid precond
		$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userPreCond',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond2'
		], $result[0]);

		// cleanup
		$config->deleteUserValue('userPreCond', 'appPreCond', 'keyPreCond');
	}

	public static function dataSetUserValueUnexpectedValue(): array {
		return [
			[true],
			[false],
			[null],
			[new \stdClass()],
		];
	}

	/**
	 * @dataProvider dataSetUserValueUnexpectedValue
	 * @param mixed $value
	 */
	public function testSetUserValueUnexpectedValue($value): void {
		$this->expectException(\UnexpectedValueException::class);

		$config = $this->getConfig();
		$config->setUserValue('userSetBool', 'appSetBool', 'keySetBool', $value);
	}


	public function testSetUserValueWithPreConditionFailure(): void {
		$this->expectException(PreConditionNotMetException::class);

		$config = $this->getConfig();

		$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';

		$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userPreCond1',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond'
		], $result[0]);

		// test if the method overwrites existing database entries with valid precond
		$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond3');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userPreCond1',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond'
		], $result[0]);

		// cleanup
		$config->deleteUserValue('userPreCond1', 'appPreCond', 'keyPreCond');
	}

	public function testSetUserValueWithPreConditionFailureWhenResultStillMatches(): void {
		$this->expectException(PreConditionNotMetException::class);

		$config = $this->getConfig();

		$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';

		$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();

		$this->assertCount(1, $result);
		$this->assertEquals([
			'userid' => 'userPreCond1',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond'
		], $result[0]);

		// test if the method throws with invalid precondition when the value is the same
		$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond', 'valuePreCond3');

		$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAll();

		$this->assertCount(1, $result);
		$this->assertEquals([
			'userid' => 'userPreCond1',
			'appid' => 'appPreCond',
			'configkey' => 'keyPreCond',
			'configvalue' => 'valuePreCond'
		], $result[0]);

		// cleanup
		$config->deleteUserValue('userPreCond1', 'appPreCond', 'keyPreCond');
	}

	public function testSetUserValueUnchanged(): void {
		// TODO - FIXME until the dependency injection is handled properly (in AllConfig)
		$this->markTestSkipped('Skipped because this is just testable if database connection can be injected');

		$resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')
			->disableOriginalConstructor()->getMock();
		$resultMock->expects($this->once())
			->method('fetchColumn')
			->willReturn('valueSetUnchanged');

		$connectionMock = $this->createMock(IDBConnection::class);
		$connectionMock->expects($this->once())
			->method('executeQuery')
			->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` ' .
					'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
				$this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged']))
			->willReturn($resultMock);
		$connectionMock->expects($this->never())
			->method('executeUpdate');

		$config = $this->getConfig(null, $connectionMock);

		$config->setUserValue('userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged', 'valueSetUnchanged');
	}

	public function testGetUserValue(): void {
		$config = $this->getConfig();

		// setup - it therefore relies on the successful execution of the previous test
		$config->setUserValue('userGet', 'appGet', 'keyGet', 'valueGet');
		$value = $config->getUserValue('userGet', 'appGet', 'keyGet');

		$this->assertEquals('valueGet', $value);

		$result = $this->connection->executeQuery(
			'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
			['userGet']
		)->fetchAll();

		$this->assertEquals(1, count($result));
		$this->assertEquals([
			'userid' => 'userGet',
			'appid' => 'appGet',
			'configkey' => 'keyGet',
			'configvalue' => 'valueGet'
		], $result[0]);

		// drop data from database - but the config option should be cached in the config object
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?', ['userGet']);

		// testing the caching mechanism
		$value = $config->getUserValue('userGet', 'appGet', 'keyGet');

		$this->assertEquals('valueGet', $value);

		$result = $this->connection->executeQuery(
			'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
			['userGet']
		)->fetchAll();

		$this->assertEquals(0, count($result));
	}

	public function testGetUserKeys(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$data = [
			['userFetch', 'appFetch1', 'keyFetch1', 'value1'],
			['userFetch', 'appFetch1', 'keyFetch2', 'value2'],
			['userFetch', 'appFetch2', 'keyFetch3', 'value3'],
			['userFetch', 'appFetch1', 'keyFetch4', 'value4'],
			['userFetch', 'appFetch4', 'keyFetch1', 'value5'],
			['userFetch', 'appFetch5', 'keyFetch1', 'value6'],
			['userFetch2', 'appFetch', 'keyFetch1', 'value7']
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$value = $config->getUserKeys('userFetch', 'appFetch1');
		$this->assertEquals(['keyFetch1', 'keyFetch2', 'keyFetch4'], $value);

		$value = $config->getUserKeys('userFetch2', 'appFetch');
		$this->assertEquals(['keyFetch1'], $value);

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testGetUserKeysAllInts(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$data = [
			['userFetch8', 'appFetch1', '123', 'value'],
			['userFetch8', 'appFetch1', '456', 'value'],
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$value = $config->getUserKeys('userFetch8', 'appFetch1');
		$this->assertEquals(['123', '456'], $value);
		$this->assertIsString($value[0]);
		$this->assertIsString($value[1]);

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testGetUserValueDefault(): void {
		$config = $this->getConfig();

		$this->assertEquals('', $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset'));
		$this->assertEquals(null, $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset', null));
		$this->assertEquals('foobar', $config->getUserValue('userGetUnset', 'appGetUnset', 'keyGetUnset', 'foobar'));
	}

	public function testGetUserValueForUsers(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$data = [
			['userFetch1', 'appFetch2', 'keyFetch1', 'value1'],
			['userFetch2', 'appFetch2', 'keyFetch1', 'value2'],
			['userFetch3', 'appFetch2', 'keyFetch1', 3],
			['userFetch4', 'appFetch2', 'keyFetch1', 'value4'],
			['userFetch5', 'appFetch2', 'keyFetch1', 'value5'],
			['userFetch6', 'appFetch2', 'keyFetch1', 'value6'],
			['userFetch7', 'appFetch2', 'keyFetch1', 'value7']
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
			['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']);
		$this->assertEquals([
			'userFetch1' => 'value1',
			'userFetch2' => 'value2',
			'userFetch3' => 3,
			'userFetch5' => 'value5'
		], $value);

		$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
			['userFetch1', 'userFetch4', 'userFetch9']);
		$this->assertEquals([
			'userFetch1' => 'value1',
			'userFetch4' => 'value4'
		], $value, 'userFetch9 is an non-existent user and should not be shown.');

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testDeleteAllUserValues(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$data = [
			['userFetch3', 'appFetch1', 'keyFetch1', 'value1'],
			['userFetch3', 'appFetch1', 'keyFetch2', 'value2'],
			['userFetch3', 'appFetch2', 'keyFetch3', 'value3'],
			['userFetch3', 'appFetch1', 'keyFetch4', 'value4'],
			['userFetch3', 'appFetch4', 'keyFetch1', 'value5'],
			['userFetch3', 'appFetch5', 'keyFetch1', 'value6'],
			['userFetch4', 'appFetch2', 'keyFetch1', 'value7']
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$config->deleteAllUserValues('userFetch3');

		$result = $this->connection->executeQuery(
			'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
		)->fetch();
		$actualCount = $result['count'];

		$this->assertEquals(1, $actualCount, 'After removing `userFetch3` there should be exactly 1 entry left.');

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testDeleteAppFromAllUsers(): void {
		$config = $this->getConfig();

		// preparation - add something to the database
		$data = [
			['userFetch5', 'appFetch1', 'keyFetch1', 'value1'],
			['userFetch5', 'appFetch1', 'keyFetch2', 'value2'],
			['userFetch5', 'appFetch2', 'keyFetch3', 'value3'],
			['userFetch5', 'appFetch1', 'keyFetch4', 'value4'],
			['userFetch5', 'appFetch4', 'keyFetch1', 'value5'],
			['userFetch5', 'appFetch5', 'keyFetch1', 'value6'],
			['userFetch6', 'appFetch2', 'keyFetch1', 'value7']
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$config->deleteAppFromAllUsers('appFetch1');

		$result = $this->connection->executeQuery(
			'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
		)->fetch();
		$actualCount = $result['count'];

		$this->assertEquals(4, $actualCount, 'After removing `appFetch1` there should be exactly 4 entries left.');

		$config->deleteAppFromAllUsers('appFetch2');

		$result = $this->connection->executeQuery(
			'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
		)->fetch();
		$actualCount = $result['count'];

		$this->assertEquals(2, $actualCount, 'After removing `appFetch2` there should be exactly 2 entries left.');

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testGetUsersForUserValue(): void {
		// mock the check for the database to run the correct SQL statements for each database type
		$systemConfig = $this->getMockBuilder('\OC\SystemConfig')
			->disableOriginalConstructor()
			->getMock();
		$config = $this->getConfig($systemConfig);

		// preparation - add something to the database
		$data = [
			['user1', 'appFetch9', 'keyFetch9', 'value9'],
			['user2', 'appFetch9', 'keyFetch9', 'value9'],
			['user3', 'appFetch9', 'keyFetch9', 'value8'],
			['user4', 'appFetch9', 'keyFetch8', 'value9'],
			['user5', 'appFetch8', 'keyFetch9', 'value9'],
			['user6', 'appFetch9', 'keyFetch9', 'value9'],
		];
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9');
		$this->assertEquals(['user1', 'user2', 'user6'], $value);

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}

	public function testGetUsersForUserValueCaseInsensitive(): void {
		// mock the check for the database to run the correct SQL statements for each database type
		$systemConfig = $this->createMock(SystemConfig::class);
		$config = $this->getConfig($systemConfig);

		$config->setUserValue('user1', 'myApp', 'myKey', 'test123');
		$config->setUserValue('user2', 'myApp', 'myKey', 'TEST123');
		$config->setUserValue('user3', 'myApp', 'myKey', 'test12345');

		$users = $config->getUsersForUserValueCaseInsensitive('myApp', 'myKey', 'test123');
		$this->assertSame(2, count($users));
		$this->assertSame(['user1', 'user2'], $users);
	}
}