aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests/Subscriber
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-11-09 16:31:59 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-11-09 16:31:59 +0100
commitf1eccfd63f214dcc730ab0d18a694a5465f425db (patch)
treee6cbd355f3a360e5619821fb1415ee26a01f11ce /src/Wallabag/CoreBundle/Tests/Subscriber
parent4529d0f4b6b20cbbd1ccb5339a753aff7d35552b (diff)
parent53cf5106891fc64f3f66cb6b3316654a9620239c (diff)
downloadwallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.tar.gz
wallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.tar.zst
wallabag-f1eccfd63f214dcc730ab0d18a694a5465f425db.zip
Merge pull request #1500 from wallabag/v2-quote-pgsql
Fix quote strategy for reserved keyword in Postgres
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Subscriber')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php
new file mode 100644
index 00000000..a26ff436
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php
@@ -0,0 +1,114 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Subscriber;
4
5use Doctrine\ORM\Mapping\ClassMetadata;
6use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7use Doctrine\Common\EventManager;
8use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber;
9
10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase
11{
12 public function dataForPrefix()
13 {
14 return array(
15 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
16 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '`wallabag_user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
17 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
18
19 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
20 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
21 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
22
23 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
24 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '`user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
25 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
26
27 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
28 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
29 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
30 );
31 }
32
33 /**
34 * @dataProvider dataForPrefix
35 */
36 public function testPrefix($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform)
37 {
38 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
39 ->disableOriginalConstructor()
40 ->getMock();
41
42 $subscriber = new TablePrefixSubscriber($prefix);
43
44 $metaClass = new ClassMetadata($entityName);
45 $metaClass->setPrimaryTable(array('name' => $tableName));
46
47 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
48
49 $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName());
50
51 $subscriber->loadClassMetadata($metaDataEvent);
52
53 $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName());
54 $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform));
55 }
56
57 /**
58 * @dataProvider dataForPrefix
59 */
60 public function testSubscribedEvents($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform)
61 {
62 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
63 ->disableOriginalConstructor()
64 ->getMock();
65
66 $metaClass = new ClassMetadata($entityName);
67 $metaClass->setPrimaryTable(array('name' => $tableName));
68
69 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
70
71 $subscriber = new TablePrefixSubscriber($prefix);
72
73 $evm = new EventManager();
74 $evm->addEventSubscriber($subscriber);
75
76 $evm->dispatchEvent('loadClassMetadata', $metaDataEvent);
77
78 $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName());
79 $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform));
80 }
81
82 public function testPrefixManyToMany()
83 {
84 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
85 ->disableOriginalConstructor()
86 ->getMock();
87
88 $subscriber = new TablePrefixSubscriber('yo_');
89
90 $metaClass = new ClassMetadata('Wallabag\UserBundle\Entity\Entry');
91 $metaClass->setPrimaryTable(array('name' => 'entry'));
92 $metaClass->mapManyToMany(array(
93 'fieldName' => 'tags',
94 'joinTable' => array('name' => null, 'schema' => null),
95 'targetEntity' => 'Tag',
96 'mappedBy' => null,
97 'inversedBy' => 'entries',
98 'cascade' => array('persist'),
99 'indexBy' => null,
100 'orphanRemoval' => false,
101 'fetch' => 2,
102 ));
103
104 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
105
106 $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName());
107
108 $subscriber->loadClassMetadata($metaDataEvent);
109
110 $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName());
111 $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']);
112 $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform()));
113 }
114}