Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4.5.0 #357

Merged
merged 59 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4e39081
Fix frontend error when recaptcha was activated in wpDiscuz.
kagg-design Aug 1, 2024
0882b27
Do not show tab links if there is one tab only.
kagg-design Aug 5, 2024
757f59e
Add file field.
kagg-design Aug 5, 2024
13accd8
Do not save file field.
kagg-design Aug 5, 2024
8d36ebc
Introduce savable form fields concept.
kagg-design Aug 5, 2024
4cd56e9
Fix typo.
kagg-design Aug 5, 2024
a201561
Fix tests.
kagg-design Aug 6, 2024
65ca328
Fix tests.
kagg-design Aug 6, 2024
d534254
Fix tests.
kagg-design Aug 6, 2024
01d3e15
Raise unit tests coverage to 100%.
kagg-design Aug 6, 2024
40d899d
Raise unit tests coverage to 100%.
kagg-design Aug 8, 2024
c6e53e0
Remove codeception.yml from the release.
kagg-design Aug 8, 2024
7f27db5
Remove codeception.yml from the release.
kagg-design Aug 8, 2024
65e0a56
Block admin code execution on frontend.
kagg-design Aug 10, 2024
86b4c8d
Update readme.txt.
kagg-design Aug 13, 2024
4ce1e6f
Fix unconditional forcing hCaptcha in Jetpack forms.
kagg-design Aug 14, 2024
54d2388
Add support for Jetpack forms in block theme templates.
kagg-design Aug 14, 2024
db0a963
Fix error messaging when there are several Jetpack forms on the same …
kagg-design Aug 14, 2024
bdc0705
phpcs.
kagg-design Aug 14, 2024
e8f3858
phpcs.
kagg-design Aug 14, 2024
1640f3a
Return Jetpack test coverage to 100%.
kagg-design Aug 14, 2024
21655a3
phpcs.
kagg-design Aug 14, 2024
a4f7c6a
phpcs.
kagg-design Aug 15, 2024
06c2d81
Add ability to test not final versions.
kagg-design Aug 15, 2024
a423c09
Update readme.txt.
kagg-design Aug 16, 2024
037185d
ESLint.
kagg-design Aug 17, 2024
6511872
Update composer.json packages.
kagg-design Aug 17, 2024
4986013
WPCS.
kagg-design Aug 19, 2024
cfa9762
Fix tests.
kagg-design Aug 19, 2024
c0cc231
Improve the layout of headers on admin pages.
kagg-design Aug 20, 2024
4ac1fbd
Fix Ninja Forms Preview.
kagg-design Aug 22, 2024
7be4308
Fix "Using ${var} in strings is deprecated".
kagg-design Aug 22, 2024
9baa546
Fix fatal error when viewing Gravity Forms entries.
kagg-design Aug 22, 2024
13ac207
Fix Elementor preview.
kagg-design Aug 22, 2024
afe4a9f
Fix unit tests.
kagg-design Aug 22, 2024
2ab4c1f
Fix unit tests.
kagg-design Aug 22, 2024
f32e345
Fix NF tests.
kagg-design Aug 22, 2024
49dde7d
Fix integration tests cross-dependency issue.
kagg-design Aug 22, 2024
ad995df
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
21d5a17
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
f1cf76f
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
93c0574
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
53008a6
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
bf9bce4
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
86e6fad
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
d3323a8
Fix integration tests deprecation issue.
kagg-design Aug 24, 2024
6c7a88c
Fix appearance of Ninja Forms editor with "Turn Off When Logged In" s…
kagg-design Aug 24, 2024
5e0d71b
Restore 100% test coverage of Wordfence.
kagg-design Aug 24, 2024
9a8e08c
Restore 100% test coverage of NF.
kagg-design Aug 24, 2024
b2e4d73
Restore 100% test coverage of NF.
kagg-design Aug 24, 2024
d85fcee
Restore 100% test coverage of NF.
kagg-design Aug 24, 2024
9a5954c
Cover Spectra by tests.
kagg-design Aug 24, 2024
53b9958
Cover CoBlocks by tests.
kagg-design Aug 25, 2024
6cbafbe
Code style.
kagg-design Aug 25, 2024
ce2e9dd
Fix readme.txt.
kagg-design Aug 26, 2024
e8284c8
Fix readme.txt.
kagg-design Aug 28, 2024
a6368d9
Update banner.
kagg-design Aug 28, 2024
f51cb1b
Bump up version.
kagg-design Aug 28, 2024
fc8a8e5
Apply suggestions from code review
e271828- Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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