Skip to content

Commit 0ba34f4

Browse files
V4.5.0 (#357)
* Fix frontend error when recaptcha was activated in wpDiscuz. * Do not show tab links if there is one tab only. * Add file field. * Do not save file field. * Introduce savable form fields concept. * Fix typo. * Fix tests. * Fix tests. * Fix tests. * Raise unit tests coverage to 100%. * Raise unit tests coverage to 100%. * Remove codeception.yml from the release. * Remove codeception.yml from the release. * Block admin code execution on frontend. * Update readme.txt. * Fix unconditional forcing hCaptcha in Jetpack forms. * Add support for Jetpack forms in block theme templates. * Fix error messaging when there are several Jetpack forms on the same page. * phpcs. * phpcs. * Return Jetpack test coverage to 100%. * phpcs. * phpcs. * Add ability to test not final versions. Fix hCaptcha nonce error on MailPoet admin pages. Fix tests. Add LostPassword form support for bbPress. Make bbPress forms working when Login/Register are off. Add Register form support for bbPress. Add Login form support for bbPress. WPCS in Divi.php. Fix error messaging for several classic Jetpack forms. * Update readme.txt. Do not scroll topbar and search in the admin. Fix scrolling after plugin/theme activation/deactivation. Fix appearance of Beaver Builder editor with "Turn Off When Logged In" setting. Fix appearance of Fluent Forms editor with "Turn Off When Logged In" setting. Refactor Pages class to clarity. Fix appearance of Formidable Forms editor with "Turn Off When Logged In" setting. Fix appearance of Forminator editor with "Turn Off When Logged In" setting. Fix appearance of Gravity Forms editor with "Turn Off When Logged In" setting. Fix appearance of Essential Addons editor with "Turn Off When Logged In" setting. Fix appearance of WPForms editor with "Turn Off When Logged In" setting. Fix appearance of Contact Form 7 editor with "Turn Off When Logged In" setting. Fix potential racing condition with Migrations. Do not use referer as it may not be provided by server. Add the ability to have multiple MailPoet forms on the same page. Make MailPoet form work at any form placement. * ESLint. * Update composer.json packages. Cleanup .distignore. Update readme.txt. Cover bbPress LostPassword by tests. Cover bbPress Register by tests. Cover bbPress Login by tests. Restore 100% test coverage of Divi. Cover Pages.php by tests. Restore 100% test coverage of class Request.php. Restore 100% test coverage of includes/request.php. Cover MailPoet by tests. Restore 100% test coverage of Migrations. Restore 100% test coverage of wpDiscuz. Restore 100% Main.php coverage. * WPCS. * Fix tests. * Improve the layout of headers on admin pages. * Fix Ninja Forms Preview. * Fix "Using ${var} in strings is deprecated". * Fix fatal error when viewing Gravity Forms entries. * Fix Elementor preview. * Fix unit tests. * Fix unit tests. * Fix NF tests. * Fix integration tests cross-dependency issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix integration tests deprecation issue. * Fix appearance of Ninja Forms editor with "Turn Off When Logged In" setting. * Restore 100% test coverage of Wordfence. * Restore 100% test coverage of NF. * Restore 100% test coverage of NF. * Restore 100% test coverage of NF. * Cover Spectra by tests. * Cover CoBlocks by tests. * Code style. * Fix readme.txt. * Fix readme.txt. * Update banner. * Bump up version. * Apply suggestions from code review --------- Co-authored-by: e271828- <e271828-@users.noreply.github.com>
1 parent 25bdd39 commit 0ba34f4

Some content is hidden

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

70 files changed

+3538
-299
lines changed

.distignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
/.tests
1010
/.wordpress-org
1111
/.yarn
12-
/bin
1312
/node_modules
1413
/src/js
1514

1615
# Files
1716
/.DS_Store
1817
/.babelrc
19-
/.codeception.yml
18+
/codeception.yml
2019
/.distignore
2120
/.editorconfig
2221
/.eslintrc.json

.tests/php/integration/AAAMainTest.php

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use HCaptcha\Jetpack\JetpackForm;
2727
use HCaptcha\Main;
2828
use HCaptcha\ElementorPro\HCaptchaHandler;
29+
use HCaptcha\Migrations\Migrations;
2930
use HCaptcha\NF\NF;
3031
use HCaptcha\Quform\Quform;
3132
use HCaptcha\Sendinblue\Sendinblue;
@@ -109,15 +110,41 @@ public function test_init(): void {
109110
$hcaptcha = hcaptcha();
110111

111112
// The plugin was loaded by codeception.
112-
self::assertSame( - PHP_INT_MAX, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
113+
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
113114

114-
remove_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ], -PHP_INT_MAX );
115+
remove_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ], Main::LOAD_PRIORITY );
115116

116117
self::assertFalse( has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
117118

118119
$hcaptcha->init();
119120

120-
self::assertSame( - PHP_INT_MAX, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
121+
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
122+
}
123+
124+
/**
125+
* Test init() on cron request.
126+
*
127+
* @return void
128+
* @throws ReflectionException ReflectionException.
129+
*/
130+
public function test_init_on_cron(): void {
131+
$hcaptcha = hcaptcha();
132+
133+
// The plugin was loaded by codeception.
134+
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
135+
136+
remove_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ], Main::LOAD_PRIORITY );
137+
138+
self::assertFalse( has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
139+
140+
add_filter( 'wp_doing_cron', '__return_true' );
141+
142+
$hcaptcha->init();
143+
144+
$migrations = $this->get_protected_property( $hcaptcha, 'migrations' );
145+
146+
self::assertFalse( has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
147+
self::assertSame( Migrations::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $migrations, 'migrate' ] ) );
121148
}
122149

123150
/**
@@ -166,9 +193,9 @@ static function () use ( $whitelisted ) {
166193
)
167194
);
168195

169-
self::assertSame( - PHP_INT_MAX, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
196+
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
170197

171-
self::assertSame( - PHP_INT_MAX + 1, has_action( 'plugins_loaded', [ $hcaptcha, 'load_modules' ] ) );
198+
self::assertSame( Main::LOAD_PRIORITY + 1, has_action( 'plugins_loaded', [ $hcaptcha, 'load_modules' ] ) );
172199

173200
self::assertSame( 10, has_filter( 'wp_resource_hints', [ $hcaptcha, 'prefetch_hcaptcha_dns' ] ) );
174201
self::assertSame( 10, has_filter( 'wp_headers', [ $hcaptcha, 'csp_headers' ] ) );
@@ -188,11 +215,11 @@ static function () use ( $whitelisted ) {
188215
$subject->init_hooks();
189216

190217
self::assertSame(
191-
- PHP_INT_MAX + 1,
218+
Main::LOAD_PRIORITY + 1,
192219
has_action( 'plugins_loaded', [ $subject, 'load_modules' ] )
193220
);
194221
self::assertSame(
195-
- PHP_INT_MAX,
222+
-PHP_INT_MAX,
196223
has_filter(
197224
'hcap_whitelist_ip',
198225
[ $subject, 'whitelist_ip' ]
@@ -285,11 +312,11 @@ static function () {
285312
$subject->init_hooks();
286313

287314
self::assertSame(
288-
- PHP_INT_MAX + 1,
315+
Main::LOAD_PRIORITY + 1,
289316
has_action( 'plugins_loaded', [ $subject, 'load_modules' ] )
290317
);
291318
self::assertSame(
292-
- PHP_INT_MAX,
319+
-PHP_INT_MAX,
293320
has_filter(
294321
'hcap_whitelist_ip',
295322
[ $subject, 'whitelist_ip' ]
@@ -341,8 +368,12 @@ public function dp_test_init_and_init_hooks_on_elementor_pro_edit_page(): array
341368
],
342369
'request2' => [
343370
'on',
344-
[ 'REQUEST_URI' => '/elementor?elementor-preview=23' ],
345-
[ 'elementor-preview' => 23 ],
371+
[],
372+
[
373+
'preview_id' => 23,
374+
'preview_nonce' => 'some',
375+
'preview' => true,
376+
],
346377
[],
347378
true,
348379
],
@@ -613,7 +644,8 @@ public function dp_test_print_inline_styles(): array {
613644
/**
614645
* Test login_head().
615646
*
616-
* @noinspection CssUnusedSymbol*/
647+
* @noinspection CssUnusedSymbol
648+
*/
617649
public function test_login_head(): void {
618650
FunctionMocker::replace(
619651
'defined',
@@ -930,7 +962,7 @@ function delayedLoad() {
930962
'custom_themes' => $custom_themes ? [ $custom_themes ] : [],
931963
// phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
932964
'config_params' => json_encode( $config_params ),
933-
'delay' => - 100,
965+
'delay' => -100,
934966
'license' => 'pro',
935967
]
936968
);
@@ -1302,11 +1334,38 @@ public function dp_test_load_modules(): array {
13021334
'back-in-stock-notifier-for-woocommerce/cwginstocknotifier.php',
13031335
\HCaptcha\BackInStockNotifier\Form::class,
13041336
],
1337+
'bbPress Login Form' => [
1338+
[ 'bbp_status', 'login' ],
1339+
'bbpress/bbpress.php',
1340+
[
1341+
\HCaptcha\BBPress\Login::class,
1342+
\HCaptcha\BBPress\LostPassword::class,
1343+
\HCaptcha\BBPress\Register::class,
1344+
],
1345+
],
1346+
'bbPress Lost Password Form' => [
1347+
[ 'bbp_status', 'lost_pass' ],
1348+
'bbpress/bbpress.php',
1349+
[
1350+
\HCaptcha\BBPress\Login::class,
1351+
\HCaptcha\BBPress\LostPassword::class,
1352+
\HCaptcha\BBPress\Register::class,
1353+
],
1354+
],
13051355
'bbPress New Topic' => [
13061356
[ 'bbp_status', 'new_topic' ],
13071357
'bbpress/bbpress.php',
13081358
NewTopic::class,
13091359
],
1360+
'bbPress Register Form' => [
1361+
[ 'bbp_status', 'register' ],
1362+
'bbpress/bbpress.php',
1363+
[
1364+
\HCaptcha\BBPress\Login::class,
1365+
\HCaptcha\BBPress\LostPassword::class,
1366+
\HCaptcha\BBPress\Register::class,
1367+
],
1368+
],
13101369
'bbPress Reply' => [
13111370
[ 'bbp_status', 'reply' ],
13121371
'bbpress/bbpress.php',
@@ -1696,7 +1755,7 @@ static function ( $override, $domain, $mofile ) use ( &$override_filter_params )
16961755

16971756
return $override;
16981757
},
1699-
- PHP_INT_MAX,
1758+
Main::LOAD_PRIORITY,
17001759
3
17011760
);
17021761

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* LoginTest class file.
4+
*
5+
* @package HCaptcha\Tests
6+
*/
7+
8+
namespace HCaptcha\Tests\Integration\BBPress;
9+
10+
use HCaptcha\BBPress\Login;
11+
use HCaptcha\Helpers\HCaptcha;
12+
use HCaptcha\Tests\Integration\HCaptchaPluginWPTestCase;
13+
14+
/**
15+
* Test Login class.
16+
*
17+
* @group bbpress
18+
* @group bbpress-login
19+
*/
20+
class LoginTest extends HCaptchaPluginWPTestCase {
21+
22+
/**
23+
* Test init_hooks().
24+
*
25+
* @return void
26+
*/
27+
public function test_init_hooks(): void {
28+
$subject = new Login();
29+
30+
self::assertSame( 10, has_filter( 'do_shortcode_tag', [ $subject, 'do_shortcode_tag' ] ) );
31+
}
32+
33+
/**
34+
* Test do_shortcode_tag().
35+
*
36+
* @return void
37+
* @noinspection PhpUnusedParameterInspection
38+
*/
39+
public function test_do_shortcode_tag(): void {
40+
$tag = 'bbp-login';
41+
$attr = [];
42+
$m = [];
43+
44+
$placeholder = '===hcaptcha placeholder===';
45+
$template = <<<HTML
46+
<form action="https://test.test/wp-login.php">
47+
$placeholder<button type="submit"/>
48+
</form>
49+
HTML;
50+
51+
$args = [
52+
'action' => 'hcaptcha_login',
53+
'name' => 'hcaptcha_login_nonce',
54+
'id' => [
55+
'source' => [ 'bbpress/bbpress.php' ],
56+
'form_id' => 'login',
57+
],
58+
];
59+
$hcaptcha = $this->get_hcap_form( $args );
60+
$signature = HCaptcha::get_signature( Login::class, 'login', true );
61+
62+
$output = str_replace( $placeholder, '', $template );
63+
$expected = str_replace( $placeholder, $hcaptcha . $signature . "\n", $template );
64+
65+
$subject = new Login();
66+
67+
// Wrong tag.
68+
self::assertSame( $output, $subject->do_shortcode_tag( $output, 'some', $attr, $m ) );
69+
70+
// Logged in.
71+
wp_set_current_user( 1 );
72+
73+
self::assertSame( $output, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
74+
75+
// Login limit not exceeded.
76+
wp_set_current_user( 0 );
77+
add_filter(
78+
'hcap_login_limit_exceeded',
79+
static function ( $value ) use ( &$limit_exceeded ) {
80+
return $limit_exceeded;
81+
}
82+
);
83+
84+
$limit_exceeded = false;
85+
86+
self::assertSame( $output, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
87+
88+
// Status is 'login'.
89+
$limit_exceeded = true;
90+
91+
hcaptcha()->settings()->set( 'bbp_status', 'login' );
92+
93+
self::assertSame( $expected, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
94+
self::assertSame( 1, did_action( 'hcap_signature' ) );
95+
96+
// Status is not 'login'.
97+
hcaptcha()->settings()->set( 'bbp_status', 'some' );
98+
99+
$expected = str_replace( $placeholder, $signature . "\n", $template );
100+
101+
self::assertSame( $expected, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
102+
self::assertSame( 2, did_action( 'hcap_signature' ) );
103+
}
104+
}

0 commit comments

Comments
 (0)