Skip to content

Commit 10d3762

Browse files
authored
V4.6.0 (#362)
* Add uninstall code. * Add uninstall code. * WPCS. * Update packages. * ESLint. * Add uninstall.php tests. * Do not use iframe in callback. * Save and use rendered widgetId. * Do not use iframe in validate(). * Do not use iframe in render/re-render. * Fix form element detection in getWidgetId. * Do not use iframe in general.js. * Fix jest. * Do not use iframe in hcaptcha-nf.js. * Do not use iframe in admin-nf.js. * Fix ESLint. * Update readme.txt. * Fix ESLint. * Fix tests. * CF7 live form in admin option. * Migrations to 4.6.0. * Migrations to 4.6.0. * Update readme.txt. * Update packages. * Fixed appearance of hCaptcha in Ninja Form admin * Remove debug code. * Fix not rendering of hCaptcha in Gravity Forms admin editor after adding the hCaptcha field. * Remove debug code. * Move the hCaptcha button before CAPTCHA in the GF admin editor. * Add hCaptcha button on GF settings page. * Remove duplicated code in EA classes. * Add hCaptcha button on GF settings page. * Code style in admin-elementor.pro. * Fix not rendering of hCaptcha in Essential Addons admin editor. * Fix tests upon introducing `h-captcha` custom HTML element. * Fix EA admin without Elementor Pro. * Cover EA 100%. * Cover Pages 100%. * Update readme.txt. * Fix switching between Security Settings on Fluent Forms Global Settings page. * Fix RTL for CF7. * Fix RTL for CF7. * Fix RTL for CF7. * Fix RTL for CF7. * Fix RTL in admin. * Fix RTL in admin. * The "protect form" tag was not widely used. * Simple Membership Login. * Simple Membership Register. * Simple Membership Lost Password. * Update readme.txt. * WPCS. * Fix unit tests. * Forminator tests. * Cover Forminator by tests 100%. * Cover Forminator by tests 100%. * Cover Formidable Forms by tests 100%. * Cover Formidable Forms by tests 100%. * Cover Kadence Form by tests 100%. * Cover Kadence Form by tests 100%. * Bump up version. * Fix tests.
1 parent 0ba34f4 commit 10d3762

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3369
-1351
lines changed

.tests/js/hcaptcha/hcaptcha.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe( 'HCaptcha', () => {
3838
hCaptcha.foundForms.push( testForm );
3939

4040
expect( hCaptcha.getFoundFormById( 'test-id' ) ).toEqual( testForm );
41-
expect( hCaptcha.getFoundFormById( 'non-existent-id' ) ).toBeUndefined();
41+
expect( hCaptcha.getFoundFormById( 'non-existent-id' ) ).toBeNull();
4242
} );
4343

4444
test( 'isSameOrDescendant', () => {
@@ -65,14 +65,14 @@ describe( 'HCaptcha', () => {
6565
} );
6666

6767
test( 'bindEvents and reset', () => {
68+
function generateUniqueId() {
69+
return Math.random().toString( 36 ).substring( 2, 9 );
70+
}
71+
6872
// Mock hcaptcha object
6973
global.hcaptcha = {
70-
render: jest.fn( ( hcaptchaElement ) => {
71-
// Mock the rendering of the hCaptcha widget by adding a dataset attribute
72-
const iframe = document.createElement( 'iframe' );
73-
iframe.dataset.hcaptchaWidgetId = 'mock-widget-id';
74-
iframe.dataset.hcaptchaResponse = '';
75-
hcaptchaElement.appendChild( iframe );
74+
render: jest.fn( () => {
75+
return generateUniqueId();
7676
} ),
7777
execute: jest.fn(),
7878
reset: jest.fn(),
@@ -132,7 +132,7 @@ describe( 'HCaptcha', () => {
132132
hCaptcha.reset( form1 );
133133

134134
// Check if hcaptcha.reset was called with the correct widget id
135-
expect( global.hcaptcha.reset ).toHaveBeenCalledWith( 'mock-widget-id' );
135+
expect( global.hcaptcha.reset ).toHaveBeenCalled();
136136

137137
// Clean up DOM elements
138138
document.body.removeChild( form1 );

.tests/php/integration/CF7/AdminTest.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ public function tearDown(): void {
4747
/**
4848
* Test init_hooks().
4949
*
50-
* @param bool $mode_auto Mode auto.
5150
* @param bool $mode_embed Mode embed.
51+
* @param bool $mode_live Mode live.
5252
* @param bool $is_admin Admin mode.
53-
* @param bool $expected Hooks expected to be added.
5453
*
5554
* @dataProvider dp_test_init_hooks
5655
*/
57-
public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_admin, bool $expected ): void {
58-
$cf7_status = array_filter( [ $mode_auto ? 'form' : '', $mode_embed ? 'embed' : '' ] );
56+
public function test_init_hooks( bool $mode_embed, bool $mode_live, bool $is_admin ): void {
57+
$cf7_status = array_filter( [ $mode_embed ? 'embed' : '', $mode_live ? 'live' : '' ] );
5958
$cf7_screen = 'toplevel_page_wpcf7';
6059

6160
if ( $is_admin ) {
@@ -76,15 +75,22 @@ public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_adm
7675

7776
$subject = new Admin();
7877

79-
if ( $is_admin && $cf7_status ) {
78+
if ( $is_admin ) {
8079
set_current_screen( $cf7_screen );
8180
}
8281

83-
if ( $expected ) {
82+
if ( $mode_embed && $is_admin ) {
8483
self::assertSame(
8584
54,
8685
has_action( 'wpcf7_admin_init', [ $subject, 'add_tag_generator_hcaptcha' ] )
8786
);
87+
} else {
88+
self::assertFalse(
89+
has_action( 'wpcf7_admin_init', [ $subject, 'add_tag_generator_hcaptcha' ] )
90+
);
91+
}
92+
93+
if ( $mode_live && $is_admin ) {
8894
self::assertSame(
8995
10,
9096
has_action( 'current_screen', [ $subject, 'current_screen' ] )
@@ -106,9 +112,6 @@ public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_adm
106112
has_action( 'admin_enqueue_scripts', [ $subject, 'enqueue_admin_scripts_after_cf7' ] )
107113
);
108114
} else {
109-
self::assertFalse(
110-
has_action( 'wpcf7_admin_init', [ $subject, 'add_tag_generator_hcaptcha' ] )
111-
);
112115
self::assertFalse(
113116
has_action( 'current_screen', [ $subject, 'current_screen' ] )
114117
);
@@ -125,6 +128,24 @@ public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_adm
125128
}
126129
}
127130

131+
/**
132+
* Data provider for test_init_hooks().
133+
*
134+
* @return array
135+
*/
136+
public function dp_test_init_hooks(): array {
137+
return [
138+
[ false, false, false ],
139+
[ false, false, true ],
140+
[ false, true, false ],
141+
[ false, true, true ],
142+
[ true, false, false ],
143+
[ true, false, true ],
144+
[ true, true, false ],
145+
[ true, true, true ],
146+
];
147+
}
148+
128149
/**
129150
* Test init_hooks() when not on CF7 admin page.
130151
*
@@ -152,24 +173,6 @@ public function test_init_hooks_NOT_on_cf7_admin_page(): void {
152173
);
153174
}
154175

155-
/**
156-
* Data provider for test_init_hooks().
157-
*
158-
* @return array
159-
*/
160-
public function dp_test_init_hooks(): array {
161-
return [
162-
[ false, false, false, false ],
163-
[ false, false, true, false ],
164-
[ false, true, false, false ],
165-
[ false, true, true, true ],
166-
[ true, false, false, false ],
167-
[ true, false, true, true ],
168-
[ true, true, false, false ],
169-
[ true, true, true, true ],
170-
];
171-
}
172-
173176
/**
174177
* Test current_screen().
175178
*
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* BaseTest class file.
4+
*
5+
* @package HCaptcha\Tests
6+
*/
7+
8+
// phpcs:disable Generic.Commenting.DocComment.MissingShort
9+
/** @noinspection PhpUndefinedNamespaceInspection */
10+
/** @noinspection PhpUndefinedClassInspection */
11+
// phpcs:enable Generic.Commenting.DocComment.MissingShort
12+
13+
namespace HCaptcha\Tests\Integration\EssentialAddons;
14+
15+
use HCaptcha\EssentialAddons\Base;
16+
use HCaptcha\Tests\Integration\HCaptchaWPTestCase;
17+
use Mockery;
18+
use Patchwork\Exceptions\NonNullToVoid;
19+
use tad\FunctionMocker\FunctionMocker;
20+
21+
/**
22+
* Class BaseTest
23+
*
24+
* @group essential-addons
25+
* @group essential-addons-login
26+
*/
27+
class BaseTest extends HCaptchaWPTestCase {
28+
29+
/**
30+
* Tear down the test.
31+
*
32+
* @return void
33+
*/
34+
public function tearDown(): void {
35+
unset( $_GET['elementor-preview'] );
36+
37+
parent::tearDown();
38+
}
39+
40+
/**
41+
* Test enqueue_scripts().
42+
*
43+
* @return void
44+
*/
45+
public function test_enqueue_scripts(): void {
46+
$subject = Mockery::mock( Base::class );
47+
48+
$subject->makePartial();
49+
50+
$subject->enqueue_scripts();
51+
52+
self::assertFalse( wp_script_is( 'admin-essential-addons' ) );
53+
54+
$_GET['elementor-preview'] = '4242';
55+
56+
$subject->enqueue_scripts();
57+
58+
self::assertTrue( wp_script_is( 'admin-essential-addons' ) );
59+
}
60+
61+
/**
62+
* Test print_hcaptcha_scripts().
63+
*
64+
* @return void
65+
*/
66+
public function test_print_hcaptcha_scripts(): void {
67+
$subject = Mockery::mock( Base::class );
68+
69+
$subject->makePartial();
70+
71+
self::assertFalse( $subject->print_hcaptcha_scripts( false ) );
72+
self::assertTrue( $subject->print_hcaptcha_scripts( true ) );
73+
74+
$_GET['elementor-preview'] = '4242';
75+
76+
self::assertTrue( $subject->print_hcaptcha_scripts( false ) );
77+
self::assertTrue( $subject->print_hcaptcha_scripts( true ) );
78+
}
79+
}

.tests/php/integration/EssentialAddons/LoginTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function test_init_hooks(): void {
6262
has_action( 'eael/login-register/before-login-footer', [ $subject, 'add_login_hcaptcha' ] )
6363
);
6464
self::assertSame( 10, has_action( 'eael/login-register/before-login', [ $subject, 'verify' ] ) );
65+
66+
self::assertSame( 10, has_action( 'wp_enqueue_scripts', [ $subject, 'enqueue_scripts' ] ) );
67+
self::assertSame( 10, has_action( 'hcap_print_hcaptcha_scripts', [ $subject, 'print_hcaptcha_scripts' ] ) );
6568
}
6669

6770
/**

.tests/php/integration/EssentialAddons/RegisterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function test_init_hooks(): void {
5252
self::assertSame( 10, has_action( 'eael/login-register/before-register', [ $subject, 'verify' ] ) );
5353

5454
self::assertSame( 10, has_action( 'wp_head', [ $subject, 'print_inline_styles' ] ) );
55+
56+
self::assertSame( 10, has_action( 'wp_enqueue_scripts', [ $subject, 'enqueue_scripts' ] ) );
57+
self::assertSame( 10, has_action( 'hcap_print_hcaptcha_scripts', [ $subject, 'print_hcaptcha_scripts' ] ) );
5558
}
5659

5760
/**

0 commit comments

Comments
 (0)