2012-02-19 15:26:20 -05:00
< ? php
/**
*
* @ package testing
* @ copyright ( c ) 2011 phpBB Group
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
*
*/
/**
* @ group functional
*/
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
{
2012-03-18 16:50:41 -04:00
protected $phpbb_extension_manager ;
2012-03-16 15:35:01 -04:00
/**
* This should only be called once before the tests are run .
* This is used to copy the fixtures to the phpBB install
*/
static public function setUpBeforeClass ()
{
parent :: setUpBeforeClass ();
2012-03-16 16:42:29 -04:00
$f_path = self :: $config [ 'phpbb_functional_path' ];
// these directories need to be created before the files can be copied
$directories = array (
$f_path . 'ext/error/class/' ,
$f_path . 'ext/error/classtype/' ,
$f_path . 'ext/error/disabled/' ,
$f_path . 'ext/foo/bar/' ,
$f_path . 'ext/foo/bar/styles/prosilver/template/' ,
$f_path . 'ext/foobar/' ,
$f_path . 'ext/foobar/styles/prosilver/template/' ,
);
2012-03-16 15:35:01 -04:00
// When you add new tests that require new fixtures, add them to the array.
2012-03-16 16:42:29 -04:00
foreach ( $directories as $dir )
{
if ( ! is_dir ( $dir ))
{
mkdir ( $dir , 0777 , true );
}
}
2012-03-16 15:35:01 -04:00
$fixtures = array (
'error/class/controller.php' ,
'error/class/ext.php' ,
'error/classtype/controller.php' ,
'error/classtype/ext.php' ,
'error/disabled/controller.php' ,
'error/disabled/ext.php' ,
'foo/bar/controller.php' ,
'foo/bar/ext.php' ,
2012-03-17 22:12:50 -04:00
'foo/bar/styles/prosilver/template/foobar_body.html' ,
2012-03-16 15:35:01 -04:00
'foobar/controller.php' ,
'foobar/ext.php' ,
2012-03-17 22:12:50 -04:00
'foobar/styles/prosilver/template/foobar_body.html' ,
2012-03-16 15:35:01 -04:00
);
foreach ( $fixtures as $fixture )
{
// we have to use self::$config['phpbb_functional_url'] because $this->root_url is not available in static classes
2012-03-16 16:42:29 -04:00
if ( ! copy ( " tests/functional/fixtures/ext/ $fixture " , " { $f_path } ext/ $fixture " ))
2012-03-16 15:35:01 -04:00
{
echo 'Could not copy file ' . $fixture ;
}
}
}
2012-03-16 17:18:08 -04:00
public static function tearDownAfterClass ()
{
$f_path = self :: $config [ 'phpbb_functional_path' ];
// @todo delete the fixtures from the $f_path board
// Note that it might be best to find a public domain function
// and port it into here instead of writing it from scratch
}
2012-03-18 16:50:41 -04:00
public function setUp ()
{
parent :: setUp ();
2012-03-18 22:57:37 +01:00
$this -> phpbb_extension_manager = $this -> get_extension_manager ();
$this -> purge_cache ();
2012-03-18 16:50:41 -04:00
}
2012-02-19 15:26:20 -05:00
/**
* Check an extension at ./ ext / foobar / which should have the class
* phpbb_ext_foobar_controller
*/
public function test_foobar ()
{
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> enable ( 'foobar' );
2012-02-19 15:26:20 -05:00
$crawler = $this -> request ( 'GET' , 'index.php?ext=foobar' );
2012-03-18 14:44:37 -04:00
$this -> assertContains ( " This is for testing purposes. " , $crawler -> filter ( '#page-body' ) -> text ());
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> purge ( 'foobar' );
2012-02-19 15:26:20 -05:00
}
/**
* Check an extension at ./ ext / foo / bar / which should have the class
* phpbb_ext_foo_bar_controller
*/
public function test_foo_bar ()
{
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> enable ( 'foo/bar' );
2012-02-19 15:26:20 -05:00
$crawler = $this -> request ( 'GET' , 'index.php?ext=foo/bar' );
2012-03-18 14:44:37 -04:00
$this -> assertContains ( " This is for testing purposes. " , $crawler -> filter ( '#page-body' ) -> text ());
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> purge ( 'foo/bar' );
2012-02-19 15:26:20 -05:00
}
/**
* Check the error produced by extension at ./ ext / error / class which has class
* phpbb_ext_foobar_controller
*/
public function test_error_class_name ()
{
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> enable ( 'error/class' );
2012-02-19 15:26:20 -05:00
$crawler = $this -> request ( 'GET' , 'index.php?ext=error/class' );
2012-03-17 22:12:50 -04:00
$this -> assertContains ( " The extension error/class is missing a controller class and cannot be accessed through the front-end. " , $crawler -> filter ( '#message' ) -> text ());
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> purge ( 'error/class' );
2012-02-19 15:26:20 -05:00
}
/**
* Check the error produced by extension at ./ ext / error / classtype which has class
* phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface
*/
public function test_error_class_type ()
{
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> enable ( 'error/classtype' );
2012-02-19 15:26:20 -05:00
$crawler = $this -> request ( 'GET' , 'index.php?ext=error/classtype' );
2012-03-17 22:12:50 -04:00
$this -> assertContains ( " The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface. " , $crawler -> filter ( '#message' ) -> text ());
2012-03-18 16:50:41 -04:00
$this -> phpbb_extension_manager -> purge ( 'error/classtype' );
2012-02-19 15:26:20 -05:00
}
/**
* Check the error produced by extension at ./ ext / error / disabled that is ( obviously )
* a disabled extension
*/
public function test_error_ext_disabled ()
{
$crawler = $this -> request ( 'GET' , 'index.php?ext=error/disabled' );
2012-03-17 22:12:50 -04:00
$this -> assertContains ( " The extension error/disabled is not enabled " , $crawler -> filter ( '#message' ) -> text ());
2012-02-19 15:26:20 -05:00
}
/**
* Check the error produced by extension at ./ ext / error / 404 that is ( obviously )
* not existant
*/
public function test_error_ext_missing ()
{
$crawler = $this -> request ( 'GET' , 'index.php?ext=error/404' );
2012-03-17 22:12:50 -04:00
$this -> assertContains ( " The extension error/404 does not exist. " , $crawler -> filter ( '#message' ) -> text ());
2012-02-19 15:26:20 -05:00
}
}