Skip to content

Commit c4ba5a2

Browse files
committed
properly testing login with null credentials
1 parent fb36bdc commit c4ba5a2

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

inc/AbstractLoader.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public abstract function getRestrictedCredentials();
113113
*/
114114
public abstract function getUserId();
115115

116+
117+
/**
118+
* Make the repository ready for login with null credentials, handling the
119+
* case where authentication is passed outside the login method.
120+
*
121+
* If the implementation does not support this feature, it must return
122+
* false for this method, otherwise true.
123+
*
124+
* @return boolean true if anonymous login is supposed to work
125+
*/
126+
public abstract function prepareAnonymousLogin();
127+
116128
/**
117129
* @return string the workspace name used for the tests
118130
*/

tests/04_Connecting/RepositoryTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace PHPCR\Tests\Connecting;
33

4+
use PHPCR\LoginException;
5+
46
require_once(__DIR__ . '/../../inc/BaseCase.php');
57

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

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

36-
/** external authentication */
39+
/**
40+
* external authentication
41+
*/
3742
public function testNoLogin()
3843
{
3944
$repository = self::$loader->getRepository();
45+
if (! self::$loader->prepareAnonymousLogin()) {
46+
$this->setExpectedException('PHPCR\LoginException');
47+
}
4048
$session = $repository->login(null, self::$loader->getWorkspaceName());
4149
$this->assertInstanceOf('PHPCR\SessionInterface', $session);
50+
$this->assertEquals(self::$loader->getWorkspaceName(), $session->getWorkspace()->getName());
4251
}
4352

53+
/**
54+
* external authentication
55+
*/
4456
public function testNoLoginAndWorkspace()
4557
{
4658
$repository = self::$loader->getRepository();
59+
if (! self::$loader->prepareAnonymousLogin()) {
60+
$this->setExpectedException('PHPCR\LoginException');
61+
}
4762
$session = $repository->login();
4863
$this->assertInstanceOf('PHPCR\SessionInterface', $session);
4964
$this->assertEquals('default', $session->getWorkspace()->getName());
@@ -55,16 +70,16 @@ public function testNoLoginAndWorkspace()
5570
public function testLoginException()
5671
{
5772
$repository = self::$loader->getRepository();
58-
$session = $repository->login(self::$loader->getInvalidCredentials());
73+
$repository->login(self::$loader->getInvalidCredentials());
5974
}
6075

6176
/**
62-
* @expectedException PHPCR\NoSuchWorkspaceException
77+
* @expectedException \PHPCR\NoSuchWorkspaceException
6378
*/
6479
public function testLoginNoSuchWorkspace()
6580
{
6681
$repository = self::$loader->getRepository();
67-
$session = $repository->login(self::$loader->getCredentials(), 'notexistingworkspace');
82+
$repository->login(self::$loader->getCredentials(), 'notexistingworkspace');
6883
}
6984

7085
/**
@@ -73,6 +88,6 @@ public function testLoginNoSuchWorkspace()
7388
public function testLoginRepositoryException()
7489
{
7590
$repository = self::$loader->getRepository();
76-
$session = $repository->login(self::$loader->getCredentials(), '//');
91+
$repository->login(self::$loader->getCredentials(), '//');
7792
}
7893
}

0 commit comments

Comments
 (0)