]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix bad type after using findByUrlAndUserId
authorJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 21 Jan 2016 15:37:25 +0000 (16:37 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 21 Jan 2016 15:37:25 +0000 (16:37 +0100)
It returns an object since few commits this part of (untested) code still use an array.
Also add test for that part of code.

src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php

index 9dd904f1a5e2efd97d6bca17dc866e08724c6c25..3e1b512ff3eb222a46b13cae9dfb3b5f5ed62eb3 100644 (file)
@@ -54,10 +54,10 @@ class EntryController extends Controller
             if (false !== $existingEntry) {
                 $this->get('session')->getFlashBag()->add(
                     'notice',
-                    'Entry already saved on '.$existingEntry['createdAt']->format('d-m-Y')
+                    'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y')
                 );
 
-                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry['id'])));
+                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId())));
             }
 
             $this->updateEntry($entry);
index 1d1620dc268bb434c50a83fc57a5a22d9ab04982..32d6a57537e253088ff6feb31badfaab8e29eea1 100644 (file)
@@ -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());
     }
 
     /**