diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-10-09 14:01:28 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-22 09:06:07 +0200 |
commit | 0c271b9eb0813162b82c6b3bc38604716398ddd1 (patch) | |
tree | 0739a26c4e2a973013d4d38bcd2e8075f19d6093 | |
parent | b1e92f8c14d3d506f2bfab628ba8ed95de0e8b51 (diff) | |
download | wallabag-0c271b9eb0813162b82c6b3bc38604716398ddd1.tar.gz wallabag-0c271b9eb0813162b82c6b3bc38604716398ddd1.tar.zst wallabag-0c271b9eb0813162b82c6b3bc38604716398ddd1.zip |
fix cs and phpdoc
4 files changed, 34 insertions, 26 deletions
diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 519fd2f5..c13a034f 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php | |||
@@ -27,7 +27,7 @@ class WallabagAnnotationController extends FOSRestController | |||
27 | ->getRepository('WallabagAnnotationBundle:Annotation') | 27 | ->getRepository('WallabagAnnotationBundle:Annotation') |
28 | ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); | 28 | ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); |
29 | $total = count($annotationRows); | 29 | $total = count($annotationRows); |
30 | $annotations = array('total' => $total, 'rows' => $annotationRows); | 30 | $annotations = ['total' => $total, 'rows' => $annotationRows]; |
31 | 31 | ||
32 | $json = $this->get('serializer')->serialize($annotations, 'json'); | 32 | $json = $this->get('serializer')->serialize($annotations, 'json'); |
33 | 33 | ||
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index b30ab267..0c709ca0 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -536,12 +536,9 @@ class WallabagRestController extends FOSRestController | |||
536 | { | 536 | { |
537 | $this->validateAuthentication(); | 537 | $this->validateAuthentication(); |
538 | 538 | ||
539 | $response = $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', | 539 | return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [ |
540 | [ | 540 | 'entry' => $entry, |
541 | 'entry' => $entry, | 541 | ]); |
542 | ]); | ||
543 | |||
544 | return $response; | ||
545 | } | 542 | } |
546 | 543 | ||
547 | /** | 544 | /** |
@@ -563,13 +560,10 @@ class WallabagRestController extends FOSRestController | |||
563 | { | 560 | { |
564 | $this->validateAuthentication(); | 561 | $this->validateAuthentication(); |
565 | 562 | ||
566 | $response = $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', | 563 | return $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [ |
567 | [ | ||
568 | 'request' => $request, | 564 | 'request' => $request, |
569 | 'entry' => $entry, | 565 | 'entry' => $entry, |
570 | ]); | 566 | ]); |
571 | |||
572 | return $response; | ||
573 | } | 567 | } |
574 | 568 | ||
575 | /** | 569 | /** |
@@ -592,13 +586,10 @@ class WallabagRestController extends FOSRestController | |||
592 | { | 586 | { |
593 | $this->validateAuthentication(); | 587 | $this->validateAuthentication(); |
594 | 588 | ||
595 | $response = $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', | 589 | return $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [ |
596 | [ | ||
597 | 'annotation' => $annotation, | 590 | 'annotation' => $annotation, |
598 | 'request' => $request, | 591 | 'request' => $request, |
599 | ]); | 592 | ]); |
600 | |||
601 | return $response; | ||
602 | } | 593 | } |
603 | 594 | ||
604 | /** | 595 | /** |
@@ -620,12 +611,9 @@ class WallabagRestController extends FOSRestController | |||
620 | { | 611 | { |
621 | $this->validateAuthentication(); | 612 | $this->validateAuthentication(); |
622 | 613 | ||
623 | $response = $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', | 614 | return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [ |
624 | [ | ||
625 | 'annotation' => $annotation, | 615 | 'annotation' => $annotation, |
626 | ]); | 616 | ]); |
627 | |||
628 | return $response; | ||
629 | } | 617 | } |
630 | 618 | ||
631 | /** | 619 | /** |
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())); |