]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
API return an error with empty quote
authoradev <adev2000@gmail.com>
Sun, 27 Oct 2019 17:51:32 +0000 (18:51 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 27 Nov 2019 13:38:35 +0000 (14:38 +0100)
Fix #4137

src/Wallabag/AnnotationBundle/Entity/Annotation.php
src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php

index a180d504786c866686a70e34b8510d133e9e3b11..ee7c19310108b904d6ac1c6533b00b14d996841d 100644 (file)
@@ -60,6 +60,7 @@ class Annotation
     /**
      * @var string
      *
+     * @Assert\NotNull()
      * @Assert\Length(
      *     max = 10000,
      *     maxMessage = "validator.quote_length_too_high"
index c73c3ded9041f4eaa5964fa570b57e17f8c9890c..aac6445c82e9aa066205ac4bec7bf1eb43f7a312 100644 (file)
@@ -18,6 +18,7 @@ class NewAnnotationType extends AbstractType
             ])
             ->add('quote', null, [
                 'empty_data' => null,
+                'trim' => false,
             ])
             ->add('ranges', CollectionType::class, [
                 'entry_type' => RangeType::class,
index f59431e470bbff03d5e31710aca8f75ecfe472a2..e5b3eb27fcc385152ff6a21499228ba4f8e334db 100644 (file)
@@ -37,7 +37,7 @@ class AnnotationRestController extends WallabagRestController
      * @ApiDoc(
      *      requirements={
      *          {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
-     *          {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"},
+     *          {"name"="quote", "dataType"="string", "required"=true, "description"="Quote for the annotation"},
      *          {"name"="text", "dataType"="string", "required"=true, "description"=""},
      *      }
      * )
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
      */