diff options
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Tests/Controller')
-rw-r--r-- | src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php deleted file mode 100644 index 3eba7193..00000000 --- a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
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 | ->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 | } | ||