Completed
Push — master ( 38c8ea...c9712b )
by Joas
40:21
created
tests/lib/Authentication/Token/PublicKeyTokenTest.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 block discarded – undo
13 13
 use Test\TestCase;
14 14
 
15 15
 class PublicKeyTokenTest extends TestCase {
16
-	public function testSetScopeAsArray(): void {
17
-		$scope = [IToken::SCOPE_FILESYSTEM => false];
18
-		$token = new PublicKeyToken();
19
-		$token->setScope($scope);
20
-		$this->assertEquals(json_encode($scope), $token->getScope());
21
-		$this->assertEquals($scope, $token->getScopeAsArray());
22
-	}
16
+    public function testSetScopeAsArray(): void {
17
+        $scope = [IToken::SCOPE_FILESYSTEM => false];
18
+        $token = new PublicKeyToken();
19
+        $token->setScope($scope);
20
+        $this->assertEquals(json_encode($scope), $token->getScope());
21
+        $this->assertEquals($scope, $token->getScopeAsArray());
22
+    }
23 23
 
24
-	public function testDefaultScope(): void {
25
-		$scope = [IToken::SCOPE_FILESYSTEM => true];
26
-		$token = new PublicKeyToken();
27
-		$this->assertEquals($scope, $token->getScopeAsArray());
28
-	}
24
+    public function testDefaultScope(): void {
25
+        $scope = [IToken::SCOPE_FILESYSTEM => true];
26
+        $token = new PublicKeyToken();
27
+        $this->assertEquals($scope, $token->getScopeAsArray());
28
+    }
29 29
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/Token/RemoteWipeTest.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -24,150 +24,150 @@
 block discarded – undo
24 24
 use Test\TestCase;
25 25
 
26 26
 class RemoteWipeTest extends TestCase {
27
-	/** @var ITokenProvider|MockObject */
28
-	private $tokenProvider;
29
-
30
-	/** @var IEventDispatcher|MockObject */
31
-	private $eventDispatcher;
32
-
33
-	/** @var LoggerInterface|MockObject */
34
-	private $logger;
35
-
36
-	/** @var RemoteWipe */
37
-	private $remoteWipe;
38
-
39
-	protected function setUp(): void {
40
-		parent::setUp();
41
-
42
-		$this->tokenProvider = $this->createMock(IProvider::class);
43
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
44
-		$this->logger = $this->createMock(LoggerInterface::class);
45
-
46
-		$this->remoteWipe = new RemoteWipe(
47
-			$this->tokenProvider,
48
-			$this->eventDispatcher,
49
-			$this->logger
50
-		);
51
-	}
52
-
53
-	public function testMarkNonWipableTokenForWipe(): void {
54
-		$token = $this->createMock(IToken::class);
55
-		$result = $this->remoteWipe->markTokenForWipe($token);
56
-		$this->assertFalse($result);
57
-	}
58
-
59
-	public function testMarkTokenForWipe(): void {
60
-		$token = $this->createMock(IWipeableToken::class);
61
-		$token->expects($this->once())
62
-			->method('wipe');
63
-
64
-		$this->tokenProvider->expects($this->once())
65
-			->method('updateToken')
66
-			->with($token);
67
-
68
-		$result = $this->remoteWipe->markTokenForWipe($token);
69
-		$this->assertTrue($result);
70
-	}
71
-
72
-	public function testMarkAllTokensForWipeNoWipeableToken(): void {
73
-		/** @var IUser|MockObject $user */
74
-		$user = $this->createMock(IUser::class);
75
-		$user->method('getUID')->willReturn('user123');
76
-		$token1 = $this->createMock(IToken::class);
77
-		$token2 = $this->createMock(IToken::class);
78
-		$this->tokenProvider->expects($this->once())
79
-			->method('getTokenByUser')
80
-			->with('user123')
81
-			->willReturn([$token1, $token2]);
82
-
83
-		$result = $this->remoteWipe->markAllTokensForWipe($user);
84
-
85
-		$this->assertFalse($result);
86
-	}
87
-
88
-	public function testMarkAllTokensForWipe(): void {
89
-		/** @var IUser|MockObject $user */
90
-		$user = $this->createMock(IUser::class);
91
-		$user->method('getUID')->willReturn('user123');
92
-		$token1 = $this->createMock(IToken::class);
93
-		$token2 = $this->createMock(IWipeableToken::class);
94
-		$this->tokenProvider->expects($this->once())
95
-			->method('getTokenByUser')
96
-			->with('user123')
97
-			->willReturn([$token1, $token2]);
98
-		$token2->expects($this->once())
99
-			->method('wipe');
100
-		$this->tokenProvider->expects($this->once())
101
-			->method('updateToken')
102
-			->with($token2);
103
-
104
-		$result = $this->remoteWipe->markAllTokensForWipe($user);
105
-
106
-		$this->assertTrue($result);
107
-	}
108
-
109
-	public function testStartWipingNotAWipeToken(): void {
110
-		$token = $this->createMock(IToken::class);
111
-		$this->tokenProvider->expects($this->once())
112
-			->method('getToken')
113
-			->with('tk1')
114
-			->willReturn($token);
115
-		$this->eventDispatcher->expects($this->never())
116
-			->method('dispatch');
117
-
118
-		$result = $this->remoteWipe->start('tk1');
119
-
120
-		$this->assertFalse($result);
121
-	}
122
-
123
-	public function testStartWiping(): void {
124
-		$token = $this->createMock(IToken::class);
125
-		$this->tokenProvider->expects($this->once())
126
-			->method('getToken')
127
-			->with('tk1')
128
-			->willThrowException(new WipeTokenException($token));
129
-		$this->eventDispatcher->expects($this->once())
130
-			->method('dispatch');
131
-		$this->eventDispatcher->expects($this->once())
132
-			->method('dispatch')
133
-			->with(RemoteWipeStarted::class, $this->equalTo(new RemoteWipeStarted($token)));
134
-
135
-		$result = $this->remoteWipe->start('tk1');
136
-
137
-		$this->assertTrue($result);
138
-	}
139
-
140
-	public function testFinishWipingNotAWipeToken(): void {
141
-		$token = $this->createMock(IToken::class);
142
-		$this->tokenProvider->expects($this->once())
143
-			->method('getToken')
144
-			->with('tk1')
145
-			->willReturn($token);
146
-		$this->eventDispatcher->expects($this->never())
147
-			->method('dispatch');
148
-
149
-		$result = $this->remoteWipe->finish('tk1');
150
-
151
-		$this->assertFalse($result);
152
-	}
153
-
154
-	public function startFinishWiping() {
155
-		$token = $this->createMock(IToken::class);
156
-		$this->tokenProvider->expects($this->once())
157
-			->method('getToken')
158
-			->with('tk1')
159
-			->willThrowException(new WipeTokenException($token));
160
-		$this->eventDispatcher->expects($this->once())
161
-			->method('dispatch');
162
-		$this->tokenProvider->expects($this->once())
163
-			->method('invalidateToken')
164
-			->with($token);
165
-		$this->eventDispatcher->expects($this->once())
166
-			->method('dispatch')
167
-			->with(RemoteWipeFinished::class, $this->equalTo(new RemoteWipeFinished($token)));
168
-
169
-		$result = $this->remoteWipe->finish('tk1');
170
-
171
-		$this->assertTrue($result);
172
-	}
27
+    /** @var ITokenProvider|MockObject */
28
+    private $tokenProvider;
29
+
30
+    /** @var IEventDispatcher|MockObject */
31
+    private $eventDispatcher;
32
+
33
+    /** @var LoggerInterface|MockObject */
34
+    private $logger;
35
+
36
+    /** @var RemoteWipe */
37
+    private $remoteWipe;
38
+
39
+    protected function setUp(): void {
40
+        parent::setUp();
41
+
42
+        $this->tokenProvider = $this->createMock(IProvider::class);
43
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
44
+        $this->logger = $this->createMock(LoggerInterface::class);
45
+
46
+        $this->remoteWipe = new RemoteWipe(
47
+            $this->tokenProvider,
48
+            $this->eventDispatcher,
49
+            $this->logger
50
+        );
51
+    }
52
+
53
+    public function testMarkNonWipableTokenForWipe(): void {
54
+        $token = $this->createMock(IToken::class);
55
+        $result = $this->remoteWipe->markTokenForWipe($token);
56
+        $this->assertFalse($result);
57
+    }
58
+
59
+    public function testMarkTokenForWipe(): void {
60
+        $token = $this->createMock(IWipeableToken::class);
61
+        $token->expects($this->once())
62
+            ->method('wipe');
63
+
64
+        $this->tokenProvider->expects($this->once())
65
+            ->method('updateToken')
66
+            ->with($token);
67
+
68
+        $result = $this->remoteWipe->markTokenForWipe($token);
69
+        $this->assertTrue($result);
70
+    }
71
+
72
+    public function testMarkAllTokensForWipeNoWipeableToken(): void {
73
+        /** @var IUser|MockObject $user */
74
+        $user = $this->createMock(IUser::class);
75
+        $user->method('getUID')->willReturn('user123');
76
+        $token1 = $this->createMock(IToken::class);
77
+        $token2 = $this->createMock(IToken::class);
78
+        $this->tokenProvider->expects($this->once())
79
+            ->method('getTokenByUser')
80
+            ->with('user123')
81
+            ->willReturn([$token1, $token2]);
82
+
83
+        $result = $this->remoteWipe->markAllTokensForWipe($user);
84
+
85
+        $this->assertFalse($result);
86
+    }
87
+
88
+    public function testMarkAllTokensForWipe(): void {
89
+        /** @var IUser|MockObject $user */
90
+        $user = $this->createMock(IUser::class);
91
+        $user->method('getUID')->willReturn('user123');
92
+        $token1 = $this->createMock(IToken::class);
93
+        $token2 = $this->createMock(IWipeableToken::class);
94
+        $this->tokenProvider->expects($this->once())
95
+            ->method('getTokenByUser')
96
+            ->with('user123')
97
+            ->willReturn([$token1, $token2]);
98
+        $token2->expects($this->once())
99
+            ->method('wipe');
100
+        $this->tokenProvider->expects($this->once())
101
+            ->method('updateToken')
102
+            ->with($token2);
103
+
104
+        $result = $this->remoteWipe->markAllTokensForWipe($user);
105
+
106
+        $this->assertTrue($result);
107
+    }
108
+
109
+    public function testStartWipingNotAWipeToken(): void {
110
+        $token = $this->createMock(IToken::class);
111
+        $this->tokenProvider->expects($this->once())
112
+            ->method('getToken')
113
+            ->with('tk1')
114
+            ->willReturn($token);
115
+        $this->eventDispatcher->expects($this->never())
116
+            ->method('dispatch');
117
+
118
+        $result = $this->remoteWipe->start('tk1');
119
+
120
+        $this->assertFalse($result);
121
+    }
122
+
123
+    public function testStartWiping(): void {
124
+        $token = $this->createMock(IToken::class);
125
+        $this->tokenProvider->expects($this->once())
126
+            ->method('getToken')
127
+            ->with('tk1')
128
+            ->willThrowException(new WipeTokenException($token));
129
+        $this->eventDispatcher->expects($this->once())
130
+            ->method('dispatch');
131
+        $this->eventDispatcher->expects($this->once())
132
+            ->method('dispatch')
133
+            ->with(RemoteWipeStarted::class, $this->equalTo(new RemoteWipeStarted($token)));
134
+
135
+        $result = $this->remoteWipe->start('tk1');
136
+
137
+        $this->assertTrue($result);
138
+    }
139
+
140
+    public function testFinishWipingNotAWipeToken(): void {
141
+        $token = $this->createMock(IToken::class);
142
+        $this->tokenProvider->expects($this->once())
143
+            ->method('getToken')
144
+            ->with('tk1')
145
+            ->willReturn($token);
146
+        $this->eventDispatcher->expects($this->never())
147
+            ->method('dispatch');
148
+
149
+        $result = $this->remoteWipe->finish('tk1');
150
+
151
+        $this->assertFalse($result);
152
+    }
153
+
154
+    public function startFinishWiping() {
155
+        $token = $this->createMock(IToken::class);
156
+        $this->tokenProvider->expects($this->once())
157
+            ->method('getToken')
158
+            ->with('tk1')
159
+            ->willThrowException(new WipeTokenException($token));
160
+        $this->eventDispatcher->expects($this->once())
161
+            ->method('dispatch');
162
+        $this->tokenProvider->expects($this->once())
163
+            ->method('invalidateToken')
164
+            ->with($token);
165
+        $this->eventDispatcher->expects($this->once())
166
+            ->method('dispatch')
167
+            ->with(RemoteWipeFinished::class, $this->equalTo(new RemoteWipeFinished($token)));
168
+
169
+        $result = $this->remoteWipe->finish('tk1');
170
+
171
+        $this->assertTrue($result);
172
+    }
173 173
 }
Please login to merge, or discard this patch.
tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,80 +11,80 @@
 block discarded – undo
11 11
 use Test\TestCase;
12 12
 
13 13
 class LinkActionTest extends TestCase {
14
-	private LinkAction $action;
15
-
16
-	protected function setUp(): void {
17
-		parent::setUp();
18
-
19
-		$this->action = new LinkAction();
20
-	}
21
-
22
-	public function testSetIcon(): void {
23
-		$icon = 'icon-test';
24
-
25
-		$this->action->setIcon($icon);
26
-		$json = $this->action->jsonSerialize();
27
-
28
-		$this->assertArrayHasKey('icon', $json);
29
-		$this->assertEquals($json['icon'], $icon);
30
-	}
31
-
32
-	public function testGetSetName(): void {
33
-		$name = 'Jane Doe';
34
-
35
-		$this->assertEmpty($this->action->getName());
36
-		$this->action->setName($name);
37
-		$this->assertEquals($name, $this->action->getName());
38
-	}
39
-
40
-	public function testGetSetPriority(): void {
41
-		$prio = 50;
42
-
43
-		$this->assertEquals(10, $this->action->getPriority());
44
-		$this->action->setPriority($prio);
45
-		$this->assertEquals($prio, $this->action->getPriority());
46
-	}
47
-
48
-	public function testSetHref(): void {
49
-		$this->action->setHref('/some/url');
50
-
51
-		$json = $this->action->jsonSerialize();
52
-		$this->assertArrayHasKey('hyperlink', $json);
53
-		$this->assertEquals('/some/url', $json['hyperlink']);
54
-	}
55
-
56
-	public function testJsonSerialize(): void {
57
-		$this->action->setIcon('icon-contacts');
58
-		$this->action->setName('Nickie Works');
59
-		$this->action->setPriority(33);
60
-		$this->action->setHref('example.com');
61
-		$this->action->setAppId('contacts');
62
-		$expected = [
63
-			'title' => 'Nickie Works',
64
-			'icon' => 'icon-contacts',
65
-			'hyperlink' => 'example.com',
66
-			'appId' => 'contacts',
67
-		];
68
-
69
-		$json = $this->action->jsonSerialize();
70
-
71
-		$this->assertEquals($expected, $json);
72
-	}
73
-
74
-	public function testJsonSerializeNoAppName(): void {
75
-		$this->action->setIcon('icon-contacts');
76
-		$this->action->setName('Nickie Works');
77
-		$this->action->setPriority(33);
78
-		$this->action->setHref('example.com');
79
-		$expected = [
80
-			'title' => 'Nickie Works',
81
-			'icon' => 'icon-contacts',
82
-			'hyperlink' => 'example.com',
83
-			'appId' => '',
84
-		];
85
-
86
-		$json = $this->action->jsonSerialize();
87
-
88
-		$this->assertEquals($expected, $json);
89
-	}
14
+    private LinkAction $action;
15
+
16
+    protected function setUp(): void {
17
+        parent::setUp();
18
+
19
+        $this->action = new LinkAction();
20
+    }
21
+
22
+    public function testSetIcon(): void {
23
+        $icon = 'icon-test';
24
+
25
+        $this->action->setIcon($icon);
26
+        $json = $this->action->jsonSerialize();
27
+
28
+        $this->assertArrayHasKey('icon', $json);
29
+        $this->assertEquals($json['icon'], $icon);
30
+    }
31
+
32
+    public function testGetSetName(): void {
33
+        $name = 'Jane Doe';
34
+
35
+        $this->assertEmpty($this->action->getName());
36
+        $this->action->setName($name);
37
+        $this->assertEquals($name, $this->action->getName());
38
+    }
39
+
40
+    public function testGetSetPriority(): void {
41
+        $prio = 50;
42
+
43
+        $this->assertEquals(10, $this->action->getPriority());
44
+        $this->action->setPriority($prio);
45
+        $this->assertEquals($prio, $this->action->getPriority());
46
+    }
47
+
48
+    public function testSetHref(): void {
49
+        $this->action->setHref('/some/url');
50
+
51
+        $json = $this->action->jsonSerialize();
52
+        $this->assertArrayHasKey('hyperlink', $json);
53
+        $this->assertEquals('/some/url', $json['hyperlink']);
54
+    }
55
+
56
+    public function testJsonSerialize(): void {
57
+        $this->action->setIcon('icon-contacts');
58
+        $this->action->setName('Nickie Works');
59
+        $this->action->setPriority(33);
60
+        $this->action->setHref('example.com');
61
+        $this->action->setAppId('contacts');
62
+        $expected = [
63
+            'title' => 'Nickie Works',
64
+            'icon' => 'icon-contacts',
65
+            'hyperlink' => 'example.com',
66
+            'appId' => 'contacts',
67
+        ];
68
+
69
+        $json = $this->action->jsonSerialize();
70
+
71
+        $this->assertEquals($expected, $json);
72
+    }
73
+
74
+    public function testJsonSerializeNoAppName(): void {
75
+        $this->action->setIcon('icon-contacts');
76
+        $this->action->setName('Nickie Works');
77
+        $this->action->setPriority(33);
78
+        $this->action->setHref('example.com');
79
+        $expected = [
80
+            'title' => 'Nickie Works',
81
+            'icon' => 'icon-contacts',
82
+            'hyperlink' => 'example.com',
83
+            'appId' => '',
84
+        ];
85
+
86
+        $json = $this->action->jsonSerialize();
87
+
88
+        $this->assertEquals($expected, $json);
89
+    }
90 90
 }
Please login to merge, or discard this patch.
tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -16,70 +16,70 @@
 block discarded – undo
16 16
 use Test\TestCase;
17 17
 
18 18
 class EMailproviderTest extends TestCase {
19
-	/** @var IActionFactory|MockObject */
20
-	private $actionFactory;
19
+    /** @var IActionFactory|MockObject */
20
+    private $actionFactory;
21 21
 
22
-	/** @var IURLGenerator|MockObject */
23
-	private $urlGenerator;
22
+    /** @var IURLGenerator|MockObject */
23
+    private $urlGenerator;
24 24
 
25
-	private EMailProvider $provider;
25
+    private EMailProvider $provider;
26 26
 
27
-	protected function setUp(): void {
28
-		parent::setUp();
27
+    protected function setUp(): void {
28
+        parent::setUp();
29 29
 
30
-		$this->actionFactory = $this->createMock(IActionFactory::class);
31
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
30
+        $this->actionFactory = $this->createMock(IActionFactory::class);
31
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
32 32
 
33
-		$this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
34
-	}
33
+        $this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
34
+    }
35 35
 
36
-	public function testProcess(): void {
37
-		$entry = $this->createMock(IEntry::class);
38
-		$action = $this->createMock(ILinkAction::class);
39
-		$iconUrl = 'https://example.com/img/actions/icon.svg';
40
-		$this->urlGenerator->expects($this->once())
41
-			->method('imagePath')
42
-			->willReturn('img/actions/icon.svg');
43
-		$this->urlGenerator->expects($this->once())
44
-			->method('getAbsoluteURL')
45
-			->with('img/actions/icon.svg')
46
-			->willReturn($iconUrl);
47
-		$entry->expects($this->once())
48
-			->method('getEMailAddresses')
49
-			->willReturn([
50
-				'[email protected]',
51
-			]);
52
-		$this->actionFactory->expects($this->once())
53
-			->method('newEMailAction')
54
-			->with($this->equalTo($iconUrl), $this->equalTo('[email protected]'), $this->equalTo('[email protected]'))
55
-			->willReturn($action);
56
-		$entry->expects($this->once())
57
-			->method('addAction')
58
-			->with($action);
36
+    public function testProcess(): void {
37
+        $entry = $this->createMock(IEntry::class);
38
+        $action = $this->createMock(ILinkAction::class);
39
+        $iconUrl = 'https://example.com/img/actions/icon.svg';
40
+        $this->urlGenerator->expects($this->once())
41
+            ->method('imagePath')
42
+            ->willReturn('img/actions/icon.svg');
43
+        $this->urlGenerator->expects($this->once())
44
+            ->method('getAbsoluteURL')
45
+            ->with('img/actions/icon.svg')
46
+            ->willReturn($iconUrl);
47
+        $entry->expects($this->once())
48
+            ->method('getEMailAddresses')
49
+            ->willReturn([
50
+                '[email protected]',
51
+            ]);
52
+        $this->actionFactory->expects($this->once())
53
+            ->method('newEMailAction')
54
+            ->with($this->equalTo($iconUrl), $this->equalTo('[email protected]'), $this->equalTo('[email protected]'))
55
+            ->willReturn($action);
56
+        $entry->expects($this->once())
57
+            ->method('addAction')
58
+            ->with($action);
59 59
 
60
-		$this->provider->process($entry);
61
-	}
60
+        $this->provider->process($entry);
61
+    }
62 62
 
63
-	public function testProcessEmptyAddress(): void {
64
-		$entry = $this->createMock(IEntry::class);
65
-		$iconUrl = 'https://example.com/img/actions/icon.svg';
66
-		$this->urlGenerator->expects($this->once())
67
-			->method('imagePath')
68
-			->willReturn('img/actions/icon.svg');
69
-		$this->urlGenerator->expects($this->once())
70
-			->method('getAbsoluteURL')
71
-			->with('img/actions/icon.svg')
72
-			->willReturn($iconUrl);
73
-		$entry->expects($this->once())
74
-			->method('getEMailAddresses')
75
-			->willReturn([
76
-				'',
77
-			]);
78
-		$this->actionFactory->expects($this->never())
79
-			->method('newEMailAction');
80
-		$entry->expects($this->never())
81
-			->method('addAction');
63
+    public function testProcessEmptyAddress(): void {
64
+        $entry = $this->createMock(IEntry::class);
65
+        $iconUrl = 'https://example.com/img/actions/icon.svg';
66
+        $this->urlGenerator->expects($this->once())
67
+            ->method('imagePath')
68
+            ->willReturn('img/actions/icon.svg');
69
+        $this->urlGenerator->expects($this->once())
70
+            ->method('getAbsoluteURL')
71
+            ->with('img/actions/icon.svg')
72
+            ->willReturn($iconUrl);
73
+        $entry->expects($this->once())
74
+            ->method('getEMailAddresses')
75
+            ->willReturn([
76
+                '',
77
+            ]);
78
+        $this->actionFactory->expects($this->never())
79
+            ->method('newEMailAction');
80
+        $entry->expects($this->never())
81
+            ->method('addAction');
82 82
 
83
-		$this->provider->process($entry);
84
-	}
83
+        $this->provider->process($entry);
84
+    }
85 85
 }
Please login to merge, or discard this patch.
tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -22,103 +22,103 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class ActionProviderStoreTest extends TestCase {
25
-	/** @var IServerContainer|MockObject */
26
-	private $serverContainer;
27
-
28
-	/** @var IAppManager|MockObject */
29
-	private $appManager;
30
-
31
-	private ActionProviderStore $actionProviderStore;
32
-
33
-	protected function setUp(): void {
34
-		parent::setUp();
35
-
36
-		$this->serverContainer = $this->createMock(IServerContainer::class);
37
-		$this->appManager = $this->createMock(AppManager::class);
38
-		$logger = $this->createMock(LoggerInterface::class);
39
-
40
-		$this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $logger);
41
-	}
42
-
43
-	public function testGetProviders(): void {
44
-		$user = $this->createMock(IUser::class);
45
-		$provider1 = $this->createMock(ProfileProvider::class);
46
-		$provider2 = $this->createMock(LocalTimeProvider::class);
47
-		$provider3 = $this->createMock(EMailProvider::class);
48
-		$provider4 = $this->createMock(IProvider::class);
49
-
50
-		$this->appManager->expects($this->once())
51
-			->method('getEnabledAppsForUser')
52
-			->with($user)
53
-			->willReturn(['contacts']);
54
-		$this->appManager->expects($this->once())
55
-			->method('getAppInfo')
56
-			->with('contacts')
57
-			->willReturn([
58
-				'contactsmenu' => [
59
-					'OCA\Contacts\Provider1',
60
-				],
61
-			]);
62
-		$this->serverContainer->expects($this->exactly(4))
63
-			->method('get')
64
-			->willReturnMap([
65
-				[ProfileProvider::class, $provider1],
66
-				[LocalTimeProvider::class, $provider2],
67
-				[EMailProvider::class, $provider3],
68
-				['OCA\Contacts\Provider1', $provider4]
69
-			]);
70
-
71
-		$providers = $this->actionProviderStore->getProviders($user);
72
-
73
-		$this->assertCount(4, $providers);
74
-		$this->assertInstanceOf(ProfileProvider::class, $providers[0]);
75
-		$this->assertInstanceOf(LocalTimeProvider::class, $providers[1]);
76
-		$this->assertInstanceOf(EMailProvider::class, $providers[2]);
77
-	}
78
-
79
-	public function testGetProvidersOfAppWithIncompleInfo(): void {
80
-		$user = $this->createMock(IUser::class);
81
-		$provider1 = $this->createMock(ProfileProvider::class);
82
-		$provider2 = $this->createMock(LocalTimeProvider::class);
83
-		$provider3 = $this->createMock(EMailProvider::class);
84
-
85
-		$this->appManager->expects($this->once())
86
-			->method('getEnabledAppsForUser')
87
-			->with($user)
88
-			->willReturn(['contacts']);
89
-		$this->appManager->expects($this->once())
90
-			->method('getAppInfo')
91
-			->with('contacts')
92
-			->willReturn([/* Empty info.xml */]);
93
-		$this->serverContainer->expects($this->exactly(3))
94
-			->method('get')
95
-			->willReturnMap([
96
-				[ProfileProvider::class, $provider1],
97
-				[LocalTimeProvider::class, $provider2],
98
-				[EMailProvider::class, $provider3],
99
-			]);
100
-
101
-		$providers = $this->actionProviderStore->getProviders($user);
102
-
103
-		$this->assertCount(3, $providers);
104
-		$this->assertInstanceOf(ProfileProvider::class, $providers[0]);
105
-		$this->assertInstanceOf(LocalTimeProvider::class, $providers[1]);
106
-		$this->assertInstanceOf(EMailProvider::class, $providers[2]);
107
-	}
108
-
109
-
110
-	public function testGetProvidersWithQueryException(): void {
111
-		$this->expectException(\Exception::class);
112
-
113
-		$user = $this->createMock(IUser::class);
114
-		$this->appManager->expects($this->once())
115
-			->method('getEnabledAppsForUser')
116
-			->with($user)
117
-			->willReturn([]);
118
-		$this->serverContainer->expects($this->once())
119
-			->method('get')
120
-			->willThrowException(new QueryException());
121
-
122
-		$this->actionProviderStore->getProviders($user);
123
-	}
25
+    /** @var IServerContainer|MockObject */
26
+    private $serverContainer;
27
+
28
+    /** @var IAppManager|MockObject */
29
+    private $appManager;
30
+
31
+    private ActionProviderStore $actionProviderStore;
32
+
33
+    protected function setUp(): void {
34
+        parent::setUp();
35
+
36
+        $this->serverContainer = $this->createMock(IServerContainer::class);
37
+        $this->appManager = $this->createMock(AppManager::class);
38
+        $logger = $this->createMock(LoggerInterface::class);
39
+
40
+        $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $logger);
41
+    }
42
+
43
+    public function testGetProviders(): void {
44
+        $user = $this->createMock(IUser::class);
45
+        $provider1 = $this->createMock(ProfileProvider::class);
46
+        $provider2 = $this->createMock(LocalTimeProvider::class);
47
+        $provider3 = $this->createMock(EMailProvider::class);
48
+        $provider4 = $this->createMock(IProvider::class);
49
+
50
+        $this->appManager->expects($this->once())
51
+            ->method('getEnabledAppsForUser')
52
+            ->with($user)
53
+            ->willReturn(['contacts']);
54
+        $this->appManager->expects($this->once())
55
+            ->method('getAppInfo')
56
+            ->with('contacts')
57
+            ->willReturn([
58
+                'contactsmenu' => [
59
+                    'OCA\Contacts\Provider1',
60
+                ],
61
+            ]);
62
+        $this->serverContainer->expects($this->exactly(4))
63
+            ->method('get')
64
+            ->willReturnMap([
65
+                [ProfileProvider::class, $provider1],
66
+                [LocalTimeProvider::class, $provider2],
67
+                [EMailProvider::class, $provider3],
68
+                ['OCA\Contacts\Provider1', $provider4]
69
+            ]);
70
+
71
+        $providers = $this->actionProviderStore->getProviders($user);
72
+
73
+        $this->assertCount(4, $providers);
74
+        $this->assertInstanceOf(ProfileProvider::class, $providers[0]);
75
+        $this->assertInstanceOf(LocalTimeProvider::class, $providers[1]);
76
+        $this->assertInstanceOf(EMailProvider::class, $providers[2]);
77
+    }
78
+
79
+    public function testGetProvidersOfAppWithIncompleInfo(): void {
80
+        $user = $this->createMock(IUser::class);
81
+        $provider1 = $this->createMock(ProfileProvider::class);
82
+        $provider2 = $this->createMock(LocalTimeProvider::class);
83
+        $provider3 = $this->createMock(EMailProvider::class);
84
+
85
+        $this->appManager->expects($this->once())
86
+            ->method('getEnabledAppsForUser')
87
+            ->with($user)
88
+            ->willReturn(['contacts']);
89
+        $this->appManager->expects($this->once())
90
+            ->method('getAppInfo')
91
+            ->with('contacts')
92
+            ->willReturn([/* Empty info.xml */]);
93
+        $this->serverContainer->expects($this->exactly(3))
94
+            ->method('get')
95
+            ->willReturnMap([
96
+                [ProfileProvider::class, $provider1],
97
+                [LocalTimeProvider::class, $provider2],
98
+                [EMailProvider::class, $provider3],
99
+            ]);
100
+
101
+        $providers = $this->actionProviderStore->getProviders($user);
102
+
103
+        $this->assertCount(3, $providers);
104
+        $this->assertInstanceOf(ProfileProvider::class, $providers[0]);
105
+        $this->assertInstanceOf(LocalTimeProvider::class, $providers[1]);
106
+        $this->assertInstanceOf(EMailProvider::class, $providers[2]);
107
+    }
108
+
109
+
110
+    public function testGetProvidersWithQueryException(): void {
111
+        $this->expectException(\Exception::class);
112
+
113
+        $user = $this->createMock(IUser::class);
114
+        $this->appManager->expects($this->once())
115
+            ->method('getEnabledAppsForUser')
116
+            ->with($user)
117
+            ->willReturn([]);
118
+        $this->serverContainer->expects($this->once())
119
+            ->method('get')
120
+            ->willThrowException(new QueryException());
121
+
122
+        $this->actionProviderStore->getProviders($user);
123
+    }
124 124
 }
Please login to merge, or discard this patch.
tests/lib/Contacts/ContactsMenu/EntryTest.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -12,93 +12,93 @@
 block discarded – undo
12 12
 use Test\TestCase;
13 13
 
14 14
 class EntryTest extends TestCase {
15
-	private Entry $entry;
16
-
17
-	protected function setUp(): void {
18
-		parent::setUp();
19
-
20
-		$this->entry = new Entry();
21
-	}
22
-
23
-	public function testSetId(): void {
24
-		$this->entry->setId(123);
25
-		$this->addToAssertionCount(1);
26
-	}
27
-
28
-	public function testSetGetFullName(): void {
29
-		$fn = 'Danette Chaille';
30
-		$this->assertEquals('', $this->entry->getFullName());
31
-		$this->entry->setFullName($fn);
32
-		$this->assertEquals($fn, $this->entry->getFullName());
33
-	}
34
-
35
-	public function testAddGetEMailAddresses(): void {
36
-		$this->assertEmpty($this->entry->getEMailAddresses());
37
-		$this->entry->addEMailAddress('[email protected]');
38
-		$this->assertEquals(['[email protected]'], $this->entry->getEMailAddresses());
39
-	}
40
-
41
-	public function testAddAndSortAction(): void {
42
-		// Three actions, two with equal priority
43
-		$action1 = new LinkAction();
44
-		$action2 = new LinkAction();
45
-		$action3 = new LinkAction();
46
-		$action1->setPriority(10);
47
-		$action1->setName('Bravo');
48
-
49
-		$action2->setPriority(0);
50
-		$action2->setName('Batman');
51
-
52
-		$action3->setPriority(10);
53
-		$action3->setName('Alfa');
54
-
55
-		$this->entry->addAction($action1);
56
-		$this->entry->addAction($action2);
57
-		$this->entry->addAction($action3);
58
-		$sorted = $this->entry->getActions();
59
-
60
-		$this->assertSame($action3, $sorted[0]);
61
-		$this->assertSame($action1, $sorted[1]);
62
-		$this->assertSame($action2, $sorted[2]);
63
-	}
64
-
65
-	public function testSetGetProperties(): void {
66
-		$props = [
67
-			'prop1' => 123,
68
-			'prop2' => 'string',
69
-		];
70
-
71
-		$this->entry->setProperties($props);
72
-
73
-		$this->assertNull($this->entry->getProperty('doesntexist'));
74
-		$this->assertEquals(123, $this->entry->getProperty('prop1'));
75
-		$this->assertEquals('string', $this->entry->getProperty('prop2'));
76
-	}
77
-
78
-	public function testJsonSerialize(): void {
79
-		$expectedJson = [
80
-			'id' => '123',
81
-			'fullName' => 'Guadalupe Frisbey',
82
-			'topAction' => null,
83
-			'actions' => [],
84
-			'lastMessage' => '',
85
-			'avatar' => null,
86
-			'emailAddresses' => ['[email protected]'],
87
-			'profileTitle' => null,
88
-			'profileUrl' => null,
89
-			'status' => null,
90
-			'statusMessage' => null,
91
-			'statusMessageTimestamp' => null,
92
-			'statusIcon' => null,
93
-			'isUser' => false,
94
-			'uid' => null,
95
-		];
96
-
97
-		$this->entry->setId(123);
98
-		$this->entry->setFullName('Guadalupe Frisbey');
99
-		$this->entry->addEMailAddress('[email protected]');
100
-		$json = $this->entry->jsonSerialize();
101
-
102
-		$this->assertEquals($expectedJson, $json);
103
-	}
15
+    private Entry $entry;
16
+
17
+    protected function setUp(): void {
18
+        parent::setUp();
19
+
20
+        $this->entry = new Entry();
21
+    }
22
+
23
+    public function testSetId(): void {
24
+        $this->entry->setId(123);
25
+        $this->addToAssertionCount(1);
26
+    }
27
+
28
+    public function testSetGetFullName(): void {
29
+        $fn = 'Danette Chaille';
30
+        $this->assertEquals('', $this->entry->getFullName());
31
+        $this->entry->setFullName($fn);
32
+        $this->assertEquals($fn, $this->entry->getFullName());
33
+    }
34
+
35
+    public function testAddGetEMailAddresses(): void {
36
+        $this->assertEmpty($this->entry->getEMailAddresses());
37
+        $this->entry->addEMailAddress('[email protected]');
38
+        $this->assertEquals(['[email protected]'], $this->entry->getEMailAddresses());
39
+    }
40
+
41
+    public function testAddAndSortAction(): void {
42
+        // Three actions, two with equal priority
43
+        $action1 = new LinkAction();
44
+        $action2 = new LinkAction();
45
+        $action3 = new LinkAction();
46
+        $action1->setPriority(10);
47
+        $action1->setName('Bravo');
48
+
49
+        $action2->setPriority(0);
50
+        $action2->setName('Batman');
51
+
52
+        $action3->setPriority(10);
53
+        $action3->setName('Alfa');
54
+
55
+        $this->entry->addAction($action1);
56
+        $this->entry->addAction($action2);
57
+        $this->entry->addAction($action3);
58
+        $sorted = $this->entry->getActions();
59
+
60
+        $this->assertSame($action3, $sorted[0]);
61
+        $this->assertSame($action1, $sorted[1]);
62
+        $this->assertSame($action2, $sorted[2]);
63
+    }
64
+
65
+    public function testSetGetProperties(): void {
66
+        $props = [
67
+            'prop1' => 123,
68
+            'prop2' => 'string',
69
+        ];
70
+
71
+        $this->entry->setProperties($props);
72
+
73
+        $this->assertNull($this->entry->getProperty('doesntexist'));
74
+        $this->assertEquals(123, $this->entry->getProperty('prop1'));
75
+        $this->assertEquals('string', $this->entry->getProperty('prop2'));
76
+    }
77
+
78
+    public function testJsonSerialize(): void {
79
+        $expectedJson = [
80
+            'id' => '123',
81
+            'fullName' => 'Guadalupe Frisbey',
82
+            'topAction' => null,
83
+            'actions' => [],
84
+            'lastMessage' => '',
85
+            'avatar' => null,
86
+            'emailAddresses' => ['[email protected]'],
87
+            'profileTitle' => null,
88
+            'profileUrl' => null,
89
+            'status' => null,
90
+            'statusMessage' => null,
91
+            'statusMessageTimestamp' => null,
92
+            'statusIcon' => null,
93
+            'isUser' => false,
94
+            'uid' => null,
95
+        ];
96
+
97
+        $this->entry->setId(123);
98
+        $this->entry->setFullName('Guadalupe Frisbey');
99
+        $this->entry->addEMailAddress('[email protected]');
100
+        $json = $this->entry->jsonSerialize();
101
+
102
+        $this->assertEquals($expectedJson, $json);
103
+    }
104 104
 }
Please login to merge, or discard this patch.
tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -12,36 +12,36 @@
 block discarded – undo
12 12
 use Test\TestCase;
13 13
 
14 14
 class ActionFactoryTest extends TestCase {
15
-	private ActionFactory $actionFactory;
15
+    private ActionFactory $actionFactory;
16 16
 
17
-	protected function setUp(): void {
18
-		parent::setUp();
17
+    protected function setUp(): void {
18
+        parent::setUp();
19 19
 
20
-		$this->actionFactory = new ActionFactory();
21
-	}
20
+        $this->actionFactory = new ActionFactory();
21
+    }
22 22
 
23
-	public function testNewLinkAction(): void {
24
-		$icon = 'icon-test';
25
-		$name = 'Test';
26
-		$href = 'some/url';
23
+    public function testNewLinkAction(): void {
24
+        $icon = 'icon-test';
25
+        $name = 'Test';
26
+        $href = 'some/url';
27 27
 
28
-		$action = $this->actionFactory->newLinkAction($icon, $name, $href);
28
+        $action = $this->actionFactory->newLinkAction($icon, $name, $href);
29 29
 
30
-		$this->assertInstanceOf(IAction::class, $action);
31
-		$this->assertEquals($name, $action->getName());
32
-		$this->assertEquals(10, $action->getPriority());
33
-	}
30
+        $this->assertInstanceOf(IAction::class, $action);
31
+        $this->assertEquals($name, $action->getName());
32
+        $this->assertEquals(10, $action->getPriority());
33
+    }
34 34
 
35
-	public function testNewEMailAction(): void {
36
-		$icon = 'icon-test';
37
-		$name = 'Test';
38
-		$href = '[email protected]';
35
+    public function testNewEMailAction(): void {
36
+        $icon = 'icon-test';
37
+        $name = 'Test';
38
+        $href = '[email protected]';
39 39
 
40
-		$action = $this->actionFactory->newEMailAction($icon, $name, $href);
40
+        $action = $this->actionFactory->newEMailAction($icon, $name, $href);
41 41
 
42
-		$this->assertInstanceOf(IAction::class, $action);
43
-		$this->assertEquals($name, $action->getName());
44
-		$this->assertEquals(10, $action->getPriority());
45
-		$this->assertEquals('mailto:[email protected]', $action->getHref());
46
-	}
42
+        $this->assertInstanceOf(IAction::class, $action);
43
+        $this->assertEquals($name, $action->getName());
44
+        $this->assertEquals(10, $action->getPriority());
45
+        $this->assertEquals('mailto:[email protected]', $action->getHref());
46
+    }
47 47
 }
Please login to merge, or discard this patch.
tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -21,202 +21,202 @@
 block discarded – undo
21 21
  * @group DB
22 22
  */
23 23
 class PartitionedQueryBuilderTest extends TestCase {
24
-	private IDBConnection $connection;
25
-	private ShardConnectionManager $shardConnectionManager;
26
-	private AutoIncrementHandler $autoIncrementHandler;
27
-
28
-	protected function setUp(): void {
29
-		if (PHP_INT_SIZE < 8) {
30
-			$this->markTestSkipped('Test requires 64bit');
31
-		}
32
-		$this->connection = Server::get(IDBConnection::class);
33
-		$this->shardConnectionManager = Server::get(ShardConnectionManager::class);
34
-		$this->autoIncrementHandler = Server::get(AutoIncrementHandler::class);
35
-
36
-		$this->setupFileCache();
37
-	}
38
-
39
-	protected function tearDown(): void {
40
-		$this->cleanupDb();
41
-		parent::tearDown();
42
-	}
43
-
44
-
45
-	private function getQueryBuilder(): PartitionedQueryBuilder {
46
-		$builder = $this->connection->getQueryBuilder();
47
-		if ($builder instanceof PartitionedQueryBuilder) {
48
-			return $builder;
49
-		} else {
50
-			return new PartitionedQueryBuilder($builder, [], $this->shardConnectionManager, $this->autoIncrementHandler);
51
-		}
52
-	}
53
-
54
-	private function setupFileCache(): void {
55
-		$this->cleanupDb();
56
-		$query = $this->getQueryBuilder();
57
-		$query->insert('storages')
58
-			->values([
59
-				'numeric_id' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
60
-				'id' => $query->createNamedParameter('test1'),
61
-			]);
62
-		$query->executeStatement();
63
-
64
-		$query = $this->getQueryBuilder();
65
-		$query->insert('filecache')
66
-			->values([
67
-				'storage' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
68
-				'path' => $query->createNamedParameter('file1'),
69
-				'path_hash' => $query->createNamedParameter(md5('file1')),
70
-			]);
71
-		$query->executeStatement();
72
-		$fileId = $query->getLastInsertId();
73
-
74
-		$query = $this->getQueryBuilder();
75
-		$query->insert('filecache_extended')
76
-			->hintShardKey('storage', 1001001)
77
-			->values([
78
-				'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
79
-				'upload_time' => $query->createNamedParameter(1234, IQueryBuilder::PARAM_INT),
80
-			]);
81
-		$query->executeStatement();
82
-
83
-		$query = $this->getQueryBuilder();
84
-		$query->insert('mounts')
85
-			->values([
86
-				'storage_id' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
87
-				'user_id' => $query->createNamedParameter('partitioned_test'),
88
-				'mount_point' => $query->createNamedParameter('/mount/point'),
89
-				'mount_provider_class' => $query->createNamedParameter('test'),
90
-				'root_id' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
91
-			]);
92
-		$query->executeStatement();
93
-	}
94
-
95
-	private function cleanupDb(): void {
96
-		$query = $this->getQueryBuilder();
97
-		$query->delete('storages')
98
-			->where($query->expr()->gt('numeric_id', $query->createNamedParameter(1000000, IQueryBuilder::PARAM_INT)));
99
-		$query->executeStatement();
100
-
101
-		$query = $this->getQueryBuilder();
102
-		$query->delete('filecache')
103
-			->where($query->expr()->gt('storage', $query->createNamedParameter(1000000, IQueryBuilder::PARAM_INT)))
104
-			->runAcrossAllShards();
105
-		$query->executeStatement();
106
-
107
-		$query = $this->getQueryBuilder();
108
-		$query->delete('filecache_extended')
109
-			->runAcrossAllShards();
110
-		$query->executeStatement();
111
-
112
-		$query = $this->getQueryBuilder();
113
-		$query->delete('mounts')
114
-			->where($query->expr()->like('user_id', $query->createNamedParameter('partitioned_%')));
115
-		$query->executeStatement();
116
-	}
117
-
118
-	public function testSimpleOnlyPartitionQuery(): void {
119
-		$builder = $this->getQueryBuilder();
120
-		$builder->addPartition(new PartitionSplit('filecache', ['filecache']));
121
-
122
-		// query borrowed from UserMountCache
123
-		$query = $builder->select('path')
124
-			->from('filecache')
125
-			->where($builder->expr()->eq('storage', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
126
-
127
-		$results = $query->executeQuery()->fetchAll();
128
-		$this->assertCount(1, $results);
129
-		$this->assertEquals($results[0]['path'], 'file1');
130
-	}
131
-
132
-	public function testSimplePartitionedQuery(): void {
133
-		$builder = $this->getQueryBuilder();
134
-		$builder->addPartition(new PartitionSplit('filecache', ['filecache']));
135
-
136
-		// query borrowed from UserMountCache
137
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
138
-			->from('mounts', 'm')
139
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
140
-			->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
141
-
142
-		$query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
143
-
144
-		$this->assertEquals(2, $query->getPartitionCount());
145
-
146
-		$results = $query->executeQuery()->fetchAll();
147
-		$this->assertCount(1, $results);
148
-		$this->assertEquals($results[0]['user_id'], 'partitioned_test');
149
-		$this->assertEquals($results[0]['mount_point'], '/mount/point');
150
-		$this->assertEquals($results[0]['mount_provider_class'], 'test');
151
-		$this->assertEquals($results[0]['path'], 'file1');
152
-	}
153
-
154
-	public function testMultiTablePartitionedQuery(): void {
155
-		$builder = $this->getQueryBuilder();
156
-		$builder->addPartition(new PartitionSplit('filecache', ['filecache', 'filecache_extended']));
157
-
158
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class', 'fe.upload_time')
159
-			->from('mounts', 'm')
160
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
161
-			->innerJoin('f', 'filecache_extended', 'fe', $builder->expr()->eq('f.fileid', 'fe.fileid'))
162
-			->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
163
-
164
-		$query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
165
-
166
-		$this->assertEquals(2, $query->getPartitionCount());
167
-
168
-		$results = $query->executeQuery()->fetchAll();
169
-		$this->assertCount(1, $results);
170
-		$this->assertEquals($results[0]['user_id'], 'partitioned_test');
171
-		$this->assertEquals($results[0]['mount_point'], '/mount/point');
172
-		$this->assertEquals($results[0]['mount_provider_class'], 'test');
173
-		$this->assertEquals($results[0]['path'], 'file1');
174
-		$this->assertEquals($results[0]['upload_time'], 1234);
175
-	}
176
-
177
-	public function testPartitionedQueryFromSplit(): void {
178
-		$builder = $this->getQueryBuilder();
179
-		$builder->addPartition(new PartitionSplit('filecache', ['filecache']));
180
-
181
-		$query = $builder->select('storage', 'm.root_id', 'm.user_id', 'm.mount_point', 'm.mount_id', 'path', 'm.mount_provider_class')
182
-			->from('filecache', 'f')
183
-			->innerJoin('f', 'mounts', 'm', $builder->expr()->eq('m.root_id', 'f.fileid'));
184
-		$query->where($builder->expr()->eq('storage', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
185
-
186
-		$query->andWhere($builder->expr()->eq('m.user_id', $builder->createNamedParameter('partitioned_test')));
187
-
188
-		$this->assertEquals(2, $query->getPartitionCount());
189
-
190
-		$results = $query->executeQuery()->fetchAll();
191
-		$this->assertCount(1, $results);
192
-		$this->assertEquals($results[0]['user_id'], 'partitioned_test');
193
-		$this->assertEquals($results[0]['mount_point'], '/mount/point');
194
-		$this->assertEquals($results[0]['mount_provider_class'], 'test');
195
-		$this->assertEquals($results[0]['path'], 'file1');
196
-	}
197
-
198
-	public function testMultiJoinPartitionedQuery(): void {
199
-		$builder = $this->getQueryBuilder();
200
-		$builder->addPartition(new PartitionSplit('filecache', ['filecache']));
201
-
202
-		// query borrowed from UserMountCache
203
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
204
-			->selectAlias('s.id', 'storage_string_id')
205
-			->from('mounts', 'm')
206
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
207
-			->innerJoin('f', 'storages', 's', $builder->expr()->eq('f.storage', 's.numeric_id'))
208
-			->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
209
-
210
-		$query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
211
-
212
-		$this->assertEquals(3, $query->getPartitionCount());
213
-
214
-		$results = $query->executeQuery()->fetchAll();
215
-		$this->assertCount(1, $results);
216
-		$this->assertEquals($results[0]['user_id'], 'partitioned_test');
217
-		$this->assertEquals($results[0]['mount_point'], '/mount/point');
218
-		$this->assertEquals($results[0]['mount_provider_class'], 'test');
219
-		$this->assertEquals($results[0]['path'], 'file1');
220
-		$this->assertEquals($results[0]['storage_string_id'], 'test1');
221
-	}
24
+    private IDBConnection $connection;
25
+    private ShardConnectionManager $shardConnectionManager;
26
+    private AutoIncrementHandler $autoIncrementHandler;
27
+
28
+    protected function setUp(): void {
29
+        if (PHP_INT_SIZE < 8) {
30
+            $this->markTestSkipped('Test requires 64bit');
31
+        }
32
+        $this->connection = Server::get(IDBConnection::class);
33
+        $this->shardConnectionManager = Server::get(ShardConnectionManager::class);
34
+        $this->autoIncrementHandler = Server::get(AutoIncrementHandler::class);
35
+
36
+        $this->setupFileCache();
37
+    }
38
+
39
+    protected function tearDown(): void {
40
+        $this->cleanupDb();
41
+        parent::tearDown();
42
+    }
43
+
44
+
45
+    private function getQueryBuilder(): PartitionedQueryBuilder {
46
+        $builder = $this->connection->getQueryBuilder();
47
+        if ($builder instanceof PartitionedQueryBuilder) {
48
+            return $builder;
49
+        } else {
50
+            return new PartitionedQueryBuilder($builder, [], $this->shardConnectionManager, $this->autoIncrementHandler);
51
+        }
52
+    }
53
+
54
+    private function setupFileCache(): void {
55
+        $this->cleanupDb();
56
+        $query = $this->getQueryBuilder();
57
+        $query->insert('storages')
58
+            ->values([
59
+                'numeric_id' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
60
+                'id' => $query->createNamedParameter('test1'),
61
+            ]);
62
+        $query->executeStatement();
63
+
64
+        $query = $this->getQueryBuilder();
65
+        $query->insert('filecache')
66
+            ->values([
67
+                'storage' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
68
+                'path' => $query->createNamedParameter('file1'),
69
+                'path_hash' => $query->createNamedParameter(md5('file1')),
70
+            ]);
71
+        $query->executeStatement();
72
+        $fileId = $query->getLastInsertId();
73
+
74
+        $query = $this->getQueryBuilder();
75
+        $query->insert('filecache_extended')
76
+            ->hintShardKey('storage', 1001001)
77
+            ->values([
78
+                'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
79
+                'upload_time' => $query->createNamedParameter(1234, IQueryBuilder::PARAM_INT),
80
+            ]);
81
+        $query->executeStatement();
82
+
83
+        $query = $this->getQueryBuilder();
84
+        $query->insert('mounts')
85
+            ->values([
86
+                'storage_id' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
87
+                'user_id' => $query->createNamedParameter('partitioned_test'),
88
+                'mount_point' => $query->createNamedParameter('/mount/point'),
89
+                'mount_provider_class' => $query->createNamedParameter('test'),
90
+                'root_id' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
91
+            ]);
92
+        $query->executeStatement();
93
+    }
94
+
95
+    private function cleanupDb(): void {
96
+        $query = $this->getQueryBuilder();
97
+        $query->delete('storages')
98
+            ->where($query->expr()->gt('numeric_id', $query->createNamedParameter(1000000, IQueryBuilder::PARAM_INT)));
99
+        $query->executeStatement();
100
+
101
+        $query = $this->getQueryBuilder();
102
+        $query->delete('filecache')
103
+            ->where($query->expr()->gt('storage', $query->createNamedParameter(1000000, IQueryBuilder::PARAM_INT)))
104
+            ->runAcrossAllShards();
105
+        $query->executeStatement();
106
+
107
+        $query = $this->getQueryBuilder();
108
+        $query->delete('filecache_extended')
109
+            ->runAcrossAllShards();
110
+        $query->executeStatement();
111
+
112
+        $query = $this->getQueryBuilder();
113
+        $query->delete('mounts')
114
+            ->where($query->expr()->like('user_id', $query->createNamedParameter('partitioned_%')));
115
+        $query->executeStatement();
116
+    }
117
+
118
+    public function testSimpleOnlyPartitionQuery(): void {
119
+        $builder = $this->getQueryBuilder();
120
+        $builder->addPartition(new PartitionSplit('filecache', ['filecache']));
121
+
122
+        // query borrowed from UserMountCache
123
+        $query = $builder->select('path')
124
+            ->from('filecache')
125
+            ->where($builder->expr()->eq('storage', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
126
+
127
+        $results = $query->executeQuery()->fetchAll();
128
+        $this->assertCount(1, $results);
129
+        $this->assertEquals($results[0]['path'], 'file1');
130
+    }
131
+
132
+    public function testSimplePartitionedQuery(): void {
133
+        $builder = $this->getQueryBuilder();
134
+        $builder->addPartition(new PartitionSplit('filecache', ['filecache']));
135
+
136
+        // query borrowed from UserMountCache
137
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
138
+            ->from('mounts', 'm')
139
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
140
+            ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
141
+
142
+        $query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
143
+
144
+        $this->assertEquals(2, $query->getPartitionCount());
145
+
146
+        $results = $query->executeQuery()->fetchAll();
147
+        $this->assertCount(1, $results);
148
+        $this->assertEquals($results[0]['user_id'], 'partitioned_test');
149
+        $this->assertEquals($results[0]['mount_point'], '/mount/point');
150
+        $this->assertEquals($results[0]['mount_provider_class'], 'test');
151
+        $this->assertEquals($results[0]['path'], 'file1');
152
+    }
153
+
154
+    public function testMultiTablePartitionedQuery(): void {
155
+        $builder = $this->getQueryBuilder();
156
+        $builder->addPartition(new PartitionSplit('filecache', ['filecache', 'filecache_extended']));
157
+
158
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class', 'fe.upload_time')
159
+            ->from('mounts', 'm')
160
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
161
+            ->innerJoin('f', 'filecache_extended', 'fe', $builder->expr()->eq('f.fileid', 'fe.fileid'))
162
+            ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
163
+
164
+        $query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
165
+
166
+        $this->assertEquals(2, $query->getPartitionCount());
167
+
168
+        $results = $query->executeQuery()->fetchAll();
169
+        $this->assertCount(1, $results);
170
+        $this->assertEquals($results[0]['user_id'], 'partitioned_test');
171
+        $this->assertEquals($results[0]['mount_point'], '/mount/point');
172
+        $this->assertEquals($results[0]['mount_provider_class'], 'test');
173
+        $this->assertEquals($results[0]['path'], 'file1');
174
+        $this->assertEquals($results[0]['upload_time'], 1234);
175
+    }
176
+
177
+    public function testPartitionedQueryFromSplit(): void {
178
+        $builder = $this->getQueryBuilder();
179
+        $builder->addPartition(new PartitionSplit('filecache', ['filecache']));
180
+
181
+        $query = $builder->select('storage', 'm.root_id', 'm.user_id', 'm.mount_point', 'm.mount_id', 'path', 'm.mount_provider_class')
182
+            ->from('filecache', 'f')
183
+            ->innerJoin('f', 'mounts', 'm', $builder->expr()->eq('m.root_id', 'f.fileid'));
184
+        $query->where($builder->expr()->eq('storage', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
185
+
186
+        $query->andWhere($builder->expr()->eq('m.user_id', $builder->createNamedParameter('partitioned_test')));
187
+
188
+        $this->assertEquals(2, $query->getPartitionCount());
189
+
190
+        $results = $query->executeQuery()->fetchAll();
191
+        $this->assertCount(1, $results);
192
+        $this->assertEquals($results[0]['user_id'], 'partitioned_test');
193
+        $this->assertEquals($results[0]['mount_point'], '/mount/point');
194
+        $this->assertEquals($results[0]['mount_provider_class'], 'test');
195
+        $this->assertEquals($results[0]['path'], 'file1');
196
+    }
197
+
198
+    public function testMultiJoinPartitionedQuery(): void {
199
+        $builder = $this->getQueryBuilder();
200
+        $builder->addPartition(new PartitionSplit('filecache', ['filecache']));
201
+
202
+        // query borrowed from UserMountCache
203
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
204
+            ->selectAlias('s.id', 'storage_string_id')
205
+            ->from('mounts', 'm')
206
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
207
+            ->innerJoin('f', 'storages', 's', $builder->expr()->eq('f.storage', 's.numeric_id'))
208
+            ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
209
+
210
+        $query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter('partitioned_test')));
211
+
212
+        $this->assertEquals(3, $query->getPartitionCount());
213
+
214
+        $results = $query->executeQuery()->fetchAll();
215
+        $this->assertCount(1, $results);
216
+        $this->assertEquals($results[0]['user_id'], 'partitioned_test');
217
+        $this->assertEquals($results[0]['mount_point'], '/mount/point');
218
+        $this->assertEquals($results[0]['mount_provider_class'], 'test');
219
+        $this->assertEquals($results[0]['path'], 'file1');
220
+        $this->assertEquals($results[0]['storage_string_id'], 'test1');
221
+    }
222 222
 }
Please login to merge, or discard this patch.
tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -23,106 +23,106 @@
 block discarded – undo
23 23
  * @group DB
24 24
  */
25 25
 class SharedQueryBuilderTest extends TestCase {
26
-	private IDBConnection $connection;
27
-	private AutoIncrementHandler $autoIncrementHandler;
28
-
29
-	protected function setUp(): void {
30
-		if (PHP_INT_SIZE < 8) {
31
-			$this->markTestSkipped('Test requires 64bit');
32
-		}
33
-		$this->connection = Server::get(IDBConnection::class);
34
-		$this->autoIncrementHandler = Server::get(AutoIncrementHandler::class);
35
-	}
36
-
37
-
38
-	private function getQueryBuilder(string $table, string $shardColumn, string $primaryColumn, array $companionTables = []): ShardedQueryBuilder {
39
-		return new ShardedQueryBuilder(
40
-			$this->connection->getQueryBuilder(),
41
-			[
42
-				new ShardDefinition($table, $primaryColumn, [], $shardColumn, new RoundRobinShardMapper(), $companionTables, [], 0, 0),
43
-			],
44
-			$this->createMock(ShardConnectionManager::class),
45
-			$this->autoIncrementHandler,
46
-		);
47
-	}
48
-
49
-	public function testGetShardKeySingleParam(): void {
50
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
51
-		$query->select('fileid', 'path')
52
-			->from('filecache')
53
-			->where($query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)));
54
-
55
-		$this->assertEquals([], $query->getPrimaryKeys());
56
-		$this->assertEquals([10], $query->getShardKeys());
57
-	}
58
-
59
-	public function testGetPrimaryKeyParam(): void {
60
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
61
-		$query->select('fileid', 'path')
62
-			->from('filecache')
63
-			->where($query->expr()->in('fileid', $query->createNamedParameter([10, 11], IQueryBuilder::PARAM_INT)));
64
-
65
-		$this->assertEquals([10, 11], $query->getPrimaryKeys());
66
-		$this->assertEquals([], $query->getShardKeys());
67
-	}
68
-
69
-	public function testValidateWithShardKey(): void {
70
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
71
-		$query->select('fileid', 'path')
72
-			->from('filecache')
73
-			->where($query->expr()->eq('storage', $query->createNamedParameter(10)));
74
-
75
-		$query->validate();
76
-		$this->assertTrue(true);
77
-	}
78
-
79
-	public function testValidateWithPrimaryKey(): void {
80
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
81
-		$query->select('fileid', 'path')
82
-			->from('filecache')
83
-			->where($query->expr()->in('fileid', $query->createNamedParameter([10, 11], IQueryBuilder::PARAM_INT)));
84
-
85
-		$query->validate();
86
-		$this->assertTrue(true);
87
-	}
88
-
89
-	public function testValidateWithNoKey(): void {
90
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
91
-		$query->select('fileid', 'path')
92
-			->from('filecache')
93
-			->where($query->expr()->lt('size', $query->createNamedParameter(0)));
94
-
95
-		$this->expectException(InvalidShardedQueryException::class);
96
-		$query->validate();
97
-		$this->fail('exception expected');
98
-	}
99
-
100
-	public function testValidateNonSharedTable(): void {
101
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
102
-		$query->select('configvalue')
103
-			->from('appconfig')
104
-			->where($query->expr()->eq('configkey', $query->createNamedParameter('test')));
105
-
106
-		$query->validate();
107
-		$this->assertTrue(true);
108
-	}
109
-
110
-	public function testGetShardKeyMultipleSingleParam(): void {
111
-		$query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
112
-		$query->select('fileid', 'path')
113
-			->from('filecache')
114
-			->where($query->expr()->andX(
115
-				$query->expr()->gt('mtime', $query->createNamedParameter(0), IQueryBuilder::PARAM_INT),
116
-				$query->expr()->orX(
117
-					$query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)),
118
-					$query->expr()->andX(
119
-						$query->expr()->eq('storage', $query->createNamedParameter(11, IQueryBuilder::PARAM_INT)),
120
-						$query->expr()->like('path', $query->createNamedParameter('foo/%'))
121
-					)
122
-				)
123
-			));
124
-
125
-		$this->assertEquals([], $query->getPrimaryKeys());
126
-		$this->assertEquals([10, 11], $query->getShardKeys());
127
-	}
26
+    private IDBConnection $connection;
27
+    private AutoIncrementHandler $autoIncrementHandler;
28
+
29
+    protected function setUp(): void {
30
+        if (PHP_INT_SIZE < 8) {
31
+            $this->markTestSkipped('Test requires 64bit');
32
+        }
33
+        $this->connection = Server::get(IDBConnection::class);
34
+        $this->autoIncrementHandler = Server::get(AutoIncrementHandler::class);
35
+    }
36
+
37
+
38
+    private function getQueryBuilder(string $table, string $shardColumn, string $primaryColumn, array $companionTables = []): ShardedQueryBuilder {
39
+        return new ShardedQueryBuilder(
40
+            $this->connection->getQueryBuilder(),
41
+            [
42
+                new ShardDefinition($table, $primaryColumn, [], $shardColumn, new RoundRobinShardMapper(), $companionTables, [], 0, 0),
43
+            ],
44
+            $this->createMock(ShardConnectionManager::class),
45
+            $this->autoIncrementHandler,
46
+        );
47
+    }
48
+
49
+    public function testGetShardKeySingleParam(): void {
50
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
51
+        $query->select('fileid', 'path')
52
+            ->from('filecache')
53
+            ->where($query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)));
54
+
55
+        $this->assertEquals([], $query->getPrimaryKeys());
56
+        $this->assertEquals([10], $query->getShardKeys());
57
+    }
58
+
59
+    public function testGetPrimaryKeyParam(): void {
60
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
61
+        $query->select('fileid', 'path')
62
+            ->from('filecache')
63
+            ->where($query->expr()->in('fileid', $query->createNamedParameter([10, 11], IQueryBuilder::PARAM_INT)));
64
+
65
+        $this->assertEquals([10, 11], $query->getPrimaryKeys());
66
+        $this->assertEquals([], $query->getShardKeys());
67
+    }
68
+
69
+    public function testValidateWithShardKey(): void {
70
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
71
+        $query->select('fileid', 'path')
72
+            ->from('filecache')
73
+            ->where($query->expr()->eq('storage', $query->createNamedParameter(10)));
74
+
75
+        $query->validate();
76
+        $this->assertTrue(true);
77
+    }
78
+
79
+    public function testValidateWithPrimaryKey(): void {
80
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
81
+        $query->select('fileid', 'path')
82
+            ->from('filecache')
83
+            ->where($query->expr()->in('fileid', $query->createNamedParameter([10, 11], IQueryBuilder::PARAM_INT)));
84
+
85
+        $query->validate();
86
+        $this->assertTrue(true);
87
+    }
88
+
89
+    public function testValidateWithNoKey(): void {
90
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
91
+        $query->select('fileid', 'path')
92
+            ->from('filecache')
93
+            ->where($query->expr()->lt('size', $query->createNamedParameter(0)));
94
+
95
+        $this->expectException(InvalidShardedQueryException::class);
96
+        $query->validate();
97
+        $this->fail('exception expected');
98
+    }
99
+
100
+    public function testValidateNonSharedTable(): void {
101
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
102
+        $query->select('configvalue')
103
+            ->from('appconfig')
104
+            ->where($query->expr()->eq('configkey', $query->createNamedParameter('test')));
105
+
106
+        $query->validate();
107
+        $this->assertTrue(true);
108
+    }
109
+
110
+    public function testGetShardKeyMultipleSingleParam(): void {
111
+        $query = $this->getQueryBuilder('filecache', 'storage', 'fileid');
112
+        $query->select('fileid', 'path')
113
+            ->from('filecache')
114
+            ->where($query->expr()->andX(
115
+                $query->expr()->gt('mtime', $query->createNamedParameter(0), IQueryBuilder::PARAM_INT),
116
+                $query->expr()->orX(
117
+                    $query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)),
118
+                    $query->expr()->andX(
119
+                        $query->expr()->eq('storage', $query->createNamedParameter(11, IQueryBuilder::PARAM_INT)),
120
+                        $query->expr()->like('path', $query->createNamedParameter('foo/%'))
121
+                    )
122
+                )
123
+            ));
124
+
125
+        $this->assertEquals([], $query->getPrimaryKeys());
126
+        $this->assertEquals([10, 11], $query->getShardKeys());
127
+    }
128 128
 }
Please login to merge, or discard this patch.