Skip to content

Commit 29f2091

Browse files
committed
have workspace option for import, use that in clone methods test. try to create missing workspaces
1 parent 0cb8087 commit 29f2091

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

inc/AbstractLoader.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPCR\Test;
44

5+
use PHPCR\NoSuchWorkspaceException;
56
use PHPCR\RepositoryFactoryInterface;
67

78
/**
@@ -204,6 +205,20 @@ private function getSessionForWorkspace($credentials, $workspaceName)
204205
$credentials = $this->getCredentials();
205206
}
206207

207-
return $repository->login($credentials, $workspaceName);
208+
try {
209+
return $repository->login($credentials, $workspaceName);
210+
} catch (NoSuchWorkspaceException $e) {
211+
$adminRepository = $this->getRepository(); // get a new repository to log into
212+
$session = $adminRepository->login($this->getCredentials(), 'default');
213+
$workspace = $session->getWorkspace();
214+
if (in_array($workspaceName, $workspace->getAccessibleWorkspaceNames())) {
215+
throw new \Exception("Failed to log into $workspaceName");
216+
}
217+
$workspace->createWorkspace($workspaceName);
218+
219+
$repository = $this->getRepository(); // get a new repository to log into
220+
221+
return $repository->login($credentials, $workspaceName);
222+
}
208223
}
209224
}

inc/FixtureLoaderInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ interface FixtureLoaderInterface
1616
* Default fixtures in the jcr system view format live folder fixtures/
1717
*
1818
* @param string $fixture the fixtures "name", i.e. "general/base"
19+
* @param string $workspaceKey the config key for the target workspace, optional
20+
*
1921
* @return void
2022
*/
21-
public function import($fixture);
23+
public function import($fixture, $workspaceKey = 'workspace');
2224
}

tests/10_Writing/CloneMethodsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static public function setupBeforeClass($fixtures = '10_Writing/clone')
2727
{
2828
parent::setupBeforeClass($fixtures);
2929

30+
self::$staticSharedFixture['ie']->import('general/additionalWorkspace', 'additionalWorkspace');
31+
3032
self::$destWs = self::$staticSharedFixture['additionalSession']->getWorkspace();
3133
self::$destWsName = self::$destWs->getName();
3234

0 commit comments

Comments
 (0)