aboutsummaryrefslogtreecommitdiffstats
path: root/tests/controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/controller')
-rw-r--r--tests/controller/common_helper_route.php82
-rw-r--r--tests/controller/config/test/routing/environment.yml (renamed from tests/controller/config/routing.yml)0
-rw-r--r--tests/controller/controller_test.php16
-rw-r--r--tests/controller/ext/vendor2/bar/config/services.yml3
-rw-r--r--tests/controller/ext/vendor2/bar/config/test/routing/environment.yml3
-rw-r--r--tests/controller/ext/vendor2/bar/controller.php18
6 files changed, 90 insertions, 32 deletions
diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php
index ff1af8119b..e0475b37d9 100644
--- a/tests/controller/common_helper_route.php
+++ b/tests/controller/common_helper_route.php
@@ -35,10 +35,6 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
);
$this->generate_route_objects();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
- $this->user = new \phpbb\user('\phpbb\datetime');
-
- $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
- $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context());
}
protected function get_phpbb_root_path()
@@ -87,15 +83,44 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$phpEx
);
- $finder = new \phpbb\finder(
- new \phpbb\filesystem(),
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $this->user = new \phpbb\user('\phpbb\datetime');
+
+ $container = new phpbb_mock_container_builder();
+ $cache_path = $phpbb_root_path . 'cache/twig';
+ $context = new \phpbb\template\context();
+ $loader = new \phpbb\template\twig\loader('');
+ $twig = new \phpbb\template\twig\environment(
+ $this->config,
+ $this->phpbb_path_helper,
+ $container,
+ $cache_path,
+ null,
+ $loader,
+ array(
+ 'cache' => false,
+ 'debug' => false,
+ 'auto_reload' => true,
+ 'autoescape' => false,
+ )
+ );
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
+
+ $this->extension_manager = new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
- new phpbb_mock_cache()
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ )
);
- $finder->set_extensions(array_keys($this->extension_manager->all_enabled()));
- $this->provider = new \phpbb\controller\provider();
- $this->provider->find_routing_files($finder);
- $this->provider->find(dirname(__FILE__) . '/');
+
+ $this->router = new phpbb_mock_router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT);
+ $this->router->find_routing_files($this->extension_manager->all_enabled(false));
+ $this->router->find(dirname(__FILE__) . '/');
// Set correct current phpBB root path
$this->root_path = $this->get_phpbb_root_path();
}
@@ -135,8 +160,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
*/
public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id));
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);
}
public function helper_url_data_with_rewrite()
@@ -175,8 +201,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);
}
public function helper_url_data_absolute()
@@ -215,8 +241,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
}
public function helper_url_data_relative_path()
@@ -255,8 +281,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
}
public function helper_url_data_network()
@@ -295,10 +321,10 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
}
-//TODO
+
public function helper_url_data_absolute_with_rewrite()
{
return array(
@@ -335,8 +361,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
}
public function helper_url_data_relative_path_with_rewrite()
@@ -375,8 +401,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
}
public function helper_url_data_network_with_rewrite()
@@ -415,7 +441,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
- $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH));
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
}
}
diff --git a/tests/controller/config/routing.yml b/tests/controller/config/test/routing/environment.yml
index 1e7df02684..1e7df02684 100644
--- a/tests/controller/config/routing.yml
+++ b/tests/controller/config/test/routing/environment.yml
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
index 62feee3fed..86615fe4dc 100644
--- a/tests/controller/controller_test.php
+++ b/tests/controller/controller_test.php
@@ -30,14 +30,19 @@ class phpbb_controller_controller_test extends phpbb_test_case
'ext_active' => '1',
'ext_path' => 'ext/vendor2/foo/',
),
+ 'vendor2/bar' => array(
+ 'ext_name' => 'vendor2/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/bar/',
+ ),
));
}
- public function test_provider()
+ public function test_router_find_files()
{
- $provider = new \phpbb\controller\provider();
- $provider->find_routing_files($this->extension_manager->get_finder());
- $routes = $provider->find(__DIR__)->get_routes();
+ $router = new \phpbb\routing\router($this->extension_manager, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT);
+ $router->find_routing_files($this->extension_manager->all_enabled(false));
+ $routes = $router->find(__DIR__)->get_routes();
// This will need to be updated if any new routes are defined
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller'));
@@ -49,6 +54,9 @@ class phpbb_controller_controller_test extends phpbb_test_case
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2'));
$this->assertEquals('/foo/bar', $routes->get('controller2')->getPath());
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller3'));
+ $this->assertEquals('/bar', $routes->get('controller3')->getPath());
+
$this->assertNull($routes->get('controller_noroute'));
}
diff --git a/tests/controller/ext/vendor2/bar/config/services.yml b/tests/controller/ext/vendor2/bar/config/services.yml
new file mode 100644
index 0000000000..05a8a1994d
--- /dev/null
+++ b/tests/controller/ext/vendor2/bar/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ bar.controller:
+ class: bar\controller
diff --git a/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml
new file mode 100644
index 0000000000..5696ecb180
--- /dev/null
+++ b/tests/controller/ext/vendor2/bar/config/test/routing/environment.yml
@@ -0,0 +1,3 @@
+controller3:
+ path: /bar
+ defaults: { _controller: bar.controller:handle }
diff --git a/tests/controller/ext/vendor2/bar/controller.php b/tests/controller/ext/vendor2/bar/controller.php
new file mode 100644
index 0000000000..ad35f5a051
--- /dev/null
+++ b/tests/controller/ext/vendor2/bar/controller.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace bar;
+
+use Symfony\Component\HttpFoundation\Response;
+
+class controller
+{
+ /**
+ * Handle method
+ *
+ * @return null
+ */
+ public function handle()
+ {
+ return new Response('Test', 200);
+ }
+}