aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/AnnotationBundle/Tests/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-11 17:56:41 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-11 17:59:42 +0100
commit09d8bb6fa26b881da478df4c7b97620cb7aea0d0 (patch)
tree2a81d844c253c5961943ba936445b154d4d32510 /src/Wallabag/AnnotationBundle/Tests/Controller
parent66e2be23717ad8af3cabe5d0c69effd492af3ece (diff)
downloadwallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.tar.gz
wallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.tar.zst
wallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.zip
Improve tests
- add more tests for coverage - add a test on annotation deletion - fix post annontation with ranges
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Tests/Controller')
-rw-r--r--src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
index c0efe272..7a877f98 100644
--- a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
+++ b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
@@ -11,11 +11,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
11 $annotation = $this->client->getContainer() 11 $annotation = $this->client->getContainer()
12 ->get('doctrine.orm.entity_manager') 12 ->get('doctrine.orm.entity_manager')
13 ->getRepository('WallabagAnnotationBundle:Annotation') 13 ->getRepository('WallabagAnnotationBundle:Annotation')
14 ->findOneBy(array('user' => 1)); 14 ->findOneByUsername('admin');
15 15
16 if (!$annotation) { 16 if (!$annotation) {
17 $this->markTestSkipped('No content found in db.'); 17 $this->markTestSkipped('No content found in db.');
18 } 18 }
19
19 $this->logInAs('admin'); 20 $this->logInAs('admin');
20 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); 21 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
21 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 22 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -32,18 +33,25 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
32 $entry = $this->client->getContainer() 33 $entry = $this->client->getContainer()
33 ->get('doctrine.orm.entity_manager') 34 ->get('doctrine.orm.entity_manager')
34 ->getRepository('WallabagCoreBundle:Entry') 35 ->getRepository('WallabagCoreBundle:Entry')
35 ->findOneBy(array('user' => 1)); 36 ->findOneByUsernameAndNotArchived('admin');
36 37
37 $headers = array('CONTENT_TYPE' => 'application/json'); 38 $headers = array('CONTENT_TYPE' => 'application/json');
38 $content = json_encode(array( 39 $content = json_encode(array(
39 'text' => 'my annotation', 40 'text' => 'my annotation',
40 'quote' => 'my quote', 41 'quote' => 'my quote',
41 'range' => '[{"start":"","startOffset":24,"end":"","endOffset":31}]', 42 'ranges' => array('start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31),
42 )); 43 ));
43 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content); 44 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content);
44 45
45 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 46 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
46 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
47 $annotation = $this->client->getContainer() 55 $annotation = $this->client->getContainer()
48 ->get('doctrine.orm.entity_manager') 56 ->get('doctrine.orm.entity_manager')
49 ->getRepository('WallabagAnnotationBundle:Annotation') 57 ->getRepository('WallabagAnnotationBundle:Annotation')
@@ -57,25 +65,56 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
57 $annotation = $this->client->getContainer() 65 $annotation = $this->client->getContainer()
58 ->get('doctrine.orm.entity_manager') 66 ->get('doctrine.orm.entity_manager')
59 ->getRepository('WallabagAnnotationBundle:Annotation') 67 ->getRepository('WallabagAnnotationBundle:Annotation')
60 ->findOneBy(array('user' => 1)); 68 ->findOneByUsername('admin');
61 69
62 $this->logInAs('admin'); 70 $this->logInAs('admin');
63 71
64 $headers = array('CONTENT_TYPE' => 'application/json'); 72 $headers = array('CONTENT_TYPE' => 'application/json');
65 $content = json_encode(array( 73 $content = json_encode(array(
66 'text' => 'a modified annotation', 74 'text' => 'a modified annotation',
67 )); 75 ));
68 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content); 76 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content);
69 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 77 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
70 78
71 $content = json_decode($this->client->getResponse()->getContent(), true); 79 $content = json_decode($this->client->getResponse()->getContent(), true);
72 80
81 $this->assertEquals('Big boss', $content['user']);
82 $this->assertEquals('v1.0', $content['annotator_schema_version']);
73 $this->assertEquals('a modified annotation', $content['text']); 83 $this->assertEquals('a modified annotation', $content['text']);
84 $this->assertEquals('content', $content['quote']);
74 85
75 $annotationUpdated = $this->client->getContainer() 86 $annotationUpdated = $this->client->getContainer()
76 ->get('doctrine.orm.entity_manager') 87 ->get('doctrine.orm.entity_manager')
77 ->getRepository('WallabagAnnotationBundle:Annotation') 88 ->getRepository('WallabagAnnotationBundle:Annotation')
78 ->findAnnotationById($annotation->getId()); 89 ->findOneById($annotation->getId());
79 $this->assertEquals('a modified annotation', $annotationUpdated->getText()); 90 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
80 } 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 = 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 }
81} 120}