Source for file FrontController_Test.php
Documentation is available at FrontController_Test.php
require_once $config->get('sysRoot'). 'alpha/controller/front/FrontController.inc';
require_once $config->get('sysRoot'). 'alpha/util/filters/ClientBlacklistFilter.inc';
* Test cases for the AlphaController class.
* @author John Collins <dev@alphaframework.org>
* @version $Id: FrontController_Test.php 1453 2011-12-04 15:12:54Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* A controller token to test with
* @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::setUp()
protected function setUp() {
$this->token = $_GET['tk'];
* @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::tearDown()
$_GET['tk'] = $this->token;
* Testing that the constructor will detect the page controller action we want to invoke from the global _GET array
$_GET['act'] = 'ViewArticle';
$this->assertEquals('ViewArticle', $front->getPageController(), 'testing that the constructor will detect the page controller action we want to invoke from the global _GET array');
* Testing that the constructor can parse the correct page controller action from a mod_rewrite style URL
$request = $config->get('sysURL'). 'ViewArticleTitle/title/Test_Title';
$_SERVER['REQUEST_URI'] = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $request);
$this->assertEquals('ViewArticleTitle', $front->getPageController(), 'testing that the constructor can parse the correct page controller action from a mod_rewrite style URL');
* Testing that the constructor can parse the correct page controller action from a mod_rewrite style URL when a controller alias is used
$request = $config->get('sysURL'). 'article/Test_Title';
$_SERVER['REQUEST_URI'] = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $request);
$front->registerAlias('ViewArticleTitle','article','title');
$this->assertEquals('ViewArticleTitle', $front->getPageController(), 'testing that the constructor can parse the correct page controller action from a mod_rewrite style URL when a controller alias is used');
* Testing that the constructor can parse the correct page controller action from an encrypted token param
$params = 'act=ViewArticleTitle&title=Test_Title';
$this->assertEquals('ViewArticleTitle', $front->getPageController(), 'testing that the constructor can parse the correct page controller action from an encrypted token param');
* Testing that the constructor can parse the correct page controller action from an encrypted token param provided on a mod-rewrite style URL
$params = 'act=ViewArticleTitle&title=Test_Title';
$_SERVER['REQUEST_URI'] = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $request);
$this->assertEquals('ViewArticleTitle', $front->getPageController(), 'testing that the constructor can parse the correct page controller action from an encrypted token param provided on a mod-rewrite style URL');
* Testing the encodeQuery method with a known encrypted result for a test key
$oldKey = $config->get('sysQSKey');
$config->set('sysQSKey', 'testkey');
$params = 'act=ViewArticleTitle&title=Test_Title';
$this->assertEquals(FrontController::encodeQuery($params), '8kqoeebEej0V-FN5-DOdA1HBDDieFcNWTib2yLSUNjq0B0FWzAupIA==', 'testing the encodeQuery method with a known encrypted result for a test key');
$config->set('sysQSKey', $oldKey);
* Testing the decodeQueryParams method with a known encrypted result for a test key
$oldKey = $config->get('sysQSKey');
$config->set('sysQSKey', 'testkey');
$tk = '8kqoeebEej0V-FN5-DOdA1HBDDieFcNWTib2yLSUNjq0B0FWzAupIA==';
$this->assertEquals('act=ViewArticleTitle&title=Test_Title', FrontController::decodeQueryParams($tk), 'testing the decodeQueryParams method with a known encrypted result for a test key');
* Testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key
$oldKey = $config->get('sysQSKey');
$config->set('sysQSKey', 'testkey');
$tk = '8kqoeebEej0V-FN5-DOdA1HBDDieFcNWTib2yLSUNjq0B0FWzAupIA==';
$this->assertEquals('ViewArticleTitle', $decoded['act'], 'testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key');
$this->assertEquals('Test_Title', $decoded['title'], 'testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key');
* Testing that a request to a bad URL will result in a ResourceNotFoundException exception
$request = $config->get('sysURL'). 'doesNotExists';
$_SERVER['REQUEST_URI'] = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $request);
$front->loadController(false);
$this->fail('testing that a request to a bad URL will result in a ResourceNotFoundException exception');
$this->assertTrue($e->getMessage() != '', 'testing that a request to a bad URL will result in a ResourceNotFoundException exception');
* Testing the setting up and checking for the existence of a controller alias
$front->registerAlias('ViewArticleTitle','article','title');
$this->assertTrue($front->hasAlias('ViewArticleTitle'), 'testing the setting up and checking for the existence of a controller alias');
$this->assertTrue($front->checkAlias('article'), 'testing the setting up and checking for the existence of a controller alias');
$this->assertEquals('ViewArticleTitle', $front->getAliasController('article'),
'testing the setting up and checking for the existence of a controller alias');
$this->assertEquals('article', $front->getControllerAlias('ViewArticleTitle'),
'testing the setting up and checking for the existence of a controller alias');
* Testing the accessing of the expected param for a given alias/controller
$front->registerAlias('ViewArticleTitle','article','title');
$this->assertEquals('title', $front->getAliasParam('article'), 'testing the accessing of the expected param for a given alias/controller');
$this->assertEquals('title', $front->getControllerParam('ViewArticleTitle'), 'testing the accessing of the expected param for a given alias/controller');
* Testing the registerFilter method with a valid filter object
foreach ($front->getFilters() as $filter) {
$this->assertTrue($found, 'testing the registerFilter method with a valid filter object');
$this->fail('testing the registerFilter method with a valid filter object');
* Testing the registerFilter method with a bad filter object
$this->fail('testing the registerFilter method with a bad filter object');
$this->assertEquals('Supplied filter object is not a valid AlphaFilterInterface instance!', $e->getMessage(), 'testing the registerFilter method with a bad filter object');
|