2015-03-06 23:37:06 +01:00
|
|
|
<?php
|
2014-08-06 06:29:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: the running of this test is handled by the thing it's testing (DevelopmentAdmin controller).
|
2015-03-06 23:37:06 +01:00
|
|
|
*
|
2014-08-06 06:29:52 +02:00
|
|
|
* @package framework
|
|
|
|
* @package tests
|
|
|
|
*/
|
|
|
|
class DevAdminControllerTest extends FunctionalTest {
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
public function setUp(){
|
|
|
|
parent::setUp();
|
|
|
|
|
2015-03-06 23:37:06 +01:00
|
|
|
Config::inst()->update('DevelopmentAdmin', 'registered_controllers', array(
|
2014-08-06 06:29:52 +02:00
|
|
|
'x1' => array(
|
|
|
|
'controller' => 'DevAdminControllerTest_Controller1',
|
|
|
|
'links' => array(
|
|
|
|
'x1' => 'x1 link description',
|
|
|
|
'x1/y1' => 'x1/y1 link description'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'x2' => array(
|
|
|
|
'controller' => 'DevAdminControllerTest_Controller2', // intentionally not a class that exists
|
|
|
|
'links' => array(
|
|
|
|
'x2' => 'x2 link description'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
public function testGoodRegisteredControllerOutput(){
|
2015-03-06 23:37:06 +01:00
|
|
|
// Check for the controller running from the registered url above
|
2014-08-06 06:29:52 +02:00
|
|
|
// (we use contains rather than equals because sometimes you get Warning: You probably want to define an entry in $_FILE_TO_URL_MAPPING)
|
|
|
|
$this->assertContains(DevAdminControllerTest_Controller1::OK_MSG, $this->getCapture('/dev/x1'));
|
|
|
|
$this->assertContains(DevAdminControllerTest_Controller1::OK_MSG, $this->getCapture('/dev/x1/y1'));
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
public function testGoodRegisteredControllerStatus(){
|
|
|
|
// Check response code is 200/OK
|
|
|
|
$this->assertEquals(false, $this->getAndCheckForError('/dev/x1'));
|
|
|
|
$this->assertEquals(false, $this->getAndCheckForError('/dev/x1/y1'));
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
// Check response code is 500/ some sort of error
|
|
|
|
$this->assertEquals(true, $this->getAndCheckForError('/dev/x2'));
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
protected function getCapture($url){
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
ob_start();
|
|
|
|
$this->get($url);
|
|
|
|
$r = ob_get_contents();
|
|
|
|
ob_end_clean();
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
return $r;
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
protected function getAndCheckForError($url){
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
if(Director::is_cli()){
|
|
|
|
// when in CLI the admin controller throws exceptions
|
|
|
|
ob_start();
|
|
|
|
try{
|
|
|
|
$this->get($url);
|
|
|
|
}catch(Exception $e){
|
|
|
|
ob_end_clean();
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
ob_end_clean();
|
|
|
|
return false;
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
}else{
|
|
|
|
// when in http the admin controller sets a response header
|
|
|
|
ob_start();
|
|
|
|
$resp = $this->get($url);
|
|
|
|
ob_end_clean();
|
|
|
|
return $resp->isError();
|
|
|
|
}
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class DevAdminControllerTest_Controller1 extends Controller {
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
const OK_MSG = 'DevAdminControllerTest_Controller1 TEST OK';
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
private static $url_handlers = array(
|
|
|
|
'' => 'index',
|
|
|
|
'y1' => 'y1Action'
|
|
|
|
);
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
private static $allowed_actions = array(
|
|
|
|
'index',
|
|
|
|
'y1Action',
|
|
|
|
);
|
2015-03-06 23:37:06 +01:00
|
|
|
|
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
public function index(){
|
|
|
|
echo self::OK_MSG;
|
|
|
|
}
|
2015-03-06 23:37:06 +01:00
|
|
|
|
2014-08-06 06:29:52 +02:00
|
|
|
public function y1Action(){
|
|
|
|
echo self::OK_MSG;
|
2015-03-06 23:37:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|