diff options
author | David King <imkingdavid@gmail.com> | 2012-10-19 19:54:19 -0400 |
---|---|---|
committer | David King <imkingdavid@gmail.com> | 2012-11-16 16:25:09 -0500 |
commit | 06158693c7b846518abfe9d72491fc7376e457f3 (patch) | |
tree | 46ce44bfeab4bb9f5275fee8ad8e01df3babaddf /tests/controller | |
parent | 65dde648cab316fd0f0715f13d57ef45452398a3 (diff) | |
download | forums-06158693c7b846518abfe9d72491fc7376e457f3.tar forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.gz forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.bz2 forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.xz forums-06158693c7b846518abfe9d72491fc7376e457f3.zip |
[feature/controller] Implement a front controller
PHPBB3-10864
Diffstat (limited to 'tests/controller')
-rw-r--r-- | tests/controller/config/routing.yml | 3 | ||||
-rw-r--r-- | tests/controller/config/services.yml | 3 | ||||
-rw-r--r-- | tests/controller/controller_test.php | 75 | ||||
-rw-r--r-- | tests/controller/ext/foo/config/routing.yml | 3 | ||||
-rw-r--r-- | tests/controller/ext/foo/config/services.yml | 3 | ||||
-rw-r--r-- | tests/controller/ext/foo/controller.php | 23 | ||||
-rw-r--r-- | tests/controller/includes/controller/foo.php | 23 |
7 files changed, 133 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..38f58c80a0 --- /dev/null +++ b/tests/controller/controller_test.php @@ -0,0 +1,75 @@ +<?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_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 + ->get_paths($this->extension_manager->get_finder()) + ->find('./tests/controller/'); + + // This will need to be updated if any new routes are defined + $this->assertEquals(2, count($routes)); + } + + public function test_controller_resolver() + { + $container = new ContainerBuilder(); + // For some reason, I cannot get it to load more than one services + // file at a time, even when givein multiple paths + // So instead, I am looping through all of the paths + 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__.'/includes/controller/foo.php'); + } + + $resolver = new phpbb_controller_resolver(new phpbb_user, $container); + $symfony_request = new Request(array(), array(), array('_controller' => 'foo.controller:handle')); + + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle')); + + $symfony_request = new Request(array(), array(), array('_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..72b8560c20 --- /dev/null +++ b/tests/controller/ext/foo/controller.php @@ -0,0 +1,23 @@ +<?php + +use Symfony\Component\HttpFoundation\Response; + +class phpbb_ext_foo_controller +{ + /** + * Constructor + */ + public function __construct() + { + } + + /** + * Handle method + * + * @return null + */ + public function handle() + { + return new Response('Test', 200); + } +} diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/includes/controller/foo.php new file mode 100644 index 0000000000..cd1c4849cb --- /dev/null +++ b/tests/controller/includes/controller/foo.php @@ -0,0 +1,23 @@ +<?php + +use Symfony\Component\HttpFoundation\Response; + +class phpbb_controller_foo +{ + /** + * Constructor + */ + public function __construct() + { + } + + /** + * Bar method + * + * @return null + */ + public function bar() + { + return new Response('bar()', 200); + } +} |