]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
Merge pull request #1693 from wallabag/v2-issue-template
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / EntryControllerTest.php
index 3a77518245e068bbb985ff6cba5adbb20a2a2107..32d6a57537e253088ff6feb31badfaab8e29eea1 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();
     }
@@ -127,10 +127,35 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $this->assertEquals(302, $client->getResponse()->getStatusCode());
 
-        $crawler = $client->followRedirect();
+        $content = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
+
+        $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
+        $this->assertEquals($this->url, $content->getUrl());
+        $this->assertContains('Google', $content->getTitle());
+    }
+
+    public function testPostNewOkUrlExist()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('button[type=submit]')->form();
+
+        $data = array(
+            'entry[url]' => $this->url,
+        );
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text')));
-        $this->assertContains('Google', $alert[0]);
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+        $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
     }
 
     /**
@@ -202,7 +227,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 +248,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 +262,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 +275,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 +293,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 +323,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 +345,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 +367,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());