Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HughParry committed Apr 24, 2024
1 parent a9550fe commit 8c760b5
Show file tree
Hide file tree
Showing 73 changed files with 14,567 additions and 15,150 deletions.
585 changes: 286 additions & 299 deletions .tests/php/integration/ACFE/FormTest.php

Large diffs are not rendered by default.

844 changes: 410 additions & 434 deletions .tests/php/integration/AutoVerify/AutoVerifyTest.php

Large diffs are not rendered by default.

219 changes: 107 additions & 112 deletions .tests/php/integration/Avada/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

// phpcs:disable Generic.Commenting.DocComment.MissingShort
/**
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpLanguageLevelInspection
*/
/**
* @noinspection PhpUndefinedClassInspection
* @noinspection PhpUndefinedClassInspection
*/
// phpcs:enable Generic.Commenting.DocComment.MissingShort

Expand All @@ -24,114 +24,109 @@
*
* @group avada
*/
class FormTest extends HCaptchaWPTestCase
{

/**
* Tear down test.
*
* @return void
*/
public function tearDown(): void // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
{
unset($_POST['formData'], $_POST['hcaptcha-widget-id']);

parent::tearDown();
}

/**
* Test init_hooks().
*
* @return void
*/
public function test_init_hooks()
{
$subject = new Form();

self::assertSame(10, has_action('fusion_form_after_open', [ $subject, 'form_after_open' ]));
self::assertSame(10, has_action('fusion_element_button_content', [ $subject, 'add_hcaptcha' ]));
self::assertSame(10, has_filter('fusion_form_demo_mode', [ $subject, 'verify' ]));
}

/**
* Test add_hcaptcha().
*
* @return void
*/
public function test_add_hcaptcha()
{
$form_id = 5;
$args = [
'id' =>
[
'source' => [ 'Avada' ],
'form_id' => $form_id,
],
];
$params = [ 'id' => $form_id ];
$wrong_html = 'some html';
$html = '<button type="submit">';
$form = $this->get_hcap_form($args);
$expected = $form . $html;

$subject = new Form();

$subject->form_after_open($args, $params);
self::assertSame($wrong_html, $subject->add_hcaptcha($wrong_html, $args));
self::assertSame($expected, $subject->add_hcaptcha($html, $args));
}

/**
* Test verify().
*
* @return void
* @noinspection PhpConditionAlreadyCheckedInspection
*/
public function test_verify()
{
$demo_mode = true;
$hcaptcha_response = 'some_response';
$form_data = "procaptcha-response=$hcaptcha_response";

$this->prepare_hcaptcha_request_verify($hcaptcha_response);

$_POST['formData'] = $form_data;

$subject = new Form();

self::assertSame($demo_mode, $subject->verify($demo_mode));
}

/**
* Test verify() when not verified.
*
* @return void
*/
public function test_verify_not_verified()
{
$hcaptcha_response = 'some_response';
$die_arr = [];
$expected = [
'{"status":"error","info":{"hcaptcha":"Please complete the Procaptcha."}}',
'',
[],
];

$this->prepare_hcaptcha_request_verify($hcaptcha_response, false);

$subject = new Form();

add_filter(
'wp_die_handler',
static function ( $name ) use ( &$die_arr ) {
return static function ( $message, $title, $args ) use ( &$die_arr ) {
$die_arr = [ $message, $title, $args ];
};
}
);

$subject->verify(true);

self::assertSame($expected, $die_arr);
}
class FormTest extends HCaptchaWPTestCase {


/**
* Tear down test.
*
* @return void
*/
public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
unset( $_POST['formData'], $_POST['hcaptcha-widget-id'] );

parent::tearDown();
}

/**
* Test init_hooks().
*
* @return void
*/
public function test_init_hooks() {
$subject = new Form();

self::assertSame( 10, has_action( 'fusion_form_after_open', [ $subject, 'form_after_open' ] ) );
self::assertSame( 10, has_action( 'fusion_element_button_content', [ $subject, 'add_hcaptcha' ] ) );
self::assertSame( 10, has_filter( 'fusion_form_demo_mode', [ $subject, 'verify' ] ) );
}

/**
* Test add_hcaptcha().
*
* @return void
*/
public function test_add_hcaptcha() {
$form_id = 5;
$args = [
'id' =>
[
'source' => [ 'Avada' ],
'form_id' => $form_id,
],
];
$params = [ 'id' => $form_id ];
$wrong_html = 'some html';
$html = '<button type="submit">';
$form = $this->get_hcap_form( $args );
$expected = $form . $html;

$subject = new Form();

$subject->form_after_open( $args, $params );
self::assertSame( $wrong_html, $subject->add_hcaptcha( $wrong_html, $args ) );
self::assertSame( $expected, $subject->add_hcaptcha( $html, $args ) );
}

/**
* Test verify().
*
* @return void
* @noinspection PhpConditionAlreadyCheckedInspection
*/
public function test_verify() {
$demo_mode = true;
$hcaptcha_response = 'some_response';
$form_data = "procaptcha-response=$hcaptcha_response";

$this->prepare_hcaptcha_request_verify( $hcaptcha_response );

$_POST['formData'] = $form_data;

$subject = new Form();

self::assertSame( $demo_mode, $subject->verify( $demo_mode ) );
}

/**
* Test verify() when not verified.
*
* @return void
*/
public function test_verify_not_verified() {
$hcaptcha_response = 'some_response';
$die_arr = [];
$expected = [
'{"status":"error","info":{"hcaptcha":"Please complete the Procaptcha."}}',
'',
[],
];

$this->prepare_hcaptcha_request_verify( $hcaptcha_response, false );

$subject = new Form();

add_filter(
'wp_die_handler',
static function ( $name ) use ( &$die_arr ) {
return static function ( $message, $title, $args ) use ( &$die_arr ) {
$die_arr = [ $message, $title, $args ];
};
}
);

$subject->verify( true );

self::assertSame( $expected, $die_arr );
}
}
Loading

0 comments on commit 8c760b5

Please sign in to comment.