Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functional_extension_controller_test
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 12
210
0.00% covered (danger)
0.00%
0 / 1
 setUpBeforeClass
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 tearDownAfterClass
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 setUp
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 test_foo_bar
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_routing_resources
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_controller_with_template
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 test_controller_template_include_js_css
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 test_missing_argument
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_exception_should_result_in_500_status_code
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_error_ext_disabled_or_404
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_login_redirect
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 test_redirect
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @group functional
16*/
17class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
18{
19    private static $helper;
20
21    protected static $fixtures = array(
22        './',
23    );
24
25    public static function setUpBeforeClass(): void
26    {
27        parent::setUpBeforeClass();
28
29        self::$helper = new phpbb_test_case_helpers(__CLASS__);
30        self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
31
32        self::install_ext('foo/bar');
33        self::install_ext('foo/foo');
34    }
35
36    public static function tearDownAfterClass(): void
37    {
38        parent::tearDownAfterClass();
39
40        self::uninstall_ext('foo/bar');
41        self::uninstall_ext('foo/foo');
42        self::$helper->restore_original_ext_dir();
43    }
44
45    protected function setUp(): void
46    {
47        parent::setUp();
48
49        $this->purge_cache();
50    }
51
52    /**
53    * Check a controller for extension foo/bar.
54    */
55    public function test_foo_bar()
56    {
57        $crawler = self::request('GET', 'app.php/foo/bar', array(), false);
58        self::assert_response_status_code();
59        $this->assertStringContainsString("foo/bar controller handle() method", $crawler->filter('body')->text());
60    }
61
62    /**
63    * Check a controller for extension foo/bar.
64    */
65    public function test_routing_resources()
66    {
67        $crawler = self::request('GET', 'app.php/foo/foo', array(), false);
68        self::assert_response_status_code();
69        $this->assertStringContainsString("foo/foo controller handle() method", $crawler->filter('body')->text());
70    }
71
72    /**
73    * Check the output of a controller using the template system
74    */
75    public function test_controller_with_template()
76    {
77        $crawler = self::request('GET', 'app.php/foo/template');
78        $this->assertStringContainsString("I am a variable", $crawler->filter('#content')->text());
79    }
80
81    /**
82    * Check includejs/includecss when the request_uri is a subdirectory
83    */
84    public function test_controller_template_include_js_css()
85    {
86        $crawler = self::request('GET', 'app.php/help/faq');
87        $this->assertStringContainsString("./../../assets/javascript/core.js", $crawler->filter('body')->html());
88    }
89
90    /**
91    * Check the error produced by calling a controller without a required
92    * argument.
93    */
94    public function test_missing_argument()
95    {
96        $crawler = self::request('GET', 'app.php/foo/baz', array(), false);
97        $this->assert_response_html(500);
98        $this->assertStringContainsString('Controller "foo\bar\controller\controller::baz" requires the "$test" argument that could not be resolved', $crawler->filter('body')->text());
99    }
100
101    /**
102    * Check the status code resulting from an exception thrown by a controller
103    */
104    public function test_exception_should_result_in_500_status_code()
105    {
106        $crawler = self::request('GET', 'app.php/foo/exception', array(), false);
107        $this->assert_response_html(500);
108        $this->assertStringContainsString('Exception thrown from foo/exception route', $crawler->filter('body')->text());
109    }
110
111    /**
112    * Check the error produced by extension at ./ext/does/not/exist.
113    *
114    * If an extension is disabled, its routes are not loaded. Because we
115    * are not looking for a controller based on a specified extension,
116    * we don't know the difference between a route in a disabled
117    * extension and a route that is not defined anyway; it is the same
118    * error message.
119    */
120    public function test_error_ext_disabled_or_404()
121    {
122        $crawler = self::request('GET', 'app.php/does/not/exist', array(), false);
123        $this->assert_response_html(404);
124
125        // Since version 5.3.0-BETA1, Symfony shows full URI when route not found. See https://github.com/symfony/symfony/pull/39893
126        $full_uri = self::$client->getRequest()->getUri();
127        $this->assertStringContainsString('No route found for "GET ' . $full_uri . '"', $crawler->filter('body')->text());
128    }
129
130    /**
131     * Check the redirect after using the login_box() form
132     */
133    public function test_login_redirect()
134    {
135        $this->markTestIncomplete('Session table contains incorrect data for controllers on CI,'
136            . 'therefore the redirect fails.');
137
138        $crawler = self::request('GET', 'app.php/foo/login_redirect');
139        $this->assertContainsLang('LOGIN', $crawler->filter('h2')->text());
140        $form = $crawler->selectButton('login')->form(array(
141            'username'    => 'admin',
142            'password'    => 'adminadmin',
143        ));
144        $this->assertStringStartsWith('./app.php/foo/login_redirect', $form->get('redirect')->getValue());
145
146        $crawler = self::submit($form);
147        $this->assertStringContainsString("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()');
148    }
149
150    /**
151    * Check the output of a controller using the template system
152    */
153    public function test_redirect()
154    {
155        $crawler = self::request('GET', 'app.php/foo/redirect');
156
157        $nodes = $crawler->filter('div')->extract(array('id'));
158
159        foreach ($nodes as $redirect)
160        {
161            if (strpos($redirect, 'redirect_expected') !== 0)
162            {
163                continue;
164            }
165
166            $row_num = str_replace('redirect_expected_', '', $redirect);
167
168            $redirect = $crawler->filter('#redirect_' . $row_num)->text();
169            $this->assertEquals($crawler->filter('#redirect_expected_' .  $row_num)->text(), $redirect);
170        }
171    }
172}