-
Notifications
You must be signed in to change notification settings - Fork 60
/
ImplementationLoader.php
217 lines (182 loc) · 8.09 KB
/
ImplementationLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Jackalope\Factory;
use Jackalope\Repository;
use Jackalope\RepositoryFactoryDoctrineDBAL;
use Jackalope\Session;
use Jackalope\Tests\Test\Tester\Generic;
use Jackalope\Tests\Test\Tester\Mysql;
use Jackalope\Tests\Test\Tester\Pgsql;
use Jackalope\Transport\DoctrineDBAL\Client;
use Jackalope\Transport\Logging\Psr3Logger;
use PHPCR\RepositoryException;
use PHPCR\SimpleCredentials;
use PHPCR\Test\AbstractLoader;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Psr16Cache;
/**
* Implementation loader for jackalope-doctrine-dbal.
*/
class ImplementationLoader extends AbstractLoader
{
private static $instance;
public static function getInstance()
{
if (null === self::$instance) {
global $dbConn;
$fixturePath = realpath(__DIR__.'/fixtures/doctrine');
self::$instance = new ImplementationLoader($dbConn, $fixturePath);
}
return self::$instance;
}
/**
* @var Connection
*/
private $connection;
/**
* @var string
*/
private $fixturePath;
protected function __construct(Connection $connection, $fixturePath)
{
parent::__construct(RepositoryFactoryDoctrineDBAL::class, $GLOBALS['phpcr.workspace']);
$this->connection = $connection;
$this->fixturePath = $fixturePath;
$this->unsupportedChapters = [
'ShareableNodes', // TODO: Not implemented, no test currently written for it
'AccessControlManagement', // TODO: Not implemented, no test currently written for it
'LifecycleManagement', // TODO: Not implemented, no test currently written for it
'RetentionAndHold', // TODO: Not implemented, no test currently written for it
'SameNameSiblings', // TODO: Not implemented, no test currently written for it
'PermissionsAndCapabilities', // TODO: Transport does not support permissions
'Observation', // TODO: Transport does not support observation
'Versioning', // TODO: Transport does not support versioning
'Locking', // TODO: Transport does not support locking
];
$this->unsupportedCases = [
'Query\\XPath', // Query language 'xpath' not implemented.
'Query\\Sql1', // Query language 'sql' is legacy and only makes sense with jackrabbit
'Writing\\CloneMethodsTest', // TODO: Support for workspace->clone, node->update, node->getCorrespondingNodePath
];
$this->unsupportedTests = [
'Connecting\\RepositoryTest::testLoginException', // TODO: figure out what would be invalid credentials
'Reading\\NodeReadMethodsTest::testGetSharedSetUnreferenced', // TODO: should this be moved to 14_ShareableNodes
'Reading\\SessionReadMethodsTest::testImpersonate', // TODO: Check if that's implemented in newer jackrabbit versions.
'Reading\\SessionNamespaceRemappingTest::testSetNamespacePrefix', // TODO: implement session scope remapping of namespaces
// TODO: implement getQuery method in Jackalope QueryManager
'Query\\QueryManagerTest::testGetQuery',
'Query\\QueryManagerTest::testGetQueryInvalid',
'Query\\QueryObjectSql2Test::testGetStoredQueryPath',
// TODO: implement CAST, see also https://github.com/jackalope/jackalope-doctrine-dbal/issues/267
'Query\QuerySql2OperationsTest::testQueryFieldDate',
// TODO fix handling of order by with missing properties
'Query\QuerySql2OperationsTest::testQueryOrderWithMissingProperty',
// this seems a bug in php with arrayiterator - and jackalope is using
// arrayiterator for the search result
// TODO https://github.com/phpcr/phpcr-api-tests/issues/22
'Query\\NodeViewTest::testSeekable',
'Writing\\CopyMethodsTest::testCopyUpdateOnCopy', // TODO: update-on-copy is currently not supported
// TODO: https://github.com/jackalope/jackalope-doctrine-dbal/issues/22
'Transactions\\TransactionMethodsTest::testTransactionCommit',
// TODO: implement creating workspace with source
'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithSource',
'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithInvalidSource',
];
if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->unsupportedTests[] = 'Query\\QuerySql2OperationsTest::testQueryRightJoin';
// there is some problem with whiping the sqlite database to test the imports
$this->unsupportedTests[] = 'Import\\ImportRepositoryContentTest::testImportXMLUuidRemoveExistingSession';
$this->unsupportedTests[] = 'Import\\ImportRepositoryContentTest::testImportXMLUuidRemoveExistingWorkspace';
$this->unsupportedTests[] = 'Import\\ImportRepositoryContentTest::testImportXMLUuidReplaceExistingSession';
$this->unsupportedTests[] = 'Import\\ImportRepositoryContentTest::testImportXMLUuidReplaceExistingWorkspace';
}
}
public function getConnection()
{
return $this->connection;
}
public function getRepositoryFactoryParameters()
{
if (empty($GLOBALS['data_caches'])) {
$caches = null;
} else {
$caches = [];
foreach (explode(',', $GLOBALS['data_caches']) as $key) {
$caches[$key] = new Psr16Cache(new ArrayAdapter());
}
}
return [
'jackalope.doctrine_dbal_connection' => $this->connection,
'jackalope.data_caches' => $caches,
Session::OPTION_AUTO_LASTMODIFIED => false,
'jackalope.logger' => new Psr3Logger(new NullLogger()),
];
}
public function getSessionWithLastModified()
{
$session = $this->getSession();
\assert($session instanceof Session);
$session->setSessionOption(Session::OPTION_AUTO_LASTMODIFIED, true);
return $session;
}
public function getCredentials()
{
return new SimpleCredentials($GLOBALS['phpcr.user'], $GLOBALS['phpcr.pass']);
}
public function getInvalidCredentials()
{
return new SimpleCredentials('nonexistinguser', '');
}
public function getRestrictedCredentials()
{
return new SimpleCredentials('anonymous', 'abc');
}
/**
* Doctrine dbal supports anonymous login.
*
* @return bool true
*/
public function prepareAnonymousLogin()
{
return true;
}
public function getUserId()
{
return $GLOBALS['phpcr.user'];
}
public function getRepository()
{
$transport = new Client(new Factory(), $this->connection);
foreach ([$GLOBALS['phpcr.workspace'], $this->otherWorkspacename] as $workspace) {
try {
$transport->createWorkspace($workspace);
} catch (RepositoryException $e) {
if ($e->getMessage() !== "Workspace '$workspace' already exists") {
// if the message is not that the workspace already exists, something went really wrong
throw $e;
}
}
}
return new Repository(null, $transport, $this->getRepositoryFactoryParameters());
}
public function getFixtureLoader()
{
$platform = $this->connection->getDatabasePlatform();
switch ($platform) {
case $platform instanceof MySQLPlatform:
$testerClass = Mysql::class;
break;
case $platform instanceof PostgreSQL94Platform || $platform instanceof PostgreSQLPlatform:
$testerClass = Pgsql::class;
break;
default:
$testerClass = Generic::class;
break;
}
return new $testerClass($this->connection, $this->fixturePath);
}
}