aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-11 17:56:41 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-11 17:59:42 +0100
commit09d8bb6fa26b881da478df4c7b97620cb7aea0d0 (patch)
tree2a81d844c253c5961943ba936445b154d4d32510 /src
parent66e2be23717ad8af3cabe5d0c69effd492af3ece (diff)
downloadwallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.tar.gz
wallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.tar.zst
wallabag-09d8bb6fa26b881da478df4c7b97620cb7aea0d0.zip
Improve tests
- add more tests for coverage - add a test on annotation deletion - fix post annontation with ranges
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php17
-rw-r--r--src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php53
-rw-r--r--src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php6
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php1
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php4
5 files changed, 66 insertions, 15 deletions
diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
index c1c6e638..7f35373f 100644
--- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
+++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
@@ -88,4 +88,21 @@ class AnnotationRepository extends EntityRepository
88 ->getQuery() 88 ->getQuery()
89 ->getOneOrNullResult(); 89 ->getOneOrNullResult();
90 } 90 }
91
92 /**
93 * Used only in test case to get the right annotation associated to the right user.
94 *
95 * @param string $username
96 *
97 * @return Annotation
98 */
99 public function findOneByUsername($username)
100 {
101 return $this->createQueryBuilder('a')
102 ->leftJoin('a.user', 'u')
103 ->where('u.username = :username')->setParameter('username', $username)
104 ->setMaxResults(1)
105 ->getQuery()
106 ->getSingleResult();
107 }
91} 108}
diff --git a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
index c0efe272..7a877f98 100644
--- a/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
+++ b/src/Wallabag/AnnotationBundle/Tests/Controller/AnnotationControllerTest.php
@@ -11,11 +11,12 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
11 $annotation = $this->client->getContainer() 11 $annotation = $this->client->getContainer()
12 ->get('doctrine.orm.entity_manager') 12 ->get('doctrine.orm.entity_manager')
13 ->getRepository('WallabagAnnotationBundle:Annotation') 13 ->getRepository('WallabagAnnotationBundle:Annotation')
14 ->findOneBy(array('user' => 1)); 14 ->findOneByUsername('admin');
15 15
16 if (!$annotation) { 16 if (!$annotation) {
17 $this->markTestSkipped('No content found in db.'); 17 $this->markTestSkipped('No content found in db.');
18 } 18 }
19
19 $this->logInAs('admin'); 20 $this->logInAs('admin');
20 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); 21 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
21 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 22 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -32,18 +33,25 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
32 $entry = $this->client->getContainer() 33 $entry = $this->client->getContainer()
33 ->get('doctrine.orm.entity_manager') 34 ->get('doctrine.orm.entity_manager')
34 ->getRepository('WallabagCoreBundle:Entry') 35 ->getRepository('WallabagCoreBundle:Entry')
35 ->findOneBy(array('user' => 1)); 36 ->findOneByUsernameAndNotArchived('admin');
36 37
37 $headers = array('CONTENT_TYPE' => 'application/json'); 38 $headers = array('CONTENT_TYPE' => 'application/json');
38 $content = json_encode(array( 39 $content = json_encode(array(
39 'text' => 'my annotation', 40 'text' => 'my annotation',
40 'quote' => 'my quote', 41 'quote' => 'my quote',
41 'range' => '[{"start":"","startOffset":24,"end":"","endOffset":31}]', 42 'ranges' => array('start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31),
42 )); 43 ));
43 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content); 44 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', array(), array(), $headers, $content);
44 45
45 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 46 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
46 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
47 $annotation = $this->client->getContainer() 55 $annotation = $this->client->getContainer()
48 ->get('doctrine.orm.entity_manager') 56 ->get('doctrine.orm.entity_manager')
49 ->getRepository('WallabagAnnotationBundle:Annotation') 57 ->getRepository('WallabagAnnotationBundle:Annotation')
@@ -57,25 +65,56 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
57 $annotation = $this->client->getContainer() 65 $annotation = $this->client->getContainer()
58 ->get('doctrine.orm.entity_manager') 66 ->get('doctrine.orm.entity_manager')
59 ->getRepository('WallabagAnnotationBundle:Annotation') 67 ->getRepository('WallabagAnnotationBundle:Annotation')
60 ->findOneBy(array('user' => 1)); 68 ->findOneByUsername('admin');
61 69
62 $this->logInAs('admin'); 70 $this->logInAs('admin');
63 71
64 $headers = array('CONTENT_TYPE' => 'application/json'); 72 $headers = array('CONTENT_TYPE' => 'application/json');
65 $content = json_encode(array( 73 $content = json_encode(array(
66 'text' => 'a modified annotation', 74 'text' => 'a modified annotation',
67 )); 75 ));
68 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content); 76 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', array(), array(), $headers, $content);
69 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 77 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
70 78
71 $content = json_decode($this->client->getResponse()->getContent(), true); 79 $content = json_decode($this->client->getResponse()->getContent(), true);
72 80
81 $this->assertEquals('Big boss', $content['user']);
82 $this->assertEquals('v1.0', $content['annotator_schema_version']);
73 $this->assertEquals('a modified annotation', $content['text']); 83 $this->assertEquals('a modified annotation', $content['text']);
84 $this->assertEquals('content', $content['quote']);
74 85
75 $annotationUpdated = $this->client->getContainer() 86 $annotationUpdated = $this->client->getContainer()
76 ->get('doctrine.orm.entity_manager') 87 ->get('doctrine.orm.entity_manager')
77 ->getRepository('WallabagAnnotationBundle:Annotation') 88 ->getRepository('WallabagAnnotationBundle:Annotation')
78 ->findAnnotationById($annotation->getId()); 89 ->findOneById($annotation->getId());
79 $this->assertEquals('a modified annotation', $annotationUpdated->getText()); 90 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
80 } 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 = array('CONTENT_TYPE' => 'application/json');
103 $content = json_encode(array(
104 'text' => 'a modified annotation',
105 ));
106 $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', array(), array(), $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 }
81} 120}
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
index a705f9de..cce39d0b 100644
--- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -162,12 +162,12 @@ class WallabagRestControllerTest extends WallabagApiTestCase
162 $this->assertCount(1, $content['tags']); 162 $this->assertCount(1, $content['tags']);
163 } 163 }
164 164
165 public function testPostArchivedEntry() 165 public function testPostArchivedAndStarredEntry()
166 { 166 {
167 $this->client->request('POST', '/api/entries.json', array( 167 $this->client->request('POST', '/api/entries.json', array(
168 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', 168 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
169 'archive' => true, 169 'archive' => true,
170 'starred' => false, 170 'starred' => true,
171 )); 171 ));
172 172
173 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 173 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -177,7 +177,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
177 $this->assertGreaterThan(0, $content['id']); 177 $this->assertGreaterThan(0, $content['id']);
178 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); 178 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
179 $this->assertEquals(true, $content['is_archived']); 179 $this->assertEquals(true, $content['is_archived']);
180 $this->assertEquals(false, $content['is_starred']); 180 $this->assertEquals(true, $content['is_starred']);
181 } 181 }
182 182
183 public function testPatchEntry() 183 public function testPatchEntry()
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 1791eac2..1930a2ae 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -16,7 +16,6 @@ use Wallabag\CoreBundle\Form\Type\RssType;
16use Wallabag\CoreBundle\Form\Type\TaggingRuleType; 16use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
17use Wallabag\CoreBundle\Form\Type\UserInformationType; 17use Wallabag\CoreBundle\Form\Type\UserInformationType;
18use Wallabag\CoreBundle\Tools\Utils; 18use Wallabag\CoreBundle\Tools\Utils;
19use Wallabag\UserBundle\Entity\User;
20 19
21class ConfigController extends Controller 20class ConfigController extends Controller
22{ 21{
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
index 92712b9d..450cdc95 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
@@ -302,8 +302,6 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
302 "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", 302 "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
303 "favorite": "1", 303 "favorite": "1",
304 "status": "1", 304 "status": "1",
305 "resolved_title": "The Massive Ryder Cup Preview",
306 "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
307 "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", 305 "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.",
308 "is_article": "1", 306 "is_article": "1",
309 "has_video": "1", 307 "has_video": "1",
@@ -317,8 +315,6 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
317 "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", 315 "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
318 "favorite": "1", 316 "favorite": "1",
319 "status": "0", 317 "status": "0",
320 "resolved_title": "The Massive Ryder Cup Preview",
321 "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
322 "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", 318 "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.",
323 "is_article": "1", 319 "is_article": "1",
324 "has_video": "0", 320 "has_video": "0",