aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/AnnotationBundle/Entity/Annotation.php1
-rw-r--r--src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php1
-rw-r--r--src/Wallabag/ApiBundle/Controller/AnnotationRestController.php2
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php30
4 files changed, 33 insertions, 1 deletions
diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
index a180d504..ee7c1931 100644
--- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php
+++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
@@ -60,6 +60,7 @@ class Annotation
60 /** 60 /**
61 * @var string 61 * @var string
62 * 62 *
63 * @Assert\NotNull()
63 * @Assert\Length( 64 * @Assert\Length(
64 * max = 10000, 65 * max = 10000,
65 * maxMessage = "validator.quote_length_too_high" 66 * maxMessage = "validator.quote_length_too_high"
diff --git a/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
index c73c3ded..aac6445c 100644
--- a/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
+++ b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
@@ -18,6 +18,7 @@ class NewAnnotationType extends AbstractType
18 ]) 18 ])
19 ->add('quote', null, [ 19 ->add('quote', null, [
20 'empty_data' => null, 20 'empty_data' => null,
21 'trim' => false,
21 ]) 22 ])
22 ->add('ranges', CollectionType::class, [ 23 ->add('ranges', CollectionType::class, [
23 'entry_type' => RangeType::class, 24 'entry_type' => RangeType::class,
diff --git a/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php b/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
index f59431e4..e5b3eb27 100644
--- a/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
@@ -37,7 +37,7 @@ class AnnotationRestController extends WallabagRestController
37 * @ApiDoc( 37 * @ApiDoc(
38 * requirements={ 38 * requirements={
39 * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"}, 39 * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
40 * {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"}, 40 * {"name"="quote", "dataType"="string", "required"=true, "description"="Quote for the annotation"},
41 * {"name"="text", "dataType"="string", "required"=true, "description"=""}, 41 * {"name"="text", "dataType"="string", "required"=true, "description"=""},
42 * } 42 * }
43 * ) 43 * )
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 2c46e0a1..74e9ba8f 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -107,6 +107,36 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
107 $this->assertSame('my annotation', $annotation->getText()); 107 $this->assertSame('my annotation', $annotation->getText());
108 } 108 }
109 109
110 public function testCouldNotSetAnnotationWithoutQuote()
111 {
112 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
113
114 /** @var Entry $entry */
115 $entry = $em
116 ->getRepository('WallabagCoreBundle:Entry')
117 ->findOneByUsernameAndNotArchived('admin');
118
119 $headers = ['CONTENT_TYPE' => 'application/json'];
120 $content = json_encode([
121 'text' => 'my annotation',
122 'quote' => null,
123 'ranges' => [
124 ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31],
125 ],
126 ]);
127 $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content);
128
129 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
130
131 $content = json_decode($this->client->getResponse()->getContent(), true);
132
133 $this->assertCount(
134 1,
135 $content['errors']['children']['quote']['errors'],
136 'The quote field should contains an error'
137 );
138 }
139
110 /** 140 /**
111 * @dataProvider dataForEachAnnotations 141 * @dataProvider dataForEachAnnotations
112 */ 142 */