|
@@ -12,13 +12,14 @@ use JKingWeb\Arsse\User;
|
12
|
12
|
use JKingWeb\Arsse\Database;
|
13
|
13
|
use JKingWeb\Arsse\Service;
|
14
|
14
|
use JKingWeb\Arsse\REST\Request;
|
15
|
|
-use JKingWeb\Arsse\REST\Response;
|
16
|
15
|
use JKingWeb\Arsse\Test\Result;
|
17
|
16
|
use JKingWeb\Arsse\Misc\Date;
|
18
|
17
|
use JKingWeb\Arsse\Misc\Context;
|
19
|
18
|
use JKingWeb\Arsse\Db\ExceptionInput;
|
20
|
19
|
use JKingWeb\Arsse\Db\Transaction;
|
21
|
20
|
use JKingWeb\Arsse\REST\NextCloudNews\V1_2;
|
|
21
|
+use Zend\Diactoros\Response\JsonResponse as Response;
|
|
22
|
+use Zend\Diactoros\Response\EmptyResponse;
|
22
|
23
|
use Phake;
|
23
|
24
|
|
24
|
25
|
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\V1_2<extended> */
|
|
@@ -317,14 +318,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
317
|
318
|
$this->clearData();
|
318
|
319
|
}
|
319
|
320
|
|
320
|
|
- protected function assertResponse(Response $exp, Response $act, string $text = null) {
|
321
|
|
- $this->assertEquals($exp, $act, $text);
|
322
|
|
- $this->assertSame($exp->payload, $act->payload, $text);
|
323
|
|
- }
|
324
|
|
-
|
325
|
321
|
public function testSendAuthenticationChallenge() {
|
326
|
322
|
Phake::when(Arsse::$user)->authHTTP->thenReturn(false);
|
327
|
|
- $exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.V1_2::REALM.'"']);
|
|
323
|
+ $exp = new EmptyResponse(401, ['WWW-Authenticate' => 'Basic realm="'.V1_2::REALM.'"']);
|
328
|
324
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/")));
|
329
|
325
|
}
|
330
|
326
|
|
|
@@ -361,12 +357,12 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
361
|
357
|
],
|
362
|
358
|
];
|
363
|
359
|
foreach ($errs[404] as $req) {
|
364
|
|
- $exp = new Response(404);
|
|
360
|
+ $exp = new EmptyResponse(404);
|
365
|
361
|
list($method, $path) = $req;
|
366
|
362
|
$this->assertResponse($exp, $this->h->dispatch(new Request($method, $path)), "$method call to $path did not return 404.");
|
367
|
363
|
}
|
368
|
364
|
foreach ($errs[405] as $allow => $cases) {
|
369
|
|
- $exp = new Response(405, "", "", ['Allow: '.$allow]);
|
|
365
|
+ $exp = new EmptyResponse(405, ['Allow' => $allow]);
|
370
|
366
|
foreach ($cases as $req) {
|
371
|
367
|
list($method, $path) = $req;
|
372
|
368
|
$this->assertResponse($exp, $this->h->dispatch(new Request($method, $path)), "$method call to $path did not return 405.");
|
|
@@ -375,29 +371,29 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
375
|
371
|
}
|
376
|
372
|
|
377
|
373
|
public function testRespondToInvalidInputTypes() {
|
378
|
|
- $exp = new Response(415, "", "", ['Accept: application/json']);
|
|
374
|
+ $exp = new EmptyResponse(415, ['Accept' => "application/json"]);
|
379
|
375
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", '<data/>', 'application/xml')));
|
380
|
|
- $exp = new Response(400);
|
|
376
|
+ $exp = new EmptyResponse(400);
|
381
|
377
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", '<data/>', 'application/json')));
|
382
|
378
|
}
|
383
|
379
|
|
384
|
380
|
public function testRespondToOptionsRequests() {
|
385
|
|
- $exp = new Response(204, "", "", [
|
386
|
|
- "Allow: HEAD,GET,POST",
|
387
|
|
- "Accept: application/json",
|
|
381
|
+ $exp = new EmptyResponse(204, [
|
|
382
|
+ 'Allow' => "HEAD,GET,POST",
|
|
383
|
+ 'Accept' => "application/json",
|
388
|
384
|
]);
|
389
|
385
|
$this->assertResponse($exp, $this->h->dispatch(new Request("OPTIONS", "/feeds")));
|
390
|
|
- $exp = new Response(204, "", "", [
|
391
|
|
- "Allow: DELETE",
|
392
|
|
- "Accept: application/json",
|
|
386
|
+ $exp = new EmptyResponse(204, [
|
|
387
|
+ 'Allow' => "DELETE",
|
|
388
|
+ 'Accept' => "application/json",
|
393
|
389
|
]);
|
394
|
390
|
$this->assertResponse($exp, $this->h->dispatch(new Request("OPTIONS", "/feeds/2112")));
|
395
|
|
- $exp = new Response(204, "", "", [
|
396
|
|
- "Allow: HEAD,GET",
|
397
|
|
- "Accept: application/json",
|
|
391
|
+ $exp = new EmptyResponse(204, [
|
|
392
|
+ 'Allow' => "HEAD,GET",
|
|
393
|
+ 'Accept' => "application/json",
|
398
|
394
|
]);
|
399
|
395
|
$this->assertResponse($exp, $this->h->dispatch(new Request("OPTIONS", "/user")));
|
400
|
|
- $exp = new Response(404);
|
|
396
|
+ $exp = new EmptyResponse(404);
|
401
|
397
|
$this->assertResponse($exp, $this->h->dispatch(new Request("OPTIONS", "/invalid/path")));
|
402
|
398
|
}
|
403
|
399
|
|
|
@@ -411,9 +407,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
411
|
407
|
['id' => 12, 'name' => "Hardware"],
|
412
|
408
|
];
|
413
|
409
|
Phake::when(Arsse::$db)->folderList(Arsse::$user->id, null, false)->thenReturn(new Result([]))->thenReturn(new Result($list));
|
414
|
|
- $exp = new Response(200, ['folders' => []]);
|
|
410
|
+ $exp = new Response(['folders' => []]);
|
415
|
411
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/folders")));
|
416
|
|
- $exp = new Response(200, ['folders' => $out]);
|
|
412
|
+ $exp = new Response(['folders' => $out]);
|
417
|
413
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/folders")));
|
418
|
414
|
}
|
419
|
415
|
|
|
@@ -441,33 +437,33 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
441
|
437
|
Phake::when(Arsse::$db)->folderAdd(Arsse::$user->id, ['name' => ""])->thenThrow(new ExceptionInput("missing"));
|
442
|
438
|
Phake::when(Arsse::$db)->folderAdd(Arsse::$user->id, ['name' => " "])->thenThrow(new ExceptionInput("whitespace"));
|
443
|
439
|
// correctly add two folders, using different means
|
444
|
|
- $exp = new Response(200, ['folders' => [$out[0]]]);
|
|
440
|
+ $exp = new Response(['folders' => [$out[0]]]);
|
445
|
441
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders", json_encode($in[0]), 'application/json')));
|
446
|
|
- $exp = new Response(200, ['folders' => [$out[1]]]);
|
|
442
|
+ $exp = new Response(['folders' => [$out[1]]]);
|
447
|
443
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders?name=Hardware")));
|
448
|
444
|
Phake::verify(Arsse::$db)->folderAdd(Arsse::$user->id, $in[0]);
|
449
|
445
|
Phake::verify(Arsse::$db)->folderAdd(Arsse::$user->id, $in[1]);
|
450
|
446
|
Phake::verify(Arsse::$db)->folderPropertiesGet(Arsse::$user->id, 1);
|
451
|
447
|
Phake::verify(Arsse::$db)->folderPropertiesGet(Arsse::$user->id, 2);
|
452
|
448
|
// test bad folder names
|
453
|
|
- $exp = new Response(422);
|
|
449
|
+ $exp = new EmptyResponse(422);
|
454
|
450
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders")));
|
455
|
451
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders", '{"name":""}', 'application/json')));
|
456
|
452
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders", '{"name":" "}', 'application/json')));
|
457
|
453
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders", '{"name":{}}', 'application/json')));
|
458
|
454
|
// try adding the same two folders again
|
459
|
|
- $exp = new Response(409);
|
|
455
|
+ $exp = new EmptyResponse(409);
|
460
|
456
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders?name=Software")));
|
461
|
|
- $exp = new Response(409);
|
|
457
|
+ $exp = new EmptyResponse(409);
|
462
|
458
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/folders", json_encode($in[1]), 'application/json')));
|
463
|
459
|
}
|
464
|
460
|
|
465
|
461
|
public function testRemoveAFolder() {
|
466
|
462
|
Phake::when(Arsse::$db)->folderRemove(Arsse::$user->id, 1)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
467
|
|
- $exp = new Response(204);
|
|
463
|
+ $exp = new EmptyResponse(204);
|
468
|
464
|
$this->assertResponse($exp, $this->h->dispatch(new Request("DELETE", "/folders/1")));
|
469
|
465
|
// fail on the second invocation because it no longer exists
|
470
|
|
- $exp = new Response(404);
|
|
466
|
+ $exp = new EmptyResponse(404);
|
471
|
467
|
$this->assertResponse($exp, $this->h->dispatch(new Request("DELETE", "/folders/1")));
|
472
|
468
|
Phake::verify(Arsse::$db, Phake::times(2))->folderRemove(Arsse::$user->id, 1);
|
473
|
469
|
}
|
|
@@ -486,22 +482,22 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
486
|
482
|
Phake::when(Arsse::$db)->folderPropertiesSet(Arsse::$user->id, 1, $in[3])->thenThrow(new ExceptionInput("whitespace"));
|
487
|
483
|
Phake::when(Arsse::$db)->folderPropertiesSet(Arsse::$user->id, 1, $in[4])->thenReturn(true); // this should be stopped by the handler before the request gets to the database
|
488
|
484
|
Phake::when(Arsse::$db)->folderPropertiesSet(Arsse::$user->id, 3, $this->anything())->thenThrow(new ExceptionInput("subjectMissing")); // folder ID 3 does not exist
|
489
|
|
- $exp = new Response(204);
|
|
485
|
+ $exp = new EmptyResponse(204);
|
490
|
486
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", json_encode($in[0]), 'application/json')));
|
491
|
|
- $exp = new Response(409);
|
|
487
|
+ $exp = new EmptyResponse(409);
|
492
|
488
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/2", json_encode($in[1]), 'application/json')));
|
493
|
|
- $exp = new Response(422);
|
|
489
|
+ $exp = new EmptyResponse(422);
|
494
|
490
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", json_encode($in[2]), 'application/json')));
|
495
|
|
- $exp = new Response(422);
|
|
491
|
+ $exp = new EmptyResponse(422);
|
496
|
492
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", json_encode($in[3]), 'application/json')));
|
497
|
|
- $exp = new Response(422);
|
|
493
|
+ $exp = new EmptyResponse(422);
|
498
|
494
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1", json_encode($in[4]), 'application/json')));
|
499
|
|
- $exp = new Response(404);
|
|
495
|
+ $exp = new EmptyResponse(404);
|
500
|
496
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/3", json_encode($in[0]), 'application/json')));
|
501
|
497
|
}
|
502
|
498
|
|
503
|
499
|
public function testRetrieveServerVersion() {
|
504
|
|
- $exp = new Response(200, [
|
|
500
|
+ $exp = new Response([
|
505
|
501
|
'version' => V1_2::VERSION,
|
506
|
502
|
'arsse_version' => Arsse::VERSION,
|
507
|
503
|
]);
|
|
@@ -521,9 +517,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
521
|
517
|
Phake::when(Arsse::$db)->subscriptionList(Arsse::$user->id)->thenReturn(new Result([]))->thenReturn(new Result($this->feeds['db']));
|
522
|
518
|
Phake::when(Arsse::$db)->articleStarred(Arsse::$user->id)->thenReturn(['total' => 0])->thenReturn(['total' => 5]);
|
523
|
519
|
Phake::when(Arsse::$db)->editionLatest(Arsse::$user->id)->thenReturn(0)->thenReturn(4758915);
|
524
|
|
- $exp = new Response(200, $exp1);
|
|
520
|
+ $exp = new Response($exp1);
|
525
|
521
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds")));
|
526
|
|
- $exp = new Response(200, $exp2);
|
|
522
|
+ $exp = new Response($exp2);
|
527
|
523
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds")));
|
528
|
524
|
}
|
529
|
525
|
|
|
@@ -556,31 +552,31 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
556
|
552
|
// set up a mock for a bad feed which succeeds the second time
|
557
|
553
|
Phake::when(Arsse::$db)->subscriptionAdd(Arsse::$user->id, "http://example.net/news.atom")->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.net/news.atom", new \PicoFeed\Client\InvalidUrlException()))->thenReturn(47);
|
558
|
554
|
// add the subscriptions
|
559
|
|
- $exp = new Response(200, $out[0]);
|
|
555
|
+ $exp = new Response($out[0]);
|
560
|
556
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[0]), 'application/json')));
|
561
|
|
- $exp = new Response(200, $out[1]);
|
|
557
|
+ $exp = new Response($out[1]);
|
562
|
558
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[1]), 'application/json')));
|
563
|
559
|
// try to add them a second time
|
564
|
|
- $exp = new Response(409);
|
|
560
|
+ $exp = new EmptyResponse(409);
|
565
|
561
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[0]), 'application/json')));
|
566
|
562
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[1]), 'application/json')));
|
567
|
563
|
// try to add a bad feed
|
568
|
|
- $exp = new Response(422);
|
|
564
|
+ $exp = new EmptyResponse(422);
|
569
|
565
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[2]), 'application/json')));
|
570
|
566
|
// try again (this will succeed), with an invalid folder ID
|
571
|
|
- $exp = new Response(200, $out[2]);
|
|
567
|
+ $exp = new Response($out[2]);
|
572
|
568
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[3]), 'application/json')));
|
573
|
569
|
// try to add no feed
|
574
|
|
- $exp = new Response(422);
|
|
570
|
+ $exp = new EmptyResponse(422);
|
575
|
571
|
$this->assertResponse($exp, $this->h->dispatch(new Request("POST", "/feeds", json_encode($in[4]), 'application/json')));
|
576
|
572
|
}
|
577
|
573
|
|
578
|
574
|
public function testRemoveASubscription() {
|
579
|
575
|
Phake::when(Arsse::$db)->subscriptionRemove(Arsse::$user->id, 1)->thenReturn(true)->thenThrow(new ExceptionInput("subjectMissing"));
|
580
|
|
- $exp = new Response(204);
|
|
576
|
+ $exp = new EmptyResponse(204);
|
581
|
577
|
$this->assertResponse($exp, $this->h->dispatch(new Request("DELETE", "/feeds/1")));
|
582
|
578
|
// fail on the second invocation because it no longer exists
|
583
|
|
- $exp = new Response(404);
|
|
579
|
+ $exp = new EmptyResponse(404);
|
584
|
580
|
$this->assertResponse($exp, $this->h->dispatch(new Request("DELETE", "/feeds/1")));
|
585
|
581
|
Phake::verify(Arsse::$db, Phake::times(2))->subscriptionRemove(Arsse::$user->id, 1);
|
586
|
582
|
}
|
|
@@ -599,17 +595,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
599
|
595
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, ['folder' => 2112])->thenThrow(new ExceptionInput("idMissing")); // folder does not exist
|
600
|
596
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, ['folder' => -1])->thenThrow(new ExceptionInput("typeViolation")); // folder is invalid
|
601
|
597
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 42, $this->anything())->thenThrow(new ExceptionInput("subjectMissing")); // subscription does not exist
|
602
|
|
- $exp = new Response(204);
|
|
598
|
+ $exp = new EmptyResponse(204);
|
603
|
599
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[0]), 'application/json')));
|
604
|
|
- $exp = new Response(204);
|
|
600
|
+ $exp = new EmptyResponse(204);
|
605
|
601
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[1]), 'application/json')));
|
606
|
|
- $exp = new Response(422);
|
|
602
|
+ $exp = new EmptyResponse(422);
|
607
|
603
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[2]), 'application/json')));
|
608
|
|
- $exp = new Response(404);
|
|
604
|
+ $exp = new EmptyResponse(404);
|
609
|
605
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/42/move", json_encode($in[3]), 'application/json')));
|
610
|
|
- $exp = new Response(422);
|
|
606
|
+ $exp = new EmptyResponse(422);
|
611
|
607
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[4]), 'application/json')));
|
612
|
|
- $exp = new Response(422);
|
|
608
|
+ $exp = new EmptyResponse(422);
|
613
|
609
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/move", json_encode($in[5]), 'application/json')));
|
614
|
610
|
}
|
615
|
611
|
|
|
@@ -629,17 +625,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
629
|
625
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, $this->identicalTo(['title' => ""]))->thenThrow(new ExceptionInput("missing"));
|
630
|
626
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 1, $this->identicalTo(['title' => false]))->thenThrow(new ExceptionInput("missing"));
|
631
|
627
|
Phake::when(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 42, $this->anything())->thenThrow(new ExceptionInput("subjectMissing"));
|
632
|
|
- $exp = new Response(422);
|
|
628
|
+ $exp = new EmptyResponse(422);
|
633
|
629
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[0]), 'application/json')));
|
634
|
|
- $exp = new Response(204);
|
|
630
|
+ $exp = new EmptyResponse(204);
|
635
|
631
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[1]), 'application/json')));
|
636
|
|
- $exp = new Response(422);
|
|
632
|
+ $exp = new EmptyResponse(422);
|
637
|
633
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[2]), 'application/json')));
|
638
|
|
- $exp = new Response(422);
|
|
634
|
+ $exp = new EmptyResponse(422);
|
639
|
635
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[3]), 'application/json')));
|
640
|
|
- $exp = new Response(404);
|
|
636
|
+ $exp = new EmptyResponse(404);
|
641
|
637
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/42/rename", json_encode($in[4]), 'application/json')));
|
642
|
|
- $exp = new Response(422);
|
|
638
|
+ $exp = new EmptyResponse(422);
|
643
|
639
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/rename", json_encode($in[6]), 'application/json')));
|
644
|
640
|
}
|
645
|
641
|
|
|
@@ -655,11 +651,11 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
655
|
651
|
],
|
656
|
652
|
];
|
657
|
653
|
Phake::when(Arsse::$db)->feedListStale->thenReturn(array_column($out, "id"));
|
658
|
|
- $exp = new Response(200, ['feeds' => $out]);
|
|
654
|
+ $exp = new Response(['feeds' => $out]);
|
659
|
655
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/all")));
|
660
|
656
|
// retrieving the list when not an admin fails
|
661
|
657
|
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
662
|
|
- $exp = new Response(403);
|
|
658
|
+ $exp = new EmptyResponse(403);
|
663
|
659
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/all")));
|
664
|
660
|
}
|
665
|
661
|
|
|
@@ -674,17 +670,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
674
|
670
|
Phake::when(Arsse::$db)->feedUpdate(42)->thenReturn(true);
|
675
|
671
|
Phake::when(Arsse::$db)->feedUpdate(2112)->thenThrow(new ExceptionInput("subjectMissing"));
|
676
|
672
|
Phake::when(Arsse::$db)->feedUpdate($this->lessThan(1))->thenThrow(new ExceptionInput("typeViolation"));
|
677
|
|
- $exp = new Response(204);
|
|
673
|
+ $exp = new EmptyResponse(204);
|
678
|
674
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[0]), 'application/json')));
|
679
|
|
- $exp = new Response(404);
|
|
675
|
+ $exp = new EmptyResponse(404);
|
680
|
676
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[1]), 'application/json')));
|
681
|
|
- $exp = new Response(422);
|
|
677
|
+ $exp = new EmptyResponse(422);
|
682
|
678
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[2]), 'application/json')));
|
683
|
679
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[3]), 'application/json')));
|
684
|
680
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[4]), 'application/json')));
|
685
|
681
|
// updating a feed when not an admin fails
|
686
|
682
|
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
687
|
|
- $exp = new Response(403);
|
|
683
|
+ $exp = new EmptyResponse(403);
|
688
|
684
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[0]), 'application/json')));
|
689
|
685
|
}
|
690
|
686
|
|
|
@@ -710,12 +706,12 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
710
|
706
|
Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->reverse(true)->folder(2112), Database::LIST_TYPICAL)->thenThrow(new ExceptionInput("idMissing"));
|
711
|
707
|
Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->reverse(true)->subscription(-1), Database::LIST_TYPICAL)->thenThrow(new ExceptionInput("typeViolation"));
|
712
|
708
|
Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->reverse(true)->folder(-1), Database::LIST_TYPICAL)->thenThrow(new ExceptionInput("typeViolation"));
|
713
|
|
- $exp = new Response(200, ['items' => $this->articles['rest']]);
|
|
709
|
+ $exp = new Response(['items' => $this->articles['rest']]);
|
714
|
710
|
// check the contents of the response
|
715
|
711
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/items"))); // first instance of base context
|
716
|
712
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/items/updated"))); // second instance of base context
|
717
|
713
|
// check error conditions
|
718
|
|
- $exp = new Response(422);
|
|
714
|
+ $exp = new EmptyResponse(422);
|
719
|
715
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/items", json_encode($in[0]), 'application/json')));
|
720
|
716
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/items", json_encode($in[1]), 'application/json')));
|
721
|
717
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/items", json_encode($in[2]), 'application/json')));
|
|
@@ -748,13 +744,13 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
748
|
744
|
$in = json_encode(['newestItemId' => 2112]);
|
749
|
745
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->folder(1)->latestEdition(2112))->thenReturn(42);
|
750
|
746
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->folder(42)->latestEdition(2112))->thenThrow(new ExceptionInput("idMissing")); // folder doesn't exist
|
751
|
|
- $exp = new Response(204);
|
|
747
|
+ $exp = new EmptyResponse(204);
|
752
|
748
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1/read", $in, 'application/json')));
|
753
|
749
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1/read?newestItemId=2112")));
|
754
|
|
- $exp = new Response(422);
|
|
750
|
+ $exp = new EmptyResponse(422);
|
755
|
751
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1/read")));
|
756
|
752
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/1/read?newestItemId=ook")));
|
757
|
|
- $exp = new Response(404);
|
|
753
|
+ $exp = new EmptyResponse(404);
|
758
|
754
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/folders/42/read", $in, 'application/json')));
|
759
|
755
|
}
|
760
|
756
|
|
|
@@ -763,13 +759,13 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
763
|
759
|
$in = json_encode(['newestItemId' => 2112]);
|
764
|
760
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->subscription(1)->latestEdition(2112))->thenReturn(42);
|
765
|
761
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->subscription(42)->latestEdition(2112))->thenThrow(new ExceptionInput("idMissing")); // subscription doesn't exist
|
766
|
|
- $exp = new Response(204);
|
|
762
|
+ $exp = new EmptyResponse(204);
|
767
|
763
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/read", $in, 'application/json')));
|
768
|
764
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/read?newestItemId=2112")));
|
769
|
|
- $exp = new Response(422);
|
|
765
|
+ $exp = new EmptyResponse(422);
|
770
|
766
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/read")));
|
771
|
767
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/1/read?newestItemId=ook")));
|
772
|
|
- $exp = new Response(404);
|
|
768
|
+ $exp = new EmptyResponse(404);
|
773
|
769
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/feeds/42/read", $in, 'application/json')));
|
774
|
770
|
}
|
775
|
771
|
|
|
@@ -777,10 +773,10 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
777
|
773
|
$read = ['read' => true];
|
778
|
774
|
$in = json_encode(['newestItemId' => 2112]);
|
779
|
775
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $read, (new Context)->latestEdition(2112))->thenReturn(42);
|
780
|
|
- $exp = new Response(204);
|
|
776
|
+ $exp = new EmptyResponse(204);
|
781
|
777
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/read", $in, 'application/json')));
|
782
|
778
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/read?newestItemId=2112")));
|
783
|
|
- $exp = new Response(422);
|
|
779
|
+ $exp = new EmptyResponse(422);
|
784
|
780
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/read")));
|
785
|
781
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/read?newestItemId=ook")));
|
786
|
782
|
}
|
|
@@ -798,12 +794,12 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
798
|
794
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $star, (new Context)->article(2112))->thenThrow(new ExceptionInput("subjectMissing")); // article doesn't exist doesn't exist
|
799
|
795
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->article(4))->thenReturn(42);
|
800
|
796
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $unstar, (new Context)->article(1337))->thenThrow(new ExceptionInput("subjectMissing")); // article doesn't exist doesn't exist
|
801
|
|
- $exp = new Response(204);
|
|
797
|
+ $exp = new EmptyResponse(204);
|
802
|
798
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/1/read")));
|
803
|
799
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/2/unread")));
|
804
|
800
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/1/3/star")));
|
805
|
801
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/4400/4/unstar")));
|
806
|
|
- $exp = new Response(404);
|
|
802
|
+ $exp = new EmptyResponse(404);
|
807
|
803
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/42/read")));
|
808
|
804
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/47/unread")));
|
809
|
805
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/1/2112/star")));
|
|
@@ -829,7 +825,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
829
|
825
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), $this->anything())->thenReturn(42);
|
830
|
826
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->editions([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
831
|
827
|
Phake::when(Arsse::$db)->articleMark(Arsse::$user->id, $this->anything(), (new Context)->articles([]))->thenThrow(new ExceptionInput("tooShort")); // data model function requires one valid integer for multiples
|
832
|
|
- $exp = new Response(204);
|
|
828
|
+ $exp = new EmptyResponse(204);
|
833
|
829
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/read/multiple")));
|
834
|
830
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/unread/multiple")));
|
835
|
831
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "/items/star/multiple")));
|
|
@@ -882,29 +878,29 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
882
|
878
|
];
|
883
|
879
|
$arr2['warnings']['improperlyConfiguredCron'] = true;
|
884
|
880
|
$arr2['warnings']['incorrectDbCharset'] = true;
|
885
|
|
- $exp = new Response(200, $arr1);
|
|
881
|
+ $exp = new Response($arr1);
|
886
|
882
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/status")));
|
887
|
883
|
}
|
888
|
884
|
|
889
|
885
|
public function testCleanUpBeforeUpdate() {
|
890
|
886
|
Phake::when(Arsse::$db)->feedCleanup()->thenReturn(true);
|
891
|
|
- $exp = new Response(204);
|
|
887
|
+ $exp = new EmptyResponse(204);
|
892
|
888
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/cleanup/before-update")));
|
893
|
889
|
Phake::verify(Arsse::$db)->feedCleanup();
|
894
|
890
|
// performing a cleanup when not an admin fails
|
895
|
891
|
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
896
|
|
- $exp = new Response(403);
|
|
892
|
+ $exp = new EmptyResponse(403);
|
897
|
893
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/cleanup/before-update")));
|
898
|
894
|
}
|
899
|
895
|
|
900
|
896
|
public function testCleanUpAfterUpdate() {
|
901
|
897
|
Phake::when(Arsse::$db)->articleCleanup()->thenReturn(true);
|
902
|
|
- $exp = new Response(204);
|
|
898
|
+ $exp = new EmptyResponse(204);
|
903
|
899
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/cleanup/after-update")));
|
904
|
900
|
Phake::verify(Arsse::$db)->articleCleanup();
|
905
|
901
|
// performing a cleanup when not an admin fails
|
906
|
902
|
Phake::when(Arsse::$user)->rightsGet->thenReturn(0);
|
907
|
|
- $exp = new Response(403);
|
|
903
|
+ $exp = new EmptyResponse(403);
|
908
|
904
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/cleanup/after-update")));
|
909
|
905
|
}
|
910
|
906
|
}
|