mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/controller] Adapt functional tests given new controller framework
PHPBB3-10864
This commit is contained in:
parent
c9588572c9
commit
7691755883
16 changed files with 69 additions and 193 deletions
|
@ -13,6 +13,14 @@
|
||||||
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
|
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
|
||||||
{
|
{
|
||||||
protected $phpbb_extension_manager;
|
protected $phpbb_extension_manager;
|
||||||
|
|
||||||
|
static protected $fixtures = array(
|
||||||
|
'foo/bar/config/routing.yml',
|
||||||
|
'foo/bar/config/services.yml',
|
||||||
|
'foo/bar/controller/controller.php',
|
||||||
|
'foo/bar/ext.php',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should only be called once before the tests are run.
|
* This should only be called once before the tests are run.
|
||||||
* This is used to copy the fixtures to the phpBB install
|
* This is used to copy the fixtures to the phpBB install
|
||||||
|
@ -22,15 +30,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
global $phpbb_root_path;
|
global $phpbb_root_path;
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
// these directories need to be created before the files can be copied
|
|
||||||
$directories = array(
|
$directories = array(
|
||||||
$phpbb_root_path . 'ext/error/class/',
|
|
||||||
$phpbb_root_path . 'ext/error/classtype/',
|
|
||||||
$phpbb_root_path . 'ext/error/disabled/',
|
|
||||||
$phpbb_root_path . 'ext/foo/bar/',
|
$phpbb_root_path . 'ext/foo/bar/',
|
||||||
$phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/',
|
$phpbb_root_path . 'ext/foo/bar/config/',
|
||||||
$phpbb_root_path . 'ext/foobar/',
|
$phpbb_root_path . 'ext/foo/bar/controller/',
|
||||||
$phpbb_root_path . 'ext/foobar/styles/prosilver/template/',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($directories as $dir)
|
foreach ($directories as $dir)
|
||||||
|
@ -41,22 +44,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fixtures = array(
|
foreach (self::$fixtures as $fixture)
|
||||||
'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',
|
|
||||||
'foo/bar/styles/prosilver/template/foobar_body.html',
|
|
||||||
'foobar/controller.php',
|
|
||||||
'foobar/ext.php',
|
|
||||||
'foobar/styles/prosilver/template/foobar_body.html',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($fixtures as $fixture)
|
|
||||||
{
|
{
|
||||||
if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"))
|
if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"))
|
||||||
{
|
{
|
||||||
|
@ -65,6 +53,27 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This should only be called once after the tests are run.
|
||||||
|
* This is used to remove the fixtures from the phpBB install
|
||||||
|
*/
|
||||||
|
static public function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
global $phpbb_root_path;
|
||||||
|
foreach (self::$fixtures as $fixture)
|
||||||
|
{
|
||||||
|
if (!unlink("{$phpbb_root_path}ext/$fixture"))
|
||||||
|
{
|
||||||
|
echo 'Could not delete file ' . $fixture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar/config");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar/controller");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo");
|
||||||
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -75,72 +84,28 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check an extension at ./ext/foobar/ which should have the class
|
* Check a controller for extension foo/bar
|
||||||
* phpbb_ext_foobar_controller
|
|
||||||
*/
|
|
||||||
public function test_foobar()
|
|
||||||
{
|
|
||||||
$this->phpbb_extension_manager->enable('foobar');
|
|
||||||
$crawler = $this->request('GET', 'index.php?ext=foobar');
|
|
||||||
$this->assert_response_success();
|
|
||||||
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
|
|
||||||
$this->phpbb_extension_manager->purge('foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check an extension at ./ext/foo/bar/ which should have the class
|
|
||||||
* phpbb_ext_foo_bar_controller
|
|
||||||
*/
|
*/
|
||||||
public function test_foo_bar()
|
public function test_foo_bar()
|
||||||
{
|
{
|
||||||
$this->phpbb_extension_manager->enable('foo/bar');
|
$this->phpbb_extension_manager->enable('foo/bar');
|
||||||
$crawler = $this->request('GET', 'index.php?ext=foo/bar');
|
$crawler = $this->request('GET', 'app.php/foo/bar');
|
||||||
$this->assert_response_success();
|
$this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
|
||||||
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
|
$this->phpbb_extension_manager->purge('foobar');
|
||||||
$this->phpbb_extension_manager->purge('foo/bar');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the error produced by extension at ./ext/error/class which has class
|
* Check the error produced by extension at ./ext/does/not/exist
|
||||||
* phpbb_ext_foobar_controller
|
*
|
||||||
|
* If an extension is disabled, its routes are not loaded. Because we
|
||||||
|
* are not looking for a controller based on a specified extension,
|
||||||
|
* we don't know the difference between a route in a disabled
|
||||||
|
* extension and a route that is not defined anyway; it is the same
|
||||||
|
* error message.
|
||||||
*/
|
*/
|
||||||
public function test_error_class_name()
|
public function test_error_ext_disabled_or_404()
|
||||||
{
|
{
|
||||||
$this->phpbb_extension_manager->enable('error/class');
|
$crawler = $this->request('GET', 'app.php/does/not/exist');
|
||||||
$crawler = $this->request('GET', 'index.php?ext=error/class');
|
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
||||||
$this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text());
|
|
||||||
$this->phpbb_extension_manager->purge('error/class');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()
|
|
||||||
{
|
|
||||||
$this->phpbb_extension_manager->enable('error/classtype');
|
|
||||||
$crawler = $this->request('GET', 'index.php?ext=error/classtype');
|
|
||||||
$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());
|
|
||||||
$this->phpbb_extension_manager->purge('error/classtype');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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');
|
|
||||||
$this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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');
|
|
||||||
$this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_foobar_controller extends phpbb_extension_controller
|
|
||||||
{
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->template->set_filenames(array(
|
|
||||||
'body' => 'index_body.html'
|
|
||||||
));
|
|
||||||
|
|
||||||
page_header('Test extension');
|
|
||||||
page_footer();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_error_class_ext extends phpbb_extension_base
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_error_classtype_controller
|
|
||||||
{
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
global $template;
|
|
||||||
$template->set_filenames(array(
|
|
||||||
'body' => 'index_body.html'
|
|
||||||
));
|
|
||||||
|
|
||||||
page_header('Test extension');
|
|
||||||
page_footer();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_error_classtype_ext extends phpbb_extension_base
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_error_disabled_controller extends phpbb_extension_controller
|
|
||||||
{
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->template->set_filenames(array(
|
|
||||||
'body' => 'index_body.html'
|
|
||||||
));
|
|
||||||
|
|
||||||
page_header('Test extension');
|
|
||||||
page_footer();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_error_disabled_ext extends phpbb_extension_base
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
3
tests/functional/fixtures/ext/foo/bar/config/routing.yml
Executable file
3
tests/functional/fixtures/ext/foo/bar/config/routing.yml
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
foo_bar_controller:
|
||||||
|
pattern: /foo/bar
|
||||||
|
defaults: { _controller: foo_bar.controller:handle }
|
3
tests/functional/fixtures/ext/foo/bar/config/services.yml
Executable file
3
tests/functional/fixtures/ext/foo/bar/config/services.yml
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
services:
|
||||||
|
foo_bar.controller:
|
||||||
|
class: phpbb_ext_foo_bar_controller
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_foo_bar_controller extends phpbb_extension_controller
|
|
||||||
{
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->template->set_filenames(array(
|
|
||||||
'body' => 'foobar_body.html'
|
|
||||||
));
|
|
||||||
|
|
||||||
page_header('Test extension');
|
|
||||||
page_footer();
|
|
||||||
}
|
|
||||||
}
|
|
10
tests/functional/fixtures/ext/foo/bar/controller/controller.php
Executable file
10
tests/functional/fixtures/ext/foo/bar/controller/controller.php
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class phpbb_ext_foo_bar_controller
|
||||||
|
{
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
return new Response('foo/bar controller handle() method', 200);
|
||||||
|
}
|
||||||
|
}
|
2
tests/functional/fixtures/ext/foo/bar/ext.php
Normal file → Executable file
2
tests/functional/fixtures/ext/foo/bar/ext.php
Normal file → Executable file
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class phpbb_ext_foo_bar_ext extends phpbb_extension_base
|
class phpbb_ext_foobar_ext extends phpbb_extension_base
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
<!-- INCLUDE overall_header.html -->
|
|
||||||
|
|
||||||
<div id="welcome">This is for testing purposes.</div>
|
|
||||||
|
|
||||||
<!-- INCLUDE overall_footer.html -->
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_foobar_controller extends phpbb_extension_controller
|
|
||||||
{
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->template->set_filenames(array(
|
|
||||||
'body' => 'foobar_body.html'
|
|
||||||
));
|
|
||||||
|
|
||||||
page_header('Test extension');
|
|
||||||
page_footer();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class phpbb_ext_foobar_ext extends phpbb_extension_base
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<!-- INCLUDE overall_header.html -->
|
|
||||||
|
|
||||||
<div id="welcome">This is for testing purposes.</div>
|
|
||||||
|
|
||||||
<!-- INCLUDE overall_footer.html -->
|
|
Loading…
Add table
Reference in a new issue