From: Jeremy Benoist Date: Thu, 21 Jan 2016 15:37:25 +0000 (+0100) Subject: Fix bad type after using findByUrlAndUserId X-Git-Tag: 2.0.0-alpha.2~1^2~3 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=a0d6ccc5ca0dc0082467cc65b006150aff2488c4;p=github%2Fwallabag%2Fwallabag.git Fix bad type after using findByUrlAndUserId It returns an object since few commits this part of (untested) code still use an array. Also add test for that part of code. --- diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 9dd904f1..3e1b512f 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -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); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 1d1620dc..32d6a575 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -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()); } /**