Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions inc/AbstractLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ public abstract function getRestrictedCredentials();
*/
public abstract function getUserId();


/**
* Make the repository ready for login with null credentials, handling the
* case where authentication is passed outside the login method.
*
* If the implementation does not support this feature, it must return
* false for this method, otherwise true.
*
* @return boolean true if anonymous login is supposed to work
*/
public abstract function prepareAnonymousLogin();

/**
* @return string the workspace name used for the tests
*/
Expand Down
25 changes: 20 additions & 5 deletions tests/04_Connecting/RepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace PHPCR\Tests\Connecting;

use PHPCR\LoginException;

require_once(__DIR__ . '/../../inc/BaseCase.php');

class RepositoryTest extends \PHPCR\Test\BaseCase
Expand All @@ -23,6 +25,7 @@ public function testLoginSession()
$repository = self::$loader->getRepository();
$session = $repository->login(self::$loader->getCredentials(), self::$loader->getWorkspaceName());
$this->assertInstanceOf('PHPCR\SessionInterface', $session);
$this->assertEquals(self::$loader->getWorkspaceName(), $session->getWorkspace()->getName());
}

public function testDefaultWorkspace()
Expand All @@ -33,17 +36,29 @@ public function testDefaultWorkspace()
$this->assertEquals('default', $session->getWorkspace()->getName());
}

/** external authentication */
/**
* external authentication
*/
public function testNoLogin()
{
$repository = self::$loader->getRepository();
if (! self::$loader->prepareAnonymousLogin()) {
$this->setExpectedException('PHPCR\LoginException');
}
$session = $repository->login(null, self::$loader->getWorkspaceName());
$this->assertInstanceOf('PHPCR\SessionInterface', $session);
$this->assertEquals(self::$loader->getWorkspaceName(), $session->getWorkspace()->getName());
}

/**
* external authentication
*/
public function testNoLoginAndWorkspace()
{
$repository = self::$loader->getRepository();
if (! self::$loader->prepareAnonymousLogin()) {
$this->setExpectedException('PHPCR\LoginException');
}
$session = $repository->login();
$this->assertInstanceOf('PHPCR\SessionInterface', $session);
$this->assertEquals('default', $session->getWorkspace()->getName());
Expand All @@ -55,16 +70,16 @@ public function testNoLoginAndWorkspace()
public function testLoginException()
{
$repository = self::$loader->getRepository();
$session = $repository->login(self::$loader->getInvalidCredentials());
$repository->login(self::$loader->getInvalidCredentials());
}

/**
* @expectedException PHPCR\NoSuchWorkspaceException
* @expectedException \PHPCR\NoSuchWorkspaceException
*/
public function testLoginNoSuchWorkspace()
{
$repository = self::$loader->getRepository();
$session = $repository->login(self::$loader->getCredentials(), 'notexistingworkspace');
$repository->login(self::$loader->getCredentials(), 'notexistingworkspace');
}

/**
Expand All @@ -73,6 +88,6 @@ public function testLoginNoSuchWorkspace()
public function testLoginRepositoryException()
{
$repository = self::$loader->getRepository();
$session = $repository->login(self::$loader->getCredentials(), '//');
$repository->login(self::$loader->getCredentials(), '//');
}
}