]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
Merge pull request #1915 from wallabag/doc-links
[github/wallabag/wallabag.git] / src / Wallabag / AnnotationBundle / Tests / Controller / AnnotationControllerTest.php
CommitLineData
f38e03dc
TC
1<?php
2
4dc87223 3namespace Wallabag\AnnotationBundle\Tests\Controller;
f38e03dc 4
4dc87223 5use Wallabag\AnnotationBundle\Tests\WallabagAnnotationTestCase;
f38e03dc 6
4dc87223 7class AnnotationControllerTest extends WallabagAnnotationTestCase
f38e03dc 8{
4dc87223 9 public function testGetAnnotations()
f38e03dc 10 {
4dc87223 11 $annotation = $this->client->getContainer()
f38e03dc 12 ->get('doctrine.orm.entity_manager')
4dc87223 13 ->getRepository('WallabagAnnotationBundle:Annotation')
09d8bb6f 14 ->findOneByUsername('admin');
f38e03dc 15
4dc87223 16 if (!$annotation) {
f38e03dc
TC
17 $this->markTestSkipped('No content found in db.');
18 }
09d8bb6f 19
f38e03dc 20 $this->logInAs('admin');
4dc87223 21 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
f38e03dc
TC
22 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
23
24 $content = json_decode($this->client->getResponse()->getContent(), true);
25 $this->assertEquals(1, $content['total']);
4dc87223 26 $this->assertEquals($annotation->getText(), $content['rows'][0]['text']);
f38e03dc
TC
27 }
28
4dc87223 29 public function testSetAnnotation()
f38e03dc
TC
30 {
31 $this->logInAs('admin');
32
33 $entry = $this->client->getContainer()
34 ->get('doctrine.orm.entity_manager')
35 ->getRepository('WallabagCoreBundle:Entry')
09d8bb6f 36 ->findOneByUsernameAndNotArchived('admin');
f38e03dc
TC
37
38 $headers = array('CONTENT_TYPE' => 'application/json');
39 $content = json_encode(array(
4dc87223 40 'text' => 'my annotation',
f38e03dc 41 'quote' => 'my quote',
09d8bb6f
JB
42 'ranges' => array('start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31),
43 ));
f38e03dc
TC
44 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content);
45
46 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
47
09d8bb6f
JB
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
4dc87223 55 $annotation = $this->client->getContainer()
f38e03dc 56 ->get('doctrine.orm.entity_manager')
4dc87223
NL
57 ->getRepository('WallabagAnnotationBundle:Annotation')
58 ->findLastAnnotationByPageId($entry->getId(), 1);
f38e03dc 59
4dc87223 60 $this->assertEquals('my annotation', $annotation->getText());
f38e03dc
TC
61 }
62
4dc87223 63 public function testEditAnnotation()
f38e03dc 64 {
4dc87223 65 $annotation = $this->client->getContainer()
f38e03dc 66 ->get('doctrine.orm.entity_manager')
4dc87223 67 ->getRepository('WallabagAnnotationBundle:Annotation')
09d8bb6f 68 ->findOneByUsername('admin');
f38e03dc
TC
69
70 $this->logInAs('admin');
71
72 $headers = array('CONTENT_TYPE' => 'application/json');
73 $content = json_encode(array(
4dc87223 74 'text' => 'a modified annotation',
09d8bb6f 75 ));
4dc87223 76 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content);
f38e03dc
TC
77 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
78
79 $content = json_decode($this->client->getResponse()->getContent(), true);
80
09d8bb6f
JB
81 $this->assertEquals('Big boss', $content['user']);
82 $this->assertEquals('v1.0', $content['annotator_schema_version']);
4dc87223 83 $this->assertEquals('a modified annotation', $content['text']);
b95ffda2 84 $this->assertEquals('my quote', $content['quote']);
f38e03dc 85
4dc87223 86 $annotationUpdated = $this->client->getContainer()
f38e03dc 87 ->get('doctrine.orm.entity_manager')
4dc87223 88 ->getRepository('WallabagAnnotationBundle:Annotation')
09d8bb6f 89 ->findOneById($annotation->getId());
4dc87223 90 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
f38e03dc 91 }
09d8bb6f
JB
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 = array('CONTENT_TYPE' => 'application/json');
103 $content = json_encode(array(
104 'text' => 'a modified annotation',
105 ));
106 $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', array(), array(), $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 }
f38e03dc 120}