From 8f2038e5b15c2d7342ed18381531e5eb95e86d46 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 26 Nov 2018 22:22:49 +0100 Subject: Fix tests --- .../Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 96474468..537283f2 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -100,8 +100,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertSame('my quote', $content['quote']); /** @var Annotation $annotation */ - $annotation = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') + $annotation = $em ->getRepository('WallabagAnnotationBundle:Annotation') ->findLastAnnotationByPageId($entry->getId(), 1); -- cgit v1.2.3 From 1e0d8ad7b728f6fb2cd886526b0fb84ef803e84f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 17 Jan 2019 14:28:05 +0100 Subject: Enable PHPStan - Fix error for level 0 & 1 (level 7 has 699 errors...) - Add `updated_at` to site_credential (so the `timestamps()` method applies correctly) --- tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 537283f2..2c46e0a1 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -1,6 +1,6 @@ Date: Sun, 27 Oct 2019 18:51:32 +0100 Subject: API return an error with empty quote Fix #4137 --- .../Controller/AnnotationControllerTest.php | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 2c46e0a1..74e9ba8f 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -107,6 +107,36 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertSame('my annotation', $annotation->getText()); } + public function testCouldNotSetAnnotationWithoutQuote() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + + /** @var Entry $entry */ + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUsernameAndNotArchived('admin'); + + $headers = ['CONTENT_TYPE' => 'application/json']; + $content = json_encode([ + 'text' => 'my annotation', + 'quote' => null, + 'ranges' => [ + ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], + ], + ]); + $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content); + + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertCount( + 1, + $content['errors']['children']['quote']['errors'], + 'The quote field should contains an error' + ); + } + /** * @dataProvider dataForEachAnnotations */ -- cgit v1.2.3 From 6a0d49ab7a8ac9e00f9df34b37b6d3e1ab40f2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Benoist?= Date: Wed, 27 Nov 2019 14:04:11 +0100 Subject: Fix tests --- .../Controller/AnnotationControllerTest.php | 41 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 74e9ba8f..260edd77 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -107,7 +107,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertSame('my annotation', $annotation->getText()); } - public function testCouldNotSetAnnotationWithoutQuote() + public function testAllowEmptyQuote() { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); @@ -126,15 +126,42 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase ]); $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content); - $this->assertSame(400, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame('Big boss', $content['user']); + $this->assertSame('v1.0', $content['annotator_schema_version']); + $this->assertSame('my annotation', $content['text']); + $this->assertSame('', $content['quote']); + } + + public function testAllowOmmittedQuote() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + + /** @var Entry $entry */ + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUsernameAndNotArchived('admin'); + + $headers = ['CONTENT_TYPE' => 'application/json']; + $content = json_encode([ + 'text' => 'my new annotation', + 'ranges' => [ + ['start' => '', 'startOffset' => 25, 'end' => '', 'endOffset' => 32], + ], + ]); + $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertCount( - 1, - $content['errors']['children']['quote']['errors'], - 'The quote field should contains an error' - ); + $this->assertSame('Big boss', $content['user']); + $this->assertSame('v1.0', $content['annotator_schema_version']); + $this->assertSame('my new annotation', $content['text']); + $this->assertSame('', $content['quote']); } /** -- cgit v1.2.3