From: Jeremy Benoist Date: Wed, 24 Aug 2016 20:29:36 +0000 (+0200) Subject: Update test X-Git-Tag: 2.1.0~56^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=eddda878a0ec375fa738e3228a72dd01b23e0fab;p=github%2Fwallabag%2Fwallabag.git Update test and some cleanup --- diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e500ad75..d71ba6cd 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -465,8 +465,12 @@ class EntryController extends Controller { $this->checkUserAction($entry); - if ('' === $entry->getUuid() || null === $entry->getUuid()) { - $this->generateEntryUuid($entry); + if (null === $entry->getUuid()) { + $entry->generateUuid(); + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } return $this->redirect($this->generateUrl('share_entry', [ @@ -488,6 +492,7 @@ class EntryController extends Controller $this->checkUserAction($entry); $entry->cleanUuid(); + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -498,31 +503,24 @@ class EntryController extends Controller } /** - * Share entry content. + * Ability to view a content publicly. * * @param Entry $entry * * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") - * @Cache(maxage="25200", public=true) + * @Cache(maxage="25200", smaxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response */ public function shareEntryAction(Entry $entry) { + if (!$this->get('craue_config')->get('share_public')) { + throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.'); + } + return $this->render( '@WallabagCore/themes/share.html.twig', - array('entry' => $entry) + ['entry' => $entry] ); } - - /** - * @param Entry $entry - */ - private function generateEntryUuid(Entry $entry) - { - $entry->generateUuid(); - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - } } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 67c2bb43..4d7e001b 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -627,7 +627,7 @@ class Entry public function generateUuid() { - if (empty($this->uuid) || is_null($this->uuid)) { + if (null === $this->uuid) { // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter $this->uuid = uniqid('', true); } diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 3b54f057..f9ac28c3 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -709,11 +709,36 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneByUser($this->getLoggedInUserId()); + // no uuid $client->request('GET', '/share/'.$content->getUuid()); - $this->assertContains('max-age=25200, public', $client->getResponse()->headers->get('cache-control')); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + + // generating the uuid + $client->request('GET', '/share/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + // follow link with uuid + $crawler = $client->followRedirect(); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); + $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); + $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); + // sharing is now disabled + $client->getContainer()->get('craue_config')->set('share_public', 0); + $client->request('GET', '/share/'.$content->getUuid()); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/view/'.$content->getId()); $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); + + // removing the share + $client->request('GET', '/share/delete/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + // share is now disable + $client->request('GET', '/share/'.$content->getUuid()); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); } }