]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
Fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / AnnotationBundle / Controller / AnnotationControllerTest.php
index 2c46e0a1deff5f7c1b870af3a76a792674d684c8..260edd770ffc6dd13882862f910598ed0f2726d0 100644 (file)
@@ -107,6 +107,63 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
         $this->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
      */