diff --git a/give.php b/give.php index da5af7d588..7f4f6967ba 100644 --- a/give.php +++ b/give.php @@ -6,7 +6,7 @@ * Description: The most robust, flexible, and intuitive way to accept donations on WordPress. * Author: GiveWP * Author URI: https://givewp.com/ - * Version: 3.15.0 + * Version: 3.15.1 * Requires at least: 6.4 * Requires PHP: 7.2 * Text Domain: give @@ -406,7 +406,7 @@ private function setup_constants() { // Plugin version. if (!defined('GIVE_VERSION')) { - define('GIVE_VERSION', '3.15.0'); + define('GIVE_VERSION', '3.15.1'); } // Plugin Root File. diff --git a/includes/admin/settings/class-settings-advanced.php b/includes/admin/settings/class-settings-advanced.php index af555eb902..c487332496 100644 --- a/includes/admin/settings/class-settings-advanced.php +++ b/includes/admin/settings/class-settings-advanced.php @@ -177,7 +177,7 @@ public function get_settings() { ], ], [ - 'name' => 'GiveWP Cache', + 'name' => __( 'GiveWP Cache', 'give' ), 'id' => 'give-clear-cache', 'buttonTitle' => __( 'Clear Cache', 'give' ), 'desc' => __( 'Click this button if you want to clear GiveWP\'s cache. The plugin stores common settings and queries in cache to optimize performance. Clearing cache will remove and begin rebuilding these saved queries.', 'give' ), diff --git a/readme.txt b/readme.txt index 2539586d7f..4ab1139602 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: donation, donate, recurring donations, fundraising, crowdfunding Requires at least: 6.4 Tested up to: 6.6 Requires PHP: 7.2 -Stable tag: 3.15.0 +Stable tag: 3.15.1 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -262,6 +262,9 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri 10. Use almost any payment gateway integration with GiveWP through our add-ons or by creating your own add-on. == Changelog == += 3.15.1: Aug 22nd, 2024 = +* Fix: Resolved an issue with the Akismet integration preventing form submissions when settings are not yet configured + = 3.15.0: Aug 14th, 2024 = * New: Added Akismet integration support to forms using the visual form builder * New: Updated the onboarding wizard to create a new form with the visual form builder diff --git a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx index de7efbe544..2b9ffbd681 100644 --- a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx +++ b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx @@ -261,7 +261,7 @@ export default function DonationFormsListTable() { className={`button button-secondary ${styles.button} ${styles.buttonSecondary}`} onClick={showLegacyDonationForms} > - {__('Switch to Legacy View')} + {__('Switch to Legacy View', 'give')} whitelistEmails = $whitelistEmails; } diff --git a/src/DonationSpam/ServiceProvider.php b/src/DonationSpam/ServiceProvider.php index 5ddeb7be15..ff48c6214f 100644 --- a/src/DonationSpam/ServiceProvider.php +++ b/src/DonationSpam/ServiceProvider.php @@ -16,9 +16,13 @@ class ServiceProvider implements ServiceProviderInterface */ public function register(): void { + /** + * @since 3.15.1 Case filtered value as an array to enforce type. + * @since 3.15.0 + */ give()->singleton(EmailAddressWhiteList::class, function () { return new EmailAddressWhiteList( - apply_filters( 'give_akismet_whitelist_emails', give_akismet_get_whitelisted_emails() ) + (array) apply_filters( 'give_akismet_whitelist_emails', give_akismet_get_whitelisted_emails() ) ); }); } diff --git a/src/Donations/DonationsAdminPage.php b/src/Donations/DonationsAdminPage.php index 6672ae7711..5a6bc78e3c 100644 --- a/src/Donations/DonationsAdminPage.php +++ b/src/Donations/DonationsAdminPage.php @@ -137,7 +137,7 @@ private function getForms() return array_merge([ [ 'value' => '0', - 'text' => 'Any', + 'text' => __('Any', 'give'), ], ], $options); } diff --git a/src/Donors/DonorsAdminPage.php b/src/Donors/DonorsAdminPage.php index c1593c575e..5e46d7f209 100644 --- a/src/Donors/DonorsAdminPage.php +++ b/src/Donors/DonorsAdminPage.php @@ -104,7 +104,7 @@ public function getForms() return array_merge([ [ 'value' => '0', - 'text' => 'Any', + 'text' => __('Any', 'give'), ], ], $options); } diff --git a/src/FormBuilder/resources/js/form-builder/src/components/EmbedForm/index.tsx b/src/FormBuilder/resources/js/form-builder/src/components/EmbedForm/index.tsx index b86663f06a..9d5334bb4c 100644 --- a/src/FormBuilder/resources/js/form-builder/src/components/EmbedForm/index.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/components/EmbedForm/index.tsx @@ -86,8 +86,8 @@ export default function EmbedFormModal({handleClose}: EmbedFormModalProps) { }, []); const postOptions = [ - {label: 'Page', value: 'page'}, - {label: 'Post', value: 'post'}, + {label: __('Page', 'give'), value: 'page'}, + {label: __('Post', 'give'), value: 'post'}, ]; const displayStyles = [ diff --git a/src/FormBuilder/resources/js/form-builder/src/promos/recurring-donations.tsx b/src/FormBuilder/resources/js/form-builder/src/promos/recurring-donations.tsx index c78823c6db..52bc464d8a 100644 --- a/src/FormBuilder/resources/js/form-builder/src/promos/recurring-donations.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/promos/recurring-donations.tsx @@ -19,8 +19,8 @@ const RecurringDonationsPromo = () => { {__('Provide donors the option of making flexible recurring donations.', 'give')}
- - + +
} diff --git a/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/email/template-options/settings.tsx b/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/email/template-options/settings.tsx index 8926d9ef7c..4a77720dc1 100644 --- a/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/email/template-options/settings.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/email/template-options/settings.tsx @@ -62,7 +62,7 @@ const EmailTemplateSettings = ({notification, templateTagsRef, settings, setSett updateEmailTemplateOption('email_subject', value)} value={option.email_subject || config.defaultValues.email_subject} /> @@ -88,8 +88,8 @@ const EmailTemplateSettings = ({notification, templateTagsRef, settings, setSett updateEmailTemplateOption('email_header', value)} // @ts-ignore value={option.email_header || config.defaultValues.email_header} @@ -100,12 +100,12 @@ const EmailTemplateSettings = ({notification, templateTagsRef, settings, setSett updateEmailTemplateOption('email_content_type', value)} - label={__('Email content type', 'givewp')} - help={__('Choose email type', 'givewp')} + label={__('Email content type', 'give')} + help={__('Choose email type', 'give')} value={option.email_content_type || config.defaultValues.email_content_type} options={[ - {label: __('HTML', 'givewp'), value: 'text/html'}, - {label: __('Plain', 'givewp'), value: 'text/plain'}, + {label: __('HTML', 'give'), value: 'text/html'}, + {label: __('Plain', 'give'), value: 'text/plain'}, ]} /> @@ -141,7 +141,7 @@ const EmailTemplateSettings = ({notification, templateTagsRef, settings, setSett > {config.supportsRecipients && (
- + {recipients.map((recipientEmail: string, index) => { return (
  • updateEmailTemplateOption('recipient', [...recipients, ''])} > - {__('Add email', 'givewp')} + {__('Add email', 'give')}
  • @@ -184,10 +184,10 @@ const EmailTemplateSettings = ({notification, templateTagsRef, settings, setSett {!config.supportsRecipients && ( null} value="{donor_email}" diff --git a/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/general/index.tsx b/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/general/index.tsx index 302a90fb8c..09da75c226 100644 --- a/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/general/index.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/settings/group-email-settings/general/index.tsx @@ -36,11 +36,11 @@ export default function EmailGeneralSettings({ settings, setSettings }) { > setSettings({ emailTemplate })} @@ -48,10 +48,10 @@ export default function EmailGeneralSettings({ settings, setSettings }) { setSettings({ emailFromName })} @@ -59,10 +59,10 @@ export default function EmailGeneralSettings({ settings, setSettings }) { setSettings({ emailFromEmail })} diff --git a/src/FormBuilder/resources/js/form-builder/src/settings/group-general/form-summary/index.jsx b/src/FormBuilder/resources/js/form-builder/src/settings/group-general/form-summary/index.jsx index 6a5bd56f85..fbe3ac4f7f 100644 --- a/src/FormBuilder/resources/js/form-builder/src/settings/group-general/form-summary/index.jsx +++ b/src/FormBuilder/resources/js/form-builder/src/settings/group-general/form-summary/index.jsx @@ -28,7 +28,7 @@ const FormSummarySettings = ({settings, setSettings}) => { <> { !isPublished && setSettings({pageSlug: cleanForSlug(formTitle)}); @@ -59,7 +59,7 @@ const FormSummarySettings = ({settings, setSettings}) => { {isExcerptEnabled && ( getMeta('_give_convertkit_override_option') === 'default' && give_is_setting_enabled(give_get_option('give_convertkit_show_subscribe_checkbox')); - return $isFormEnabled ? $isGloballyEnabled : $isFormDisabled; + return ! ($isFormDisabled || ( ! $isGloballyEnabled && ! $isFormEnabled)); } /** diff --git a/src/Subscriptions/SubscriptionsAdminPage.php b/src/Subscriptions/SubscriptionsAdminPage.php index 7709278132..ecb0dfdaac 100644 --- a/src/Subscriptions/SubscriptionsAdminPage.php +++ b/src/Subscriptions/SubscriptionsAdminPage.php @@ -79,7 +79,7 @@ private function getForms() return array_merge([ [ 'value' => '0', - 'text' => 'Any', + 'text' => __('Any', 'give'), ] ], $options); } diff --git a/src/Subscriptions/resources/components/SubscriptionsListTable.tsx b/src/Subscriptions/resources/components/SubscriptionsListTable.tsx index 26fe0ef876..90d1ffc8bd 100644 --- a/src/Subscriptions/resources/components/SubscriptionsListTable.tsx +++ b/src/Subscriptions/resources/components/SubscriptionsListTable.tsx @@ -141,7 +141,7 @@ export default function SubscriptionsListTable() { listTableBlankSlate={ListTableBlankSlate} > ); diff --git a/tests/Feature/FormMigration/Steps/TestActiveCampaign.php b/tests/Feature/FormMigration/Steps/TestActiveCampaign.php index b19d1b595d..417cd91dcc 100644 --- a/tests/Feature/FormMigration/Steps/TestActiveCampaign.php +++ b/tests/Feature/FormMigration/Steps/TestActiveCampaign.php @@ -4,94 +4,106 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\ActiveCampaign; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; class TestActiveCampaign extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** - * @since 3.10.0 + * @unreleased */ - public function testProcessShouldUpdateActiveCampaignBlockAttributesFromV2FormMeta(): void + public function testFormConfiguredToUseGlobalActiveCampaignSettingsMigratesUsingGlobalSettingsWhenGloballyEnabled() { - $meta = [ - 'give_activecampaign_label' => __('Subscribe to our newsletter?'), - 'give_activecampaign_lists' => ['1', '2'], - 'give_activecampaign_tags' => ['tag 1', 'tag 2'], + // Arrange + $options = [ + 'give_activecampaign_globally_enabled' => 'on', + 'give_activecampaign_label' => __('Subscribe to our newsletter?'), + 'give_activecampaign_lists' => ['1', '2'], + 'give_activecampaign_tags' => ['tag 1', 'tag 2'], 'give_activecampaign_checkbox_default' => true, ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $meta = ['activecampaign_per_form_options' => 'global']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $mailchimp = new ActiveCampaign($payload); - - $mailchimp->process(); - - $block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); + // Act + $v3Form = $this->migrateForm($v2Form, ActiveCampaign::class); - $this->assertSame($meta['give_activecampaign_label'], $block->getAttribute('label')); - $this->assertSame($meta['give_activecampaign_lists'], $block->getAttribute('selectedLists')); - $this->assertSame($meta['give_activecampaign_tags'], $block->getAttribute('selectedTags')); + // Assert + $block = $v3Form->blocks->findByName('give-activecampaign/activecampaign'); + $this->assertSame($options['give_activecampaign_label'], $block->getAttribute('label')); + $this->assertSame($options['give_activecampaign_lists'], $block->getAttribute('selectedLists')); + $this->assertSame($options['give_activecampaign_tags'], $block->getAttribute('selectedTags')); $this->assertTrue(true, $block->getAttribute('defaultChecked')); } /** - * @since 3.10.0 + * @unreleased */ - public function testProcessShouldUpdateActiveCampaignBlockAttributesFromGlobalSettings(): void + public function testFormConfiguredToUseGlobalActiveCampaignSettingsIsMigratedWithoutActiveCampaignBlockWhenNotGloballyEnabled() { - $meta = [ - 'give_activecampaign_label' => __('Subscribe to our newsletter?'), - 'give_activecampaign_lists' => ['1', '2'], - 'give_activecampaign_tags' => ['tag 1', 'tag 2'], - 'give_activecampaign_checkbox_default' => true, - ]; - - foreach ($meta as $key => $value) { - give_update_option($key, $value); - } - - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); + // Arrange + give_update_option('give_activecampaign_globally_enabled', 'off'); + $meta = ['activecampaign_per_form_options' => 'global']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $payload = FormMigrationPayload::fromFormV2($formV2); + // Act + $v3Form = $this->migrateForm($v2Form, ActiveCampaign::class); - $mailchimp = new ActiveCampaign($payload); - - $mailchimp->process(); - - $block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); - - $this->assertSame($meta['give_activecampaign_label'], $block->getAttribute('label')); - $this->assertSame($meta['give_activecampaign_lists'], $block->getAttribute('selectedLists')); - $this->assertSame($meta['give_activecampaign_tags'], $block->getAttribute('selectedTags')); - $this->assertTrue(true, $block->getAttribute('defaultChecked')); + // Assert + $block = $v3Form->blocks->findByName('give-activecampaign/activecampaign'); + $this->assertNull($block); } /** - * @since 3.10.0 + * @unreleased */ - public function testProcessShouldUpdateActiveCampaignBlockAttributesWhenNoMeta(): void + public function testFormConfiguredToDisableActiveCampaignIsMigratedWithoutActiveCampaignBlock() { - $formV2 = $this->createSimpleDonationForm(); + // Arrange + $meta = ['activecampaign_per_form_options' => 'disabled']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $payload = FormMigrationPayload::fromFormV2($formV2); + // Act + $v3Form = $this->migrateForm($v2Form, ActiveCampaign::class); - $mailchimp = new ActiveCampaign($payload); + // Assert + $block = $v3Form->blocks->findByName('give-activecampaign/activecampaign'); + $this->assertNull($block); + } - $mailchimp->process(); + /** + * @unreleased + */ + public function testFormConfiguredToUseCustomizedActiveCampaignSettingsIsMigrated() + { + // Arrange + $meta = [ + 'activecampaign_per_form_options' => 'customized', + 'give_activecampaign_label' => __('Subscribe to our newsletter?'), + 'give_activecampaign_lists' => ['1', '2'], + 'give_activecampaign_tags' => ['tag 1', 'tag 2'], + 'give_activecampaign_checkbox_default' => true, + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); + // Act + $v3Form = $this->migrateForm($v2Form, ActiveCampaign::class); - $this->assertSame(__('Subscribe to our newsletter?'), $block->getAttribute('label')); - $this->assertSame([], $block->getAttribute('selectedLists')); - $this->assertNull(null, $block->getAttribute('selectedTags')); + // Assert + $block = $v3Form->blocks->findByName('give-activecampaign/activecampaign'); + $this->assertSame($meta['give_activecampaign_label'], $block->getAttribute('label')); + $this->assertSame($meta['give_activecampaign_lists'], $block->getAttribute('selectedLists')); + $this->assertSame($meta['give_activecampaign_tags'], $block->getAttribute('selectedTags')); $this->assertTrue(true, $block->getAttribute('defaultChecked')); } } diff --git a/tests/Feature/FormMigration/Steps/TestConstantContact.php b/tests/Feature/FormMigration/Steps/TestConstantContact.php index 52369f1d0c..048cda4889 100644 --- a/tests/Feature/FormMigration/Steps/TestConstantContact.php +++ b/tests/Feature/FormMigration/Steps/TestConstantContact.php @@ -2,94 +2,91 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\ConstantContact; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; /** + * @unreleased Update to use FormMigrationProcessor trait * @since 3.7.0 - * - * @covers \Give\FormMigration\Steps\DonationGoal */ class TestConstantContact extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.7.0 */ - public function testProcessShouldUpdateConstantContactBlockAttributesWithV2FormMeta(): void + public function testFormMigratesUsingGlobalSettingsWhenGloballyEnabled(): void { - $meta = [ - '_give_constant_contact_custom_label' => 'Subscribe to our newsletter?', - '_give_constant_contact_checked_default' => 'on', - '_give_constant_contact' => ['1928414891'], + // Arrange + $options = [ + 'give_constant_contact_show_checkout_signup' => 'on', + 'give_constant_contact_label' => 'Subscribe to our newsletter?', + 'give_constant_contact_checked_default' => 'on', + 'give_constant_contact_list' => ['1928414891'], ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $meta = ['_give_constant_contact_disabled' => 'false']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $constantContact = new ConstantContact($payload); - - $constantContact->process(); - - $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); + // Act + $v3Form = $this->migrateForm($v2Form, ConstantContact::class); + // Assert + $block = $v3Form->blocks->findByName('givewp/constantcontact'); $this->assertTrue(true, $block->getAttribute('checked' === 'on')); - $this->assertSame($meta['_give_constant_contact_custom_label'], $block->getAttribute('label')); - $this->assertSame($meta['_give_constant_contact'], $block->getAttribute('selectedEmailLists')); + $this->assertSame($options['give_constant_contact_label'], $block->getAttribute('label')); + $this->assertSame($options['give_constant_contact_list'], $block->getAttribute('selectedEmailLists')); } /** - * @since 3.7.0 + * @unreleased */ - public function testProcessShouldUpdateConstantContactBlockAttributesWithGlobalSettings(): void + public function testFormConfiguredToDisableConstantContactIsMigratedWithoutConstantContactBlock() { - $meta = [ - 'give_constant_contact_label' => 'Subscribe to our newsletter?', - 'give_constant_contact_checked_default' => 'on', - 'give_constant_contact_list' => ['1928414891'], - ]; - - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); + // Arrange + give_update_option('give_constant_contact_show_checkout_signup', 'on'); + $meta = ['_give_constant_contact_disable' => 'true']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $payload = FormMigrationPayload::fromFormV2($formV2); + // Act + $v3Form = $this->migrateForm($v2Form, ConstantContact::class); - foreach ($meta as $key => $value) { - give_update_option($key, $value); - } - - $constantContact = new ConstantContact($payload); - - $constantContact->process(); - - $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); - - $this->assertTrue(true, $block->getAttribute('checked' === 'on')); - $this->assertSame($meta['give_constant_contact_label'], $block->getAttribute('label')); - $this->assertSame($meta['give_constant_contact_list'], $block->getAttribute('selectedEmailLists')); + // Assert + $block = $v3Form->blocks->findByName('givewp/constantcontact'); + $this->assertNull($block); } /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.7.0 */ - public function testProcessShouldUpdateConstantContactBlockAttributesWhenNoMeta(): void + public function testFormConfiguredToUseCustomizedConstantContactSettingsIsMigrated(): void { - $formV2 = $this->createSimpleDonationForm(); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $constantContact = new ConstantContact($payload); - - $constantContact->process(); + // Arrange + $meta = [ + '_give_constant_contact_enable' => 'true', + '_give_constant_contact_custom_label' => 'Subscribe to our newsletter?', + '_give_constant_contact_checked_default' => 'on', + '_give_constant_contact' => ['1928414891'], + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); + // Act + $v3Form = $this->migrateForm($v2Form, ConstantContact::class); + // Assert + $block = $v3Form->blocks->findByName('givewp/constantcontact'); $this->assertTrue(true, $block->getAttribute('checked' === 'on')); - $this->assertSame('Subscribe to our newsletter?', $block->getAttribute('label')); - $this->assertNull(null, $block->getAttribute('selectedEmailLists')); + $this->assertSame($meta['_give_constant_contact_custom_label'], $block->getAttribute('label')); + $this->assertSame($meta['_give_constant_contact'], $block->getAttribute('selectedEmailLists')); } } diff --git a/tests/Feature/FormMigration/Steps/TestConvertKit.php b/tests/Feature/FormMigration/Steps/TestConvertKit.php index 9c51256eb2..e2ab34e3b1 100644 --- a/tests/Feature/FormMigration/Steps/TestConvertKit.php +++ b/tests/Feature/FormMigration/Steps/TestConvertKit.php @@ -4,94 +4,108 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\ConvertKit; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; class TestConvertKit extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.11.0 */ - public function testProcessShouldUpdateConvertkitBlockAttributesFromV2FormMeta(): void + public function testFormConfiguredToUseGlobalConvertKitSettingsMigratesUsingGlobalSettingsWhenGloballyEnabled() { - $meta = [ - '_give_convertkit_custom_label' => __('Subscribe to newsletter?' , 'give'), - '_give_convertkit' => '6352843', - '_give_convertkit_tags' => ['4619079', '4619080'], - '_give_convertkit_checked_default' => true, + // Arrange + $options = [ + 'give_convertkit_show_subscribe_checkbox' => 'enabled', + 'give_convertkit_label' => __('Subscribe to newsletter?', 'give'), + 'give_convertkit_list' => '6352843', + '_give_convertkit_tags' => ['4619079', '4619080'], + 'give_convertkit_checked_default' => true, ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $meta = ['_give_convertkit_override_option' => 'default']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $convertkit = new ConvertKit($payload); - - $convertkit->process(); - - $block = $payload->formV3->blocks->findByName('givewp-convertkit/convertkit'); + // Act + $v3Form = $this->migrateForm($v2Form, ConvertKit::class); - $this->assertSame($meta['_give_convertkit_custom_label'], $block->getAttribute('label')); - $this->assertSame($meta['_give_convertkit_tags'], $block->getAttribute('tagSubscribers')); - $this->assertSame($meta['_give_convertkit'], $block->getAttribute('selectedForm')); + // Assert + $block = $v3Form->blocks->findByName('givewp-convertkit/convertkit'); + $this->assertSame($options['give_convertkit_label'], $block->getAttribute('label')); + $this->assertSame($options['give_convertkit_list'], $block->getAttribute('selectedForm')); + $this->assertSame($options['_give_convertkit_tags'], $block->getAttribute('tagSubscribers')); $this->assertTrue(true, $block->getAttribute('defaultChecked')); } /** - * @since 3.11.0 + * @unreleased */ - public function testProcessShouldUpdateConvertkitBlockAttributesFromGlobalSettings(): void + public function testFormConfiguredToUseGlobalConvertKitSettingsIsMigratedWithoutConvertKitBlockWhenNotGloballyEnabled() { - $meta = [ - 'give_convertkit_label' => __('Subscribe to newsletter?', 'give'), - 'give_convertkit_list' => '6352843', - '_give_convertkit_tags' => ['4619079', '4619080'], - 'give_convertkit_checked_default' => true, - ]; + // Arrange + give_update_option('give_convertkit_show_subscribe_checkbox', 'disabled'); + $meta = ['_give_convertkit_override_option' => 'default']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - foreach ($meta as $key => $value) { - give_update_option($key, $value); - } + // Act + $v3Form = $this->migrateForm($v2Form, ConvertKit::class); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $convertkit = new ConvertKit($payload); + // Assert + $block = $v3Form->blocks->findByName('givewp-convertkit/convertkit'); + $this->assertNull($block); + } - $convertkit->process(); + /** + * @unreleased + */ + public function testFormConfiguredToDisableConvertKitIsMigratedWithoutConvertKitBlock() + { + // Arrange + $meta = ['_give_convertkit_override_option' => 'disabled']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $block = $payload->formV3->blocks->findByName('givewp-convertkit/convertkit'); + // Act + $v3Form = $this->migrateForm($v2Form, ConvertKit::class); - $this->assertSame($meta['give_convertkit_label'], $block->getAttribute('label')); - $this->assertSame($meta['give_convertkit_list'], $block->getAttribute('selectedForm')); - $this->assertSame($meta['_give_convertkit_tags'], $block->getAttribute('tagSubscribers')); - $this->assertTrue(true, $block->getAttribute('defaultChecked')); + // Assert + $block = $v3Form->blocks->findByName('givewp-convertkit/convertkit'); + $this->assertNull($block); } /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.11.0 */ - public function testProcessShouldUpdateConvertkitBlockAttributesWhenNoMeta(): void + public function testFormConfiguredToUseCustomizedConvertKitSettingsIsMigrated() { - $formV2 = $this->createSimpleDonationForm(); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $convertkit = new ConvertKit($payload); - - $convertkit->process(); + // Arrange + $meta = [ + '_give_convertkit_override_option' => 'customize', + '_give_convertkit_custom_label' => __('Subscribe to newsletter?' , 'give'), + '_give_convertkit' => '6352843', + '_give_convertkit_tags' => ['4619079', '4619080'], + '_give_convertkit_checked_default' => true, + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $block = $payload->formV3->blocks->findByName('givewp-convertkit/convertkit'); + // Act + $v3Form = $this->migrateForm($v2Form, ConvertKit::class); - $this->assertSame(__('Subscribe to newsletter?', 'give'), $block->getAttribute('label')); - $this->assertSame('', $block->getAttribute('selectedForm')); - $this->assertNull(null, $block->getAttribute('tagSubscribers')); + // Assert + $block = $v3Form->blocks->findByName('givewp-convertkit/convertkit'); + $this->assertSame($meta['_give_convertkit_custom_label'], $block->getAttribute('label')); + $this->assertSame($meta['_give_convertkit_tags'], $block->getAttribute('tagSubscribers')); + $this->assertSame($meta['_give_convertkit'], $block->getAttribute('selectedForm')); $this->assertTrue(true, $block->getAttribute('defaultChecked')); } } diff --git a/tests/Feature/FormMigration/Steps/TestDonationGoal.php b/tests/Feature/FormMigration/Steps/TestDonationGoal.php index 5628134dd9..e5905cd885 100644 --- a/tests/Feature/FormMigration/Steps/TestDonationGoal.php +++ b/tests/Feature/FormMigration/Steps/TestDonationGoal.php @@ -2,26 +2,31 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\DonationGoal; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; /** + * @unreleased Update to use FormMigrationProcessor trait * @since 3.4.0 * * @covers \Give\FormMigration\Steps\DonationGoal */ class TestDonationGoal extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.4.0 */ public function testProcessShouldUpdateDonationFormDonationGoalSettings(): void { + // Arrange $meta = [ '_give_goal_option' => 'enabled', '_give_goal_setting' => 'enabled', @@ -30,17 +35,13 @@ public function testProcessShouldUpdateDonationFormDonationGoalSettings(): void '_give_close_form_when_goal_achieved' => 'enabled', '_give_form_goal_achieved_message' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $donationGoal = new DonationGoal($payload); - - $donationGoal->process(); - - $settings = $payload->formV3->settings; + // Act + $v3Form = $this->migrateForm($v2Form, DonationGoal::class); + // Assert + $settings = $v3Form->settings; $this->assertTrue(true, $settings->enableDonationGoal); $this->assertTrue($settings->goalType->isAmount()); $this->assertSame((string)$meta['_give_set_goal'], $settings->goalAmount); diff --git a/tests/Feature/FormMigration/Steps/TestDonationOptions.php b/tests/Feature/FormMigration/Steps/TestDonationOptions.php index 3c4d0240b4..389282a4e1 100644 --- a/tests/Feature/FormMigration/Steps/TestDonationOptions.php +++ b/tests/Feature/FormMigration/Steps/TestDonationOptions.php @@ -2,11 +2,11 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\DonationOptions; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; /** * @since 3.4.0 @@ -14,13 +14,17 @@ * @covers \Give\FormMigration\Steps\DonationOptions */ class TestDonationOptions extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.4.0 */ public function testProcessShouldUpdateDonationAmountBlockAttributes(): void { + // Arrange $meta = [ '_give_price_option' => 'set', '_give_set_price' => '100', @@ -28,17 +32,13 @@ public function testProcessShouldUpdateDonationAmountBlockAttributes(): void '_give_custom_amount_range_minimum' => '1', '_give_custom_amount_range_maximum' => '1000', ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $donationOptions = new DonationOptions($payload); - - $donationOptions->process(); - - $block = $payload->formV3->blocks->findByName('givewp/donation-amount'); + // Act + $v3Form = $this->migrateForm($v2Form, DonationOptions::class); + // Assert + $block = $v3Form->blocks->findByName('givewp/donation-amount'); $this->assertSame($meta['_give_price_option'], $block->getAttribute('priceOption')); $this->assertSame($meta['_give_set_price'], $block->getAttribute('setPrice')); $this->assertTrue($block->getAttribute('customAmount')); @@ -47,27 +47,25 @@ public function testProcessShouldUpdateDonationAmountBlockAttributes(): void } /** + * @unreleased Update test to use FormMigrationProcessor::migrateForm method * @since 3.12.0 Updated test to include donation levels with descriptions * @since 3.4.0 */ public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonationLevels(): void { + //Arrange $meta = [ '_give_custom_amount' => 'enabled', '_give_custom_amount_range_minimum' => '1', '_give_custom_amount_range_maximum' => '1000', ]; + $v2Form = $this->createMultiLevelDonationForm(['meta' => $meta]); - $formV2 = $this->createMultiLevelDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $donationOptions = new DonationOptions($payload); - - $donationOptions->process(); - - $block = $payload->formV3->blocks->findByName('givewp/donation-amount'); + // Act + $v3Form = $this->migrateForm($v2Form, DonationOptions::class); + // Assert + $block = $v3Form->blocks->findByName('givewp/donation-amount'); $expectedLevels = [ [ 'value' => 10.00, diff --git a/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php b/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php index 89f94a1b72..ea4f2117c5 100644 --- a/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php +++ b/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php @@ -2,41 +2,43 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\DoubleTheDonation; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; /** + * @unreleased Update to use FormMigrationProcessor trait * @since 3.8.0 * * @covers \Give\FormMigration\Steps\DoubleTheDonation */ class TestDoubleTheDonation extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; public function testProcessShouldUpdateDoubleTheDonationBlockAttributes(): void { + // Arrange $meta = [ 'give_dtd_label' => 'DTD Label', + 'dtd_enable_disable' => 'enabled', ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + // Act + $v3Form = $this->migrateForm($v2Form, DoubleTheDonation::class); + + // Assert $company = [ 'company_id' => '', 'company_name' => '', 'entered_text' => '', ]; - - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - $payload = FormMigrationPayload::fromFormV2($formV2); - - $dtd = new DoubleTheDonation($payload); - $dtd->process(); - - $block = $payload->formV3->blocks->findByName('givewp/dtd'); - + $block = $v3Form->blocks->findByName('givewp/dtd'); $this->assertSame($meta['give_dtd_label'], $block->getAttribute('label')); $this->assertEqualsIgnoringCase($company, $block->getAttribute('company')); } diff --git a/tests/Feature/FormMigration/Steps/TestMailchimp.php b/tests/Feature/FormMigration/Steps/TestMailchimp.php index 7c9e9be78c..2d27a131a6 100644 --- a/tests/Feature/FormMigration/Steps/TestMailchimp.php +++ b/tests/Feature/FormMigration/Steps/TestMailchimp.php @@ -4,106 +4,115 @@ namespace Give\Tests\Feature\FormMigration\Steps; -use Give\FormMigration\DataTransferObjects\FormMigrationPayload; use Give\FormMigration\Steps\Mailchimp; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; +use Give\Tests\Unit\FormMigration\TestTraits\FormMigrationProcessor; class TestMailchimp extends TestCase { - use RefreshDatabase, LegacyDonationFormAdapter; + use FormMigrationProcessor; + use LegacyDonationFormAdapter; + use RefreshDatabase; /** - * @since 3.7.0 + * @unreleased */ - public function testProcessShouldUpdateMailchimpBlockAttributesFromV2FormMeta(): void + public function testMailchimpSettingsAreMigratedWhenGloballyEnabledAndNotDisabledForSpecificFormUsingGlobalSettings(): void { - $meta = [ - '_give_mailchimp_custom_label' => __('Subscribe to newsletter?'), - '_give_mailchimp_tags' => ['Animal-Rescue-Campaign', 'Housing-And-Shelter-Campaign'], - '_give_mailchimp' => ['de73f3f82f'], - '_give_mailchimp_checked_default' => true, - '_give_mailchimp_send_donation_data' => true, - '_give_mailchimp_send_ffm' => true, + // Arrange + $options = [ + 'give_mailchimp_show_checkout_signup' => 'on', + 'give_mailchimp_label' => __('Subscribe to newsletter?'), + 'give_mailchimp_list' => ['de73f3f82f'], + 'give_mailchimp_checked_default' => true, + 'give_mailchimp_double_opt_in' => true, + 'give_mailchimp_donation_data' => true, + 'give_mailchimp_ffm_pass_field' => true, ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $v2Form = $this->createSimpleDonationForm(); - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); - - $payload = FormMigrationPayload::fromFormV2($formV2); - - $mailchimp = new Mailchimp($payload); - - $mailchimp->process(); - - $block = $payload->formV3->blocks->findByName('givewp/mailchimp'); + // Act + $v3Form = $this->migrateForm($v2Form, Mailchimp::class); - $this->assertSame($meta['_give_mailchimp_custom_label'], $block->getAttribute('label')); - $this->assertSame($meta['_give_mailchimp_tags'], $block->getAttribute('subscriberTags')); - $this->assertSame($meta['_give_mailchimp'], $block->getAttribute('defaultAudiences')); + // Assert + $block = $v3Form->blocks->findByName('givewp/mailchimp'); + $this->assertSame($options['give_mailchimp_label'], $block->getAttribute('label')); + $this->assertSame($options['give_mailchimp_list'], $block->getAttribute('defaultAudiences')); + $this->assertNull(null, $block->getAttribute('subscriberTags')); $this->assertTrue(true, $block->getAttribute('checked')); + $this->assertTrue(true, $block->getAttribute('doubleOptIn')); $this->assertTrue(true, $block->getAttribute('sendDonationData')); $this->assertTrue(true, $block->getAttribute('sendFFMData')); } /** - * @since 3.7.0 + * @unreleased */ - public function testProcessShouldUpdateMailchimpBlockAttributesFromGlobalSettings(): void + public function testMailchimpSettingsAreMigratedWhenGloballyEnabledAndNotDisabledForSpecificFormUsingFormSettings(): void { + // Arrange + give_update_option('give_mailchimp_show_checkout_signup', 'on'); $meta = [ - 'give_mailchimp_label' => __('Subscribe to newsletter?'), - 'give_mailchimp_list' => ['de73f3f82f'], - 'give_mailchimp_checked_default' => true, - 'give_mailchimp_double_opt_in' => true, - 'give_mailchimp_donation_data' => true, - 'give_mailchimp_ffm_pass_field' => true, + '_give_mailchimp_custom_label' => __('Subscribe to newsletter?'), + '_give_mailchimp_tags' => ['Animal-Rescue-Campaign', 'Housing-And-Shelter-Campaign'], + '_give_mailchimp' => ['de73f3f82f'], + '_give_mailchimp_checked_default' => true, + '_give_mailchimp_send_donation_data' => true, + '_give_mailchimp_send_ffm' => true, ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - foreach ($meta as $key => $value) { - give_update_option($key, $value); - } - - $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); + // Act + $v3Form = $this->migrateForm($v2Form, Mailchimp::class); - $payload = FormMigrationPayload::fromFormV2($formV2); - - $mailchimp = new Mailchimp($payload); - - $mailchimp->process(); - - $block = $payload->formV3->blocks->findByName('givewp/mailchimp'); - - $this->assertSame($meta['give_mailchimp_label'], $block->getAttribute('label')); - $this->assertSame($meta['give_mailchimp_list'], $block->getAttribute('defaultAudiences')); - $this->assertNull(null, $block->getAttribute('subscriberTags')); + // Assert + $block = $v3Form->blocks->findByName('givewp/mailchimp'); + $this->assertSame($meta['_give_mailchimp_custom_label'], $block->getAttribute('label')); + $this->assertSame($meta['_give_mailchimp_tags'], $block->getAttribute('subscriberTags')); + $this->assertSame($meta['_give_mailchimp'], $block->getAttribute('defaultAudiences')); $this->assertTrue(true, $block->getAttribute('checked')); - $this->assertTrue(true, $block->getAttribute('doubleOptIn')); $this->assertTrue(true, $block->getAttribute('sendDonationData')); $this->assertTrue(true, $block->getAttribute('sendFFMData')); } /** - * @since 3.7.0 + * @unreleased */ - public function testProcessShouldUpdateMailchimpBlockAttributesWhenNoMeta(): void + public function testMailchimpSettingsAreNotMigratedWhenNotGloballyEnabledOrEnabledPerForm() { - $formV2 = $this->createSimpleDonationForm(); + // Arrange + give_update_option('give_mailchimp_show_checkout_signup', 'off'); + $meta = ['_give_mailchimp_enable' => 'false']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $payload = FormMigrationPayload::fromFormV2($formV2); + // Act + $v3Form = $this->migrateForm($v2Form, Mailchimp::class); - $mailchimp = new Mailchimp($payload); + // Assert + $block = $v3Form->blocks->findByName('givewp/mailchimp'); + $this->assertNull($block); + } - $mailchimp->process(); + /** + * @unreleased + */ + public function testMailchimpSettingsAreNotMigratedWhenGloballyEnabledButDisabledForSpecificForm() + { + // Arrange + give_update_option('give_mailchimp_show_checkout_signup', 'off'); + $meta = ['_give_mailchimp_disable' => 'false']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); - $block = $payload->formV3->blocks->findByName('givewp/mailchimp'); + // Act + $v3Form = $this->migrateForm($v2Form, Mailchimp::class); - $this->assertSame(__('Subscribe to newsletter?'), $block->getAttribute('label')); - $this->assertNull(null, $block->getAttribute('subscriberTags')); - $this->assertSame([''], $block->getAttribute('defaultAudiences')); - $this->assertTrue(true, $block->getAttribute('checked')); - $this->assertTrue(true, $block->getAttribute('doubleOptIn')); - $this->assertTrue(true, $block->getAttribute('sendDonationData')); - $this->assertTrue(true, $block->getAttribute('sendFFMData')); + // Assert + $block = $v3Form->blocks->findByName('givewp/mailchimp'); + $this->assertNull($block); } } diff --git a/tests/Unit/DonationSpam/ServiceProviderTest.php b/tests/Unit/DonationSpam/ServiceProviderTest.php new file mode 100644 index 0000000000..0e8596e247 --- /dev/null +++ b/tests/Unit/DonationSpam/ServiceProviderTest.php @@ -0,0 +1,25 @@ +validate('name@email.test'); + + $this->assertTrue(true); + } +} diff --git a/tests/Unit/FormMigration/TestTraits/FormMigrationProcessor.php b/tests/Unit/FormMigration/TestTraits/FormMigrationProcessor.php new file mode 100644 index 0000000000..b966ad51b8 --- /dev/null +++ b/tests/Unit/FormMigration/TestTraits/FormMigrationProcessor.php @@ -0,0 +1,29 @@ +formV3->save(); + + return $payload->formV3; + } +}