diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php')
-rw-r--r-- | tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 81f9e9ec..96474468 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | |||
@@ -49,12 +49,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
49 | $this->logInAs('admin'); | 49 | $this->logInAs('admin'); |
50 | } | 50 | } |
51 | 51 | ||
52 | $this->client->request('GET', $prefixUrl.'/'.$entry->getId().'.json'); | 52 | $this->client->request('GET', $prefixUrl . '/' . $entry->getId() . '.json'); |
53 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 53 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
54 | 54 | ||
55 | $content = json_decode($this->client->getResponse()->getContent(), true); | 55 | $content = json_decode($this->client->getResponse()->getContent(), true); |
56 | $this->assertGreaterThanOrEqual(1, $content['total']); | 56 | $this->assertGreaterThanOrEqual(1, $content['total']); |
57 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); | 57 | $this->assertSame($annotation->getText(), $content['rows'][0]['text']); |
58 | 58 | ||
59 | // we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager | 59 | // we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager |
60 | $annotation = $em->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationById($annotation->getId()); | 60 | $annotation = $em->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationById($annotation->getId()); |
@@ -84,18 +84,20 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
84 | $content = json_encode([ | 84 | $content = json_encode([ |
85 | 'text' => 'my annotation', | 85 | 'text' => 'my annotation', |
86 | 'quote' => 'my quote', | 86 | 'quote' => 'my quote', |
87 | 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | 87 | 'ranges' => [ |
88 | ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | ||
89 | ], | ||
88 | ]); | 90 | ]); |
89 | $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); | 91 | $this->client->request('POST', $prefixUrl . '/' . $entry->getId() . '.json', [], [], $headers, $content); |
90 | 92 | ||
91 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 93 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
92 | 94 | ||
93 | $content = json_decode($this->client->getResponse()->getContent(), true); | 95 | $content = json_decode($this->client->getResponse()->getContent(), true); |
94 | 96 | ||
95 | $this->assertEquals('Big boss', $content['user']); | 97 | $this->assertSame('Big boss', $content['user']); |
96 | $this->assertEquals('v1.0', $content['annotator_schema_version']); | 98 | $this->assertSame('v1.0', $content['annotator_schema_version']); |
97 | $this->assertEquals('my annotation', $content['text']); | 99 | $this->assertSame('my annotation', $content['text']); |
98 | $this->assertEquals('my quote', $content['quote']); | 100 | $this->assertSame('my quote', $content['quote']); |
99 | 101 | ||
100 | /** @var Annotation $annotation */ | 102 | /** @var Annotation $annotation */ |
101 | $annotation = $this->client->getContainer() | 103 | $annotation = $this->client->getContainer() |
@@ -103,7 +105,37 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
103 | ->getRepository('WallabagAnnotationBundle:Annotation') | 105 | ->getRepository('WallabagAnnotationBundle:Annotation') |
104 | ->findLastAnnotationByPageId($entry->getId(), 1); | 106 | ->findLastAnnotationByPageId($entry->getId(), 1); |
105 | 107 | ||
106 | $this->assertEquals('my annotation', $annotation->getText()); | 108 | $this->assertSame('my annotation', $annotation->getText()); |
109 | } | ||
110 | |||
111 | /** | ||
112 | * @dataProvider dataForEachAnnotations | ||
113 | */ | ||
114 | public function testSetAnnotationWithQuoteTooLong($prefixUrl) | ||
115 | { | ||
116 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
117 | |||
118 | if ('annotations' === $prefixUrl) { | ||
119 | $this->logInAs('admin'); | ||
120 | } | ||
121 | |||
122 | /** @var Entry $entry */ | ||
123 | $entry = $em | ||
124 | ->getRepository('WallabagCoreBundle:Entry') | ||
125 | ->findOneByUsernameAndNotArchived('admin'); | ||
126 | |||
127 | $longQuote = str_repeat('a', 10001); | ||
128 | $headers = ['CONTENT_TYPE' => 'application/json']; | ||
129 | $content = json_encode([ | ||
130 | 'text' => 'my annotation', | ||
131 | 'quote' => $longQuote, | ||
132 | 'ranges' => [ | ||
133 | ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | ||
134 | ], | ||
135 | ]); | ||
136 | $this->client->request('POST', $prefixUrl . '/' . $entry->getId() . '.json', [], [], $headers, $content); | ||
137 | |||
138 | $this->assertSame(400, $this->client->getResponse()->getStatusCode()); | ||
107 | } | 139 | } |
108 | 140 | ||
109 | /** | 141 | /** |
@@ -134,21 +166,21 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
134 | $content = json_encode([ | 166 | $content = json_encode([ |
135 | 'text' => 'a modified annotation', | 167 | 'text' => 'a modified annotation', |
136 | ]); | 168 | ]); |
137 | $this->client->request('PUT', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); | 169 | $this->client->request('PUT', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content); |
138 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 170 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
139 | 171 | ||
140 | $content = json_decode($this->client->getResponse()->getContent(), true); | 172 | $content = json_decode($this->client->getResponse()->getContent(), true); |
141 | 173 | ||
142 | $this->assertEquals('Big boss', $content['user']); | 174 | $this->assertSame('Big boss', $content['user']); |
143 | $this->assertEquals('v1.0', $content['annotator_schema_version']); | 175 | $this->assertSame('v1.0', $content['annotator_schema_version']); |
144 | $this->assertEquals('a modified annotation', $content['text']); | 176 | $this->assertSame('a modified annotation', $content['text']); |
145 | $this->assertEquals('my quote', $content['quote']); | 177 | $this->assertSame('my quote', $content['quote']); |
146 | 178 | ||
147 | /** @var Annotation $annotationUpdated */ | 179 | /** @var Annotation $annotationUpdated */ |
148 | $annotationUpdated = $em | 180 | $annotationUpdated = $em |
149 | ->getRepository('WallabagAnnotationBundle:Annotation') | 181 | ->getRepository('WallabagAnnotationBundle:Annotation') |
150 | ->findOneById($annotation->getId()); | 182 | ->findOneById($annotation->getId()); |
151 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); | 183 | $this->assertSame('a modified annotation', $annotationUpdated->getText()); |
152 | 184 | ||
153 | $em->remove($annotationUpdated); | 185 | $em->remove($annotationUpdated); |
154 | $em->flush(); | 186 | $em->flush(); |
@@ -186,12 +218,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
186 | $content = json_encode([ | 218 | $content = json_encode([ |
187 | 'text' => 'a modified annotation', | 219 | 'text' => 'a modified annotation', |
188 | ]); | 220 | ]); |
189 | $this->client->request('DELETE', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); | 221 | $this->client->request('DELETE', $prefixUrl . '/' . $annotation->getId() . '.json', [], [], $headers, $content); |
190 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 222 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
191 | 223 | ||
192 | $content = json_decode($this->client->getResponse()->getContent(), true); | 224 | $content = json_decode($this->client->getResponse()->getContent(), true); |
193 | 225 | ||
194 | $this->assertEquals('This is my annotation /o/', $content['text']); | 226 | $this->assertSame('This is my annotation /o/', $content['text']); |
195 | 227 | ||
196 | $annotationDeleted = $em | 228 | $annotationDeleted = $em |
197 | ->getRepository('WallabagAnnotationBundle:Annotation') | 229 | ->getRepository('WallabagAnnotationBundle:Annotation') |