Skip to content

Commit

Permalink
V4.5.0 (#357)
Browse files Browse the repository at this point in the history
* 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- <[email protected]>
  • Loading branch information
kagg-design and e271828- authored Aug 28, 2024
1 parent 25bdd39 commit 0ba34f4
Show file tree
Hide file tree
Showing 70 changed files with 3,538 additions and 299 deletions.
3 changes: 1 addition & 2 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
/.tests
/.wordpress-org
/.yarn
/bin
/node_modules
/src/js

# Files
/.DS_Store
/.babelrc
/.codeception.yml
/codeception.yml
/.distignore
/.editorconfig
/.eslintrc.json
Expand Down
87 changes: 73 additions & 14 deletions .tests/php/integration/AAAMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use HCaptcha\Jetpack\JetpackForm;
use HCaptcha\Main;
use HCaptcha\ElementorPro\HCaptchaHandler;
use HCaptcha\Migrations\Migrations;
use HCaptcha\NF\NF;
use HCaptcha\Quform\Quform;
use HCaptcha\Sendinblue\Sendinblue;
Expand Down Expand Up @@ -109,15 +110,41 @@ public function test_init(): void {
$hcaptcha = hcaptcha();

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

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

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

$hcaptcha->init();

self::assertSame( - PHP_INT_MAX, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
}

/**
* Test init() on cron request.
*
* @return void
* @throws ReflectionException ReflectionException.
*/
public function test_init_on_cron(): void {
$hcaptcha = hcaptcha();

// The plugin was loaded by codeception.
self::assertSame( Main::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );

remove_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ], Main::LOAD_PRIORITY );

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

add_filter( 'wp_doing_cron', '__return_true' );

$hcaptcha->init();

$migrations = $this->get_protected_property( $hcaptcha, 'migrations' );

self::assertFalse( has_action( 'plugins_loaded', [ $hcaptcha, 'init_hooks' ] ) );
self::assertSame( Migrations::LOAD_PRIORITY, has_action( 'plugins_loaded', [ $migrations, 'migrate' ] ) );
}

/**
Expand Down Expand Up @@ -166,9 +193,9 @@ static function () use ( $whitelisted ) {
)
);

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

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

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

self::assertSame(
- PHP_INT_MAX + 1,
Main::LOAD_PRIORITY + 1,
has_action( 'plugins_loaded', [ $subject, 'load_modules' ] )
);
self::assertSame(
- PHP_INT_MAX,
-PHP_INT_MAX,
has_filter(
'hcap_whitelist_ip',
[ $subject, 'whitelist_ip' ]
Expand Down Expand Up @@ -285,11 +312,11 @@ static function () {
$subject->init_hooks();

self::assertSame(
- PHP_INT_MAX + 1,
Main::LOAD_PRIORITY + 1,
has_action( 'plugins_loaded', [ $subject, 'load_modules' ] )
);
self::assertSame(
- PHP_INT_MAX,
-PHP_INT_MAX,
has_filter(
'hcap_whitelist_ip',
[ $subject, 'whitelist_ip' ]
Expand Down Expand Up @@ -341,8 +368,12 @@ public function dp_test_init_and_init_hooks_on_elementor_pro_edit_page(): array
],
'request2' => [
'on',
[ 'REQUEST_URI' => '/elementor?elementor-preview=23' ],
[ 'elementor-preview' => 23 ],
[],
[
'preview_id' => 23,
'preview_nonce' => 'some',
'preview' => true,
],
[],
true,
],
Expand Down Expand Up @@ -613,7 +644,8 @@ public function dp_test_print_inline_styles(): array {
/**
* Test login_head().
*
* @noinspection CssUnusedSymbol*/
* @noinspection CssUnusedSymbol
*/
public function test_login_head(): void {
FunctionMocker::replace(
'defined',
Expand Down Expand Up @@ -930,7 +962,7 @@ function delayedLoad() {
'custom_themes' => $custom_themes ? [ $custom_themes ] : [],
// phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
'config_params' => json_encode( $config_params ),
'delay' => - 100,
'delay' => -100,
'license' => 'pro',
]
);
Expand Down Expand Up @@ -1302,11 +1334,38 @@ public function dp_test_load_modules(): array {
'back-in-stock-notifier-for-woocommerce/cwginstocknotifier.php',
\HCaptcha\BackInStockNotifier\Form::class,
],
'bbPress Login Form' => [
[ 'bbp_status', 'login' ],
'bbpress/bbpress.php',
[
\HCaptcha\BBPress\Login::class,
\HCaptcha\BBPress\LostPassword::class,
\HCaptcha\BBPress\Register::class,
],
],
'bbPress Lost Password Form' => [
[ 'bbp_status', 'lost_pass' ],
'bbpress/bbpress.php',
[
\HCaptcha\BBPress\Login::class,
\HCaptcha\BBPress\LostPassword::class,
\HCaptcha\BBPress\Register::class,
],
],
'bbPress New Topic' => [
[ 'bbp_status', 'new_topic' ],
'bbpress/bbpress.php',
NewTopic::class,
],
'bbPress Register Form' => [
[ 'bbp_status', 'register' ],
'bbpress/bbpress.php',
[
\HCaptcha\BBPress\Login::class,
\HCaptcha\BBPress\LostPassword::class,
\HCaptcha\BBPress\Register::class,
],
],
'bbPress Reply' => [
[ 'bbp_status', 'reply' ],
'bbpress/bbpress.php',
Expand Down Expand Up @@ -1696,7 +1755,7 @@ static function ( $override, $domain, $mofile ) use ( &$override_filter_params )

return $override;
},
- PHP_INT_MAX,
Main::LOAD_PRIORITY,
3
);

Expand Down
104 changes: 104 additions & 0 deletions .tests/php/integration/BBPress/LoginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* LoginTest class file.
*
* @package HCaptcha\Tests
*/

namespace HCaptcha\Tests\Integration\BBPress;

use HCaptcha\BBPress\Login;
use HCaptcha\Helpers\HCaptcha;
use HCaptcha\Tests\Integration\HCaptchaPluginWPTestCase;

/**
* Test Login class.
*
* @group bbpress
* @group bbpress-login
*/
class LoginTest extends HCaptchaPluginWPTestCase {

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

self::assertSame( 10, has_filter( 'do_shortcode_tag', [ $subject, 'do_shortcode_tag' ] ) );
}

/**
* Test do_shortcode_tag().
*
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function test_do_shortcode_tag(): void {
$tag = 'bbp-login';
$attr = [];
$m = [];

$placeholder = '===hcaptcha placeholder===';
$template = <<<HTML
<form action="https://test.test/wp-login.php">
$placeholder<button type="submit"/>
</form>
HTML;

$args = [
'action' => 'hcaptcha_login',
'name' => 'hcaptcha_login_nonce',
'id' => [
'source' => [ 'bbpress/bbpress.php' ],
'form_id' => 'login',
],
];
$hcaptcha = $this->get_hcap_form( $args );
$signature = HCaptcha::get_signature( Login::class, 'login', true );

$output = str_replace( $placeholder, '', $template );
$expected = str_replace( $placeholder, $hcaptcha . $signature . "\n", $template );

$subject = new Login();

// Wrong tag.
self::assertSame( $output, $subject->do_shortcode_tag( $output, 'some', $attr, $m ) );

// Logged in.
wp_set_current_user( 1 );

self::assertSame( $output, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );

// Login limit not exceeded.
wp_set_current_user( 0 );
add_filter(
'hcap_login_limit_exceeded',
static function ( $value ) use ( &$limit_exceeded ) {
return $limit_exceeded;
}
);

$limit_exceeded = false;

self::assertSame( $output, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );

// Status is 'login'.
$limit_exceeded = true;

hcaptcha()->settings()->set( 'bbp_status', 'login' );

self::assertSame( $expected, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
self::assertSame( 1, did_action( 'hcap_signature' ) );

// Status is not 'login'.
hcaptcha()->settings()->set( 'bbp_status', 'some' );

$expected = str_replace( $placeholder, $signature . "\n", $template );

self::assertSame( $expected, $subject->do_shortcode_tag( $output, $tag, $attr, $m ) );
self::assertSame( 2, did_action( 'hcap_signature' ) );
}
}
Loading

0 comments on commit 0ba34f4

Please sign in to comment.