Skip to content

Commit

Permalink
Fix test for PHP 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 19, 2023
1 parent 1e72b94 commit 1ce276b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
40 changes: 22 additions & 18 deletions .tests/php/integration/Mailchimp/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
* @package HCaptcha\Tests
*/

// phpcs:ignore Generic.Commenting.DocComment.MissingShort
/** @noinspection PhpUndefinedClassInspection */

namespace HCaptcha\Tests\Integration\Mailchimp;

use HCaptcha\Mailchimp\Form;
use HCaptcha\Tests\Integration\HCaptchaWPTestCase;
use MC4WP_Form;
use MC4WP_Form_Element;
use Mockery;

/**
Expand All @@ -18,11 +23,9 @@ class FormTest extends HCaptchaWPTestCase {

/**
* Test add_hcap_error_messages().
*
* @noinspection PhpParamsInspection
*/
public function test_add_hcap_error_messages() {
$form = Mockery::mock( 'MC4WP_Form' );
$form = Mockery::mock( MC4WP_Form::class );

$messages = [
'foo' => [
Expand Down Expand Up @@ -86,46 +89,47 @@ public function test_add_hcap_error_messages() {

/**
* Test add_captcha().
*
* @noinspection PhpParamsInspection
*/
public function test_add_captcha() {
$content = '<input type="submit">';
$expected =
$content = '<input type="submit">';
$expected =
$this->get_hcap_form() .
wp_nonce_field( 'hcaptcha_mailchimp', 'hcaptcha_mailchimp_nonce', true, false ) .
'<input type="submit">';
$mc4wp_form = (object) [
'ID' => 5,
];
$subject = new Form();

self::assertSame( $expected, $subject->add_captcha( $content, $mc4wp_form, null ) );
$mc4wp_form = Mockery::mock( MC4WP_Form::class );
$mc4wp_form->ID = 5;

$element = Mockery::mock( MC4WP_Form_Element::class );

$subject = new Form();

self::assertSame( $expected, $subject->add_captcha( $content, $mc4wp_form, $element ) );
}

/**
* Test verify().
*
* @noinspection PhpParamsInspection
*/
public function test_verify() {
$this->prepare_hcaptcha_verify_POST( 'hcaptcha_mailchimp_nonce', 'hcaptcha_mailchimp' );

$mc4wp_form = Mockery::mock( MC4WP_Form::class );

$subject = new Form();

self::assertSame( [], $subject->verify( [], null ) );
self::assertSame( [], $subject->verify( [], $mc4wp_form ) );
}

/**
* Test verify() not verified.
*
* @noinspection PhpParamsInspection
*/
public function test_verify_not_verified() {
$this->prepare_hcaptcha_verify_POST( 'hcaptcha_mailchimp_nonce', 'hcaptcha_mailchimp', false );

$mc4wp_form = Mockery::mock( MC4WP_Form::class );

$subject = new Form();

self::assertSame( [ 'fail' ], $subject->verify( [], null ) );
self::assertSame( [ 'fail' ], $subject->verify( [], $mc4wp_form ) );
}
}
3 changes: 3 additions & 0 deletions src/php/Mailchimp/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace HCaptcha\Mailchimp;

use HCaptcha\Helpers\HCaptcha;
use MC4WP_Form;
use MC4WP_Form_Element;

/**
* Class Form.
Expand Down Expand Up @@ -74,6 +76,7 @@ public function add_hcap_error_messages( array $messages, MC4WP_Form $form ): ar
*
* @return string
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUndefinedFieldInspection
*/
public function add_captcha( string $content, MC4WP_Form $form, MC4WP_Form_Element $element ): string {
$args = [
Expand Down
3 changes: 1 addition & 2 deletions src/php/NF/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public function __construct() {
* @param mixed $data Data.
*
* @return null|string
* @noinspection PhpUnusedParameterInspection
*/
public function validate( array $field, $data ) {
public function validate( $field, $data ) {
$value = $field['value'] ?? '';

return hcaptcha_request_verify( $value );
Expand Down

0 comments on commit 1ce276b

Please sign in to comment.