]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix `findOneByUrl` side effect in tests 1583/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 15 Jan 2016 14:28:22 +0000 (15:28 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 15 Jan 2016 14:28:32 +0000 (15:28 +0100)
Fix #1566

src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php
src/Wallabag/ImportBundle/Import/PocketImport.php
src/Wallabag/ImportBundle/Import/WallabagV1Import.php
src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php

index 3d22c7bcaa15d48b7a0633c68c6c920f5b1d2918..1949bdf8ffb5490f2cfc835898418d874f607477 100644 (file)
@@ -49,8 +49,7 @@ class EntryController extends Controller
 
         if ($form->isValid()) {
             // check for existing entry, if it exists, redirect to it with a message
-            $existingEntry = $this->get('wallabag_core.entry_repository')
-                ->existByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
+            $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
 
             if (false !== $existingEntry) {
                 $this->get('session')->getFlashBag()->add(
index a16be9e01924d4cefb89b6a37db999fb341ef704..82eb947462ea1db1e7653d9ffc725313c04ab127 100644 (file)
@@ -235,10 +235,9 @@ class EntryRepository extends EntityRepository
      *
      * @return array|bool
      */
-    public function existByUrlAndUserId($url, $userId)
+    public function findByUrlAndUserId($url, $userId)
     {
         $res = $this->createQueryBuilder('e')
-            ->select('e.id, e.createdAt')
             ->where('e.url = :url')->setParameter('url', $url)
             ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
             ->getQuery()
index 3a77518245e068bbb985ff6cba5adbb20a2a2107..1d1620dc268bb434c50a83fc57a5a22d9ab04982 100644 (file)
@@ -38,7 +38,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $form = $crawler->filter('button[type=submit]')->form();
 
         $data = array(
-            'entry[url]' => 'https://www.wallabag.org/blog/2016/01/08/wallabag-alpha1-v2',
+            'entry[url]' => $this->url,
         );
 
         $client->submit($form, $data);
@@ -82,7 +82,7 @@ class EntryControllerTest extends WallabagCoreTestCase
             ->get('doctrine.orm.entity_manager');
         $entry = $em
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
         $em->remove($entry);
         $em->flush();
     }
@@ -202,7 +202,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $client->request('GET', '/view/'.$content->getId());
 
@@ -223,7 +223,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         // empty content
         $content->setContent('');
@@ -237,7 +237,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $this->assertNotEmpty($content->getContent());
     }
@@ -250,7 +250,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $crawler = $client->request('GET', '/edit/'.$content->getId());
 
@@ -268,7 +268,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $crawler = $client->request('GET', '/edit/'.$content->getId());
 
@@ -298,7 +298,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $client->request('GET', '/archive/'.$content->getId());
 
@@ -320,7 +320,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $client->request('GET', '/star/'.$content->getId());
 
@@ -342,7 +342,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUrl($this->url);
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
         $client->request('GET', '/delete/'.$content->getId());
 
index ce3cabe8d36af3f82d8c782a7d7855c1eb0245c1..c4905478b27552e4304b23908e0069fff65e2389 100644 (file)
@@ -31,4 +31,21 @@ abstract class WallabagCoreTestCase extends WebTestCase
 
         $this->client->submit($form, $data);
     }
+
+    /**
+     * Return the user id of the logged in user.
+     * You should be sure that you called `logInAs` before.
+     *
+     * @return int
+     */
+    public function getLoggedInUserId()
+    {
+        $token = static::$kernel->getContainer()->get('security.token_storage')->getToken();
+
+        if (null !== $token) {
+            return $token->getUser()->getId();
+        }
+
+        throw new \RuntimeException('No logged in User.');
+    }
 }
index cdcec1e283b279badc2eacbf662ef56272238d93..72b9047c8fdc3acc39267b67a4af11adc31f2634 100644 (file)
@@ -214,7 +214,7 @@ class PocketImport implements ImportInterface
 
             $existingEntry = $this->em
                 ->getRepository('WallabagCoreBundle:Entry')
-                ->existByUrlAndUserId($url, $this->user->getId());
+                ->findByUrlAndUserId($url, $this->user->getId());
 
             if (false !== $existingEntry) {
                 ++$this->skippedEntries;
index 393089d63f1e6f6c4ad3ff9d305ad44b575498a0..6f8feaf36b2924c0bc2ea717103bfa59689ef5d7 100644 (file)
@@ -127,7 +127,7 @@ class WallabagV1Import implements ImportInterface
         foreach ($entries as $importedEntry) {
             $existingEntry = $this->em
                 ->getRepository('WallabagCoreBundle:Entry')
-                ->existByUrlAndUserId($importedEntry['url'], $this->user->getId());
+                ->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
 
             if (false !== $existingEntry) {
                 ++$this->skippedEntries;
index 043b2114e802711e46666c8e6df42fa4e0333921..76225fe4f21be2b119f7b17b9c247a7e5f3d1dc4 100644 (file)
@@ -248,7 +248,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $entryRepo->expects($this->exactly(2))
-            ->method('existByUrlAndUserId')
+            ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true));
 
         $tag = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Tag')
index d5b41777caf041f0f6b46b5571bf2f2eb21fd1e9..90483480816d5c212d52f100dd4a75a69b4687c1 100644 (file)
@@ -53,7 +53,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $entryRepo->expects($this->exactly(3))
-            ->method('existByUrlAndUserId')
+            ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true, false));
 
         $this->em