From: <gem...@li...> - 2012-03-08 15:44:45
|
Revision: 538 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=538&view=rev Author: mennodekker Date: 2012-03-08 15:44:35 +0000 (Thu, 08 Mar 2012) Log Message: ----------- Fixed unit tests, added tests and updated default project.ini also added consentDefault to let a project overrule the global default 'Unknown' Modified Paths: -------------- trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/Util.php trunk/library/classes/GemsEscort.php trunk/new_project/application/configs/project.ini trunk/test/bootstrap.php trunk/test/classes/Gems/UtilTest.php Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/library/classes/Gems/User/User.php 2012-03-08 15:44:35 UTC (rev 538) @@ -601,7 +601,8 @@ if ($menuItem) { // Prevent redirecting to the current page. if (! ($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) { - echo $menuItem->get('label') . '<br/>'; + //Probably a debug statement so commented out MD20120308 + //echo $menuItem->get('label') . '<br/>'; $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoRoute($menuItem->toRouteUrl($request), null, true); Modified: trunk/library/classes/Gems/Util.php =================================================================== --- trunk/library/classes/Gems/Util.php 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/library/classes/Gems/Util.php 2012-03-08 15:44:35 UTC (rev 538) @@ -113,15 +113,33 @@ } + /** + * Retrieve the consentCODE to use for rejected responses by the survey system + * The mapping of actual consents to consentCODEs is done in the gems__consents table + * + * @return string Default value is 'do not use' + * @throws Gems_Exception_Coding + */ public function getConsentRejected() { + if (isset($this->project->consentRejected)) { + return $this->project->consentRejected; + } + if (isset($this->project->concentRejected)) { + throw new Gems_Exception_Coding('project.ini setting was changed from "concentRejected" to "consentRejected", please update your project.ini'); return $this->project->concentRejected; } return 'do not use'; } + /** + * Retrieve the array of possible consentCODEs to use for responses by the survey system + * The mapping of actual consents to consentCODEs is done in the gems__consents table + * + * @return array Default consent codes are 'do not use' and 'consent given' + */ public function getConsentTypes() { if (isset($this->project->consentTypes)) { @@ -172,7 +190,23 @@ } /** + * Get the default user consent * + * This is de consent description from gems__consents, not the consentCODE + * + * @return string + */ + public function getDefaultConsent() + { + if (isset($this->project->consentDefault)) { + return $this->project->consentDefault; + } + + return 'Unkown'; + } + + /** + * * @return Gems_Util_DbLookup */ public function getDbLookup() Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/library/classes/GemsEscort.php 2012-03-08 15:44:35 UTC (rev 538) @@ -1488,9 +1488,6 @@ */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { - // Npow is a good time to check for required values - $this->project->checkRequiredValues(); - $loader = $this->getLoader(); $user = $loader->getCurrentUser(); @@ -1502,6 +1499,10 @@ $this->menu = $loader->createMenu($this); $this->_updateVariable('menu'); + // Now is a good time to check for required values + // Moved down here to prevent unit test from failing on missing salt + $this->project->checkRequiredValues(); + $source = $this->menu->getParameterSource(); $this->getLoader()->getOrganization()->applyToMenuSource($source); Modified: trunk/new_project/application/configs/project.ini =================================================================== --- trunk/new_project/application/configs/project.ini 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/new_project/application/configs/project.ini 2012-03-08 15:44:35 UTC (rev 538) @@ -187,7 +187,7 @@ layoutPrepare.dojo = 0 layoutPrepare.jQuery = 1 -layoutPrepare.login.class = rightFloat +layoutPrepareArgs.login.class = rightFloat ;layoutPrepareArgs.contact.class = rightFloat layoutPrepareArgs.time.class = rightFloat layoutPrepareArgs.user.class = rightFloat @@ -276,6 +276,13 @@ tokens.from = 01; tokens.to = ol; +;--------------------------------------------------------- +; CONSENT SECTION +;--------------------------------------------------------- +consentRejected = 'do not use' +consentTypes = 'do not use|consent given' +consentDefault = 'Unknown' ;Default setup makes this 'do not use' + [testing : production] admin.user = superadmin admin.pwd = superadmin Modified: trunk/test/bootstrap.php =================================================================== --- trunk/test/bootstrap.php 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/test/bootstrap.php 2012-03-08 15:44:35 UTC (rev 538) @@ -42,12 +42,12 @@ * Setup environment */ define('GEMS_WEB_DIR', dirname(__FILE__)); -define('GEMS_ROOT_DIR', '../new_project'); -define('GEMS_LIBRARY_DIR', '../library'); +define('GEMS_ROOT_DIR', realpath(dirname(__FILE__) . '/../new_project')); +define('GEMS_LIBRARY_DIR', realpath(dirname(__FILE__) . '/../library')); define('GEMS_PROJECT_NAME', 'newProject'); define('GEMS_PROJECT_NAME_UC', ucfirst(GEMS_PROJECT_NAME)); define('APPLICATION_ENV', 'testing'); -define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/' . GEMS_ROOT_DIR . '/application')); +define('APPLICATION_PATH', GEMS_ROOT_DIR . '/application'); $GLOBALS['GEMS_DIRS'] = array( GEMS_PROJECT_NAME_UC => APPLICATION_PATH . '/classes', @@ -62,6 +62,7 @@ set_include_path( $path . '/library/classes' . PATH_SEPARATOR . GEMS_ROOT_DIR . '/application/classes' . PATH_SEPARATOR . + GEMS_WEB_DIR . '/classes' . PATH_SEPARATOR . get_include_path()); // Set up autoload. Modified: trunk/test/classes/Gems/UtilTest.php =================================================================== --- trunk/test/classes/Gems/UtilTest.php 2012-03-08 10:40:53 UTC (rev 537) +++ trunk/test/classes/Gems/UtilTest.php 2012-03-08 15:44:35 UTC (rev 538) @@ -1,4 +1,5 @@ <?php +require_once 'IndexControllerTest.php'; /** * Copyright (c) 2011, Erasmus MC @@ -38,6 +39,8 @@ /** * Test class for Gems_Util * + * As this class depends on all sorts of stuff being loaded we extend the IndexControllerTest + * * @author Michiel Rook <mi...@to...> * @package Gems * @subpackage Util @@ -45,32 +48,115 @@ * @license New BSD License * @since Class available since version 1.0 */ -class Gems_UtilTest extends PHPUnit_Framework_TestCase +class Gems_UtilTest extends IndexControllerTest//Zend_Test_PHPUnit_ControllerTestCase { - public function testAllowedIP1() { + /** + * @var Gems_Util + */ + protected $object; + + public function setUp() + { + parent::setUp(); + + //Fix errors in the default config + $this->_fixSetup(); + + //Now load the object we are going to test + $this->object = GemsEscort::getInstance()->loader->getUtil(); + } + + public function testAllowedIP1() + { $this->assertTrue(Gems_Util::isAllowedIP('10.0.0.1', '10.0.0.0-10.0.0.255')); } - public function testAllowedIP2() { + public function testAllowedIP2() + { $this->assertFalse(Gems_Util::isAllowedIP('10.0.1.1', '10.0.0.0-10.0.0.255')); } - public function testAllowedIP3() { + public function testAllowedIP3() + { $this->assertTrue(Gems_Util::isAllowedIP('127.0.0.1', '127.0.0.1')); } - public function testAllowedIP4() { + public function testAllowedIP4() + { $this->assertFalse(Gems_Util::isAllowedIP('127.0.0.1', '192.168.0.1')); } - public function testAllowedIP5() { + public function testAllowedIP5() + { $this->assertTrue(Gems_Util::isAllowedIP('127.0.0.1', '192.168.0.1|127.0.0.1')); } - - public function testAllowedIPEmptyRange() { + + public function testAllowedIPEmptyRange() + { $this->assertTrue(Gems_Util::isAllowedIP('127.0.0.1', '')); } + public function testConsentTypes() + { + //check the ini file to be the default + $expected = array( + 'do not use' => 'do not use', + 'consent given' => 'consent given' + ); + $actual = $this->object->getConsentTypes(); + $this->assertEquals($expected, $actual); + + //Check if we can read from an altered ini file + $project = GemsEscort::getInstance()->project; + $project->consentTypes = 'test|test2|test3'; + $expected = array( + 'test' => 'test', + 'test2' => 'test2', + 'test3' => 'test3', + ); + $actual = $this->object->getConsentTypes(); + $this->assertEquals($expected, $actual); + + //Check for class default when not found in ini + unset($project->consentTypes); + $expected = array( + 'do not use' => 'do not use', + 'consent given' => 'consent given' + ); + $actual = $this->object->getConsentTypes(); + $this->assertEquals($expected, $actual); + } + + public function testConsentRejected() + { + //Check the ini default + $expected = 'do not use'; + $actual = $this->object->getConsentRejected(); + $this->assertEquals($expected, $actual); + + //Check if we can read from an altered ini file + $project = GemsEscort::getInstance()->project; + $expected = 'test'; + $project->consentRejected = $expected; + $actual = $this->object->getConsentRejected(); + $this->assertEquals($expected, $actual); + + //Check for class default when not found in ini + unset($project->consentRejected); + $expected = 'do not use'; + $actual = $this->object->getConsentRejected(); + $this->assertEquals($expected, $actual); + + //Check for incorrect spelling used before 1.5.2 + unset($project->consentRejected); + $project->concentRejected = 'test2'; + try { + $actual = $this->object->getConsentRejected(); + } catch (Exception $e) { + } + $this->assertInstanceOf('Gems_Exception_Coding', $e, 'No failure on misspelled concentRejected in project.ini'); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |