aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/AnnotationBundle/Controller
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-06-23 09:18:18 +0200
committerGitHub <noreply@github.com>2016-06-23 09:18:18 +0200
commitd37bb05c881bfdbeb1144b327edd4dcc2cbb163f (patch)
tree1b90f7e733a83af4741a8cb7f49edf3e303f8677 /tests/Wallabag/AnnotationBundle/Controller
parent891a026e31ad54ca90b70f6026f23260cfadb7fd (diff)
parent99451fe4b76051d61922a6beb7ee9e79cc6e7893 (diff)
downloadwallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.gz
wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.zst
wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.zip
Merge pull request #2132 from wallabag/sf3.1
Jump to Symfony 3.1
Diffstat (limited to 'tests/Wallabag/AnnotationBundle/Controller')
-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}