]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
Use --prefer-dist to improve CI perf
[github/wallabag/wallabag.git] / src / Wallabag / AnnotationBundle / Tests / Controller / AnnotationControllerTest.php
CommitLineData
f38e03dc
TC
1<?php
2
4dc87223 3namespace Wallabag\AnnotationBundle\Tests\Controller;
f38e03dc 4
4dc87223 5use Wallabag\AnnotationBundle\Tests\WallabagAnnotationTestCase;
f38e03dc 6
4dc87223 7class AnnotationControllerTest extends WallabagAnnotationTestCase
f38e03dc 8{
4dc87223 9 public function testGetAnnotations()
f38e03dc 10 {
4dc87223 11 $annotation = $this->client->getContainer()
f38e03dc 12 ->get('doctrine.orm.entity_manager')
4dc87223 13 ->getRepository('WallabagAnnotationBundle:Annotation')
f38e03dc
TC
14 ->findOneBy(array('user' => 1));
15
4dc87223 16 if (!$annotation) {
f38e03dc
TC
17 $this->markTestSkipped('No content found in db.');
18 }
19 $this->logInAs('admin');
4dc87223 20 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
f38e03dc
TC
21 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
22
23 $content = json_decode($this->client->getResponse()->getContent(), true);
24 $this->assertEquals(1, $content['total']);
4dc87223 25 $this->assertEquals($annotation->getText(), $content['rows'][0]['text']);
f38e03dc
TC
26 }
27
4dc87223 28 public function testSetAnnotation()
f38e03dc
TC
29 {
30 $this->logInAs('admin');
31
32 $entry = $this->client->getContainer()
33 ->get('doctrine.orm.entity_manager')
34 ->getRepository('WallabagCoreBundle:Entry')
35 ->findOneBy(array('user' => 1));
36
37 $headers = array('CONTENT_TYPE' => 'application/json');
38 $content = json_encode(array(
4dc87223 39 'text' => 'my annotation',
f38e03dc
TC
40 'quote' => 'my quote',
41 'range' => '[{"start":"","startOffset":24,"end":"","endOffset":31}]',
42 ));
43 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content);
44
45 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
46
4dc87223 47 $annotation = $this->client->getContainer()
f38e03dc 48 ->get('doctrine.orm.entity_manager')
4dc87223
NL
49 ->getRepository('WallabagAnnotationBundle:Annotation')
50 ->findLastAnnotationByPageId($entry->getId(), 1);
f38e03dc 51
4dc87223 52 $this->assertEquals('my annotation', $annotation->getText());
f38e03dc
TC
53 }
54
4dc87223 55 public function testEditAnnotation()
f38e03dc 56 {
4dc87223 57 $annotation = $this->client->getContainer()
f38e03dc 58 ->get('doctrine.orm.entity_manager')
4dc87223 59 ->getRepository('WallabagAnnotationBundle:Annotation')
f38e03dc
TC
60 ->findOneBy(array('user' => 1));
61
62 $this->logInAs('admin');
63
64 $headers = array('CONTENT_TYPE' => 'application/json');
65 $content = json_encode(array(
4dc87223 66 'text' => 'a modified annotation',
f38e03dc 67 ));
4dc87223 68 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content);
f38e03dc
TC
69 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
70
71 $content = json_decode($this->client->getResponse()->getContent(), true);
72
4dc87223 73 $this->assertEquals('a modified annotation', $content['text']);
f38e03dc 74
4dc87223 75 $annotationUpdated = $this->client->getContainer()
f38e03dc 76 ->get('doctrine.orm.entity_manager')
4dc87223
NL
77 ->getRepository('WallabagAnnotationBundle:Annotation')
78 ->findAnnotationById($annotation->getId());
79 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
f38e03dc
TC
80 }
81}