aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-06-23 11:47:46 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-06-23 11:47:46 +0200
commitf49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4 (patch)
tree156b1a29cfbe1962e68d409c3dea5a3911a34e9c /tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
parent49e2854d5c15bbce3f24f91da34450e8f209295b (diff)
parentfb5c17a9ab5e10b1de9caa50e73638fdae19cb78 (diff)
downloadwallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.gz
wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.zst
wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.zip
Merge branch 'master' into 2.1
Diffstat (limited to 'tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php')
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php120
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
new file mode 100644
index 00000000..70849f74
--- /dev/null
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -0,0 +1,120 @@
1<?php
2
3namespace Tests\AnnotationBundle\Controller;
4
5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase;
6
7class 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 ->findOneByUsername('admin');
15
16 if (!$annotation) {
17 $this->markTestSkipped('No content found in db.');
18 }
19
20 $this->logInAs('admin');
21 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
22 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
23
24 $content = json_decode($this->client->getResponse()->getContent(), true);
25 $this->assertEquals(1, $content['total']);
26 $this->assertEquals($annotation->getText(), $content['rows'][0]['text']);
27 }
28
29 public function testSetAnnotation()
30 {
31 $this->logInAs('admin');
32
33 $entry = $this->client->getContainer()
34 ->get('doctrine.orm.entity_manager')
35 ->getRepository('WallabagCoreBundle:Entry')
36 ->findOneByUsernameAndNotArchived('admin');
37
38 $headers = ['CONTENT_TYPE' => 'application/json'];
39 $content = json_encode([
40 'text' => 'my annotation',
41 'quote' => 'my quote',
42 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31],
43 ]);
44 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content);
45
46 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
47
48 $content = json_decode($this->client->getResponse()->getContent(), true);
49
50 $this->assertEquals('Big boss', $content['user']);
51 $this->assertEquals('v1.0', $content['annotator_schema_version']);
52 $this->assertEquals('my annotation', $content['text']);
53 $this->assertEquals('my quote', $content['quote']);
54
55 $annotation = $this->client->getContainer()
56 ->get('doctrine.orm.entity_manager')
57 ->getRepository('WallabagAnnotationBundle:Annotation')
58 ->findLastAnnotationByPageId($entry->getId(), 1);
59
60 $this->assertEquals('my annotation', $annotation->getText());
61 }
62
63 public function testEditAnnotation()
64 {
65 $annotation = $this->client->getContainer()
66 ->get('doctrine.orm.entity_manager')
67 ->getRepository('WallabagAnnotationBundle:Annotation')
68 ->findOneByUsername('admin');
69
70 $this->logInAs('admin');
71
72 $headers = ['CONTENT_TYPE' => 'application/json'];
73 $content = json_encode([
74 'text' => 'a modified annotation',
75 ]);
76 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content);
77 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
78
79 $content = json_decode($this->client->getResponse()->getContent(), true);
80
81 $this->assertEquals('Big boss', $content['user']);
82 $this->assertEquals('v1.0', $content['annotator_schema_version']);
83 $this->assertEquals('a modified annotation', $content['text']);
84 $this->assertEquals('my quote', $content['quote']);
85
86 $annotationUpdated = $this->client->getContainer()
87 ->get('doctrine.orm.entity_manager')
88 ->getRepository('WallabagAnnotationBundle:Annotation')
89 ->findOneById($annotation->getId());
90 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
91 }
92
93 public function testDeleteAnnotation()
94 {
95 $annotation = $this->client->getContainer()
96 ->get('doctrine.orm.entity_manager')
97 ->getRepository('WallabagAnnotationBundle:Annotation')
98 ->findOneByUsername('admin');
99
100 $this->logInAs('admin');
101
102 $headers = ['CONTENT_TYPE' => 'application/json'];
103 $content = json_encode([
104 'text' => 'a modified annotation',
105 ]);
106 $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content);
107 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
108
109 $content = json_decode($this->client->getResponse()->getContent(), true);
110
111 $this->assertEquals('a modified annotation', $content['text']);
112
113 $annotationDeleted = $this->client->getContainer()
114 ->get('doctrine.orm.entity_manager')
115 ->getRepository('WallabagAnnotationBundle:Annotation')
116 ->findOneById($annotation->getId());
117
118 $this->assertNull($annotationDeleted);
119 }
120}