diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-01 21:27:35 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-22 17:59:35 +0200 |
commit | 23634d5d842dabcf5d7475e2becb7e127824239e (patch) | |
tree | b91688722a996c46f27e8fe0542c356424483da3 /tests/Wallabag/AnnotationBundle/Controller | |
parent | 891a026e31ad54ca90b70f6026f23260cfadb7fd (diff) | |
download | wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.tar.gz wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.tar.zst wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.zip |
Jump to Symfony 3.1
Diffstat (limited to 'tests/Wallabag/AnnotationBundle/Controller')
-rw-r--r-- | tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 120 |
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 | |||
3 | namespace Tests\AnnotationBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\AnnotationBundle\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 | ->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 | } | ||