aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-09-28 19:35:55 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-09-28 19:35:55 +0200
commit159986c4fbf63dd93136ea5c52ff0be705aefaf3 (patch)
treee62f6ecb3174fac7e04e625d39ec4cd5808b2dcd /src
parentda3d4998c0972557952c83b610f8f45fdcd31b72 (diff)
downloadwallabag-159986c4fbf63dd93136ea5c52ff0be705aefaf3.tar.gz
wallabag-159986c4fbf63dd93136ea5c52ff0be705aefaf3.tar.zst
wallabag-159986c4fbf63dd93136ea5c52ff0be705aefaf3.zip
Fix Postgres tests
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php36
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php32
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php6
3 files changed, 52 insertions, 22 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 87b9befe..0e82b9b2 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -161,4 +161,40 @@ class EntryRepository extends EntityRepository
161 161
162 return $languages; 162 return $languages;
163 } 163 }
164
165 /**
166 * Used only in test case to get the right entry associated to the right user
167 *
168 * @param string $username
169 *
170 * @return Entry
171 */
172 public function findOneByUsernameAndNotStarred($username)
173 {
174 return $this->createQueryBuilder('e')
175 ->leftJoin('e.user', 'u')
176 ->where('u.username = :username')->setParameter('username', $username)
177 ->andWhere('e.isStarred = false')
178 ->setMaxResults(1)
179 ->getQuery()
180 ->getSingleResult();
181 }
182
183 /**
184 * Used only in test case to get the right entry associated to the right user
185 *
186 * @param string $username
187 *
188 * @return Entry
189 */
190 public function findOneByUsernameAndNotArchived($username)
191 {
192 return $this->createQueryBuilder('e')
193 ->leftJoin('e.user', 'u')
194 ->where('u.username = :username')->setParameter('username', $username)
195 ->andWhere('e.isArchived = false')
196 ->setMaxResults(1)
197 ->getQuery()
198 ->getSingleResult();
199 }
164} 200}
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index cbd84a97..456c747a 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -101,7 +101,7 @@ class EntryControllerTest extends WallabagCoreTestCase
101 $content = $client->getContainer() 101 $content = $client->getContainer()
102 ->get('doctrine.orm.entity_manager') 102 ->get('doctrine.orm.entity_manager')
103 ->getRepository('WallabagCoreBundle:Entry') 103 ->getRepository('WallabagCoreBundle:Entry')
104 ->findOneByIsArchived(false); 104 ->findOneByUsernameAndNotArchived('admin');
105 105
106 $client->request('GET', '/view/'.$content->getId()); 106 $client->request('GET', '/view/'.$content->getId());
107 107
@@ -117,7 +117,7 @@ class EntryControllerTest extends WallabagCoreTestCase
117 $content = $client->getContainer() 117 $content = $client->getContainer()
118 ->get('doctrine.orm.entity_manager') 118 ->get('doctrine.orm.entity_manager')
119 ->getRepository('WallabagCoreBundle:Entry') 119 ->getRepository('WallabagCoreBundle:Entry')
120 ->findOneByIsArchived(false); 120 ->findOneByUsernameAndNotArchived('admin');
121 121
122 $crawler = $client->request('GET', '/edit/'.$content->getId()); 122 $crawler = $client->request('GET', '/edit/'.$content->getId());
123 123
@@ -135,7 +135,7 @@ class EntryControllerTest extends WallabagCoreTestCase
135 $content = $client->getContainer() 135 $content = $client->getContainer()
136 ->get('doctrine.orm.entity_manager') 136 ->get('doctrine.orm.entity_manager')
137 ->getRepository('WallabagCoreBundle:Entry') 137 ->getRepository('WallabagCoreBundle:Entry')
138 ->findOneByIsArchived(false); 138 ->findOneByUsernameAndNotArchived('admin');
139 139
140 $crawler = $client->request('GET', '/edit/'.$content->getId()); 140 $crawler = $client->request('GET', '/edit/'.$content->getId());
141 141
@@ -165,7 +165,7 @@ class EntryControllerTest extends WallabagCoreTestCase
165 $content = $client->getContainer() 165 $content = $client->getContainer()
166 ->get('doctrine.orm.entity_manager') 166 ->get('doctrine.orm.entity_manager')
167 ->getRepository('WallabagCoreBundle:Entry') 167 ->getRepository('WallabagCoreBundle:Entry')
168 ->findOneByIsArchived(false); 168 ->findOneByUsernameAndNotArchived('admin');
169 169
170 $client->request('GET', '/archive/'.$content->getId()); 170 $client->request('GET', '/archive/'.$content->getId());
171 171
@@ -174,7 +174,7 @@ class EntryControllerTest extends WallabagCoreTestCase
174 $res = $client->getContainer() 174 $res = $client->getContainer()
175 ->get('doctrine.orm.entity_manager') 175 ->get('doctrine.orm.entity_manager')
176 ->getRepository('WallabagCoreBundle:Entry') 176 ->getRepository('WallabagCoreBundle:Entry')
177 ->findOneById($content->getId()); 177 ->find($content->getId());
178 178
179 $this->assertEquals($res->isArchived(), true); 179 $this->assertEquals($res->isArchived(), true);
180 } 180 }
@@ -187,7 +187,7 @@ class EntryControllerTest extends WallabagCoreTestCase
187 $content = $client->getContainer() 187 $content = $client->getContainer()
188 ->get('doctrine.orm.entity_manager') 188 ->get('doctrine.orm.entity_manager')
189 ->getRepository('WallabagCoreBundle:Entry') 189 ->getRepository('WallabagCoreBundle:Entry')
190 ->findOneByIsStarred(false); 190 ->findOneByUsernameAndNotStarred('admin');
191 191
192 $client->request('GET', '/star/'.$content->getId()); 192 $client->request('GET', '/star/'.$content->getId());
193 193
@@ -209,7 +209,7 @@ class EntryControllerTest extends WallabagCoreTestCase
209 $content = $client->getContainer() 209 $content = $client->getContainer()
210 ->get('doctrine.orm.entity_manager') 210 ->get('doctrine.orm.entity_manager')
211 ->getRepository('WallabagCoreBundle:Entry') 211 ->getRepository('WallabagCoreBundle:Entry')
212 ->findOneByIsStarred(false); 212 ->findOneByUsernameAndNotStarred('admin');
213 213
214 $client->request('GET', '/delete/'.$content->getId()); 214 $client->request('GET', '/delete/'.$content->getId());
215 215
@@ -222,21 +222,15 @@ class EntryControllerTest extends WallabagCoreTestCase
222 222
223 public function testViewOtherUserEntry() 223 public function testViewOtherUserEntry()
224 { 224 {
225 $this->logInAs('bob'); 225 $this->logInAs('admin');
226 $client = $this->getClient(); 226 $client = $this->getClient();
227 227
228 $content = $client->getContainer() 228 $content = $client->getContainer()
229 ->get('doctrine.orm.entity_manager') 229 ->get('doctrine.orm.entity_manager')
230 ->getRepository('WallabagCoreBundle:Entry') 230 ->getRepository('WallabagCoreBundle:Entry')
231 ->createQueryBuilder('e') 231 ->findOneByUsernameAndNotArchived('bob');
232 ->select('e.id')
233 ->leftJoin('e.user', 'u')
234 ->where('u.username != :username')->setParameter('username', 'bob')
235 ->setMaxResults(1)
236 ->getQuery()
237 ->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
238 232
239 $client->request('GET', '/view/'.$content['id']); 233 $client->request('GET', '/view/'.$content->getId());
240 234
241 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 235 $this->assertEquals(403, $client->getResponse()->getStatusCode());
242 } 236 }
@@ -360,7 +354,7 @@ class EntryControllerTest extends WallabagCoreTestCase
360 $form['entry_filter[isStarred]']->untick(); 354 $form['entry_filter[isStarred]']->untick();
361 355
362 $crawler = $client->submit($form); 356 $crawler = $client->submit($form);
363 $this->assertCount(2, $crawler->filter('div[class=entry]')); 357 $this->assertCount(1, $crawler->filter('div[class=entry]'));
364 358
365 $form = $crawler->filter('button[id=submit-filter]')->form(); 359 $form = $crawler->filter('button[id=submit-filter]')->form();
366 $form['entry_filter[isArchived]']->untick(); 360 $form['entry_filter[isArchived]']->untick();
@@ -391,11 +385,11 @@ class EntryControllerTest extends WallabagCoreTestCase
391 $crawler = $client->request('GET', '/unread/list'); 385 $crawler = $client->request('GET', '/unread/list');
392 $form = $crawler->filter('button[id=submit-filter]')->form(); 386 $form = $crawler->filter('button[id=submit-filter]')->form();
393 $data = array( 387 $data = array(
394 'entry_filter[language]' => 'de', 388 'entry_filter[language]' => 'fr',
395 ); 389 );
396 390
397 $crawler = $client->submit($form, $data); 391 $crawler = $client->submit($form, $data);
398 $this->assertCount(1, $crawler->filter('div[class=entry]')); 392 $this->assertCount(3, $crawler->filter('div[class=entry]'));
399 393
400 $form = $crawler->filter('button[id=submit-filter]')->form(); 394 $form = $crawler->filter('button[id=submit-filter]')->form();
401 $data = array( 395 $data = array(
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
index d25b2db5..dc93dd6b 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
@@ -24,7 +24,7 @@ class TagControllerTest extends WallabagCoreTestCase
24 $entry = $client->getContainer() 24 $entry = $client->getContainer()
25 ->get('doctrine.orm.entity_manager') 25 ->get('doctrine.orm.entity_manager')
26 ->getRepository('WallabagCoreBundle:Entry') 26 ->getRepository('WallabagCoreBundle:Entry')
27 ->findOneBy(array()); 27 ->findOneByUsernameAndNotArchived('admin');
28 28
29 $crawler = $client->request('GET', '/view/'.$entry->getId()); 29 $crawler = $client->request('GET', '/view/'.$entry->getId());
30 30
@@ -46,7 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase
46 $newEntry = $client->getContainer() 46 $newEntry = $client->getContainer()
47 ->get('doctrine.orm.entity_manager') 47 ->get('doctrine.orm.entity_manager')
48 ->getRepository('WallabagCoreBundle:Entry') 48 ->getRepository('WallabagCoreBundle:Entry')
49 ->findOneById($entry->getId()); 49 ->find($entry->getId());
50 50
51 $this->assertEquals(1, count($newEntry->getTags())); 51 $this->assertEquals(1, count($newEntry->getTags()));
52 52
@@ -61,7 +61,7 @@ class TagControllerTest extends WallabagCoreTestCase
61 $newEntry = $client->getContainer() 61 $newEntry = $client->getContainer()
62 ->get('doctrine.orm.entity_manager') 62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry') 63 ->getRepository('WallabagCoreBundle:Entry')
64 ->findOneById($entry->getId()); 64 ->find($entry->getId());
65 65
66 $this->assertEquals(2, count($newEntry->getTags())); 66 $this->assertEquals(2, count($newEntry->getTags()));
67 } 67 }