Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
27.85% |
22 / 79 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_manifest_controller_test | |
27.85% |
22 / 79 |
|
60.00% |
3 / 5 |
19.52 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| manifest_data | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
2 | |||
| test_manifest | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| manifest_with_bot_data | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| test_manifest_with_bot | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 15 | |
| 16 | class phpbb_manifest_controller_test extends phpbb_test_case |
| 17 | { |
| 18 | protected $config; |
| 19 | protected $user; |
| 20 | protected $manifest; |
| 21 | |
| 22 | protected function setUp(): void |
| 23 | { |
| 24 | global $config, $user, $phpbb_root_path, $phpEx; |
| 25 | |
| 26 | parent::setUp(); |
| 27 | |
| 28 | $config = $this->config = new phpbb\config\config([ |
| 29 | 'sitename' => 'phpBB Testing Framework', |
| 30 | 'sitename_short' => '', |
| 31 | 'force_server_vars' => false, |
| 32 | 'script_path' => '', |
| 33 | ]); |
| 34 | |
| 35 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 36 | $lang_loader = new phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 37 | $language = new phpbb\language\language($lang_loader); |
| 38 | $user = $this->user = new phpbb\user($language, '\phpbb\datetime'); |
| 39 | |
| 40 | $this->manifest = new phpbb\manifest($this->config, $phpbb_dispatcher, $this->user); |
| 41 | } |
| 42 | |
| 43 | public static function manifest_data() |
| 44 | { |
| 45 | return [ |
| 46 | 'using board url root path' => [ |
| 47 | [ |
| 48 | 'force_server_vars' => false, |
| 49 | ], |
| 50 | [ |
| 51 | 'name' => 'phpBB Testing Framework', |
| 52 | 'short_name' => 'phpBB Testin', |
| 53 | 'display' => 'standalone', |
| 54 | 'orientation' => 'portrait', |
| 55 | 'start_url' => '/', |
| 56 | 'scope' => '/', |
| 57 | ], |
| 58 | ], |
| 59 | 'using script path' => [ |
| 60 | [ |
| 61 | 'force_server_vars' => true, |
| 62 | 'script_path' => '/foo/', |
| 63 | ], |
| 64 | [ |
| 65 | 'name' => 'phpBB Testing Framework', |
| 66 | 'short_name' => 'phpBB Testin', |
| 67 | 'display' => 'standalone', |
| 68 | 'orientation' => 'portrait', |
| 69 | 'start_url' => '/foo/', |
| 70 | 'scope' => '/foo/', |
| 71 | ], |
| 72 | ], |
| 73 | 'with shortname' => [ |
| 74 | [ |
| 75 | 'sitename_short' => 'phpBB Test', |
| 76 | ], |
| 77 | [ |
| 78 | 'name' => 'phpBB Testing Framework', |
| 79 | 'short_name' => 'phpBB Test', |
| 80 | 'display' => 'standalone', |
| 81 | 'orientation' => 'portrait', |
| 82 | 'start_url' => '/', |
| 83 | 'scope' => '/', |
| 84 | ], |
| 85 | ], |
| 86 | 'without shortname or script path' => [ |
| 87 | [], |
| 88 | [ |
| 89 | 'name' => 'phpBB Testing Framework', |
| 90 | 'short_name' => 'phpBB Testin', |
| 91 | 'display' => 'standalone', |
| 92 | 'orientation' => 'portrait', |
| 93 | 'start_url' => '/', |
| 94 | 'scope' => '/', |
| 95 | ], |
| 96 | ], |
| 97 | ]; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @dataProvider manifest_data |
| 102 | */ |
| 103 | public function test_manifest($configs, $expected) |
| 104 | { |
| 105 | foreach ($configs as $key => $value) |
| 106 | { |
| 107 | $this->config->set($key, $value); |
| 108 | } |
| 109 | |
| 110 | $response = $this->manifest->handle(); |
| 111 | |
| 112 | $this->assertInstanceOf(JsonResponse::class, $response); |
| 113 | |
| 114 | $this->assertEquals($expected, json_decode($response->getContent(), true)); |
| 115 | } |
| 116 | |
| 117 | public static function manifest_with_bot_data() |
| 118 | { |
| 119 | return [ |
| 120 | 'is a bot' => [true, 'yes'], |
| 121 | 'not a bot' => [false, null], |
| 122 | ]; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @dataProvider manifest_with_bot_data |
| 127 | */ |
| 128 | public function test_manifest_with_bot($is_bot, $expected) |
| 129 | { |
| 130 | $this->user->data['is_bot'] = $is_bot; |
| 131 | |
| 132 | $response = $this->manifest->handle(); |
| 133 | |
| 134 | $this->assertInstanceOf(JsonResponse::class, $response); |
| 135 | |
| 136 | $this->assertEquals($expected, $response->headers->get('X-PHPBB-IS-BOT')); |
| 137 | } |
| 138 | } |