aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/AnnotationBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/AnnotationBundle')
-rw-r--r--src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php120
-rw-r--r--src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php63
2 files changed, 0 insertions, 183 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
3namespace Wallabag\AnnotationBundle\Tests\Controller;
4
5use Wallabag\AnnotationBundle\Tests\WallabagAnnotationTestCase;
6
7class 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}
diff --git a/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php b/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php
deleted file mode 100644
index a9035acc..00000000
--- a/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php
+++ /dev/null
@@ -1,63 +0,0 @@
1<?php
2
3namespace Wallabag\AnnotationBundle\Tests;
4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie;
7
8abstract class WallabagAnnotationTestCase extends WebTestCase
9{
10 /**
11 * @var Client
12 */
13 protected $client = null;
14
15 /**
16 * @var \FOS\UserBundle\Model\UserInterface
17 */
18 protected $user;
19
20 public function setUp()
21 {
22 $this->client = $this->createAuthorizedClient();
23 }
24
25 public function logInAs($username)
26 {
27 $crawler = $this->client->request('GET', '/login');
28 $form = $crawler->filter('button[type=submit]')->form();
29 $data = [
30 '_username' => $username,
31 '_password' => 'mypassword',
32 ];
33
34 $this->client->submit($form, $data);
35 }
36
37 /**
38 * @return Client
39 */
40 protected function createAuthorizedClient()
41 {
42 $client = static::createClient();
43 $container = $client->getContainer();
44
45 /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */
46 $userManager = $container->get('fos_user.user_manager');
47 /** @var $loginManager \FOS\UserBundle\Security\LoginManager */
48 $loginManager = $container->get('fos_user.security.login_manager');
49 $firewallName = $container->getParameter('fos_user.firewall_name');
50
51 $this->user = $userManager->findUserBy(['username' => 'admin']);
52 $loginManager->loginUser($firewallName, $this->user);
53
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()));
56 $container->get('session')->save();
57
58 $session = $container->get('session');
59 $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));
60
61 return $client;
62 }
63}