diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-02-07 16:52:59 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-02-26 18:13:17 +0100 |
commit | f38e03dc02c96344677fd2720912605b21c90b5d (patch) | |
tree | 2028cecf5d0930e1569ddb977e245ea44bedc38a /src/Wallabag/CommentBundle/Tests | |
parent | d3f1a9dc1ac181033ec54f9149d2807199fa8f17 (diff) | |
download | wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.tar.gz wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.tar.zst wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.zip |
Comment work with annotator v2
- add missing annotator.js file and fix typo
- edit & delete routes, started tests
- basic tests
Diffstat (limited to 'src/Wallabag/CommentBundle/Tests')
-rw-r--r-- | src/Wallabag/CommentBundle/Tests/Controller/CommentControllerTest.php | 81 | ||||
-rw-r--r-- | src/Wallabag/CommentBundle/Tests/WallabagCommentTestCase.php | 63 |
2 files changed, 144 insertions, 0 deletions
diff --git a/src/Wallabag/CommentBundle/Tests/Controller/CommentControllerTest.php b/src/Wallabag/CommentBundle/Tests/Controller/CommentControllerTest.php new file mode 100644 index 00000000..f8b2a56f --- /dev/null +++ b/src/Wallabag/CommentBundle/Tests/Controller/CommentControllerTest.php | |||
@@ -0,0 +1,81 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CommentBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CommentBundle\Tests\WallabagCommentTestCase; | ||
6 | |||
7 | class CommentControllerTest extends WallabagCommentTestCase | ||
8 | { | ||
9 | public function testGetComments() | ||
10 | { | ||
11 | $comment = $this->client->getContainer() | ||
12 | ->get('doctrine.orm.entity_manager') | ||
13 | ->getRepository('WallabagCommentBundle:Comment') | ||
14 | ->findOneBy(array('user' => 1)); | ||
15 | |||
16 | if (!$comment) { | ||
17 | $this->markTestSkipped('No content found in db.'); | ||
18 | } | ||
19 | $this->logInAs('admin'); | ||
20 | $crawler = $this->client->request('GET', 'annotations/'.$comment->getEntry()->getId().'.json'); | ||
21 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
22 | |||
23 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
24 | $this->assertEquals(1, $content['total']); | ||
25 | $this->assertEquals($comment->getText(), $content['rows'][0]['text']); | ||
26 | } | ||
27 | |||
28 | public function testSetcomment() | ||
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( | ||
39 | 'text' => 'my comment', | ||
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 | |||
47 | $comment = $this->client->getContainer() | ||
48 | ->get('doctrine.orm.entity_manager') | ||
49 | ->getRepository('WallabagCommentBundle:Comment') | ||
50 | ->findLastCommentByPageId($entry->getId(), 1); | ||
51 | |||
52 | $this->assertEquals('my comment', $comment->getText()); | ||
53 | } | ||
54 | |||
55 | public function testEditcomment() | ||
56 | { | ||
57 | $comment = $this->client->getContainer() | ||
58 | ->get('doctrine.orm.entity_manager') | ||
59 | ->getRepository('WallabagCommentBundle:Comment') | ||
60 | ->findOneBy(array('user' => 1)); | ||
61 | |||
62 | $this->logInAs('admin'); | ||
63 | |||
64 | $headers = array('CONTENT_TYPE' => 'application/json'); | ||
65 | $content = json_encode(array( | ||
66 | 'text' => 'a modified comment', | ||
67 | )); | ||
68 | $crawler = $this->client->request('PUT', 'annotations/'.$comment->getId().'.json', array(), array(), $headers, $content); | ||
69 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
70 | |||
71 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
72 | |||
73 | $this->assertEquals('a modified comment', $content['text']); | ||
74 | |||
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()); | ||
80 | } | ||
81 | } | ||
diff --git a/src/Wallabag/CommentBundle/Tests/WallabagCommentTestCase.php b/src/Wallabag/CommentBundle/Tests/WallabagCommentTestCase.php new file mode 100644 index 00000000..f4a2ae6c --- /dev/null +++ b/src/Wallabag/CommentBundle/Tests/WallabagCommentTestCase.php | |||
@@ -0,0 +1,63 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CommentBundle\Tests; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
6 | use Symfony\Component\BrowserKit\Cookie; | ||
7 | |||
8 | abstract class WallabagCommentTestCase 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 = array( | ||
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(array('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 | } | ||