Skip to content

Commit 7fae9cf

Browse files
V3.8.0 (#310)
* Provide api_url via method. * Provide verify_url via method. * Position Brevo in alphabet order on Integrations page. * Add search of plugin and themes on the Integrations page. * Add magnifying glass to search. * Add hCaptcha icon to the menu. * Toggle sections on General page. * Fix tests. * Update readme.txt. * Add hcap_src filter. * Add hcap_api_host filter. * Fix testing config with test accounts. * Fixed bug with saving Notification state * ESLint. * Add search on Integrations page notification. * Add search on Integrations page notification. * Add search on Integrations page notification. * Add search on Integrations page notification. * Remove deprecated. * Make section header clickable on General page. * Fix compatibility of Ninja Forms with GeoDirectory. * Fix compatibility of Beaver Builder, Divi, MailPoet and Passster with GeoDirectory. * Updated integration with Back In Stock Notifier. * Dialog system. * Select new theme on deactivation of the current one. * Improve UX of the Dialog system. * Add tests after for deactivating theme. * Add backend parameter. * Force https on api host and params. * Update readme.txt. * Do not deactivate a theme when it is the only one on the site. * Fix positioning of the menu icon. * Fix General and Dialog styles on mobile. * Fix General and Dialog styles on mobile. * Fix General and Dialog styles on mobile. * Move Dialogs to pure JS. * Move Dialogs to pure JS. * Add customized alert. * Allow click to the lef/right from container. * Do not activate non-existing theme. * Fix error messages in settings on mobile. * Fix error messages in settings on mobile. * ESLint. * Fix multiple issues with swapping themes. * USe backend for /checksiteconfig. * Fix jest for Dialog. * Bump up version. * Apply suggestions from code review * Apply suggestions from code review --------- Co-authored-by: e271828- <e271828-@users.noreply.github.com>
1 parent 668957b commit 7fae9cf

Some content is hidden

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

43 files changed

+1553
-387
lines changed

.tests/js/assets-js-files/integrations.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,15 @@ describe( 'integrations', () => {
146146
$( $img.get( 0 ) ).trigger( 'click' );
147147
expect( postSpy ).not.toHaveBeenCalled();
148148

149-
jest.spyOn( global, 'confirm' ).mockReturnValueOnce( true );
149+
// Mock window.kaggDialog object and methods
150+
window.kaggDialog = {
151+
confirm: jest.fn( ( settings ) => settings.onAction( true ) ),
152+
};
153+
// jest.spyOn( global, 'kaggDialog.confirm' ).mockReturnValueOnce( true );
150154

151155
$( $img.get( 1 ) ).trigger( 'click' );
156+
157+
// expect( window.kaggDialog ).toHaveBeenCalled();
152158
expect( postSpy ).toHaveBeenCalled();
153159
} );
154160
} );

.tests/php/integration/Admin/NotificationsTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function test_init( bool $empty_keys ) {
4242
$secret_key = '';
4343

4444
$expected = [
45-
'register' =>
45+
'register' =>
4646
[
4747
'title' => 'Get your hCaptcha site keys',
4848
'message' => 'To use <a href="https://www.hcaptcha.com/?r=wp&utm_source=wordpress&utm_medium=wpplugin&utm_campaign=sk" target="_blank">hCaptcha</a>, please register <a href="https://www.hcaptcha.com/signup-interstitial/?r=wp&utm_source=wordpress&utm_medium=wpplugin&utm_campaign=sk" target="_blank">here</a> to get your site and secret keys.',
@@ -52,7 +52,7 @@ public function test_init( bool $empty_keys ) {
5252
'text' => 'Get site keys',
5353
],
5454
],
55-
'pro-free-trial' =>
55+
'pro-free-trial' =>
5656
[
5757
'title' => 'Try Pro for free',
5858
'message' => 'Want low friction and custom themes? <a href="https://www.hcaptcha.com/pro?r=wp&utm_source=wordpress&utm_medium=wpplugin&utm_campaign=not" target="_blank">hCaptcha Pro</a> is for you. <a href="https://dashboard.hcaptcha.com/?r=wp&utm_source=wordpress&utm_medium=wpplugin&utm_campaign=not" target="_blank">Start a free trial in your dashboard</a>, no credit card required.',
@@ -62,14 +62,22 @@ public function test_init( bool $empty_keys ) {
6262
'text' => 'Try Pro',
6363
],
6464
],
65-
'post-leadership' => [
65+
'post-leadership' => [
6666
'title' => 'hCaptcha\'s Leadership',
6767
'message' => 'hCaptcha Named a Technology Leader in Bot Management: 2023 SPARK Matrix™',
6868
'button' => [
6969
'url' => 'https://www.hcaptcha.com/post/hcaptcha-named-a-technology-leader-in-bot-management/?r=wp&utm_source=wordpress&utm_medium=wpplugin&utm_campaign=not',
7070
'text' => 'Read post',
7171
],
7272
],
73+
'search-integrations' => [
74+
'title' => 'Search on Integrations page',
75+
'message' => 'Now you can search for plugin an themes on the Integrations page.',
76+
'button' => [
77+
'url' => 'http://test.test/wp-admin/options-general.php?page=hcaptcha&tab=integrations#hcaptcha-integrations-search',
78+
'text' => 'Start search',
79+
],
80+
],
7381
];
7482

7583
if ( ! $empty_keys ) {

.tests/php/integration/Mailchimp/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function test_add_hcap_error_messages() {
5959
'type' => 'error',
6060
'text' => 'The response parameter has already been checked, or has another issue.',
6161
],
62-
'not-using-dummy-passcode' => [
62+
'not-using-dummy-secret' => [
6363
'type' => 'error',
6464
'text' => 'You have used a testing sitekey but have not used its matching secret.',
6565
],

.tests/php/integration/includes/RequestTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,4 @@ public function test_hcaptcha_get_verify_message_html_not_validated_empty_POST()
378378

379379
self::assertSame( '<strong>hCaptcha error:</strong> Please complete the hCaptcha.', hcaptcha_get_verify_message_html( $nonce_field_name, $nonce_action_name ) );
380380
}
381-
382-
/**
383-
* Test hcap_hcaptcha_error_message().
384-
*/
385-
public function test_hcap_hcaptcha_error_message() {
386-
$hcaptcha_content = 'Some content';
387-
$expected = '<p id="hcap_error" class="error hcap_error">The hCaptcha is invalid.</p>' . $hcaptcha_content;
388-
389-
self::assertSame( $expected, hcap_hcaptcha_error_message( $hcaptcha_content ) );
390-
}
391381
}

.tests/php/unit/HCaptchaTestCase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@ protected function get_test_general_form_fields(): array {
617617
'section' => 'enterprise',
618618
'helper' => 'See Enterprise docs.',
619619
],
620+
'backend' => [
621+
'label' => 'Backend',
622+
'type' => 'text',
623+
'section' => 'enterprise',
624+
'default' => 'api.hcaptcha.com',
625+
'helper' => 'See Enterprise docs.',
626+
],
620627
'off_when_logged_in' => [
621628
'label' => 'Other Settings',
622629
'type' => 'checkbox',
@@ -1011,7 +1018,7 @@ protected function get_test_integrations_form_fields(): array {
10111018
],
10121019
'sendinblue_status' =>
10131020
[
1014-
'label' => 'Sendinblue',
1021+
'label' => 'Brevo',
10151022
'type' => 'checkbox',
10161023
'options' =>
10171024
[

.tests/php/unit/Settings/Abstracts/SettingsBaseTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,18 @@ public function test_base_admin_enqueue_scripts() {
501501
$subject = Mockery::mock( SettingsBase::class )->makePartial();
502502
$subject->shouldAllowMockingProtectedMethods();
503503
$subject->shouldReceive( 'get_active_tab' )->once()->andReturn( $page );
504-
$subject->shouldReceive( 'plugin_url' )->once()->andReturn( $plugin_url );
505-
$subject->shouldReceive( 'plugin_version' )->once()->andReturn( $plugin_version );
504+
$subject->shouldReceive( 'plugin_url' )->twice()->andReturn( $plugin_url );
505+
$subject->shouldReceive( 'plugin_version' )->twice()->andReturn( $plugin_version );
506506
$subject->shouldReceive( 'is_options_screen' )->andReturn( true );
507507

508+
WP_Mock::userFunction( 'wp_enqueue_style' )
509+
->with(
510+
SettingsBase::PREFIX . '-settings-admin',
511+
$plugin_url . '/assets/css/settings-admin.css',
512+
[],
513+
$plugin_version
514+
)
515+
->once();
508516
WP_Mock::userFunction( 'wp_enqueue_style' )
509517
->with(
510518
SettingsBase::PREFIX . '-' . SettingsBase::HANDLE,
@@ -657,6 +665,7 @@ public function test_tabs_callback() {
657665
->with( 'tab', strtolower( $tab_class_name ), $subject_url )->andReturn( $tab_url_arg );
658666

659667
$expected = ' <div class="kagg-settings-tabs">
668+
<span class="kagg-settings-links">
660669
<a
661670
class="kagg-settings-tab active"
662671
href="http://test.test/wp-admin/admin.php?page=hcaptcha">
@@ -665,7 +674,8 @@ class="kagg-settings-tab active"
665674
class="kagg-settings-tab"
666675
href="http://test.test/wp-admin/admin.php?page=hcaptcha&tab=integrations">
667676
Integrations </a>
668-
</div>
677+
</span>
678+
</div>
669679
';
670680

671681
ob_start();

.tests/php/unit/Settings/GeneralTest.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,21 @@ public function test_page_title() {
8787
public function test_menu_title() {
8888
$subject = Mockery::mock( General::class )->makePartial()->shouldAllowMockingProtectedMethods();
8989

90-
$method = 'menu_title';
91-
self::assertSame( 'hCaptcha', $subject->$method() );
90+
FunctionMocker::replace(
91+
'constant',
92+
static function ( $name ) {
93+
if ( 'HCAPTCHA_URL' === $name ) {
94+
return HCAPTCHA_TEST_URL;
95+
}
96+
97+
return '';
98+
}
99+
);
100+
101+
$method = 'menu_title';
102+
$expected = '<img class="kagg-settings-menu-image" src="https://site.org/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/hcaptcha-icon.svg" alt="hCaptcha icon"><span class="kagg-settings-menu-title">hCaptcha</span>';
103+
104+
self::assertSame( $expected, $subject->$method() );
92105
}
93106

94107
/**
@@ -195,6 +208,7 @@ public function test_setup_fields_not_on_options_screen() {
195208
* @throws ReflectionException ReflectionException.
196209
*/
197210
public function test_section_callback( string $section_id, string $expected ) {
211+
$user = (object) [ 'ID' => 1 ];
198212
$notifications = Mockery::mock( Notifications::class )->makePartial();
199213
$subject = Mockery::mock( General::class )->makePartial()->shouldAllowMockingProtectedMethods();
200214

@@ -204,6 +218,8 @@ public function test_section_callback( string $section_id, string $expected ) {
204218
$notifications->shouldReceive( 'show' )->once();
205219
}
206220

221+
WP_Mock::userFunction( 'wp_get_current_user' )->andReturn( $user );
222+
WP_Mock::userFunction( 'get_user_meta' )->andReturn( [] );
207223
WP_Mock::passthruFunction( 'wp_kses_post' );
208224

209225
ob_start();
@@ -223,22 +239,52 @@ public function dp_test_section_callback(): array {
223239
' <h2>
224240
General </h2>
225241
<div id="hcaptcha-message"></div>
226-
<h3 class="hcaptcha-section-keys">Keys</h3>
242+
<h3 class="hcaptcha-section-keys">
243+
<span class="hcaptcha-section-header-title">
244+
Keys </span>
245+
<span class="hcaptcha-section-header-toggle">
246+
</span>
247+
</h3>
227248
',
228249
],
229250
'appearance' => [
230251
General::SECTION_APPEARANCE,
231-
' <h3 class="hcaptcha-section-appearance">Appearance</h3>
252+
' <h3 class="hcaptcha-section-appearance">
253+
<span class="hcaptcha-section-header-title">
254+
Appearance </span>
255+
<span class="hcaptcha-section-header-toggle">
256+
</span>
257+
</h3>
232258
',
233259
],
234260
'custom' => [
235261
General::SECTION_CUSTOM,
236-
' <h3 class="hcaptcha-section-custom">Custom</h3>
262+
' <h3 class="hcaptcha-section-custom">
263+
<span class="hcaptcha-section-header-title">
264+
Custom </span>
265+
<span class="hcaptcha-section-header-toggle">
266+
</span>
267+
</h3>
268+
',
269+
],
270+
'enterprise' => [
271+
General::SECTION_ENTERPRISE,
272+
' <h3 class="hcaptcha-section-enterprise">
273+
<span class="hcaptcha-section-header-title">
274+
Enterprise </span>
275+
<span class="hcaptcha-section-header-toggle">
276+
</span>
277+
</h3>
237278
',
238279
],
239280
'other' => [
240281
General::SECTION_OTHER,
241-
' <h3 class="hcaptcha-section-other">Other</h3>
282+
' <h3 class="hcaptcha-section-other">
283+
<span class="hcaptcha-section-header-title">
284+
Other </span>
285+
<span class="hcaptcha-section-header-toggle">
286+
</span>
287+
</h3>
242288
',
243289
],
244290
'wrong' => [ 'wrong', '' ],
@@ -309,14 +355,21 @@ static function ( $name ) use ( $plugin_url, $plugin_version ) {
309355
->andReturn( $nonce )
310356
->once();
311357

358+
WP_Mock::userFunction( 'wp_create_nonce' )
359+
->with( General::TOGGLE_SECTION_ACTION )
360+
->andReturn( $nonce )
361+
->once();
362+
312363
WP_Mock::userFunction( 'wp_localize_script' )
313364
->with(
314365
General::HANDLE,
315366
General::OBJECT,
316367
[
317368
'ajaxUrl' => $ajax_url,
318369
'checkConfigAction' => General::CHECK_CONFIG_ACTION,
319-
'nonce' => $nonce,
370+
'checkConfigNonce' => $nonce,
371+
'toggleSectionAction' => General::TOGGLE_SECTION_ACTION,
372+
'toggleSectionNonce' => $nonce,
320373
'modeLive' => General::MODE_LIVE,
321374
'modeTestPublisher' => General::MODE_TEST_PUBLISHER,
322375
'modeTestEnterpriseSafeEndUser' => General::MODE_TEST_ENTERPRISE_SAFE_END_USER,

.tests/php/unit/Settings/IntegrationsTest.php

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace HCaptcha\Tests\Unit\Settings;
1414

15+
use HCaptcha\Admin\Dialog;
1516
use HCaptcha\Settings\PluginSettingsBase;
1617
use KAGG\Settings\Abstracts\SettingsBase;
1718
use HCaptcha\Settings\Integrations;
@@ -84,8 +85,21 @@ public function test_page_title() {
8485
public function test_menu_title() {
8586
$subject = Mockery::mock( Integrations::class )->makePartial()->shouldAllowMockingProtectedMethods();
8687

87-
$method = 'menu_title';
88-
self::assertSame( 'hCaptcha', $subject->$method() );
88+
FunctionMocker::replace(
89+
'constant',
90+
static function ( $name ) {
91+
if ( 'HCAPTCHA_URL' === $name ) {
92+
return HCAPTCHA_TEST_URL;
93+
}
94+
95+
return '';
96+
}
97+
);
98+
99+
$method = 'menu_title';
100+
$expected = '<img class="kagg-settings-menu-image" src="https://site.org/wp-content/plugins/hcaptcha-wordpress-plugin/assets/images/hcaptcha-icon.svg" alt="hCaptcha icon"><span class="kagg-settings-menu-title">hCaptcha</span>';
101+
102+
self::assertSame( $expected, $subject->$method() );
89103
}
90104

91105
/**
@@ -207,6 +221,7 @@ public function test_setup_fields_not_on_options_screen() {
207221
* @param string $expected Expected value.
208222
*
209223
* @dataProvider dp_test_section_callback
224+
* @throws ReflectionException ReflectionException.
210225
*/
211226
public function test_section_callback( string $id, string $expected ) {
212227
WP_Mock::passthruFunction( 'wp_kses_post' );
@@ -261,6 +276,26 @@ public function test_admin_enqueue_scripts() {
261276
$ajax_url = 'https://test.test/wp-admin/admin-ajax.php';
262277
$nonce = 'some_nonce';
263278

279+
$theme = Mockery::mock( 'WP_Theme' );
280+
$default_theme = Mockery::mock( 'WP_Theme' );
281+
282+
FunctionMocker::replace(
283+
'\WP_Theme::get_core_default_theme',
284+
static function () use ( $default_theme ) {
285+
return $default_theme;
286+
}
287+
);
288+
289+
$theme->shouldReceive( 'get_stylesheet' )->andReturn( 'Divi' );
290+
$theme->shouldReceive( 'get' )->with( 'Name' )->andReturn( 'Divi' );
291+
$default_theme->shouldReceive( 'get_stylesheet' )->andReturn( 'twentytwentyone' );
292+
$default_theme->shouldReceive( 'get' )->andReturn( 'Twenty Twenty-One' );
293+
294+
$themes = [
295+
'Divi' => $theme,
296+
'twentytwentyone' => $default_theme,
297+
];
298+
264299
$subject = Mockery::mock( Integrations::class )->makePartial();
265300
$subject->shouldAllowMockingProtectedMethods();
266301
$subject->shouldReceive( 'is_options_screen' )->with()->andReturn( true );
@@ -281,6 +316,25 @@ static function ( $name ) use ( $plugin_url, $plugin_version ) {
281316
}
282317
);
283318

319+
WP_Mock::userFunction( 'wp_enqueue_script' )
320+
->with(
321+
Integrations::DIALOG_HANDLE,
322+
$plugin_url . "/assets/js/kagg-dialog$min_prefix.js",
323+
[],
324+
$plugin_version,
325+
true
326+
)
327+
->once();
328+
329+
WP_Mock::userFunction( 'wp_enqueue_style' )
330+
->with(
331+
Integrations::DIALOG_HANDLE,
332+
$plugin_url . "/assets/css/kagg-dialog$min_prefix.css",
333+
[],
334+
$plugin_version
335+
)
336+
->once();
337+
284338
WP_Mock::userFunction( 'wp_enqueue_script' )
285339
->with(
286340
Integrations::HANDLE,
@@ -291,6 +345,9 @@ static function ( $name ) use ( $plugin_url, $plugin_version ) {
291345
)
292346
->once();
293347

348+
WP_Mock::userFunction( 'wp_get_themes' )->with()->andReturn( $themes )->once();
349+
WP_Mock::userFunction( 'wp_get_theme' )->with()->andReturn( $theme )->once();
350+
294351
WP_Mock::userFunction( 'admin_url' )
295352
->with( 'admin-ajax.php' )
296353
->andReturn( $ajax_url )
@@ -313,6 +370,13 @@ static function ( $name ) use ( $plugin_url, $plugin_version ) {
313370
'deactivateMsg' => 'Deactivate %s plugin?',
314371
'activateThemeMsg' => 'Activate %s theme?',
315372
'deactivateThemeMsg' => 'Deactivate %s theme?',
373+
'selectThemeMsg' => 'Select theme to activate:',
374+
'onlyOneThemeMsg' => 'Cannot deactivate the only theme on the site.',
375+
'unexpectedErrorMsg' => 'Unexpected error.',
376+
'OKBtnText' => 'OK',
377+
'CancelBtnText' => 'Cancel',
378+
'themes' => [ 'twentytwentyone' => 'Twenty Twenty-One' ],
379+
'defaultTheme' => 'twentytwentyone',
316380
]
317381
)
318382
->once();
@@ -321,7 +385,7 @@ static function ( $name ) use ( $plugin_url, $plugin_version ) {
321385
->with(
322386
Integrations::HANDLE,
323387
$plugin_url . "/assets/css/integrations$min_prefix.css",
324-
[ PluginSettingsBase::PREFIX . '-' . SettingsBase::HANDLE ],
388+
[ PluginSettingsBase::PREFIX . '-' . SettingsBase::HANDLE, Integrations::DIALOG_HANDLE ],
325389
$plugin_version
326390
)
327391
->once();

0 commit comments

Comments
 (0)