diff --git a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php index 4e7decdcb2cf2bc192a8219f6f3f59462d5f8b14..da179177f1ff5c8bedfd80fc2d4b5685426d113e 100644 --- a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php +++ b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php @@ -94,8 +94,7 @@ class ChoiceAuth extends AbstractBase */ protected function validateConfig() { - if (!isset($this->config->ChoiceAuth) - || !isset($this->config->ChoiceAuth->choice_order) + if (!isset($this->config->ChoiceAuth->choice_order) || !strlen($this->config->ChoiceAuth->choice_order) ) { throw new AuthException( @@ -117,7 +116,7 @@ class ChoiceAuth extends AbstractBase { parent::setConfig($config); $this->strategies = array_map( - 'trim', explode(',', $config->ChoiceAuth->choice_order) + 'trim', explode(',', $this->getConfig()->ChoiceAuth->choice_order) ); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8d05282301e2f381d315af0b0353122c88c3b6f5 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ChoiceAuthTest.php @@ -0,0 +1,128 @@ +<?php +/** + * ChoiceAuth test class. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2011. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +namespace VuFindTest\Auth; +use VuFind\Auth\ChoiceAuth, VuFind\Auth\PluginManager, + VuFind\Db\Row\User as UserRow, Zend\Config\Config; + +/** + * ChoiceAuth test class. + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +class ChoiceAuthTest extends \VuFindTest\Unit\TestCase +{ + /** + * Test config validation + * + * @return void + * @expectedException \VuFind\Exception\Auth + * @expectedExceptionMessage One or more ChoiceAuth parameters are missing. + */ + public function testBadConfiguration() + { + $ca = new ChoiceAuth(); + $ca->setConfig(new Config(array())); + } + + /** + * Test default getPluginManager behavior + * + * @return void + * @expectedException \Exception + * @expectedExceptionMessage Plugin manager missing. + */ + public function testMissingPluginManager() + { + $ca = new ChoiceAuth(); + $ca->getPluginManager(); + } + + /** + * Get a ChoiceAuth object. + * + * @param string $strategies Strategies setting + * + * @return ChoiceAuth + */ + protected function getChoiceAuth($strategies = 'Database,Shibboleth') + { + $ca = new ChoiceAuth(); + $ca->setConfig( + new Config(array('ChoiceAuth' => array('choice_order' => $strategies))) + ); + $ca->setPluginManager($this->getMockPluginManager()); + return $ca; + } + + /** + * Get a mock plugin manager. + * + * @return PluginManager + */ + protected function getMockPluginManager() + { + $pm = new PluginManager(); + $mockDb = $this->getMockBuilder('VuFind\Auth\Database') + ->disableOriginalConstructor() + ->getMock(); + $mockShib = $this->getMockBuilder('VuFind\Auth\Shibboleth') + ->disableOriginalConstructor() + ->getMock(); + $pm->setService('Database', $mockDb); + $pm->setService('Shibboleth', $mockShib); + return $pm; + } + + /** + * Get a mock user object + * + * @return UserRow + */ + protected function getMockUser() + { + return $this->getMockBuilder('VuFind\Db\Row\User') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Get a mock request object + * + * @return \Zend\Http\PhpEnvironment\Request + */ + protected function getMockRequest() + { + return $this->getMockBuilder('Zend\Http\PhpEnvironment\Request') + ->disableOriginalConstructor() + ->getMock(); + } +} \ No newline at end of file