diff options
Diffstat (limited to 'tests/Wallabag/AnnotationBundle')
-rw-r--r-- | tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | 28 | ||||
-rw-r--r-- | tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | 6 |
2 files changed, 27 insertions, 7 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 70849f74..9b2a6f8d 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | |||
@@ -3,11 +3,17 @@ | |||
3 | namespace Tests\AnnotationBundle\Controller; | 3 | namespace Tests\AnnotationBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; | 5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | 8 | ||
7 | class AnnotationControllerTest extends WallabagAnnotationTestCase | 9 | class AnnotationControllerTest extends WallabagAnnotationTestCase |
8 | { | 10 | { |
11 | /** | ||
12 | * Test fetching annotations for an entry | ||
13 | */ | ||
9 | public function testGetAnnotations() | 14 | public function testGetAnnotations() |
10 | { | 15 | { |
16 | /** @var Annotation $annotation */ | ||
11 | $annotation = $this->client->getContainer() | 17 | $annotation = $this->client->getContainer() |
12 | ->get('doctrine.orm.entity_manager') | 18 | ->get('doctrine.orm.entity_manager') |
13 | ->getRepository('WallabagAnnotationBundle:Annotation') | 19 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -18,7 +24,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
18 | } | 24 | } |
19 | 25 | ||
20 | $this->logInAs('admin'); | 26 | $this->logInAs('admin'); |
21 | $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); | 27 | $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); |
22 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 28 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
23 | 29 | ||
24 | $content = json_decode($this->client->getResponse()->getContent(), true); | 30 | $content = json_decode($this->client->getResponse()->getContent(), true); |
@@ -26,10 +32,14 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
26 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); | 32 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); |
27 | } | 33 | } |
28 | 34 | ||
35 | /** | ||
36 | * Test creating an annotation for an entry | ||
37 | */ | ||
29 | public function testSetAnnotation() | 38 | public function testSetAnnotation() |
30 | { | 39 | { |
31 | $this->logInAs('admin'); | 40 | $this->logInAs('admin'); |
32 | 41 | ||
42 | /** @var Entry $entry */ | ||
33 | $entry = $this->client->getContainer() | 43 | $entry = $this->client->getContainer() |
34 | ->get('doctrine.orm.entity_manager') | 44 | ->get('doctrine.orm.entity_manager') |
35 | ->getRepository('WallabagCoreBundle:Entry') | 45 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -41,7 +51,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
41 | 'quote' => 'my quote', | 51 | 'quote' => 'my quote', |
42 | 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | 52 | 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], |
43 | ]); | 53 | ]); |
44 | $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content); | 54 | $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content); |
45 | 55 | ||
46 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 56 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
47 | 57 | ||
@@ -52,6 +62,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
52 | $this->assertEquals('my annotation', $content['text']); | 62 | $this->assertEquals('my annotation', $content['text']); |
53 | $this->assertEquals('my quote', $content['quote']); | 63 | $this->assertEquals('my quote', $content['quote']); |
54 | 64 | ||
65 | /** @var Annotation $annotation */ | ||
55 | $annotation = $this->client->getContainer() | 66 | $annotation = $this->client->getContainer() |
56 | ->get('doctrine.orm.entity_manager') | 67 | ->get('doctrine.orm.entity_manager') |
57 | ->getRepository('WallabagAnnotationBundle:Annotation') | 68 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -60,8 +71,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
60 | $this->assertEquals('my annotation', $annotation->getText()); | 71 | $this->assertEquals('my annotation', $annotation->getText()); |
61 | } | 72 | } |
62 | 73 | ||
74 | /** | ||
75 | * Test editing an existing annotation | ||
76 | */ | ||
63 | public function testEditAnnotation() | 77 | public function testEditAnnotation() |
64 | { | 78 | { |
79 | /** @var Annotation $annotation */ | ||
65 | $annotation = $this->client->getContainer() | 80 | $annotation = $this->client->getContainer() |
66 | ->get('doctrine.orm.entity_manager') | 81 | ->get('doctrine.orm.entity_manager') |
67 | ->getRepository('WallabagAnnotationBundle:Annotation') | 82 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -73,7 +88,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
73 | $content = json_encode([ | 88 | $content = json_encode([ |
74 | 'text' => 'a modified annotation', | 89 | 'text' => 'a modified annotation', |
75 | ]); | 90 | ]); |
76 | $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); | 91 | $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); |
77 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 92 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
78 | 93 | ||
79 | $content = json_decode($this->client->getResponse()->getContent(), true); | 94 | $content = json_decode($this->client->getResponse()->getContent(), true); |
@@ -83,6 +98,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
83 | $this->assertEquals('a modified annotation', $content['text']); | 98 | $this->assertEquals('a modified annotation', $content['text']); |
84 | $this->assertEquals('my quote', $content['quote']); | 99 | $this->assertEquals('my quote', $content['quote']); |
85 | 100 | ||
101 | /** @var Annotation $annotationUpdated */ | ||
86 | $annotationUpdated = $this->client->getContainer() | 102 | $annotationUpdated = $this->client->getContainer() |
87 | ->get('doctrine.orm.entity_manager') | 103 | ->get('doctrine.orm.entity_manager') |
88 | ->getRepository('WallabagAnnotationBundle:Annotation') | 104 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -90,8 +106,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
90 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); | 106 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); |
91 | } | 107 | } |
92 | 108 | ||
109 | /** | ||
110 | * Test deleting an annotation | ||
111 | */ | ||
93 | public function testDeleteAnnotation() | 112 | public function testDeleteAnnotation() |
94 | { | 113 | { |
114 | /** @var Annotation $annotation */ | ||
95 | $annotation = $this->client->getContainer() | 115 | $annotation = $this->client->getContainer() |
96 | ->get('doctrine.orm.entity_manager') | 116 | ->get('doctrine.orm.entity_manager') |
97 | ->getRepository('WallabagAnnotationBundle:Annotation') | 117 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -103,7 +123,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
103 | $content = json_encode([ | 123 | $content = json_encode([ |
104 | 'text' => 'a modified annotation', | 124 | 'text' => 'a modified annotation', |
105 | ]); | 125 | ]); |
106 | $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); | 126 | $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); |
107 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 127 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
108 | 128 | ||
109 | $content = json_decode($this->client->getResponse()->getContent(), true); | 129 | $content = json_decode($this->client->getResponse()->getContent(), true); |
diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 82790a5c..ef3f1324 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | |||
@@ -8,7 +8,7 @@ use Symfony\Component\BrowserKit\Cookie; | |||
8 | abstract class WallabagAnnotationTestCase extends WebTestCase | 8 | abstract class WallabagAnnotationTestCase extends WebTestCase |
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * @var Client | 11 | * @var \Symfony\Bundle\FrameworkBundle\Client |
12 | */ | 12 | */ |
13 | protected $client = null; | 13 | protected $client = null; |
14 | 14 | ||
@@ -35,7 +35,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * @return Client | 38 | * @return \Symfony\Bundle\FrameworkBundle\Client |
39 | */ | 39 | */ |
40 | protected function createAuthorizedClient() | 40 | protected function createAuthorizedClient() |
41 | { | 41 | { |
@@ -49,7 +49,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
49 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 49 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
50 | 50 | ||
51 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 51 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
52 | $loginManager->loginUser($firewallName, $this->user); | 52 | $loginManager->logInUser($firewallName, $this->user); |
53 | 53 | ||
54 | // save the login token into the session and put it in a cookie | 54 | // save the login token into the session and put it in a cookie |
55 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); | 55 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); |