diff options
Diffstat (limited to 'tests/controller')
| -rw-r--r-- | tests/controller/common_helper_route.php | 86 | ||||
| -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.php | 18 | ||||
| -rw-r--r-- | tests/controller/ext/vendor2/bar/config/services.yml | 3 | ||||
| -rw-r--r-- | tests/controller/ext/vendor2/bar/config/test/routing/environment.yml | 3 | ||||
| -rw-r--r-- | tests/controller/ext/vendor2/bar/controller.php | 18 | 
6 files changed, 94 insertions, 34 deletions
diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index ff1af8119b..3e4b5fd38d 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() @@ -78,7 +74,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case  		$this->symfony_request = new \phpbb\symfony_request(  			$this->request  		); -		$this->filesystem = new \phpbb\filesystem(); +		$this->filesystem = new \phpbb\filesystem\filesystem();  		$this->phpbb_path_helper = new \phpbb\path_helper(  			$this->symfony_request,  			$this->filesystem, @@ -87,15 +83,46 @@ 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')); +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +		$this->user = new \phpbb\user($lang, '\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($this->filesystem, ''); +		$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->filesystem, $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 +162,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 +203,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 +243,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 +283,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 +323,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 +363,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 +403,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 +443,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..5c0290ee6f 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(new \phpbb\filesystem\filesystem(), $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'));  	} @@ -74,7 +82,7 @@ class phpbb_controller_controller_test extends phpbb_test_case  			include(__DIR__.'/phpbb/controller/foo.php');  		} -		$resolver = new \phpbb\controller\resolver(new \phpbb\user('\phpbb\datetime'), $container, dirname(__FILE__) . '/'); +		$resolver = new \phpbb\controller\resolver($container, dirname(__FILE__) . '/');  		$symfony_request = new Request();  		$symfony_request->attributes->set('_controller', 'foo.controller:handle'); 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); +	} +}  | 
