1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 16:22:22 +02:00

[feature/controller] Add controller functional test with template

PHPBB3-10864
This commit is contained in:
David King 2012-11-16 11:41:05 -05:00
parent ba1acdca03
commit 5b013ddf5c
5 changed files with 52 additions and 5 deletions

View File

@ -18,7 +18,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
'foo/bar/config/routing.yml',
'foo/bar/config/services.yml',
'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/config/',
$phpbb_root_path . 'ext/foo/bar/controller/',
$phpbb_root_path . 'ext/foo/bar/styles/prosilver/template',
);
foreach ($directories as $dir)
@ -43,10 +44,12 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
mkdir($dir, 0777, true);
}
}
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()
{
global $phpbb_root_path;
foreach (self::$fixtures as $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/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");
}
@ -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()
{
@ -88,6 +95,21 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
$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()
{
$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
* are not looking for a controller based on a specified extension,

View File

@ -5,3 +5,7 @@ foo_bar_controller:
foo_baz_controller:
pattern: /foo/baz
defaults: { _controller: foo_bar.controller:baz }
foo_template_controller:
pattern: /foo/template
defaults: { _controller: foo_bar.controller:template }

View File

@ -1,3 +1,6 @@
services:
foo_bar.controller:
class: phpbb_ext_foo_bar_controller
arguments:
- @controller.helper
- @template

View File

@ -3,6 +3,14 @@ use Symfony\Component\HttpFoundation\Response;
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()
{
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);
}
public function template()
{
$this->template->assign_var('A_VARIABLE', 'I am a variable');
return $this->helper->render('foo_bar_body.html');
}
}

View File

@ -0,0 +1,3 @@
<!-- INCLUDE overall_header.html -->
<div id="content">{A_VARIABLE}</div>
<!-- INCLUDE overall_footer.html -->