Skip to content

Commit

Permalink
V4.1.2 (#338)
Browse files Browse the repository at this point in the history
* Improve processing of nested and multipage forms.

* Option to have hCaptcha menu under Settings.

* Option to have hCaptcha menu under Settings.

* Fix the General admin page on the mobile.

* Fix Forms and Events admin pages on the mobile.

* Fix Forms and Events admin pages on the mobile.

* Bump up version.
  • Loading branch information
kagg-design authored May 13, 2024
1 parent 9daed7a commit 77825b6
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 98 deletions.
73 changes: 62 additions & 11 deletions .tests/php/integration/GravityForms/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use HCaptcha\GravityForms\Base;
use HCaptcha\GravityForms\Form;
use HCaptcha\Tests\Integration\HCaptchaWPTestCase;
use Mockery;
use ReflectionException;
use tad\FunctionMocker\FunctionMocker;

Expand Down Expand Up @@ -276,48 +277,98 @@ public function dp_test_verify(): array {
* @return void
*/
public function test_verify_when_should_not_be_verified() {
$form_id = 23;
$target_page = "gform_target_page_number_$form_id";
$form_id = 2;
$nested_form_id = 9;
$multipage_form_id = 3;
$source_page_name = "gform_source_page_number_$multipage_form_id";
$target_page_name = "gform_target_page_number_$multipage_form_id";
$hcaptcha_field = (object) [
'type' => 'hcaptcha',
];
$form = [
$nested_form_field = Mockery::mock( 'GP_Field_Nested_Form' );
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$nested_form_field->gpnfForm = $form_id;
$form_fields = [
'id' => $form_id,
'fields' => [ $hcaptcha_field ],
];
$validation_result = [
$nested_form_fields = [
'id' => $nested_form_id,
'fields' => [ $nested_form_field ],
];
$multipage_form_fields = [
'id' => $nested_form_id,
'pagination' => [
'pages' => [
0 => [],
1 => [],
],
],
];
$validation_result = [
'is_valid' => true,
'form' => [],
'failed_validation_page' => 0,
];
$context = 'form-submit';
$context = 'form-submit';

$subject = new Form();

// The POST 'gform_submit' not set.
self::assertSame( $validation_result, $subject->verify( $validation_result, $context ) );

$_POST['gform_submit'] = $form_id;
// Nested form.
$_POST['gform_submit'] = $form_id;
$_POST['gpnf_parent_form_id'] = $nested_form_id;

// The POST 'gpnf_parent_form_id' is set.
$_POST['gpnf_parent_form_id'] = 5;
FunctionMocker::replace(
'GFFormsModel::get_form_meta',
static function ( $id ) use (
$form_id,
$form_fields,
$nested_form_id,
$nested_form_fields,
$multipage_form_id,
$multipage_form_fields
) {
if ( $id === $form_id ) {
return $form_fields;
}

if ( $id === $nested_form_id ) {
return $nested_form_fields;
}

if ( $id === $multipage_form_id ) {
return $multipage_form_fields;
}

return [];
}
);

self::assertSame( $validation_result, $subject->verify( $validation_result, $context ) );

// Not a nested form.
unset( $_POST['gpnf_parent_form_id'] );

// Multipage form.
$_POST['gform_submit'] = $multipage_form_id;

// The POST target_page is set and not 0.
$_POST[ $target_page ] = 3;
$_POST[ $source_page_name ] = 1;
$_POST[ $target_page_name ] = 2;

self::assertSame( $validation_result, $subject->verify( $validation_result, $context ) );

// The POST target_page is set and 0.
$_POST[ $target_page ] = 0;
$_POST[ $source_page_name ] = 2;
$_POST[ $target_page_name ] = 0;

self::assertSame( $validation_result, $subject->verify( $validation_result, $context ) );

// The POST target_page is unset.
unset( $_POST[ $target_page ] );
unset( $_POST[ $target_page_name ] );

self::assertSame( $validation_result, $subject->verify( $validation_result, $context ) );
}
Expand Down
11 changes: 10 additions & 1 deletion .tests/php/unit/HCaptchaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,19 @@ protected function get_test_general_form_fields(): array {
'type' => 'checkbox',
'section' => General::SECTION_APPEARANCE,
'options' => [
'on' => 'Force hCaptcha',
'on' => 'Force',
],
'helper' => 'Force hCaptcha check before submit.',
],
'menu_position' => [
'label' => 'Tabs Menu Under Settings',
'type' => 'checkbox',
'section' => 'appearance',
'options' => [
'on' => 'Tabs',
],
'helper' => 'When on, the hCaptcha admin menu is placed under Settings.',
],
'custom_themes' => [
'label' => 'Custom Themes',
'type' => 'checkbox',
Expand Down
34 changes: 7 additions & 27 deletions assets/css/events.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
color: #f0f2f5;
}


#hcaptcha-events-chart {
background-color: #ffffff;
position: relative;
Expand All @@ -49,31 +48,12 @@
width: 220px;
}

.hcaptcha-hide {
display: none;
}
@media (max-width: 600px) {
#hcaptcha-options #hcaptcha-events-wrap table tbody tr td {
padding: 3px 8px 3px 35%;
}

.hcaptcha-excerpt {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.hcaptcha-excerpt:hover .hcaptcha-hide {
position: absolute;
color: #f0f2f5;
background: #5c6f8a;
z-index: 1;
display: block;
max-width: 300px;
width: max-content;
padding: 8px 10px;
top: 0;
left: 0;
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
border-radius: 6px;
border: 1px solid #c3c4c7;
white-space: normal;
text-align: center;
#hcaptcha-options #hcaptcha-events-wrap table tbody tr td.column-primary {
padding: 3px 10px;
}
}
35 changes: 8 additions & 27 deletions assets/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,12 @@
aspect-ratio: 3/1;
}

.hcaptcha-hide {
display: none;
}

.hcaptcha-excerpt {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.hcaptcha-excerpt:hover .hcaptcha-hide {
position: absolute;
color: #f0f2f5;
background: #5c6f8a;
z-index: 1;
display: block;
max-width: 300px;
width: max-content;
padding: 8px 10px;
top: 0;
left: 0;
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
border-radius: 6px;
border: 1px solid #c3c4c7;
white-space: normal;
text-align: center;
@media (max-width: 600px) {
#hcaptcha-options #hcaptcha-forms-wrap table tbody tr td {
padding: 3px 8px 3px 35%;
}

#hcaptcha-options #hcaptcha-forms-wrap table tbody tr td.column-primary {
padding: 3px 10px;
}
}
78 changes: 62 additions & 16 deletions assets/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ h3.closed .hcaptcha-section-header-toggle:after {
grid-template-columns: repeat(4, 1fr);
grid-template-areas:
"theme size language mode"
"force force . .";
"force force position position";
gap: 10px 20px;
padding: 15px 20px;
}
Expand All @@ -153,6 +153,10 @@ h3.closed .hcaptcha-section-header-toggle:after {
grid-area: force;
}

.hcaptcha-section-appearance + table tbody tr.hcaptcha-general-menu-position {
grid-area: position;
}

.hcaptcha-section-appearance + table tbody tr th {
padding: 0 0 10px 0;
width: auto;
Expand All @@ -162,6 +166,10 @@ h3.closed .hcaptcha-section-header-toggle:after {
width: max-content;
}

.hcaptcha-section-appearance + table tbody tr.hcaptcha-general-menu-position td {
width: max-content;
}

.hcaptcha-section-appearance + table tbody tr td select {
width: 100%;
}
Expand Down Expand Up @@ -352,35 +360,73 @@ h3.closed .hcaptcha-section-header-toggle:after {
}

@media (max-width: 600px) {
.hcaptcha-general table tbody tr td {
width: auto;
.hcaptcha-section-keys + table tbody {
grid-template-columns: repeat(2, 1fr) !important;
grid-template-areas:
"site-key site-key"
"secret-key secret-key"
"sample-hcaptcha sample-hcaptcha"
"check-config reset-notifications";
}

.hcaptcha-section-keys + table tbody {
grid-template-areas: unset;
.hcaptcha-section-appearance + table tbody {
grid-template-columns: repeat(2, 1fr) !important;
grid-template-areas:
"theme size"
"language mode"
"force force"
"position position";
}

.hcaptcha-section-keys + table tbody tr {
grid-area: unset !important;
.hcaptcha-section-appearance + table tbody tr td {
width: unset !important;
}

.hcaptcha-section-other + table tbody {
grid-template-areas: unset;
.hcaptcha-section-custom + table tbody {
grid-template-columns: repeat(2, 1fr) !important;
grid-template-areas:
"custom-themes custom-themes"
"custom-prop custom-value"
"config-params config-params";
}

.hcaptcha-section-other + table tbody tr {
grid-area: unset !important;
.hcaptcha-section-custom + table tbody tr td {
width: unset !important;
}

.hcaptcha-section-enterprise + table tbody {
grid-template-columns: repeat(1, 1fr) !important;
}

.hcaptcha-section-enterprise + table tbody tr td {
width: unset !important;
}

.hcaptcha-section-other + table tbody {
grid-template-columns: repeat(1, 1fr) !important;
grid-template-areas:
"logged"
"recaptcha"
"network"
"whitelisted"
"login-limit"
"login-interval"
"delay";
}

.hcaptcha-section-other + table tbody tr.hcaptcha-general-whitelisted-ips td {
width: auto;
.hcaptcha-section-other + table tbody tr td {
width: unset !important;
}

.hcaptcha-section-statistics + table tbody {
grid-template-areas: unset;
grid-template-columns: repeat(1, 1fr);
grid-template-areas:
"statistics"
"collect-ip"
"collect-ua";
}

.hcaptcha-section-statistics + table tbody tr {
grid-area: unset !important;
.hcaptcha-section-statistics + table tbody tr td {
width: unset !important;
}
}
29 changes: 29 additions & 0 deletions assets/css/settings-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,35 @@ body.settings_page_hcaptcha {
animation: blink 3s linear;
}

.hcaptcha-hide {
display: none;
}

.hcaptcha-excerpt {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.hcaptcha-excerpt:hover .hcaptcha-hide {
position: absolute;
color: #f0f2f5;
background: #5c6f8a;
z-index: 1;
display: block;
max-width: 300px;
width: max-content;
padding: 8px 10px;
top: 0;
left: 0;
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
border-radius: 6px;
border: 1px solid #c3c4c7;
white-space: normal;
text-align: center;
}

@media (max-width: 782px) {
.hcaptcha-settings-tabs {
margin: 10px -12px 0 -10px;
Expand Down
3 changes: 2 additions & 1 deletion assets/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
document.addEventListener( 'DOMContentLoaded', function() {
const ctx = document.getElementById( 'eventsChart' );
const aspectRatio = window.innerWidth > 600 ? 3 : 2;

new Chart( ctx, {
type: 'bar',
Expand All @@ -28,7 +29,7 @@ document.addEventListener( 'DOMContentLoaded', function() {
options: {
responsive: true,
maintainAspectRatio: true,
aspectRatio: 3,
aspectRatio,
scales: {
x: {
type: 'time',
Expand Down
Loading

0 comments on commit 77825b6

Please sign in to comment.