diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-02-26 18:17:37 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-02-26 18:17:37 +0100 |
commit | 162954763e6f68e0cf4002822007683bde62fc25 (patch) | |
tree | a85f850eddb30b3435d1bb5f45d16d9ab465bbf9 /src/Wallabag/AnnotationBundle/Tests/Controller | |
parent | d3f1a9dc1ac181033ec54f9149d2807199fa8f17 (diff) | |
parent | b07c7dfe787313b75e0996265e13cccc78da41be (diff) | |
download | wallabag-162954763e6f68e0cf4002822007683bde62fc25.tar.gz wallabag-162954763e6f68e0cf4002822007683bde62fc25.tar.zst wallabag-162954763e6f68e0cf4002822007683bde62fc25.zip |
Merge pull request #1653 from wallabag/v2-annotator-comments
V2 annotator comments
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Tests/Controller')
-rw-r--r-- | src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php new file mode 100644 index 00000000..c0efe272 --- /dev/null +++ b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php | |||
@@ -0,0 +1,81 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\AnnotationBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\AnnotationBundle\Tests\WallabagAnnotationTestCase; | ||
6 | |||
7 | class AnnotationControllerTest extends WallabagAnnotationTestCase | ||
8 | { | ||
9 | public function testGetAnnotations() | ||
10 | { | ||
11 | $annotation = $this->client->getContainer() | ||
12 | ->get('doctrine.orm.entity_manager') | ||
13 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
14 | ->findOneBy(array('user' => 1)); | ||
15 | |||
16 | if (!$annotation) { | ||
17 | $this->markTestSkipped('No content found in db.'); | ||
18 | } | ||
19 | $this->logInAs('admin'); | ||
20 | $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); | ||
21 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
22 | |||
23 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
24 | $this->assertEquals(1, $content['total']); | ||
25 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); | ||
26 | } | ||
27 | |||
28 | public function testSetAnnotation() | ||
29 | { | ||
30 | $this->logInAs('admin'); | ||
31 | |||
32 | $entry = $this->client->getContainer() | ||
33 | ->get('doctrine.orm.entity_manager') | ||
34 | ->getRepository('WallabagCoreBundle:Entry') | ||
35 | ->findOneBy(array('user' => 1)); | ||
36 | |||
37 | $headers = array('CONTENT_TYPE' => 'application/json'); | ||
38 | $content = json_encode(array( | ||
39 | 'text' => 'my annotation', | ||
40 | 'quote' => 'my quote', | ||
41 | 'range' => '[{"start":"","startOffset":24,"end":"","endOffset":31}]', | ||
42 | )); | ||
43 | $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content); | ||
44 | |||
45 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
46 | |||
47 | $annotation = $this->client->getContainer() | ||
48 | ->get('doctrine.orm.entity_manager') | ||
49 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
50 | ->findLastAnnotationByPageId($entry->getId(), 1); | ||
51 | |||
52 | $this->assertEquals('my annotation', $annotation->getText()); | ||
53 | } | ||
54 | |||
55 | public function testEditAnnotation() | ||
56 | { | ||
57 | $annotation = $this->client->getContainer() | ||
58 | ->get('doctrine.orm.entity_manager') | ||
59 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
60 | ->findOneBy(array('user' => 1)); | ||
61 | |||
62 | $this->logInAs('admin'); | ||
63 | |||
64 | $headers = array('CONTENT_TYPE' => 'application/json'); | ||
65 | $content = json_encode(array( | ||
66 | 'text' => 'a modified annotation', | ||
67 | )); | ||
68 | $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content); | ||
69 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
70 | |||
71 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
72 | |||
73 | $this->assertEquals('a modified annotation', $content['text']); | ||
74 | |||
75 | $annotationUpdated = $this->client->getContainer() | ||
76 | ->get('doctrine.orm.entity_manager') | ||
77 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
78 | ->findAnnotationById($annotation->getId()); | ||
79 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); | ||
80 | } | ||
81 | } | ||