2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* PagesControllerTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5436
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-18 04:34:44 +00:00
|
|
|
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('PagesController', 'Controller');
|
2022-12-31 01:56:11 +00:00
|
|
|
App::uses('CakeRequest', 'Network');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* PagesControllerTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class PagesControllerTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-16 23:52:54 +00:00
|
|
|
* testDisplay method
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDisplay() {
|
2010-01-14 04:35:56 +00:00
|
|
|
App::build(array(
|
2011-03-22 05:16:51 +00:00
|
|
|
'View' => array(
|
2012-03-12 02:20:25 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
|
2011-03-22 05:16:51 +00:00
|
|
|
)
|
2010-01-14 04:35:56 +00:00
|
|
|
));
|
2011-07-03 19:02:46 +00:00
|
|
|
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
2008-10-16 23:52:54 +00:00
|
|
|
|
2011-05-16 21:38:28 +00:00
|
|
|
$Pages->viewPath = 'Posts';
|
2008-10-16 23:52:54 +00:00
|
|
|
$Pages->display('index');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/posts index/', $Pages->response->body());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('index', $Pages->viewVars['page']);
|
2008-10-16 23:52:54 +00:00
|
|
|
|
2011-05-15 04:44:41 +00:00
|
|
|
$Pages->viewPath = 'Themed';
|
|
|
|
$Pages->display('TestTheme', 'Posts', 'index');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/posts index themed view/', $Pages->response->body());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('TestTheme', $Pages->viewVars['page']);
|
|
|
|
$this->assertEquals('Posts', $Pages->viewVars['subpage']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2013-04-21 21:29:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that missing view renders 404 page in production
|
|
|
|
*
|
|
|
|
* @expectedException NotFoundException
|
|
|
|
* @expectedExceptionCode 404
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMissingView() {
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
|
|
|
$Pages->display('non_existing_page');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that missing view in debug mode renders missing_view error page
|
|
|
|
*
|
|
|
|
* @expectedException MissingViewException
|
|
|
|
* @expectedExceptionCode 500
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMissingViewInDebug() {
|
|
|
|
Configure::write('debug', 1);
|
|
|
|
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
|
|
|
$Pages->display('non_existing_page');
|
|
|
|
}
|
2016-11-27 09:03:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test directory traversal protection
|
|
|
|
*
|
|
|
|
* @expectedException ForbiddenException
|
|
|
|
* @expectedExceptionCode 403
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDirectoryTraversalProtection() {
|
|
|
|
App::build(array(
|
|
|
|
'View' => array(
|
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
|
|
|
$Pages->display('..', 'Posts', 'index');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|