3 namespace Wallabag\CommentBundle\Tests\Controller
;
5 use Wallabag\CommentBundle\Tests\WallabagCommentTestCase
;
7 class CommentControllerTest
extends WallabagCommentTestCase
9 public function testGetComments()
11 $comment = $this->client
->getContainer()
12 ->get('doctrine.orm.entity_manager')
13 ->getRepository('WallabagCommentBundle:Comment')
14 ->findOneBy(array('user' => 1));
17 $this->markTestSkipped('No content found in db.');
19 $this->logInAs('admin');
20 $crawler = $this->client
->request('GET', 'annotations/'.$comment->getEntry()->getId().'.json');
21 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
23 $content = json_decode($this->client
->getResponse()->getContent(), true);
24 $this->assertEquals(1, $content['total']);
25 $this->assertEquals($comment->getText(), $content['rows'][0]['text']);
28 public function testSetcomment()
30 $this->logInAs('admin');
32 $entry = $this->client
->getContainer()
33 ->get('doctrine.orm.entity_manager')
34 ->getRepository('WallabagCoreBundle:Entry')
35 ->findOneBy(array('user' => 1));
37 $headers = array('CONTENT_TYPE' => 'application/json');
38 $content = json_encode(array(
39 'text' => 'my comment',
40 'quote' => 'my quote',
41 'range' => '[{"start":"","startOffset":24,"end":"","endOffset":31}]',
43 $crawler = $this->client
->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content);
45 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
47 $comment = $this->client
->getContainer()
48 ->get('doctrine.orm.entity_manager')
49 ->getRepository('WallabagCommentBundle:Comment')
50 ->findLastCommentByPageId($entry->getId(), 1);
52 $this->assertEquals('my comment', $comment->getText());
55 public function testEditcomment()
57 $comment = $this->client
->getContainer()
58 ->get('doctrine.orm.entity_manager')
59 ->getRepository('WallabagCommentBundle:Comment')
60 ->findOneBy(array('user' => 1));
62 $this->logInAs('admin');
64 $headers = array('CONTENT_TYPE' => 'application/json');
65 $content = json_encode(array(
66 'text' => 'a modified comment',
68 $crawler = $this->client
->request('PUT', 'annotations/'.$comment->getId().'.json', array(), array(), $headers, $content);
69 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
71 $content = json_decode($this->client
->getResponse()->getContent(), true);
73 $this->assertEquals('a modified comment', $content['text']);
75 $commentUpdated = $this->client
->getContainer()
76 ->get('doctrine.orm.entity_manager')
77 ->getRepository('WallabagCommentBundle:Comment')
78 ->findCommentById($comment->getId());
79 $this->assertEquals('a modified comment', $commentUpdated->getText());