Skip to content
Snippets Groups Projects
Commit f285760c authored by Demian Katz's avatar Demian Katz
Browse files

More tests.

parent d51c3512
No related merge requests found
...@@ -79,6 +79,17 @@ class ManagerTest extends \VuFindTest\Unit\TestCase ...@@ -79,6 +79,17 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
$config = array('Authentication' => array('method' => 'ChoiceAuth')); $config = array('Authentication' => array('method' => 'ChoiceAuth'));
$manager = $this->getManager($config); $manager = $this->getManager($config);
$this->assertEquals(array('Database', 'Shibboleth'), $manager->getSelectableAuthOptions()); $this->assertEquals(array('Database', 'Shibboleth'), $manager->getSelectableAuthOptions());
// Advanced case -- ChoiceAuth's getSelectableAuthOptions returns false.
$pm = $this->getMockPluginManager();
$mockChoice = $this->getMockBuilder('VuFind\Auth\ChoiceAuth')
->disableOriginalConstructor()
->getMock();
$mockChoice->expects($this->any())->method('getSelectableAuthOptions')->will($this->returnValue(false));
$pm->setService('ChoiceAuth2', $mockChoice);
$config = array('Authentication' => array('method' => 'ChoiceAuth2'));
$manager = $this->getManager($config, null, null, $pm);
$this->assertEquals(array('ChoiceAuth2'), $manager->getSelectableAuthOptions());
} }
/** /**
...@@ -362,7 +373,7 @@ class ManagerTest extends \VuFindTest\Unit\TestCase ...@@ -362,7 +373,7 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
*/ */
public function testUnanticipatedException() public function testUnanticipatedException()
{ {
$e = new \Exception('What happened here?'); $e = new \Exception('It is normal to see this in the error log during testing...');
$request = $this->getMockRequest(); $request = $this->getMockRequest();
$pm = $this->getMockPluginManager(); $pm = $this->getMockPluginManager();
$db = $pm->get('Database'); $db = $pm->get('Database');
...@@ -410,6 +421,24 @@ class ManagerTest extends \VuFindTest\Unit\TestCase ...@@ -410,6 +421,24 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
$this->assertTrue($manager->checkForExpiredCredentials()); $this->assertTrue($manager->checkForExpiredCredentials());
} }
/**
* Test the persistence of a user account in the session.
*
* @return void
*/
public function testUserLoginFromSession()
{
$table = $this->getMockUserTable();
$user = $this->getMockUser();
$userArray = new \ArrayObject();
$userArray->append($user);
$table->expects($this->once())->method('select')->with($this->equalTo(array('id' => 'foo')))->will($this->returnValue($userArray->getIterator()));
$manager = $this->getManager(array(), $table);
$session = $this->getProperty($manager, 'session');
$session->userId = 'foo';
$this->assertEquals($user, $manager->isLoggedIn());
}
/** /**
* Get a manager object to test with. * Get a manager object to test with.
* *
...@@ -424,9 +453,7 @@ class ManagerTest extends \VuFindTest\Unit\TestCase ...@@ -424,9 +453,7 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
{ {
$config = new Config($config); $config = new Config($config);
if (null === $userTable) { if (null === $userTable) {
$userTable = $this->getMockBuilder('VuFind\Db\Table\User') $userTable = $this->getMockUserTable();
->disableOriginalConstructor()
->getMock();
} }
if (null === $sessionManager) { if (null === $sessionManager) {
$sessionManager = $this->getMockSessionManager(); $sessionManager = $this->getMockSessionManager();
...@@ -437,6 +464,18 @@ class ManagerTest extends \VuFindTest\Unit\TestCase ...@@ -437,6 +464,18 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
return new Manager($config, $userTable, $sessionManager, $pm); return new Manager($config, $userTable, $sessionManager, $pm);
} }
/**
* Get a mock user table.
*
* @return UserTable
*/
protected function getMockUserTable()
{
return $this->getMockBuilder('VuFind\Db\Table\User')
->disableOriginalConstructor()
->getMock();
}
/** /**
* Get a mock session manager. * Get a mock session manager.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment