X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FAnnotationBundle%2FController%2FAnnotationControllerTest.php;h=260edd770ffc6dd13882862f910598ed0f2726d0;hb=d816ef0530358c5b6fb757b5cfb4ca142b26ce90;hp=537283f2539a8127a35a478d9a80f738f5180a62;hpb=39502b4748709948658fd236a1883b902c6fd470;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 537283f2..260edd77 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -1,6 +1,6 @@ assertSame('my annotation', $annotation->getText()); } + public function testAllowEmptyQuote() + { + $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(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->assertSame('Big boss', $content['user']); + $this->assertSame('v1.0', $content['annotator_schema_version']); + $this->assertSame('my new annotation', $content['text']); + $this->assertSame('', $content['quote']); + } + /** * @dataProvider dataForEachAnnotations */