diff options
| author | Nathan Guse <nathaniel.guse@gmail.com> | 2012-11-20 23:19:51 -0600 |
|---|---|---|
| committer | Nathan Guse <nathaniel.guse@gmail.com> | 2012-11-20 23:19:51 -0600 |
| commit | 61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e (patch) | |
| tree | 210fe8026aecc70a45d48e52c58ef77d43b85787 /tests/controller/controller_test.php | |
| parent | 570c5ad3c08378f377385aaff7d3810ccb8db3ff (diff) | |
| parent | b453f359ff6dab58b0eaf94548c4e58110fb02ec (diff) | |
| download | forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.gz forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.bz2 forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.xz forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.zip | |
Merge branch 'develop' of git://github.com/phpbb/phpbb3 into ticket/11103
Conflicts:
phpBB/config/services.yml
phpBB/index.php
Diffstat (limited to 'tests/controller/controller_test.php')
| -rw-r--r-- | tests/controller/controller_test.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php new file mode 100644 index 0000000000..198fb3c6dd --- /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_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__.'/includes/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')); + } +} |
