aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/AnnotationBundle/Controller
diff options
context:
space:
mode:
authorlizyn <zhiylin@outlook.com>2020-02-24 10:04:13 +0800
committerGitHub <noreply@github.com>2020-02-24 10:04:13 +0800
commitb19df31d78d881a43bcf6b3215e5fc3781e8e8aa (patch)
treed0d9861694a4b5e5fbfdbeb53c255ecd15fe9328 /tests/Wallabag/AnnotationBundle/Controller
parent4d0c632c70ea50d459c3c55ddda2e0f394dd51cb (diff)
parent04d918cae0227c06a41d27fb6533dddbf30dfe71 (diff)
downloadwallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.tar.gz
wallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.tar.zst
wallabag-b19df31d78d881a43bcf6b3215e5fc3781e8e8aa.zip
Merge pull request #1 from wallabag/master
Keep up with the master again
Diffstat (limited to 'tests/Wallabag/AnnotationBundle/Controller')
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php62
1 files changed, 59 insertions, 3 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 96474468..260edd77 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\AnnotationBundle\Controller; 3namespace Tests\Wallabag\AnnotationBundle\Controller;
4 4
5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; 5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation; 6use Wallabag\AnnotationBundle\Entity\Annotation;
@@ -100,14 +100,70 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
100 $this->assertSame('my quote', $content['quote']); 100 $this->assertSame('my quote', $content['quote']);
101 101
102 /** @var Annotation $annotation */ 102 /** @var Annotation $annotation */
103 $annotation = $this->client->getContainer() 103 $annotation = $em
104 ->get('doctrine.orm.entity_manager')
105 ->getRepository('WallabagAnnotationBundle:Annotation') 104 ->getRepository('WallabagAnnotationBundle:Annotation')
106 ->findLastAnnotationByPageId($entry->getId(), 1); 105 ->findLastAnnotationByPageId($entry->getId(), 1);
107 106
108 $this->assertSame('my annotation', $annotation->getText()); 107 $this->assertSame('my annotation', $annotation->getText());
109 } 108 }
110 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
111 /** 167 /**
112 * @dataProvider dataForEachAnnotations 168 * @dataProvider dataForEachAnnotations
113 */ 169 */