diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 13:42:13 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-08-23 16:49:21 +0200 |
commit | a7e2218e253138ed53e18b4775dce291c78246c5 (patch) | |
tree | b42d5a26987149f8372c49ef7f78a63ed81867e3 | |
parent | 222e09f140099f3b1b8f6db1846d35e6810d43a3 (diff) | |
download | wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.gz wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.zst wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.zip |
Add test and fix migration
-rw-r--r-- | app/DoctrineMigrations/Version20160410190541.php | 35 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 3 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 18 |
3 files changed, 51 insertions, 5 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index b30a898c..775dd680 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php | |||
@@ -4,16 +4,43 @@ namespace Application\Migrations; | |||
4 | 4 | ||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | 5 | use Doctrine\DBAL\Migrations\AbstractMigration; |
6 | use Doctrine\DBAL\Schema\Schema; | 6 | use Doctrine\DBAL\Schema\Schema; |
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | 10 | ||
8 | class Version20160410190541 extends AbstractMigration | 11 | class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface |
9 | { | 12 | { |
10 | /** | 13 | /** |
14 | * @var ContainerInterface | ||
15 | */ | ||
16 | private $container; | ||
17 | |||
18 | public function setContainer(ContainerInterface $container = null) | ||
19 | { | ||
20 | $this->container = $container; | ||
21 | } | ||
22 | |||
23 | /** | ||
11 | * @param Schema $schema | 24 | * @param Schema $schema |
12 | */ | 25 | */ |
13 | public function up(Schema $schema) | 26 | public function up(Schema $schema) |
14 | { | 27 | { |
15 | $this->addSql('ALTER TABLE wallabag_entry ADD uuid LONGTEXT DEFAULT NULL'); | 28 | $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); |
16 | $this->addSql('UPDATE wallabag_entry SET uuid = uuid()'); | 29 | |
30 | $em = $this->container->get('doctrine.orm.entity_manager'); | ||
31 | $queryBuilder = $this->connection->createQueryBuilder(); | ||
32 | $queryBuilder | ||
33 | ->select('e.uuid') | ||
34 | ->andWhere('e.uuid IS NULL'); | ||
35 | $entries = $queryBuilder->execute(); | ||
36 | |||
37 | /** @var Entry $entry */ | ||
38 | foreach ($entries as $entry) { | ||
39 | $entry->generateUuid(); | ||
40 | $em->persist($entry); | ||
41 | $em->clear(); | ||
42 | } | ||
43 | $em->flush(); | ||
17 | } | 44 | } |
18 | 45 | ||
19 | /** | 46 | /** |
@@ -21,6 +48,6 @@ class Version20160410190541 extends AbstractMigration | |||
21 | */ | 48 | */ |
22 | public function down(Schema $schema) | 49 | public function down(Schema $schema) |
23 | { | 50 | { |
24 | $this->addSql('ALTER TABLE `wallabag_entry` DROP uuid'); | 51 | $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); |
25 | } | 52 | } |
26 | } | 53 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 3c742828..a629efc7 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -630,7 +630,8 @@ class Entry | |||
630 | public function generateUuid() | 630 | public function generateUuid() |
631 | { | 631 | { |
632 | if (empty($this->uuid) || is_null($this->uuid)) { | 632 | if (empty($this->uuid) || is_null($this->uuid)) { |
633 | $this->uuid = uniqid(); | 633 | // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter |
634 | $this->uuid = uniqid('', true); | ||
634 | } | 635 | } |
635 | } | 636 | } |
636 | } | 637 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 5c739c78..3b54f057 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -698,4 +698,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
698 | $crawler = $client->submit($form, $data); | 698 | $crawler = $client->submit($form, $data); |
699 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 699 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
700 | } | 700 | } |
701 | |||
702 | public function testCache() | ||
703 | { | ||
704 | $this->logInAs('admin'); | ||
705 | $client = $this->getClient(); | ||
706 | |||
707 | $content = $client->getContainer() | ||
708 | ->get('doctrine.orm.entity_manager') | ||
709 | ->getRepository('WallabagCoreBundle:Entry') | ||
710 | ->findOneByUser($this->getLoggedInUserId()); | ||
711 | |||
712 | $client->request('GET', '/share/'.$content->getUuid()); | ||
713 | $this->assertContains('max-age=25200, public', $client->getResponse()->headers->get('cache-control')); | ||
714 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
715 | |||
716 | $client->request('GET', '/view/'.$content->getId()); | ||
717 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
718 | } | ||
701 | } | 719 | } |