aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-12-04 16:09:49 -0800
committerGitHub <noreply@github.com>2019-12-04 16:09:49 -0800
commitd816ef0530358c5b6fb757b5cfb4ca142b26ce90 (patch)
tree3421186de099cf0e6f5338486187541d0a5f96e9
parent43141054d1534c82ac181cdbe693fd13b787b281 (diff)
parent6a0d49ab7a8ac9e00f9df34b37b6d3e1ab40f2a9 (diff)
downloadwallabag-d816ef0530358c5b6fb757b5cfb4ca142b26ce90.tar.gz
wallabag-d816ef0530358c5b6fb757b5cfb4ca142b26ce90.tar.zst
wallabag-d816ef0530358c5b6fb757b5cfb4ca142b26ce90.zip
Merge pull request #4161 from aaa2000/bug-empty-quote
API return an error with empty quote
-rw-r--r--src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php3
-rw-r--r--src/Wallabag/ApiBundle/Controller/AnnotationRestController.php4
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php57
3 files changed, 61 insertions, 3 deletions
diff --git a/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
index c73c3ded..48bc2c59 100644
--- a/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
+++ b/src/Wallabag/AnnotationBundle/Form/NewAnnotationType.php
@@ -17,7 +17,8 @@ class NewAnnotationType extends AbstractType
17 'empty_data' => '', 17 'empty_data' => '',
18 ]) 18 ])
19 ->add('quote', null, [ 19 ->add('quote', null, [
20 'empty_data' => null, 20 'empty_data' => '',
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..66693189 100644
--- a/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php
@@ -37,8 +37,8 @@ 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", "description"="The annotated text"},
41 * {"name"="text", "dataType"="string", "required"=true, "description"=""}, 41 * {"name"="text", "dataType"="string", "required"=true, "description"="Content of annotation"},
42 * } 42 * }
43 * ) 43 * )
44 * 44 *
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 2c46e0a1..260edd77 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -107,6 +107,63 @@ 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 testAllowEmptyQuote()
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(200, $this->client->getResponse()->getStatusCode());
130
131 $content = json_decode($this->client->getResponse()->getContent(), true);
132
133 $this->assertSame('Big boss', $content['user']);
134 $this->assertSame('v1.0', $content['annotator_schema_version']);
135 $this->assertSame('my annotation', $content['text']);
136 $this->assertSame('', $content['quote']);
137 }
138
139 public function testAllowOmmittedQuote()
140 {
141 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
142
143 /** @var Entry $entry */
144 $entry = $em
145 ->getRepository('WallabagCoreBundle:Entry')
146 ->findOneByUsernameAndNotArchived('admin');
147
148 $headers = ['CONTENT_TYPE' => 'application/json'];
149 $content = json_encode([
150 'text' => 'my new annotation',
151 'ranges' => [
152 ['start' => '', 'startOffset' => 25, 'end' => '', 'endOffset' => 32],
153 ],
154 ]);
155 $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content);
156
157 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
158
159 $content = json_decode($this->client->getResponse()->getContent(), true);
160
161 $this->assertSame('Big boss', $content['user']);
162 $this->assertSame('v1.0', $content['annotator_schema_version']);
163 $this->assertSame('my new annotation', $content['text']);
164 $this->assertSame('', $content['quote']);
165 }
166
110 /** 167 /**
111 * @dataProvider dataForEachAnnotations 168 * @dataProvider dataForEachAnnotations
112 */ 169 */