|
24 | 24 | use OCA\Mail\Contracts\IUserPreferences;
|
25 | 25 | use OCA\Mail\Controller\MessagesController;
|
26 | 26 | use OCA\Mail\Db\MailAccount;
|
| 27 | +use OCA\Mail\Db\Mailbox; |
| 28 | +use OCA\Mail\Db\Message as DbMessage; |
27 | 29 | use OCA\Mail\Db\Tag;
|
28 | 30 | use OCA\Mail\Exception\ClientException;
|
29 | 31 | use OCA\Mail\Exception\ServiceException;
|
@@ -1161,4 +1163,60 @@ public function testGetDkim() {
|
1161 | 1163 | $this->assertInstanceOf(JSONResponse::class, $actualResponse);
|
1162 | 1164 | $this->assertEquals(['valid' => true], $actualResponse->getData());
|
1163 | 1165 | }
|
| 1166 | + |
| 1167 | + public static function provideCacheBusterData(): array { |
| 1168 | + return [ |
| 1169 | + [null, false], |
| 1170 | + ['', false], |
| 1171 | + ['abcdef123', true], |
| 1172 | + ]; |
| 1173 | + } |
| 1174 | + |
| 1175 | + /** @dataProvider provideCacheBusterData */ |
| 1176 | + public function testIndexCacheBuster(?string $cacheBuster, bool $expectCaching): void { |
| 1177 | + $mailbox = new Mailbox(); |
| 1178 | + $mailbox->setAccountId(100); |
| 1179 | + $this->mailManager->expects(self::once()) |
| 1180 | + ->method('getMailbox') |
| 1181 | + ->with($this->userId, 100) |
| 1182 | + ->willReturn($mailbox); |
| 1183 | + $mailAccount = new MailAccount(); |
| 1184 | + $account = new Account($mailAccount); |
| 1185 | + $this->accountService->expects(self::once()) |
| 1186 | + ->method('find') |
| 1187 | + ->with($this->userId, 100) |
| 1188 | + ->willReturn($account); |
| 1189 | + |
| 1190 | + $this->userPreferences->expects(self::once()) |
| 1191 | + ->method('getPreference') |
| 1192 | + ->with($this->userId, 'sort-order', 'newest') |
| 1193 | + ->willReturnArgument(2); |
| 1194 | + |
| 1195 | + $messages = [ |
| 1196 | + new DbMessage(), |
| 1197 | + new DbMessage(), |
| 1198 | + ]; |
| 1199 | + $this->mailSearch->expects(self::once()) |
| 1200 | + ->method('findMessages') |
| 1201 | + ->with( |
| 1202 | + $account, |
| 1203 | + $mailbox, |
| 1204 | + 'DESC', |
| 1205 | + null, |
| 1206 | + null, |
| 1207 | + null, |
| 1208 | + $this->userId, |
| 1209 | + 'threaded', |
| 1210 | + )->willReturn($messages); |
| 1211 | + |
| 1212 | + $actualResponse = $this->controller->index(100, null, null, null, null, $cacheBuster); |
| 1213 | + |
| 1214 | + $cacheForHeader = $actualResponse->getHeaders()['Cache-Control'] ?? null; |
| 1215 | + $this->assertNotNull($cacheForHeader); |
| 1216 | + if ($expectCaching) { |
| 1217 | + $this->assertEquals('private, max-age=604800, immutable', $cacheForHeader); |
| 1218 | + } else { |
| 1219 | + $this->assertEquals('no-cache, no-store, must-revalidate', $cacheForHeader); |
| 1220 | + } |
| 1221 | + } |
1164 | 1222 | }
|
0 commit comments