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-11-16 09:23:57 -05:00
|
|
|
|
|
|
|
static protected $fixtures = array(
|
|
|
|
'foo/bar/config/routing.yml',
|
|
|
|
'foo/bar/config/services.yml',
|
|
|
|
'foo/bar/controller/controller.php',
|
|
|
|
'foo/bar/ext.php',
|
|
|
|
);
|
|
|
|
|
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()
|
|
|
|
{
|
2012-03-19 09:56:48 -04:00
|
|
|
global $phpbb_root_path;
|
2012-03-16 15:35:01 -04:00
|
|
|
parent::setUpBeforeClass();
|
2012-03-16 16:42:29 -04:00
|
|
|
|
|
|
|
$directories = array(
|
2012-03-19 09:56:48 -04:00
|
|
|
$phpbb_root_path . 'ext/foo/bar/',
|
2012-11-16 09:23:57 -05:00
|
|
|
$phpbb_root_path . 'ext/foo/bar/config/',
|
|
|
|
$phpbb_root_path . 'ext/foo/bar/controller/',
|
2012-03-16 16:42:29 -04:00
|
|
|
);
|
2012-03-19 09:56:48 -04:00
|
|
|
|
2012-03-16 16:42:29 -04:00
|
|
|
foreach ($directories as $dir)
|
|
|
|
{
|
|
|
|
if (!is_dir($dir))
|
|
|
|
{
|
|
|
|
mkdir($dir, 0777, true);
|
|
|
|
}
|
|
|
|
}
|
2012-11-16 09:23:57 -05:00
|
|
|
|
|
|
|
foreach (self::$fixtures as $fixture)
|
2012-03-16 15:35:01 -04:00
|
|
|
{
|
2012-11-16 10:42:10 -05:00
|
|
|
copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture");
|
2012-03-16 15:35:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-16 09:23:57 -05:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2012-11-16 10:42:10 -05:00
|
|
|
unlink("{$phpbb_root_path}ext/$fixture");
|
2012-11-16 09:23:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
2012-11-16 09:23:57 -05:00
|
|
|
* Check a controller for extension foo/bar
|
2012-02-19 15:26:20 -05:00
|
|
|
*/
|
|
|
|
public function test_foo_bar()
|
|
|
|
{
|
2012-03-18 16:50:41 -04:00
|
|
|
$this->phpbb_extension_manager->enable('foo/bar');
|
2012-11-16 09:23:57 -05:00
|
|
|
$crawler = $this->request('GET', 'app.php/foo/bar');
|
|
|
|
$this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
|
2012-11-16 10:30:50 -05:00
|
|
|
$this->phpbb_extension_manager->purge('foo/bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_missing_argument()
|
|
|
|
{
|
|
|
|
$this->phpbb_extension_manager->enable('foo/bar');
|
|
|
|
$crawler = $this->request('GET', 'app.php/foo/baz');
|
|
|
|
$this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text());
|
|
|
|
$this->phpbb_extension_manager->purge('foo/bar');
|
2012-02-19 15:26:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-16 09:23:57 -05:00
|
|
|
* 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,
|
|
|
|
* 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.
|
2012-02-19 15:26:20 -05:00
|
|
|
*/
|
2012-11-16 09:23:57 -05:00
|
|
|
public function test_error_ext_disabled_or_404()
|
2012-02-19 15:26:20 -05:00
|
|
|
{
|
2012-11-16 09:23:57 -05:00
|
|
|
$crawler = $this->request('GET', 'app.php/does/not/exist');
|
|
|
|
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
2012-02-19 15:26:20 -05:00
|
|
|
}
|
|
|
|
}
|