aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/AnnotationBundle
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-03-12 11:10:21 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-03-12 11:10:21 +0100
commit6ab56c7b2c225b74b000e9ecedfe28aa0f8d1e18 (patch)
treecfb8e6887628780ba7a571565f561f00019a0e0b /src/Wallabag/AnnotationBundle
parent55e61971f393d679a47e18f48cd2e04403ce4368 (diff)
parentb95ffda2a105af4c6f4f86aca025a0bf967bc86a (diff)
downloadwallabag-6ab56c7b2c225b74b000e9ecedfe28aa0f8d1e18.tar.gz
wallabag-6ab56c7b2c225b74b000e9ecedfe28aa0f8d1e18.tar.zst
wallabag-6ab56c7b2c225b74b000e9ecedfe28aa0f8d1e18.zip
Merge pull request #1775 from wallabag/v2-few-fixes
Some fixes
Diffstat (limited to 'src/Wallabag/AnnotationBundle')
-rw-r--r--src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php18
-rw-r--r--src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php53
2 files changed, 64 insertions, 7 deletions
diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
index c1c6e638..5f7da70e 100644
--- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
+++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
@@ -88,4 +88,22 @@ class AnnotationRepository extends EntityRepository
88 ->getQuery() 88 ->getQuery()
89 ->getOneOrNullResult(); 89 ->getOneOrNullResult();
90 } 90 }
91
92 /**
93 * Used only in test case to get the right annotation associated to the right user.
94 *
95 * @param string $username
96 *
97 * @return Annotation
98 */
99 public function findOneByUsername($username)
100 {
101 return $this->createQueryBuilder('a')
102 ->leftJoin('a.user', 'u')
103 ->where('u.username = :username')->setParameter('username', $username)
104 ->orderBy('a.id', 'DESC')
105 ->setMaxResults(1)
106 ->getQuery()
107 ->getSingleResult();
108 }
91} 109}
diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
index c0efe272..e972c2de 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('my quote', $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}