-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImplementationLoader.php
167 lines (140 loc) · 4.8 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
<?php
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\Connection;
/**
* Implementation loader for jackalope-doctrine-dbal
*/
class ImplementationLoader extends \PHPCR\Test\AbstractLoader
{
private static $instance = null;
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('Jackalope\RepositoryFactoryDoctrineDBAL', $GLOBALS['phpcr.workspace']);
$this->connection = $connection;
$this->fixturePath = $fixturePath;
$this->unsupportedChapters = array(
'Reading',
'Query',
'Export',
'NodeTypeDiscovery',
'PermissionsAndCapabilities',
'Writing',
'Import',
'Observation',
'WorkspaceManagement',
'AccessControlManagement',
'ShareableNodes',
'Versioning',
'AccessControlManagement',
'Locking',
'LifecycleManagement',
'NodeTypeManagement',
'RetentionAndHold',
'Transactions',
'SameNameSiblings',
'OrderableChildNodes',
);
$this->unsupportedCases = array();
$this->unsupportedTests = array();
if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->unsupportedTests[] = 'Query\\QuerySql2OperationsTest::testQueryRightJoin';
}
}
public function getConnection()
{
return $this->connection;
}
public function getRepositoryFactoryParameters()
{
if (empty($GLOBALS['data_caches'])) {
$caches = null;
} else {
$caches = array();
foreach (explode(',', $GLOBALS['data_caches']) as $key) {
$caches[$key] = new ArrayCache();
}
}
return array(
'jackalope.doctrine_dbal_connection' => $this->connection,
'jackalope.data_caches' => $caches,
\Jackalope\Session::OPTION_AUTO_LASTMODIFIED => false,
'jackalope.logger' => new \Jackalope\Transport\Logging\Psr3Logger(new \Psr\Log\NullLogger()),
);
}
public function getSessionWithLastModified()
{
/** @var $session \Jackalope\Session */
$session = $this->getSession();
$session->setSessionOption(\Jackalope\Session::OPTION_AUTO_LASTMODIFIED, true);
return $session;
}
public function getCredentials()
{
return new \PHPCR\SimpleCredentials($GLOBALS['phpcr.user'], $GLOBALS['phpcr.pass']);
}
public function getInvalidCredentials()
{
return new \PHPCR\SimpleCredentials('nonexistinguser', '');
}
public function getRestrictedCredentials()
{
return new \PHPCR\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 \Jackalope\Transport\Contentful\Client(new \Jackalope\Factory, $this->connection);
foreach (array($GLOBALS['phpcr.workspace'], $this->otherWorkspacename) as $workspace) {
try {
$transport->createWorkspace($workspace);
} catch (\PHPCR\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 \Jackalope\Repository(null, $transport, $this->getRepositoryFactoryParameters());
}
public function getFixtureLoader()
{
$testerClass = '\\Jackalope\\Test\\Tester\\' . ucfirst(strtolower($this->connection->getWrappedConnection()->getAttribute(PDO::ATTR_DRIVER_NAME)));
if (!class_exists($testerClass)) {
// load Generic Tester if no database specific Tester class found
$testerClass = '\\Jackalope\\Test\\Tester\\Generic';
}
return new $testerClass(
new \PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($this->connection->getWrappedConnection(), "tests"),
$this->fixturePath
);
}
}