]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix tests 4161/head
authorJérémy Benoist <j0k3r@users.noreply.github.com>
Wed, 27 Nov 2019 13:04:11 +0000 (14:04 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 27 Nov 2019 13:46:27 +0000 (14:46 +0100)
tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php

index 74e9ba8fdf1aef00aec0c221bdf7819c937452b6..260edd770ffc6dd13882862f910598ed0f2726d0 100644 (file)
@@ -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']);
     }
 
     /**