aboutsummaryrefslogtreecommitdiffstats
path: root/tests/controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/controller')
-rw-r--r--tests/controller/config/services.yml2
-rw-r--r--tests/controller/controller_test.php12
-rw-r--r--tests/controller/ext/foo/config/services.yml2
-rw-r--r--tests/controller/ext/foo/controller.php4
-rw-r--r--tests/controller/helper_url_test.php106
-rw-r--r--tests/controller/phpbb/controller/foo.php4
6 files changed, 95 insertions, 35 deletions
diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml
index f1bd047489..e4412af3d7 100644
--- a/tests/controller/config/services.yml
+++ b/tests/controller/config/services.yml
@@ -1,3 +1,3 @@
services:
core_foo.controller:
- class: phpbb_controller_foo
+ class: phpbb\controller\foo
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
index dfc4f80469..10fced05a2 100644
--- a/tests/controller/controller_test.php
+++ b/tests/controller/controller_test.php
@@ -31,7 +31,7 @@ class phpbb_controller_controller_test extends phpbb_test_case
public function test_provider()
{
- $provider = new phpbb_controller_provider;
+ $provider = new \phpbb\controller\provider;
$routes = $provider
->import_paths_from_finder($this->extension_manager->get_finder())
->find('./tests/controller/');
@@ -53,24 +53,24 @@ class phpbb_controller_controller_test extends phpbb_test_case
// Autoloading classes within the tests folder does not work
// so I'll include them manually.
- if (!class_exists('phpbb_ext_foo_controller'))
+ if (!class_exists('foo\\controller'))
{
include(__DIR__.'/ext/foo/controller.php');
}
- if (!class_exists('phpbb_controller_foo'))
+ if (!class_exists('phpbb\\controller\\foo'))
{
include(__DIR__.'/phpbb/controller/foo.php');
}
- $resolver = new phpbb_controller_resolver(new phpbb_user, $container);
+ $resolver = new \phpbb\controller\resolver(new \phpbb\user, $container);
$symfony_request = new Request();
$symfony_request->attributes->set('_controller', 'foo.controller:handle');
- $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle'));
+ $this->assertEquals($resolver->getController($symfony_request), array(new foo\controller, 'handle'));
$symfony_request = new Request();
$symfony_request->attributes->set('_controller', 'core_foo.controller:bar');
- $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar'));
+ $this->assertEquals($resolver->getController($symfony_request), array(new phpbb\controller\foo, 'bar'));
}
}
diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml
index ce0e18c610..9ed67d5bc2 100644
--- a/tests/controller/ext/foo/config/services.yml
+++ b/tests/controller/ext/foo/config/services.yml
@@ -1,3 +1,3 @@
services:
foo.controller:
- class: phpbb_ext_foo_controller
+ class: foo\controller
diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php
index cfc5c20622..ce2233b3c9 100644
--- a/tests/controller/ext/foo/controller.php
+++ b/tests/controller/ext/foo/controller.php
@@ -1,8 +1,10 @@
<?php
+namespace foo;
+
use Symfony\Component\HttpFoundation\Response;
-class phpbb_ext_foo_controller
+class controller
{
/**
* Handle method
diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php
index 6686b77e8f..4ea177074f 100644
--- a/tests/controller/helper_url_test.php
+++ b/tests/controller/helper_url_test.php
@@ -12,50 +12,106 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_controller_helper_url_test extends phpbb_test_case
{
- public function helper_url_data()
+ public function helper_url_data_no_rewrite()
{
return array(
- array('foo/bar?t=1&amp;f=2', false, true, false, 'app.php?t=1&amp;f=2&amp;controller=foo/bar', 'parameters in url-argument'),
- array('foo/bar', 't=1&amp;f=2', true, false, 'app.php?controller=foo/bar&amp;t=1&amp;f=2', 'parameters in params-argument using amp'),
- array('foo/bar', 't=1&f=2', false, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using &'),
- array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php?controller=foo/bar&amp;t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('foo/bar?t=1&amp;f=2', false, true, false, 'app.php/foo/bar?t=1&amp;f=2', 'parameters in url-argument'),
+ array('foo/bar', 't=1&amp;f=2', true, false, 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument using amp'),
+ array('foo/bar', 't=1&f=2', false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument using &'),
+ array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
// Custom sid parameter
- array('foo/bar', 't=1&amp;f=2', true, 'custom-sid', 'app.php?controller=foo/bar&amp;t=1&amp;f=2&amp;sid=custom-sid', 'using session_id'),
+ array('foo/bar', 't=1&amp;f=2', true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'using session_id'),
// Testing anchors
- array('foo/bar?t=1&amp;f=2#anchor', false, true, false, 'app.php?t=1&amp;f=2&amp;controller=foo/bar#anchor', 'anchor in url-argument'),
- array('foo/bar', 't=1&amp;f=2#anchor', true, false, 'app.php?controller=foo/bar&amp;t=1&amp;f=2#anchor', 'anchor in params-argument'),
- array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php?controller=foo/bar&amp;t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('foo/bar?t=1&amp;f=2#anchor', false, true, false, 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in url-argument'),
+ array('foo/bar', 't=1&amp;f=2#anchor', true, false, 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument'),
+ array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
// Anchors and custom sid
- array('foo/bar?t=1&amp;f=2#anchor', false, true, 'custom-sid', 'app.php?t=1&amp;f=2&amp;controller=foo/bar&amp;sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
- array('foo/bar', 't=1&amp;f=2#anchor', true, 'custom-sid', 'app.php?controller=foo/bar&amp;t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
- array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php?controller=foo/bar&amp;t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('foo/bar?t=1&amp;f=2#anchor', false, true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
+ array('foo/bar', 't=1&amp;f=2#anchor', true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
+ array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
// Empty parameters should not append the &amp;
- array('foo/bar', false, true, false, 'app.php?controller=foo/bar', 'no params using bool false'),
- array('foo/bar', '', true, false, 'app.php?controller=foo/bar', 'no params using empty string'),
- array('foo/bar', array(), true, false, 'app.php?controller=foo/bar', 'no params using empty array'),
+ array('foo/bar', false, true, false, 'app.php/foo/bar', 'no params using bool false'),
+ array('foo/bar', '', true, false, 'app.php/foo/bar', 'no params using empty string'),
+ array('foo/bar', array(), true, false, 'app.php/foo/bar', 'no params using empty array'),
);
}
/**
- * @dataProvider helper_url_data
+ * @dataProvider helper_url_data_no_rewrite()
*/
- public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description)
+ public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
- $this->style_resource_locator = new phpbb_style_resource_locator();
- $this->user = $this->getMock('phpbb_user');
- $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
- $this->style_resource_locator = new phpbb_style_resource_locator();
- $this->style_provider = new phpbb_style_path_provider();
- $this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
-
- $helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');
+ $this->user = $this->getMock('\phpbb\user');
+ $phpbb_filesystem = new \phpbb\filesystem(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ $phpbb_root_path,
+ $phpEx
+ );
+ $this->template = new phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context());
+
+ // We don't use mod_rewrite in these tests
+ $config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $helper = new \phpbb\controller\helper($this->template, $this->user, $config, '', 'php');
+ $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
+ }
+
+ public function helper_url_data_with_rewrite()
+ {
+ return array(
+ array('foo/bar?t=1&amp;f=2', false, true, false, 'foo/bar?t=1&amp;f=2', 'parameters in url-argument'),
+ array('foo/bar', 't=1&amp;f=2', true, false, 'foo/bar?t=1&amp;f=2', 'parameters in params-argument using amp'),
+ array('foo/bar', 't=1&f=2', false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument using &'),
+ array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('foo/bar', 't=1&amp;f=2', true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'using session_id'),
+
+ // Testing anchors
+ array('foo/bar?t=1&amp;f=2#anchor', false, true, false, 'foo/bar?t=1&amp;f=2#anchor', 'anchor in url-argument'),
+ array('foo/bar', 't=1&amp;f=2#anchor', true, false, 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument'),
+ array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('foo/bar?t=1&amp;f=2#anchor', false, true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
+ array('foo/bar', 't=1&amp;f=2#anchor', true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
+ array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp;
+ array('foo/bar', false, true, false, 'foo/bar', 'no params using bool false'),
+ array('foo/bar', '', true, false, 'foo/bar', 'no params using empty string'),
+ array('foo/bar', array(), true, false, 'foo/bar', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_with_rewrite()
+ */
+ public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $this->user = $this->getMock('\phpbb\user');
+ $phpbb_filesystem = new \phpbb\filesystem(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ $phpbb_root_path,
+ $phpEx
+ );
+ $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context());
+
+ $config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $helper = new \phpbb\controller\helper($this->template, $this->user, $config, '', 'php');
$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
}
}
diff --git a/tests/controller/phpbb/controller/foo.php b/tests/controller/phpbb/controller/foo.php
index 04576e16c4..98669f428f 100644
--- a/tests/controller/phpbb/controller/foo.php
+++ b/tests/controller/phpbb/controller/foo.php
@@ -1,8 +1,10 @@
<?php
+namespace phpbb\controller;
+
use Symfony\Component\HttpFoundation\Response;
-class phpbb_controller_foo
+class foo
{
/**
* Bar method