aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/fixtures/ext/foo/bar/controller/controller.php
blob: 558b2029480f7c445b2e81c8d0c0cfa10fb5fdaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php

namespace foo\bar\controller;

use Symfony\Component\HttpFoundation\Response;

class controller
{
	protected $template;
	protected $helper;
	protected $path_helper;
	protected $config;

	public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, $root_path, $php_ext)
	{
		$this->template = $template;
		$this->helper = $helper;
		$this->path_helper = $path_helper;
		$this->config = $config;
		$this->root_path = $root_path;
		$this->php_ext = $php_ext;
	}

	public function handle()
	{
		return new Response('foo/bar controller handle() method', 200);
	}

	public function baz($test)
	{
		return new Response('Value of "test" URL argument is: ' . $test);
	}

	public function template()
	{
		$this->template->assign_var('A_VARIABLE', 'I am a variable');

		return $this->helper->render('foo_bar_body.html');
	}

	public function exception()
	{
		throw new \phpbb\controller\exception('Exception thrown from foo/exception route');
	}

	public function redirect()
	{
		$url_root = generate_board_url();

		$rewrite_prefix = (!empty($this->config['enable_mod_rewrite'])) ? '' : 'app.php/';

		$redirects = array(
			array(
				append_sid($this->root_path . 'index.' . $this->php_ext),
				'index.php',
			),
			array(
				append_sid($this->root_path . 'foo/bar/index.' . $this->php_ext),
				'foo/bar/index.php',
			),
			array(
				append_sid($this->root_path . 'tests/index.' . $this->php_ext),
				'tests/index.php',
			),
			array(
				$this->helper->url('index'),
				$rewrite_prefix . 'index',
			),
			array(
				$this->helper->url('tests/index'),
				$rewrite_prefix . 'tests/index',
			),
			array(
				$this->helper->url('tests/../index'),
				$rewrite_prefix . 'index',
			),
			/*
			// helper URLs starting with  ../ are prone to failure.
			// Do not test them right now.
			array(
				$this->helper->url('../index'),
				'../index',
			),
			array(
				$this->helper->url('../../index'),
				'../index',
			),
			array(
				$this->helper->url('../tests/index'),
				$rewrite_prefix . '../tests/index',
			),
			array(
				$this->helper->url('../tests/../index'),
				'../index',
			),
			array(
				$this->helper->url('../../tests/index'),
				'../tests/index',
			),
			*/
		);

		foreach ($redirects as $redirect)
		{
			$this->template->assign_block_vars('redirects', array(
				'URL'		=> redirect($redirect[0], true),
			));

			$this->template->assign_block_vars('redirects_expected', array(
				'URL'		=> $this->path_helper->clean_url($url_root . '/' . $redirect[1]),
			));
		}

		return $this->helper->render('redirect_body.html');
	}
}