Skip to content

Commit d0c5823

Browse files
author
hCaptcha GHA
committed
Update FluentForm tests.
1 parent ddd0c8d commit d0c5823

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

.tests/php/integration/FluentForm/FormTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ReflectionException;
2121
use stdClass;
2222
use tad\FunctionMocker\FunctionMocker;
23-
use FluentForm\App\Modules\Form\FormFieldsParser;
2423

2524
/**
2625
* Test FluentForm.
@@ -208,6 +207,8 @@ public function test_print_hcaptcha_scripts(): void {
208207
* Test enqueue_scripts().
209208
*
210209
* @return void
210+
* @throws ReflectionException ReflectionException.
211+
* @noinspection ES6ConvertVarToLetConst
211212
*/
212213
public function test_enqueue_scripts(): void {
213214
global $wp_scripts;
@@ -355,15 +356,15 @@ public function test_is_fluent_forms_admin_page(): void {
355356

356357
$subject->shouldAllowMockingProtectedMethods();
357358

358-
// Not admin page.
359+
// Not an admin page.
359360
self::assertFalse( $subject->is_fluent_forms_admin_page() );
360361

361-
// Not Formidable admin page.
362+
// Not a Fluent Forms admin page.
362363
set_current_screen( 'some' );
363364

364365
self::assertFalse( $subject->is_fluent_forms_admin_page() );
365366

366-
// Success path. Formidable admin pages.
367+
// Success path. Fluent Forms admin pages.
367368
foreach ( $fluent_forms_admin_pages as $page ) {
368369
set_current_screen( $page );
369370

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Form stub file
4+
*
5+
* @package HCaptcha\Tests
6+
*/
7+
8+
// phpcs:disable Generic.Commenting.DocComment.MissingShort
9+
/** @noinspection PhpIllegalPsrClassPathInspection */
10+
/** @noinspection PhpUndefinedClassInspection */
11+
// phpcs:enable Generic.Commenting.DocComment.MissingShort
12+
13+
// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
14+
15+
namespace FluentForm\App\Models;
16+
17+
use stdClass;
18+
19+
/**
20+
* Form stub.
21+
*/
22+
class Form {
23+
24+
/**
25+
* Find form by ID.
26+
*
27+
* @param int $form_id Form ID.
28+
*
29+
* @return stdClass
30+
* @noinspection PhpUnusedParameterInspection
31+
*/
32+
public static function find( int $form_id ): stdClass {
33+
return new stdClass();
34+
}
35+
}

.tests/php/integration/Stubs/FluentForm/App/Modules/Form/FormFieldsParser.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace FluentForm\App\Modules\Form;
1616

17+
use FluentForm\App\Models\Form as FluentForm;
1718
use stdClass;
1819

1920
/**
@@ -32,12 +33,13 @@ public static function resetData(): void {
3233
/**
3334
* Has element.
3435
*
35-
* @param stdClass $form Form object.
36-
* @param string $element Element name.
36+
* @param FluentForm|stdClass $form Form object.
37+
* @param string $element Element name.
3738
*
3839
* @return bool
40+
* @noinspection PhpUnusedParameterInspection
3941
*/
40-
public static function hasElement( stdClass $form, string $element ): bool {
41-
return true;
42+
public static function hasElement( $form, string $element ): bool {
43+
return false;
4244
}
4345
}

src/php/FluentForm/Form.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,13 @@ public function print_inline_styles(): void {
390390
* @return bool
391391
*/
392392
protected function has_own_hcaptcha( $form ): bool {
393-
FormFieldsParser::resetData();
394-
395-
if ( FormFieldsParser::hasElement( $form, 'hcaptcha' ) ) {
396-
return true;
397-
}
398-
399-
return false;
393+
return $this->has_element( $form, 'hcaptcha' );
400394
}
401395

402396
/**
403397
* Get hCaptcha.
404398
*
405399
* @return string
406-
* @noinspection PhpUndefinedMethodInspection
407400
*/
408401
protected function get_hcaptcha(): string {
409402
$form = FluentForm::find( $this->form_id );
@@ -427,11 +420,11 @@ protected function get_hcaptcha(): string {
427420
/**
428421
* Whether the form is a login form.
429422
*
430-
* @param FluentForm $form Form.
423+
* @param FluentForm|stdClass $form Form.
431424
*
432425
* @return bool
433426
*/
434-
private function is_login_form( FluentForm $form ): bool {
427+
private function is_login_form( $form ): bool {
435428

436429
return (
437430
has_action( 'fluentform/before_insert_submission' ) &&
@@ -443,16 +436,15 @@ private function is_login_form( FluentForm $form ): bool {
443436
/**
444437
* Whether the form has an element.
445438
*
446-
* @param FluentForm $form Form.
447-
* @param string $element_name Element name.
439+
* @param FluentForm|stdClass $form Form.
440+
* @param string $element_name Element name.
448441
*
449442
* @return bool
450-
* @noinspection PhpUndefinedFieldInspection
451443
*/
452-
private function has_element( FluentForm $form, string $element_name ): bool {
453-
$fields_json = $form->form_fields;
444+
private function has_element( $form, string $element_name ): bool {
445+
FormFieldsParser::resetData();
454446

455-
return false !== strpos( $fields_json, '"element":"' . $element_name . '"' );
447+
return FormFieldsParser::hasElement( $form, $element_name );
456448
}
457449

458450
/**

0 commit comments

Comments
 (0)