From c4ba5a27d6aa84917646e43c2cbca931836e4dfe Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 12 Mar 2013 21:46:45 +0100 Subject: [PATCH] properly testing login with null credentials --- inc/AbstractLoader.php | 12 ++++++++++++ tests/04_Connecting/RepositoryTest.php | 25 ++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/inc/AbstractLoader.php b/inc/AbstractLoader.php index 4ffd6e0d..d9e5fd20 100644 --- a/inc/AbstractLoader.php +++ b/inc/AbstractLoader.php @@ -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 */ diff --git a/tests/04_Connecting/RepositoryTest.php b/tests/04_Connecting/RepositoryTest.php index af6ba8d7..04edd796 100644 --- a/tests/04_Connecting/RepositoryTest.php +++ b/tests/04_Connecting/RepositoryTest.php @@ -1,6 +1,8 @@ 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() @@ -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()); @@ -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'); } /** @@ -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(), '//'); } }