mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/controller] Add controller functional test with template
PHPBB3-10864
This commit is contained in:
parent
ba1acdca03
commit
5b013ddf5c
5 changed files with 52 additions and 5 deletions
|
@ -18,7 +18,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
'foo/bar/config/routing.yml',
|
'foo/bar/config/routing.yml',
|
||||||
'foo/bar/config/services.yml',
|
'foo/bar/config/services.yml',
|
||||||
'foo/bar/controller/controller.php',
|
'foo/bar/controller/controller.php',
|
||||||
'foo/bar/ext.php',
|
'foo/bar/styles/prosilver/template/foo_bar_body.html',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
$phpbb_root_path . 'ext/foo/bar/',
|
$phpbb_root_path . 'ext/foo/bar/',
|
||||||
$phpbb_root_path . 'ext/foo/bar/config/',
|
$phpbb_root_path . 'ext/foo/bar/config/',
|
||||||
$phpbb_root_path . 'ext/foo/bar/controller/',
|
$phpbb_root_path . 'ext/foo/bar/controller/',
|
||||||
|
$phpbb_root_path . 'ext/foo/bar/styles/prosilver/template',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($directories as $dir)
|
foreach ($directories as $dir)
|
||||||
|
@ -46,7 +47,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
|
|
||||||
foreach (self::$fixtures as $fixture)
|
foreach (self::$fixtures as $fixture)
|
||||||
{
|
{
|
||||||
copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture");
|
copy(
|
||||||
|
"tests/functional/fixtures/ext/$fixture",
|
||||||
|
"{$phpbb_root_path}ext/$fixture");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +60,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
static public function tearDownAfterClass()
|
static public function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
global $phpbb_root_path;
|
global $phpbb_root_path;
|
||||||
|
|
||||||
foreach (self::$fixtures as $fixture)
|
foreach (self::$fixtures as $fixture)
|
||||||
{
|
{
|
||||||
unlink("{$phpbb_root_path}ext/$fixture");
|
unlink("{$phpbb_root_path}ext/$fixture");
|
||||||
|
@ -64,6 +68,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
|
|
||||||
rmdir("{$phpbb_root_path}ext/foo/bar/config");
|
rmdir("{$phpbb_root_path}ext/foo/bar/config");
|
||||||
rmdir("{$phpbb_root_path}ext/foo/bar/controller");
|
rmdir("{$phpbb_root_path}ext/foo/bar/controller");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver");
|
||||||
|
rmdir("{$phpbb_root_path}ext/foo/bar/styles");
|
||||||
rmdir("{$phpbb_root_path}ext/foo/bar");
|
rmdir("{$phpbb_root_path}ext/foo/bar");
|
||||||
rmdir("{$phpbb_root_path}ext/foo");
|
rmdir("{$phpbb_root_path}ext/foo");
|
||||||
}
|
}
|
||||||
|
@ -78,7 +85,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a controller for extension foo/bar
|
* Check a controller for extension foo/bar.
|
||||||
*/
|
*/
|
||||||
public function test_foo_bar()
|
public function test_foo_bar()
|
||||||
{
|
{
|
||||||
|
@ -88,6 +95,21 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
$this->phpbb_extension_manager->purge('foo/bar');
|
$this->phpbb_extension_manager->purge('foo/bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the output of a controller using the template system
|
||||||
|
*/
|
||||||
|
public function test_controller_with_template()
|
||||||
|
{
|
||||||
|
$this->phpbb_extension_manager->enable('foo/bar');
|
||||||
|
$crawler = $this->request('GET', 'app.php/foo/template');
|
||||||
|
$this->assertContains("I am a variable", $crawler->filter('#content')->text());
|
||||||
|
$this->phpbb_extension_manager->purge('foo/bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the error produced by calling a controller without a required
|
||||||
|
* argument.
|
||||||
|
*/
|
||||||
public function test_missing_argument()
|
public function test_missing_argument()
|
||||||
{
|
{
|
||||||
$this->phpbb_extension_manager->enable('foo/bar');
|
$this->phpbb_extension_manager->enable('foo/bar');
|
||||||
|
@ -97,7 +119,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the error produced by extension at ./ext/does/not/exist
|
* Check the error produced by extension at ./ext/does/not/exist.
|
||||||
*
|
*
|
||||||
* If an extension is disabled, its routes are not loaded. Because we
|
* If an extension is disabled, its routes are not loaded. Because we
|
||||||
* are not looking for a controller based on a specified extension,
|
* are not looking for a controller based on a specified extension,
|
||||||
|
|
|
@ -5,3 +5,7 @@ foo_bar_controller:
|
||||||
foo_baz_controller:
|
foo_baz_controller:
|
||||||
pattern: /foo/baz
|
pattern: /foo/baz
|
||||||
defaults: { _controller: foo_bar.controller:baz }
|
defaults: { _controller: foo_bar.controller:baz }
|
||||||
|
|
||||||
|
foo_template_controller:
|
||||||
|
pattern: /foo/template
|
||||||
|
defaults: { _controller: foo_bar.controller:template }
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
services:
|
services:
|
||||||
foo_bar.controller:
|
foo_bar.controller:
|
||||||
class: phpbb_ext_foo_bar_controller
|
class: phpbb_ext_foo_bar_controller
|
||||||
|
arguments:
|
||||||
|
- @controller.helper
|
||||||
|
- @template
|
||||||
|
|
|
@ -3,6 +3,14 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class phpbb_ext_foo_bar_controller
|
class phpbb_ext_foo_bar_controller
|
||||||
{
|
{
|
||||||
|
protected $template;
|
||||||
|
|
||||||
|
public function __construct(phpbb_controller_helper $helper, phpbb_template $template)
|
||||||
|
{
|
||||||
|
$this->template = $template;
|
||||||
|
$this->helper = $helper;
|
||||||
|
}
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
return new Response('foo/bar controller handle() method', 200);
|
return new Response('foo/bar controller handle() method', 200);
|
||||||
|
@ -12,4 +20,11 @@ class phpbb_ext_foo_bar_controller
|
||||||
{
|
{
|
||||||
return new Response('Value of "test" URL argument is: ' . $test);
|
return new Response('Value of "test" URL argument is: ' . $test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function template()
|
||||||
|
{
|
||||||
|
$this->template->assign_var('A_VARIABLE', 'I am a variable');
|
||||||
|
|
||||||
|
return $this->helper->render('foo_bar_body.html');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<!-- INCLUDE overall_header.html -->
|
||||||
|
<div id="content">{A_VARIABLE}</div>
|
||||||
|
<!-- INCLUDE overall_footer.html -->
|
Loading…
Add table
Reference in a new issue