aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-01-15 15:47:13 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-01-15 15:47:13 +0100
commit86719c63bf47686ca55020e6b0443344de36d45a (patch)
treee985658fe7e6ae5c5f016417533a36dac4e80f50 /src
parent1930c19d8214c05ceefac5ac011a6b6e7e4a983d (diff)
parent78833672469f7beb0c4a195aa0a76f7ca4133057 (diff)
downloadwallabag-86719c63bf47686ca55020e6b0443344de36d45a.tar.gz
wallabag-86719c63bf47686ca55020e6b0443344de36d45a.tar.zst
wallabag-86719c63bf47686ca55020e6b0443344de36d45a.zip
Merge pull request #1583 from wallabag/v2-fix-delete
Fix `findOneByUrl` side effect in tests
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php3
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php20
-rw-r--r--src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php17
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php2
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php2
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php2
8 files changed, 33 insertions, 18 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index aa70307b..9dd904f1 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -49,8 +49,7 @@ class EntryController extends Controller
49 49
50 if ($form->isValid()) { 50 if ($form->isValid()) {
51 // check for existing entry, if it exists, redirect to it with a message 51 // check for existing entry, if it exists, redirect to it with a message
52 $existingEntry = $this->get('wallabag_core.entry_repository') 52 $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
53 ->existByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
54 53
55 if (false !== $existingEntry) { 54 if (false !== $existingEntry) {
56 $this->get('session')->getFlashBag()->add( 55 $this->get('session')->getFlashBag()->add(
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index a16be9e0..82eb9474 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -235,10 +235,9 @@ class EntryRepository extends EntityRepository
235 * 235 *
236 * @return array|bool 236 * @return array|bool
237 */ 237 */
238 public function existByUrlAndUserId($url, $userId) 238 public function findByUrlAndUserId($url, $userId)
239 { 239 {
240 $res = $this->createQueryBuilder('e') 240 $res = $this->createQueryBuilder('e')
241 ->select('e.id, e.createdAt')
242 ->where('e.url = :url')->setParameter('url', $url) 241 ->where('e.url = :url')->setParameter('url', $url)
243 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 242 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
244 ->getQuery() 243 ->getQuery()
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 3a775182..1d1620dc 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -38,7 +38,7 @@ class EntryControllerTest extends WallabagCoreTestCase
38 $form = $crawler->filter('button[type=submit]')->form(); 38 $form = $crawler->filter('button[type=submit]')->form();
39 39
40 $data = array( 40 $data = array(
41 'entry[url]' => 'https://www.wallabag.org/blog/2016/01/08/wallabag-alpha1-v2', 41 'entry[url]' => $this->url,
42 ); 42 );
43 43
44 $client->submit($form, $data); 44 $client->submit($form, $data);
@@ -82,7 +82,7 @@ class EntryControllerTest extends WallabagCoreTestCase
82 ->get('doctrine.orm.entity_manager'); 82 ->get('doctrine.orm.entity_manager');
83 $entry = $em 83 $entry = $em
84 ->getRepository('WallabagCoreBundle:Entry') 84 ->getRepository('WallabagCoreBundle:Entry')
85 ->findOneByUrl($this->url); 85 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
86 $em->remove($entry); 86 $em->remove($entry);
87 $em->flush(); 87 $em->flush();
88 } 88 }
@@ -202,7 +202,7 @@ class EntryControllerTest extends WallabagCoreTestCase
202 $content = $client->getContainer() 202 $content = $client->getContainer()
203 ->get('doctrine.orm.entity_manager') 203 ->get('doctrine.orm.entity_manager')
204 ->getRepository('WallabagCoreBundle:Entry') 204 ->getRepository('WallabagCoreBundle:Entry')
205 ->findOneByUrl($this->url); 205 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
206 206
207 $client->request('GET', '/view/'.$content->getId()); 207 $client->request('GET', '/view/'.$content->getId());
208 208
@@ -223,7 +223,7 @@ class EntryControllerTest extends WallabagCoreTestCase
223 $content = $client->getContainer() 223 $content = $client->getContainer()
224 ->get('doctrine.orm.entity_manager') 224 ->get('doctrine.orm.entity_manager')
225 ->getRepository('WallabagCoreBundle:Entry') 225 ->getRepository('WallabagCoreBundle:Entry')
226 ->findOneByUrl($this->url); 226 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
227 227
228 // empty content 228 // empty content
229 $content->setContent(''); 229 $content->setContent('');
@@ -237,7 +237,7 @@ class EntryControllerTest extends WallabagCoreTestCase
237 $content = $client->getContainer() 237 $content = $client->getContainer()
238 ->get('doctrine.orm.entity_manager') 238 ->get('doctrine.orm.entity_manager')
239 ->getRepository('WallabagCoreBundle:Entry') 239 ->getRepository('WallabagCoreBundle:Entry')
240 ->findOneByUrl($this->url); 240 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
241 241
242 $this->assertNotEmpty($content->getContent()); 242 $this->assertNotEmpty($content->getContent());
243 } 243 }
@@ -250,7 +250,7 @@ class EntryControllerTest extends WallabagCoreTestCase
250 $content = $client->getContainer() 250 $content = $client->getContainer()
251 ->get('doctrine.orm.entity_manager') 251 ->get('doctrine.orm.entity_manager')
252 ->getRepository('WallabagCoreBundle:Entry') 252 ->getRepository('WallabagCoreBundle:Entry')
253 ->findOneByUrl($this->url); 253 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
254 254
255 $crawler = $client->request('GET', '/edit/'.$content->getId()); 255 $crawler = $client->request('GET', '/edit/'.$content->getId());
256 256
@@ -268,7 +268,7 @@ class EntryControllerTest extends WallabagCoreTestCase
268 $content = $client->getContainer() 268 $content = $client->getContainer()
269 ->get('doctrine.orm.entity_manager') 269 ->get('doctrine.orm.entity_manager')
270 ->getRepository('WallabagCoreBundle:Entry') 270 ->getRepository('WallabagCoreBundle:Entry')
271 ->findOneByUrl($this->url); 271 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
272 272
273 $crawler = $client->request('GET', '/edit/'.$content->getId()); 273 $crawler = $client->request('GET', '/edit/'.$content->getId());
274 274
@@ -298,7 +298,7 @@ class EntryControllerTest extends WallabagCoreTestCase
298 $content = $client->getContainer() 298 $content = $client->getContainer()
299 ->get('doctrine.orm.entity_manager') 299 ->get('doctrine.orm.entity_manager')
300 ->getRepository('WallabagCoreBundle:Entry') 300 ->getRepository('WallabagCoreBundle:Entry')
301 ->findOneByUrl($this->url); 301 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
302 302
303 $client->request('GET', '/archive/'.$content->getId()); 303 $client->request('GET', '/archive/'.$content->getId());
304 304
@@ -320,7 +320,7 @@ class EntryControllerTest extends WallabagCoreTestCase
320 $content = $client->getContainer() 320 $content = $client->getContainer()
321 ->get('doctrine.orm.entity_manager') 321 ->get('doctrine.orm.entity_manager')
322 ->getRepository('WallabagCoreBundle:Entry') 322 ->getRepository('WallabagCoreBundle:Entry')
323 ->findOneByUrl($this->url); 323 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
324 324
325 $client->request('GET', '/star/'.$content->getId()); 325 $client->request('GET', '/star/'.$content->getId());
326 326
@@ -342,7 +342,7 @@ class EntryControllerTest extends WallabagCoreTestCase
342 $content = $client->getContainer() 342 $content = $client->getContainer()
343 ->get('doctrine.orm.entity_manager') 343 ->get('doctrine.orm.entity_manager')
344 ->getRepository('WallabagCoreBundle:Entry') 344 ->getRepository('WallabagCoreBundle:Entry')
345 ->findOneByUrl($this->url); 345 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
346 346
347 $client->request('GET', '/delete/'.$content->getId()); 347 $client->request('GET', '/delete/'.$content->getId());
348 348
diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
index ce3cabe8..c4905478 100644
--- a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
+++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
@@ -31,4 +31,21 @@ abstract class WallabagCoreTestCase extends WebTestCase
31 31
32 $this->client->submit($form, $data); 32 $this->client->submit($form, $data);
33 } 33 }
34
35 /**
36 * Return the user id of the logged in user.
37 * You should be sure that you called `logInAs` before.
38 *
39 * @return int
40 */
41 public function getLoggedInUserId()
42 {
43 $token = static::$kernel->getContainer()->get('security.token_storage')->getToken();
44
45 if (null !== $token) {
46 return $token->getUser()->getId();
47 }
48
49 throw new \RuntimeException('No logged in User.');
50 }
34} 51}
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index cdcec1e2..72b9047c 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -214,7 +214,7 @@ class PocketImport implements ImportInterface
214 214
215 $existingEntry = $this->em 215 $existingEntry = $this->em
216 ->getRepository('WallabagCoreBundle:Entry') 216 ->getRepository('WallabagCoreBundle:Entry')
217 ->existByUrlAndUserId($url, $this->user->getId()); 217 ->findByUrlAndUserId($url, $this->user->getId());
218 218
219 if (false !== $existingEntry) { 219 if (false !== $existingEntry) {
220 ++$this->skippedEntries; 220 ++$this->skippedEntries;
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 393089d6..6f8feaf3 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -127,7 +127,7 @@ class WallabagV1Import implements ImportInterface
127 foreach ($entries as $importedEntry) { 127 foreach ($entries as $importedEntry) {
128 $existingEntry = $this->em 128 $existingEntry = $this->em
129 ->getRepository('WallabagCoreBundle:Entry') 129 ->getRepository('WallabagCoreBundle:Entry')
130 ->existByUrlAndUserId($importedEntry['url'], $this->user->getId()); 130 ->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
131 131
132 if (false !== $existingEntry) { 132 if (false !== $existingEntry) {
133 ++$this->skippedEntries; 133 ++$this->skippedEntries;
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
index 043b2114..76225fe4 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
@@ -248,7 +248,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
248 ->getMock(); 248 ->getMock();
249 249
250 $entryRepo->expects($this->exactly(2)) 250 $entryRepo->expects($this->exactly(2))
251 ->method('existByUrlAndUserId') 251 ->method('findByUrlAndUserId')
252 ->will($this->onConsecutiveCalls(false, true)); 252 ->will($this->onConsecutiveCalls(false, true));
253 253
254 $tag = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Tag') 254 $tag = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Tag')
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
index d5b41777..90483480 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
@@ -53,7 +53,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
53 ->getMock(); 53 ->getMock();
54 54
55 $entryRepo->expects($this->exactly(3)) 55 $entryRepo->expects($this->exactly(3))
56 ->method('existByUrlAndUserId') 56 ->method('findByUrlAndUserId')
57 ->will($this->onConsecutiveCalls(false, true, false)); 57 ->will($this->onConsecutiveCalls(false, true, false));
58 58
59 $this->em 59 $this->em