]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
API return an error with empty quote
[github/wallabag/wallabag.git] / tests / Wallabag / AnnotationBundle / Controller / AnnotationControllerTest.php
index 2c46e0a1deff5f7c1b870af3a76a792674d684c8..74e9ba8fdf1aef00aec0c221bdf7819c937452b6 100644 (file)
@@ -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
      */