Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
102 / 102 |
|
100.00% |
25 / 25 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_captcha_legacy_wrapper_test | |
100.00% |
102 / 102 |
|
100.00% |
25 / 25 |
25 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_available_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_available_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_has_config_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_has_config_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_name_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_name_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_name_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_init_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_hidden_fields_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_hidden_fields_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_with_error | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_validate_without_error | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_solved_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_solved_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_reset_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_attempt_count_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_attempt_count_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_template_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_template_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_demo_template_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_demo_template_without_method_exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_garbage_collect_with_method_exists | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_acp_page_with_method_exists | |
100.00% |
6 / 6 |
|
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 phpbb\captcha\plugins\confirm_type; |
| 15 | use phpbb\captcha\plugins\legacy_wrapper; |
| 16 | |
| 17 | class phpbb_captcha_legacy_wrapper_test extends phpbb_test_case |
| 18 | { |
| 19 | private $legacy_captcha; |
| 20 | private $legacy_wrapper; |
| 21 | |
| 22 | public function setUp(): void |
| 23 | { |
| 24 | $this->legacy_captcha = $this->createMock(stdClass::class); |
| 25 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 26 | } |
| 27 | |
| 28 | public function test_is_available_with_method_exists(): void |
| 29 | { |
| 30 | // Simulate is_available method exists in the legacy captcha |
| 31 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 32 | ->addMethods(['is_available']) |
| 33 | ->getMock(); |
| 34 | $this->legacy_captcha->method('is_available')->willReturn(true); |
| 35 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 36 | |
| 37 | $this->assertTrue($this->legacy_wrapper->is_available()); |
| 38 | } |
| 39 | |
| 40 | public function test_is_available_without_method_exists(): void |
| 41 | { |
| 42 | // Simulate is_available method does not exist in the legacy captcha |
| 43 | $this->assertFalse($this->legacy_wrapper->is_available()); |
| 44 | } |
| 45 | |
| 46 | public function test_has_config_with_method_exists(): void |
| 47 | { |
| 48 | // Simulate has_config method exists in the legacy captcha |
| 49 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 50 | ->addMethods(['has_config']) |
| 51 | ->getMock(); |
| 52 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 53 | $this->legacy_captcha->method('has_config')->willReturn(true); |
| 54 | |
| 55 | $this->assertTrue($this->legacy_wrapper->has_config()); |
| 56 | } |
| 57 | |
| 58 | public function test_has_config_without_method_exists(): void |
| 59 | { |
| 60 | // Simulate has_config method does not exist in the legacy captcha |
| 61 | $this->assertFalse($this->legacy_wrapper->has_config()); |
| 62 | } |
| 63 | |
| 64 | public function test_get_name_with_method_exists(): void |
| 65 | { |
| 66 | // Simulate get_name method exists in the legacy captcha |
| 67 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 68 | ->addMethods(['get_name']) |
| 69 | ->getMock(); |
| 70 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 71 | $this->legacy_captcha->method('get_name')->willReturn('LegacyCaptchaName'); |
| 72 | |
| 73 | $this->assertSame('LegacyCaptchaName', $this->legacy_wrapper->get_name()); |
| 74 | } |
| 75 | |
| 76 | public function test_get_name_without_method_exists(): void |
| 77 | { |
| 78 | // Simulate get_name method does not exist in the legacy captcha |
| 79 | $this->assertSame('', $this->legacy_wrapper->get_name()); |
| 80 | } |
| 81 | |
| 82 | public function test_set_name_with_method_exists(): void |
| 83 | { |
| 84 | // Simulate set_name method exists in the legacy captcha |
| 85 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 86 | ->addMethods(['set_name']) |
| 87 | ->getMock(); |
| 88 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 89 | $this->legacy_captcha->expects($this->once())->method('set_name')->with('NewName'); |
| 90 | |
| 91 | $this->legacy_wrapper->set_name('NewName'); |
| 92 | } |
| 93 | |
| 94 | public function test_init_with_method_exists(): void |
| 95 | { |
| 96 | // Simulate init method exists in the legacy captcha |
| 97 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 98 | ->addMethods(['init']) |
| 99 | ->getMock(); |
| 100 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 101 | $this->legacy_captcha->expects($this->once())->method('init')->with(confirm_type::REGISTRATION->value); |
| 102 | |
| 103 | $this->legacy_wrapper->init(confirm_type::REGISTRATION); |
| 104 | } |
| 105 | |
| 106 | public function test_get_hidden_fields_with_method_exists(): void |
| 107 | { |
| 108 | // Simulate get_hidden_fields method exists in the legacy captcha |
| 109 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 110 | ->addMethods(['get_hidden_fields']) |
| 111 | ->getMock(); |
| 112 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 113 | $this->legacy_captcha->method('get_hidden_fields')->willReturn(['field1' => 'value1']); |
| 114 | |
| 115 | $this->assertSame(['field1' => 'value1'], $this->legacy_wrapper->get_hidden_fields()); |
| 116 | } |
| 117 | |
| 118 | public function test_get_hidden_fields_without_method_exists(): void |
| 119 | { |
| 120 | // Simulate get_hidden_fields method does not exist in the legacy captcha |
| 121 | $this->assertSame([], $this->legacy_wrapper->get_hidden_fields()); |
| 122 | } |
| 123 | |
| 124 | public function test_validate_with_error(): void |
| 125 | { |
| 126 | // Simulate validate method returns an error |
| 127 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 128 | ->addMethods(['validate']) |
| 129 | ->getMock(); |
| 130 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 131 | $this->legacy_captcha->method('validate')->willReturn('Captcha Error'); |
| 132 | |
| 133 | $this->assertFalse($this->legacy_wrapper->validate()); |
| 134 | $this->assertSame('Captcha Error', $this->legacy_wrapper->get_error()); |
| 135 | } |
| 136 | |
| 137 | public function test_validate_without_method_exists(): void |
| 138 | { |
| 139 | $this->assertFalse($this->legacy_wrapper->validate()); |
| 140 | } |
| 141 | |
| 142 | public function test_validate_without_error(): void |
| 143 | { |
| 144 | // Simulate validate method does not return an error |
| 145 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 146 | ->addMethods(['validate']) |
| 147 | ->getMock(); |
| 148 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 149 | $this->legacy_captcha->method('validate')->willReturn(null); |
| 150 | |
| 151 | $this->assertTrue($this->legacy_wrapper->validate()); |
| 152 | } |
| 153 | |
| 154 | public function test_is_solved_with_method_exists(): void |
| 155 | { |
| 156 | // Simulate is_solved method exists in the legacy captcha |
| 157 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 158 | ->addMethods(['is_solved']) |
| 159 | ->getMock(); |
| 160 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 161 | $this->legacy_captcha->method('is_solved')->willReturn(true); |
| 162 | |
| 163 | $this->assertTrue($this->legacy_wrapper->is_solved()); |
| 164 | } |
| 165 | |
| 166 | public function test_is_solved_without_method_exists(): void |
| 167 | { |
| 168 | // Simulate is_solved method does not exist in the legacy captcha |
| 169 | $this->assertFalse($this->legacy_wrapper->is_solved()); |
| 170 | } |
| 171 | |
| 172 | public function test_reset_with_method_exists(): void |
| 173 | { |
| 174 | // Simulate reset method exists in the legacy captcha |
| 175 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 176 | ->addMethods(['reset']) |
| 177 | ->getMock(); |
| 178 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 179 | $this->legacy_captcha->expects($this->once())->method('reset'); |
| 180 | |
| 181 | $this->legacy_wrapper->reset(); |
| 182 | } |
| 183 | |
| 184 | public function test_get_attempt_count_with_method_exists(): void |
| 185 | { |
| 186 | // Simulate get_attempt_count method exists in the legacy captcha |
| 187 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 188 | ->addMethods(['get_attempt_count']) |
| 189 | ->getMock(); |
| 190 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 191 | $this->legacy_captcha->method('get_attempt_count')->willReturn(5); |
| 192 | |
| 193 | $this->assertSame(5, $this->legacy_wrapper->get_attempt_count()); |
| 194 | } |
| 195 | |
| 196 | public function test_get_attempt_count_without_method_exists(): void |
| 197 | { |
| 198 | // Simulate get_attempt_count method does not exist in the legacy captcha |
| 199 | $this->assertSame(PHP_INT_MAX, $this->legacy_wrapper->get_attempt_count()); |
| 200 | } |
| 201 | |
| 202 | public function test_get_template_with_method_exists(): void |
| 203 | { |
| 204 | // Simulate get_template method exists in the legacy captcha |
| 205 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 206 | ->addMethods(['get_template']) |
| 207 | ->getMock(); |
| 208 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 209 | $this->legacy_captcha->method('get_template')->willReturn('template_content'); |
| 210 | |
| 211 | $this->assertSame('template_content', $this->legacy_wrapper->get_template()); |
| 212 | } |
| 213 | |
| 214 | public function test_get_template_without_method_exists(): void |
| 215 | { |
| 216 | // Simulate get_template method does not exist in the legacy captcha |
| 217 | $this->assertSame('', $this->legacy_wrapper->get_template()); |
| 218 | } |
| 219 | |
| 220 | public function test_get_demo_template_with_method_exists(): void |
| 221 | { |
| 222 | // Simulate get_demo_template method exists in the legacy captcha |
| 223 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 224 | ->addMethods(['get_demo_template']) |
| 225 | ->getMock(); |
| 226 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 227 | $this->legacy_captcha->method('get_demo_template')->willReturn('demo_template_content'); |
| 228 | |
| 229 | $this->assertSame('demo_template_content', $this->legacy_wrapper->get_demo_template()); |
| 230 | } |
| 231 | |
| 232 | public function test_get_demo_template_without_method_exists(): void |
| 233 | { |
| 234 | // Simulate get_demo_template method does not exist in the legacy captcha |
| 235 | $this->assertSame('', $this->legacy_wrapper->get_demo_template()); |
| 236 | } |
| 237 | |
| 238 | public function test_garbage_collect_with_method_exists(): void |
| 239 | { |
| 240 | // Simulate garbage_collect method exists in the legacy captcha |
| 241 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 242 | ->addMethods(['garbage_collect']) |
| 243 | ->getMock(); |
| 244 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 245 | $this->legacy_captcha->expects($this->once())->method('garbage_collect')->with(confirm_type::REGISTRATION->value); |
| 246 | |
| 247 | $this->legacy_wrapper->garbage_collect(confirm_type::REGISTRATION); |
| 248 | } |
| 249 | |
| 250 | public function test_acp_page_with_method_exists(): void |
| 251 | { |
| 252 | // Simulate acp_page method exists in the legacy captcha |
| 253 | $this->legacy_captcha = $this->getMockBuilder(stdClass::class) |
| 254 | ->addMethods(['acp_page']) |
| 255 | ->getMock(); |
| 256 | $this->legacy_wrapper = new legacy_wrapper($this->legacy_captcha); |
| 257 | $this->legacy_captcha->expects($this->once())->method('acp_page')->with(1, 'module'); |
| 258 | |
| 259 | $this->legacy_wrapper->acp_page(1, 'module'); |
| 260 | } |
| 261 | } |