Skip to content

Commit

Permalink
V2.9.0 (#249)
Browse files Browse the repository at this point in the history
* Fix tests.

* Fix tests.

* Fix ignoring hCaptcha on comments with Akismet.

* Fix WordPress and WooCommerce settings "interfere" #245.

* Update readme.txt.

* Add visualisation of activation and deactivation.

* Update readme.txt.

* Update readme.txt.

* Update readme.txt.

* Fix tests.

* Add widget filter to ACFE.

* Update readme.txt.

* Protection against widget id counterfeiting.

* Protection against widget id counterfeiting.

* Add widget filter to Asgaros.

* Simplify the code.

* Add widget filter to Avada.

* Add widget filter to Avada.

* Fix endless loop on login with invisible hCaptcha and Safari 14-15.

* Add widget filter to BBPress.

* Add widget filter to Beaver Builder.

* Fix code due to changes in the Brizy plugin.

* Add widget filter to Brizy.

* Update readme.txt.

* Update readme.txt.

* Add widget filter to BuddyPress.

* Fix invisible hCaptcha with Beaver Builder (ajax).

* Fix invisible hCaptcha with Beaver Builder (ajax).

* Back In Stock Notifier support.

* Commence with Colorlib Customizer.

* Fix Divi login issue.

* Add compatibility with Colorlib Login Customizer.

* Update yarn.lock.

* Minor refactoring.

* Fix bug in hcaptcha.js with formElement.requestSubmit.
Fix tests.

* Add Divi Email Optin support.

* Add animation on activation/deactivation plugin.

* Fix tests.

* Fix transparency on some logos.

* Add widget filter to Download Manager.
Fix bug in Download Manager.

* Add widget filter to Elementor.
Fix bug in caused by changes in Elementor.

* Update readme.txt.

* Add widget filter to Fluent
Form.

* Fix tests.

* Update readme.txt.

* ESLInt.

* Add widget filter to Forminator
Form.

* Add widget filter to GiveWP
Form.
Fix bug caused by plugin update.

* WPCS.

* Bump up version.
  • Loading branch information
kagg-design authored Jun 5, 2023
1 parent 7e5280e commit 3367397
Show file tree
Hide file tree
Showing 61 changed files with 2,721 additions and 1,331 deletions.
132 changes: 71 additions & 61 deletions .tests/js/assets-js-files/integrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,77 @@ global.HCaptchaIntegrationsObject = {

function getDom() {
return `
<html lang="en">
<body>
<div id="hcaptcha-integrations-message"></div>
<table class="form-table">
<tbody>
<tr class="hcaptcha-integrations-wp-status">
<th scope="row">
<img src="https://test.test/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/wp-core-logo.png" alt="WP Core Logo">
</th>
<td>
<fieldset>
<label for="wp_status_1">
<input id="wp_status_1" name="hcaptcha_settings[wp_status][]" type="checkbox" value="comment" checked="checked">
Comment Form
</label>
<br>
<label for="wp_status_2">
<input id="wp_status_2" name="hcaptcha_settings[wp_status][]" type="checkbox" value="login" checked="checked">
Login Form
</label>
<br>
<label for="wp_status_3">
<input id="wp_status_3" name="hcaptcha_settings[wp_status][]" type="checkbox" value="lost_pass" checked="checked">
Lost Password Form
</label>
<br>
<label for="wp_status_4">
<input id="wp_status_4" name="hcaptcha_settings[wp_status][]" type="checkbox" value="password_protected" checked="checked">
Post/Page Password Form
</label>
<br>
<label for="wp_status_5">
<input id="wp_status_5" name="hcaptcha_settings[wp_status][]" type="checkbox" value="register" checked="checked">
Register Form
</label>
<br>
</fieldset>
</td>
</tr>
</tbody>
</table>
<table class="form-table">
<tbody>
<tr class="hcaptcha-integrations-acfe-status">
<th scope="row">
<img src="https://test.test/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/acf-extended-logo.png" alt="ACF Extended Logo">
</th>
<td>
<fieldset disabled="disabled">
<label for="acfe_status_1">
<input id="acfe_status_1" name="hcaptcha_settings[acfe_status][]" type="checkbox" value="form" checked="checked">
ACF Extended Form
</label>
<br>
</fieldset>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<html lang="en">
<body>
<div id="wpwrap">
<div id="hcaptcha-integrations-message"></div>
<table class="form-table">
<tbody>
<tr class="hcaptcha-integrations-wp-status">
<th scope="row">
<img src="https://test.test/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/wp-core-logo.png"
alt="WP Core Logo">
</th>
<td>
<fieldset>
<label for="wp_status_1">
<input id="wp_status_1" name="hcaptcha_settings[wp_status][]" type="checkbox" value="comment"
checked="checked">
Comment Form
</label>
<br>
<label for="wp_status_2">
<input id="wp_status_2" name="hcaptcha_settings[wp_status][]" type="checkbox" value="login"
checked="checked">
Login Form
</label>
<br>
<label for="wp_status_3">
<input id="wp_status_3" name="hcaptcha_settings[wp_status][]" type="checkbox" value="lost_pass"
checked="checked">
Lost Password Form
</label>
<br>
<label for="wp_status_4">
<input id="wp_status_4" name="hcaptcha_settings[wp_status][]" type="checkbox"
value="password_protected" checked="checked">
Post/Page Password Form
</label>
<br>
<label for="wp_status_5">
<input id="wp_status_5" name="hcaptcha_settings[wp_status][]" type="checkbox" value="register"
checked="checked">
Register Form
</label>
<br>
</fieldset>
</td>
</tr>
</tbody>
</table>
<table class="form-table">
<tbody>
<tr class="hcaptcha-integrations-acfe-status">
<th scope="row">
<img src="https://test.test/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/acf-extended-logo.png"
alt="ACF Extended Logo">
</th>
<td>
<fieldset disabled="disabled">
<label for="acfe_status_1">
<input id="acfe_status_1" name="hcaptcha_settings[acfe_status][]" type="checkbox" value="form"
checked="checked">
ACF Extended Form
</label>
<br>
</fieldset>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
`;
}

Expand Down
4 changes: 2 additions & 2 deletions .tests/js/hcaptcha/hcaptcha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ describe( 'HCaptcha', () => {
document.body.appendChild( form3 );

// Spy on addEventListener before calling bindEvents
const form1ClickHandler = jest.spyOn( form1, 'addEventListener' );
const submit1ClickHandler = jest.spyOn( submit1, 'addEventListener' );

hCaptcha.bindEvents();

// Check that hcaptcha.render was called twice (for form1 and form2)
expect( global.hcaptcha.render ).toHaveBeenCalledTimes( 2 );

// Check that an event listener was added to form1 for invisible hCaptcha
expect( form1ClickHandler ).toHaveBeenCalledWith( 'click', expect.any( Function ), false );
expect( submit1ClickHandler ).toHaveBeenCalledWith( 'click', expect.any( Function ), true );

// Simulate click event on form1
const clickEvent = new Event( 'click', { bubbles: true } );
Expand Down
9 changes: 9 additions & 0 deletions .tests/php/integration/AMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use HCaptcha\BuddyPress\CreateGroup;
use HCaptcha\CF7\CF7;
use HCaptcha\Divi\Contact;
use HCaptcha\Divi\EmailOptin;
use HCaptcha\FluentForm\Form;
use HCaptcha\Jetpack\JetpackForm;
use HCaptcha\Main;
Expand Down Expand Up @@ -510,6 +511,9 @@ public function test_print_inline_styles() {
#af-wrapper div.editor-row.editor-row-hcaptcha .h-captcha {
margin-bottom: 0;
}
.brz-forms2.brz-forms2__item .h-captcha {
margin-bottom: 0;
}
form.wpsc-create-ticket .h-captcha {
margin: 0 15px 15px 15px;
}
Expand Down Expand Up @@ -1084,6 +1088,11 @@ public function dp_test_load_modules() {
'Divi',
Contact::class,
],
'Divi Email Optin Form' => [
[ 'divi_status', 'email_optin' ],
'Divi',
EmailOptin::class,
],
'Divi Login Form' => [
[ 'divi_status', 'login' ],
'Divi',
Expand Down
50 changes: 29 additions & 21 deletions .tests/php/integration/CF7/CF7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,37 @@ public function tearDown(): void {
public function test_init_hooks() {
$subject = new CF7();

self::assertSame( 10, has_filter( 'wpcf7_form_elements', [ $subject, 'wpcf7_form_elements' ] ) );
self::assertSame( 20, has_filter( 'do_shortcode_tag', [ $subject, 'wpcf7_shortcode' ] ) );
self::assertTrue( shortcode_exists( 'cf7-hcaptcha' ) );
self::assertSame( 20, has_filter( 'wpcf7_validate', [ $subject, 'verify_hcaptcha' ] ) );
self::assertSame( 9, has_action( 'wp_print_footer_scripts', [ $subject, 'enqueue_scripts' ] ) );
}

/**
* Test hcap_cf7_wpcf7_form_elements().
* Test wpcf7_shortcode().
*
* @param string $hcaptcha_size Widget size/visibility.
*
* @dataProvider dp_test_hcap_cf7_wpcf7_form_elements
* @dataProvider dp_test_wpcf7_shortcode
*/
public function test_hcap_cf7_wpcf7_form_elements( $hcaptcha_size ) {
$form =
public function test_wpcf7_shortcode( $hcaptcha_size ) {
$output =
'<form>' .
'<input type="submit" value="Send">' .
'</form>';

$uniqid = 'hcap_cf7-6004092a854114.24546665';

$nonce = wp_nonce_field( 'wp_rest', '_wpnonce', true, false );

$tag = 'contact-form-7';
$attr = [];
$m = [
'[contact-form-7 id="177" title="Contact form 1"]',
'',
'contact-form-7',
'id="177" title="Contact form 1"',
'',
'',
'',
];
$uniqid = 'hcap_cf7-6004092a854114.24546665';
$nonce = wp_nonce_field( 'wp_rest', '_wpnonce', true, false );
$hcaptcha_site_key = 'some site key';
$hcaptcha_theme = 'some theme';

Expand All @@ -99,16 +107,16 @@ static function ( $prefix, $more_entropy ) use ( $uniqid ) {
}
);

$callback = 'invisible' === $hcaptcha_size ? '" data-callback="hCaptchaSubmit' : '';
$callback = 'invisible' === $hcaptcha_size ? 'data-callback="hCaptchaSubmit"' : '';

$expected =
'<form>' .
'<span class="wpcf7-form-control-wrap" data-name="hcap-cf7">' .
'<span id="' . $uniqid .
'" class="wpcf7-form-control h-captcha" data-sitekey="' . $hcaptcha_site_key .
'" data-theme="' . $hcaptcha_theme .
$callback .
'" data-size="' . $hcaptcha_size . '">' .
'<span id="' . $uniqid . '"' .
' class="wpcf7-form-control h-captcha" data-sitekey="' . $hcaptcha_site_key . '"' .
' data-theme="' . $hcaptcha_theme . '"' .
' data-size="' . $hcaptcha_size . '"' .
' ' . $callback . '>' .
'</span>' .
'</span>' .
$nonce .
Expand All @@ -117,20 +125,20 @@ static function ( $prefix, $more_entropy ) use ( $uniqid ) {

$subject = new CF7();

self::assertSame( $expected, $subject->wpcf7_form_elements( $form ) );
self::assertSame( $expected, $subject->wpcf7_shortcode( $output, $tag, $attr, $m ) );

$form = str_replace( '<input', '[cf7-hcaptcha]<input', $form );
$output = str_replace( '<input', '[cf7-hcaptcha]<input', $output );
$expected = str_replace( '<br>', '', $expected );

self::assertSame( $expected, $subject->wpcf7_form_elements( $form ) );
self::assertSame( $expected, $subject->wpcf7_shortcode( $output, $tag, $attr, $m ) );
}

/**
* Data provide for test_hcap_cf7_wpcf7_form_elements().
* Data provide for test_wpcf7_shortcode().
*
* @return array
*/
public function dp_test_hcap_cf7_wpcf7_form_elements() {
public function dp_test_wpcf7_shortcode() {
return [
'visible' => [ 'normal' ],
'invisible' => [ 'invisible' ],
Expand Down
7 changes: 7 additions & 0 deletions .tests/php/integration/ElementorPro/HCaptchaHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ public function test_render_field() {
'data-size' => $size,
],
];
$form_id = 'test_form';
$data = [
'settings' => [
'form_id' => $form_id,
],
];
$expected = '<div class="elementor-field" id="form-field-_014ea7c"><div class="elementor-hcaptcha"> <div
class="h-captcha"
data-sitekey="some site key"
Expand All @@ -546,6 +552,7 @@ class="h-captcha"

$widget = Mockery::mock( Widget_Base::class );
$widget->shouldReceive( 'add_render_attribute' )->with( $render_attributes )->once();
$widget->shouldReceive( 'get_raw_data' )->with()->once()->andReturn( $data );

$subject = new HCaptchaHandler();

Expand Down
4 changes: 3 additions & 1 deletion .tests/php/integration/FluentForm/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function test_constructor_and_init_hooks() {
public function test_add_captcha() {
hcaptcha()->init_hooks();

$form = (object) [];
$form = (object) [
'id' => 1,
];

$mock = Mockery::mock( Form::class )->makePartial();
$mock->shouldAllowMockingProtectedMethods();
Expand Down
1 change: 1 addition & 0 deletions .tests/php/integration/HCaptchaWPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function setUp(): void {
FunctionMocker::setUp();
parent::setUp();

hcaptcha()->has_result = false;
$_SERVER['REQUEST_URI'] = 'http://test.test/';
}

Expand Down
8 changes: 0 additions & 8 deletions .tests/php/integration/NF/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

/**
* Test Fields class.
*
* Cannot activate Ninja Forms plugin with php 8.0
* due to some bug with uksort() in \Ninja_Forms::plugins_loaded()
* caused by antecedent/patchwork.
*
* @requires PHP < 8.0
*/
class FieldsTest extends HCaptchaPluginWPTestCase {

Expand All @@ -30,8 +24,6 @@ class FieldsTest extends HCaptchaPluginWPTestCase {

/**
* Test __construct().
*
* @noinspection PhpUndefinedMethodInspection
*/
public function test_constructor() {
$subject = new Fields();
Expand Down
6 changes: 0 additions & 6 deletions .tests/php/integration/NF/NFTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@

/**
* Test ninja-forms-hcaptcha.php file.
*
* Cannot activate Ninja Forms plugin with php 8.0
* due to some bug with uksort() in \Ninja_Forms::plugins_loaded()
* caused by antecedent/patchwork.
*
* @requires PHP < 8.0
*/
class NFTest extends HCaptchaPluginWPTestCase {

Expand Down
5 changes: 0 additions & 5 deletions .tests/php/integration/WC/CheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
*
* WooCommerce requires PHP 7.3.
*
* Cannot activate WooCommerce plugin with php 8.0
* due to some bug with usort() in \WC_Install::needs_db_update()
* caused by antecedent/patchwork.
*
* @requires PHP >= 7.3
* @requires PHP < 8.0
*
* @group wc-checkout
* @group wc
Expand Down
7 changes: 2 additions & 5 deletions .tests/php/integration/WCWishlists/CreateListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
*
* WooCommerce requires PHP 7.3.
*
* Cannot activate WooCommerce plugin with php 8.0
* due to some bug with usort() in \WC_Install::needs_db_update()
* caused by antecedent/patchwork.
*
* @requires PHP >= 7.3
* @requires PHP < 8.0
*
* @group wcwishlist
*/
class CreateListTest extends HCaptchaPluginWPTestCase {

Expand Down
2 changes: 1 addition & 1 deletion .tests/php/integration/WP/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function test_constructor_and_init_hooks( $active ) {
}

self::assertSame(
10,
20,
has_filter( 'pre_comment_approved', [ $subject, 'verify' ] )
);
}
Expand Down
Loading

0 comments on commit 3367397

Please sign in to comment.