aboutsummaryrefslogtreecommitdiffstats
path: root/tests/controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/controller')
-rw-r--r--tests/controller/config/routing.yml3
-rw-r--r--tests/controller/config/services.yml3
-rw-r--r--tests/controller/controller_test.php76
-rw-r--r--tests/controller/ext/foo/config/routing.yml3
-rw-r--r--tests/controller/ext/foo/config/services.yml3
-rw-r--r--tests/controller/ext/foo/controller.php16
-rw-r--r--tests/controller/helper_url_test.php61
-rw-r--r--tests/controller/phpbb/controller/foo.php16
8 files changed, 181 insertions, 0 deletions
diff --git a/tests/controller/config/routing.yml b/tests/controller/config/routing.yml
new file mode 100644
index 0000000000..175b11f130
--- /dev/null
+++ b/tests/controller/config/routing.yml
@@ -0,0 +1,3 @@
+core_controller:
+ pattern: /core_foo
+ defaults: { _controller: core_foo.controller:bar }
diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml
new file mode 100644
index 0000000000..f1bd047489
--- /dev/null
+++ b/tests/controller/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ core_foo.controller:
+ class: phpbb_controller_foo
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
new file mode 100644
index 0000000000..dfc4f80469
--- /dev/null
+++ b/tests/controller/controller_test.php
@@ -0,0 +1,76 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\RouteCollection;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
+class phpbb_controller_controller_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'foo' => array(
+ 'ext_name' => 'foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/foo/',
+ ),
+ ));
+ }
+
+ public function test_provider()
+ {
+ $provider = new phpbb_controller_provider;
+ $routes = $provider
+ ->import_paths_from_finder($this->extension_manager->get_finder())
+ ->find('./tests/controller/');
+
+ // This will need to be updated if any new routes are defined
+ $this->assertEquals(2, sizeof($routes));
+ }
+
+ public function test_controller_resolver()
+ {
+ $container = new ContainerBuilder();
+ // YamlFileLoader only uses one path at a time, so we need to loop
+ // through all of the ones we are using.
+ foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path)
+ {
+ $loader = new YamlFileLoader($container, new FileLocator($path));
+ $loader->load('services.yml');
+ }
+
+ // Autoloading classes within the tests folder does not work
+ // so I'll include them manually.
+ if (!class_exists('phpbb_ext_foo_controller'))
+ {
+ include(__DIR__.'/ext/foo/controller.php');
+ }
+ if (!class_exists('phpbb_controller_foo'))
+ {
+ include(__DIR__.'/phpbb/controller/foo.php');
+ }
+
+ $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'));
+
+ $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'));
+ }
+}
diff --git a/tests/controller/ext/foo/config/routing.yml b/tests/controller/ext/foo/config/routing.yml
new file mode 100644
index 0000000000..4799fec37d
--- /dev/null
+++ b/tests/controller/ext/foo/config/routing.yml
@@ -0,0 +1,3 @@
+controller1:
+ pattern: /foo
+ defaults: { _controller: foo.controller:handle }
diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml
new file mode 100644
index 0000000000..ce0e18c610
--- /dev/null
+++ b/tests/controller/ext/foo/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ foo.controller:
+ class: phpbb_ext_foo_controller
diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php
new file mode 100644
index 0000000000..cfc5c20622
--- /dev/null
+++ b/tests/controller/ext/foo/controller.php
@@ -0,0 +1,16 @@
+<?php
+
+use Symfony\Component\HttpFoundation\Response;
+
+class phpbb_ext_foo_controller
+{
+ /**
+ * Handle method
+ *
+ * @return null
+ */
+ public function handle()
+ {
+ return new Response('Test', 200);
+ }
+}
diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php
new file mode 100644
index 0000000000..6686b77e8f
--- /dev/null
+++ b/tests/controller/helper_url_test.php
@@ -0,0 +1,61 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_controller_helper_url_test extends phpbb_test_case
+{
+
+ public function helper_url_data()
+ {
+ 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'),
+
+ // 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'),
+
+ // 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)'),
+
+ // 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'),
+
+ // 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'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data
+ */
+ public function test_helper_url($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->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
new file mode 100644
index 0000000000..04576e16c4
--- /dev/null
+++ b/tests/controller/phpbb/controller/foo.php
@@ -0,0 +1,16 @@
+<?php
+
+use Symfony\Component\HttpFoundation\Response;
+
+class phpbb_controller_foo
+{
+ /**
+ * Bar method
+ *
+ * @return null
+ */
+ public function bar()
+ {
+ return new Response('bar()', 200);
+ }
+}