aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-10-25 15:55:19 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-11-07 14:15:33 +0100
commit735068d1814a4b7a688e1d19cd17b13e8c5da3eb (patch)
tree2f97dd9e9e11fa481c80273827f953b02c76b888 /src/Wallabag/CoreBundle/Tests
parentbd0f3d32c9ccb8f7a1409edb960b909a5e6a096d (diff)
downloadwallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.tar.gz
wallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.tar.zst
wallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.zip
Add tests on TablePrefixSubscriber
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php115
1 files changed, 115 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..4c138610
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Subscriber/TablePrefixSubscriberTest.php
@@ -0,0 +1,115 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Subscriber;
4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Doctrine\ORM\Mapping\ClassMetadata;
7use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
8use Doctrine\Common\EventManager;
9use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber;
10
11class TablePrefixSubscriberTest extends KernelTestCase
12{
13 public function dataForPrefix()
14 {
15 return array(
16 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
17 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '`wallabag_user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
18 array('wallabag_', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'wallabag_user', '"wallabag_user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
19
20 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
21 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
22 array('wallabag_', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'wallabag_user', 'wallabag_user', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
23
24 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
25 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '`user`', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
26 array('', 'Wallabag\UserBundle\Entity\User', '`user`', 'user', 'user', '"user"', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
27
28 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\PostgreSqlPlatform()),
29 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\MySqlPlatform()),
30 array('', 'Wallabag\UserBundle\Entity\User', 'user', 'user', 'user', 'user', new \Doctrine\DBAL\Platforms\SqlitePlatform()),
31 );
32 }
33
34 /**
35 * @dataProvider dataForPrefix
36 */
37 public function testPrefix($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform)
38 {
39 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
40 ->disableOriginalConstructor()
41 ->getMock();
42
43 $subscriber = new TablePrefixSubscriber($prefix);
44
45 $metaClass = new ClassMetadata($entityName);
46 $metaClass->setPrimaryTable(array('name' => $tableName));
47
48 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
49
50 $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName());
51
52 $subscriber->loadClassMetadata($metaDataEvent);
53
54 $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName());
55 $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform));
56 }
57
58 /**
59 * @dataProvider dataForPrefix
60 */
61 public function testSubscribedEvents($prefix, $entityName, $tableName, $tableNameExpected, $finalTableName, $finalTableNameQuoted, $platform)
62 {
63 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
64 ->disableOriginalConstructor()
65 ->getMock();
66
67 $metaClass = new ClassMetadata($entityName);
68 $metaClass->setPrimaryTable(array('name' => $tableName));
69
70 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
71
72 $subscriber = new TablePrefixSubscriber($prefix);
73
74 $evm = new EventManager();
75 $evm->addEventSubscriber($subscriber);
76
77 $evm->dispatchEvent('loadClassMetadata', $metaDataEvent);
78
79 $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName());
80 $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform));
81 }
82
83 public function testPrefixManyToMany()
84 {
85 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
86 ->disableOriginalConstructor()
87 ->getMock();
88
89 $subscriber = new TablePrefixSubscriber('yo_');
90
91 $metaClass = new ClassMetadata('Wallabag\UserBundle\Entity\Entry');
92 $metaClass->setPrimaryTable(array('name' => 'entry'));
93 $metaClass->mapManyToMany(array(
94 'fieldName' => 'tags',
95 'joinTable' => array('name' => null, 'schema' => null),
96 'targetEntity' => 'Tag',
97 'mappedBy' => null,
98 'inversedBy' => 'entries',
99 'cascade' => array('persist'),
100 'indexBy' => null,
101 'orphanRemoval' => false,
102 'fetch' => 2,
103 ));
104
105 $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
106
107 $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName());
108
109 $subscriber->loadClassMetadata($metaDataEvent);
110
111 $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName());
112 $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']);
113 $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform()));
114 }
115}