diff --git a/tests/Feature/FormMigration/Steps/TestEmailSettings.php b/tests/Feature/FormMigration/Steps/TestEmailSettings.php new file mode 100644 index 0000000000..ad5ad999a9 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestEmailSettings.php @@ -0,0 +1,91 @@ + 'enabled', + '_give_email_template' => 'default', + '_give_email_logo' => 'logo.png', + '_give_from_name' => 'Charity Org', + '_give_from_email' => 'email@example.org', + ]; + + $notifications = Give_Email_Notifications::get_instance()->get_email_notifications(); + foreach ($notifications as $notification) { + add_filter("give_{$notification->config['id']}_get_recipients", [$this, 'getNotificationRecipients'], 1, 3); + + $prefix = '_give_' . $notification->config['id']; + $notificationMeta = [ + $prefix . '_notification' => 'enabled', + $prefix . '_email_subject' => $notification->config['label'], + $prefix . '_email_header' => 'Header for: ' . $notification->config['label'], + $prefix . '_email_message' => 'Message for: ' . $notification->config['label'], + $prefix . '_email_content_type' => 'text/html', + ]; + + if ($notification->config['has_recipient_field']) { + $notificationMeta[$prefix . '_recipient'] = [['email' => 'donor@charity.org']]; + } + $meta = array_merge($meta, $notificationMeta); + } + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, EmailSettings::class); + + // Assert + $this->assertSame($meta['_give_email_options'], $v3Form->settings->emailOptionsStatus); + $this->assertSame($meta['_give_email_template'], $v3Form->settings->emailTemplate); + $this->assertSame($meta['_give_email_logo'], $v3Form->settings->emailLogo); + $this->assertSame($meta['_give_from_name'], $v3Form->settings->emailFromName); + $this->assertSame($meta['_give_from_email'], $v3Form->settings->emailFromEmail); + + foreach ($notifications as $notification) { + $configId = $notification->config['id']; + $this->assertSame('enabled', $v3Form->settings->emailTemplateOptions[$configId]['status']); + $this->assertSame($notification->config['label'], $v3Form->settings->emailTemplateOptions[$configId]['email_subject']); + $this->assertSame('Header for: ' . $notification->config['label'], $v3Form->settings->emailTemplateOptions[$configId]['email_header']); + $this->assertSame('Message for: ' . $notification->config['label'], $v3Form->settings->emailTemplateOptions[$configId]['email_message']); + $this->assertSame('text/html', $v3Form->settings->emailTemplateOptions[$configId]['email_content_type']); + + if ($notification->config['has_recipient_field']) { + $this->assertSame(['donor@charity.org'], + $v3Form->settings->emailTemplateOptions[$configId]['recipient']); + } + + remove_filter("give_{$notification->config['id']}_get_recipients", [$this, 'getNotificationRecipients'], 1); + } + } + + public function getNotificationRecipients($recipientEmail, $instance, $formId) + { + return Give_Email_Notification_Util::get_value( + $instance, + Give_Email_Setting_Field::get_prefix( $instance, $formId ) . 'recipient', + $formId + ); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFeeRecovery.php b/tests/Feature/FormMigration/Steps/TestFeeRecovery.php new file mode 100644 index 0000000000..fd94bf9ca2 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFeeRecovery.php @@ -0,0 +1,114 @@ + 'enabled', + 'give_fee_configuration' => 'all_gateways', + 'give_fee_percentage' => 5, + 'give_fee_base_amount' => 0.50, + 'give_fee_maximum_fee_amount' => 20.00, + 'give_fee_breakdown' => 'enabled', + 'give_fee_mode' => 'donor_opt_in', + 'give_fee_checkbox_label' => 'Fee Recovery checkbox label', + 'give_fee_explanation' => 'Message for fee recovery', + ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $meta = ['_form_give_fee_recovery' => 'global']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FeeRecovery::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp-fee-recovery/fee-recovery'); + $this->assertSame(true, $block->getAttribute('useGlobalSettings')); + $this->assertSame(true, $block->getAttribute('feeSupportForAllGateways')); + $this->assertSame([], $block->getAttribute('perGatewaySettings')); + $this->assertSame(5.0, $block->getAttribute('feePercentage')); + $this->assertSame(0.5, $block->getAttribute('feeBaseAmount')); + $this->assertSame(20.0, $block->getAttribute('maxFeeAmount')); + $this->assertSame(true, $block->getAttribute('includeInDonationSummary')); + $this->assertSame(true, $block->getAttribute('donorOptIn')); + $this->assertSame('Fee Recovery checkbox label', $block->getAttribute('feeCheckboxLabel')); + $this->assertSame('Message for fee recovery', $block->getAttribute('feeMessage')); + } + + /** + * @unreleased + */ + public function testFeeRecoveryProcessWithPerFormSettings(): void + { + // Arrange + $meta = [ + '_form_give_fee_recovery' => 'enabled', + '_form_give_fee_configuration' => 'all_gateways', + '_form_give_fee_percentage' => 5, + '_form_give_fee_base_amount' => 0.50, + '_form_give_fee_maximum_fee_amount' => 20.00, + '_form_breakdown' => 'enabled', + '_form_give_fee_mode' => 'donor_opt_in', + '_form_give_fee_checkbox_label' => 'Fee Recovery checkbox label', + '_form_give_fee_explanation' => 'Message for fee recovery', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FeeRecovery::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp-fee-recovery/fee-recovery'); + $this->assertSame(false, $block->getAttribute('useGlobalSettings')); + $this->assertSame(true, $block->getAttribute('feeSupportForAllGateways')); + $this->assertSame(5.0, $block->getAttribute('feePercentage')); + $this->assertSame(0.5, $block->getAttribute('feeBaseAmount')); + $this->assertSame(20.0, $block->getAttribute('maxFeeAmount')); + $this->assertSame(true, $block->getAttribute('includeInDonationSummary')); + $this->assertSame(true, $block->getAttribute('donorOptIn')); + $this->assertSame('Fee Recovery checkbox label', $block->getAttribute('feeCheckboxLabel')); + $this->assertSame('Message for fee recovery', $block->getAttribute('feeMessage')); + } + + /** + * @unreleased + */ + public function testFeeRecoveryProcessWithGlobalSettingsDisabled(): void + { + // Arrange + give_update_option('give_fee_recovery', 'disabled'); + $meta = ['_form_give_fee_recovery' => 'global']; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FeeRecovery::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp-fee-recovery/fee-recovery'); + $this->assertNull($block); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormExcerpt.php b/tests/Feature/FormMigration/Steps/TestFormExcerpt.php new file mode 100644 index 0000000000..0272774cfb --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormExcerpt.php @@ -0,0 +1,39 @@ + 'This is a test excerpt', + ]; + $v2Form = $this->createSimpleDonationForm(['form' => $form]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormExcerpt::class); + + // Assert + $this->assertSame($form['post_excerpt'], $v3Form->settings->formExcerpt); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormFeaturedImage.php b/tests/Feature/FormMigration/Steps/TestFormFeaturedImage.php new file mode 100644 index 0000000000..e1a614c271 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormFeaturedImage.php @@ -0,0 +1,106 @@ + 'sequoia', + '_give_sequoia_form_template_settings' => [ + 'introduction' => [ + 'image' => 'https://example.com/image.jpg', + ], + ], + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFeaturedImage::class); + + // Assert + $this->assertSame('https://example.com/image.jpg', $v3Form->settings->designSettingsImageUrl); + $this->assertSame('center', $v3Form->settings->designSettingsImageStyle); + } + + /** + * @unreleased + */ + public function testClassicTemplateHeaderBackgroundImageIsMigratedCorrectly(): void + { + // Arrange + $meta = [ + '_give_form_template' => 'classic', + '_give_classic_form_template_settings' => [ + 'visual_appearance' => [ + 'header_background_image' => 'https://example.com/image.jpg', + ], + ], + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFeaturedImage::class); + + // Assert + $this->assertSame('https://example.com/image.jpg', $v3Form->settings->designSettingsImageUrl); + } + + /** + * @unreleased + */ + public function testFallbackImageIsMigratedWhenFeaturedImageIsMissing(): void + { + // Arrange + $v2Form = $this->createSimpleDonationForm(); + update_post_meta($v2Form->id, '_thumbnail_id', '1'); + add_filter('wp_get_attachment_image_src', function ($image, $attachmentId) { + if ($attachmentId === 1) { + return ['https://example.com/image.jpg', 100, 100, false]; + } + + return $image; + }, 10, 2); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFeaturedImage::class); + + // Assert + $this->assertSame('https://example.com/image.jpg', $v3Form->settings->designSettingsImageUrl); + } + + /** + * @unreleased + */ + public function testNoImageIsMigratedWhenNoImageExists () + { + // Arrange + $v2Form = $this->createSimpleDonationForm(); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFeaturedImage::class); + + // Assert + $this->assertEmpty($v3Form->settings->designSettingsImageUrl); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormFields.php b/tests/Feature/FormMigration/Steps/TestFormFields.php new file mode 100644 index 0000000000..18d9842782 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormFields.php @@ -0,0 +1,88 @@ + ['Mr.', 'Mrs.', 'Ms.', 'Dr.'], + ]; + foreach ($options as $key => $value) { + give_update_option($key, $value); + } + $meta = [ + '_give_name_title_prefix' => 'required', + '_give_title_prefixes' => ['Mr.', 'Mrs.', 'Ms.', 'Dr.'], + '_give_last_name_field_required' => 'required', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFields::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp/donor-name'); + $this->assertTrue($block->getAttribute('showHonorific')); + $this->assertEquals($options['title_prefixes'], $block->getAttribute('honorifics')); + $this->assertTrue($block->getAttribute('requireLastName')); + } + + /** + * @unreleased + */ + public function testDonorCommentsFormFieldProcess() + { + // Arrange + $meta = [ + '_give_donor_comment' => 'enabled', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFields::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp/donor-comments'); + $this->assertNotNull($block); + } + + /** + * @unreleased + */ + public function testAnonymousDonationsFormFieldProcess() + { + // Arrange + $meta = [ + '_give_anonymous_donation' => 'enabled', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormFields::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp/anonymous'); + $this->assertNotNull($block); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormGrid.php b/tests/Feature/FormMigration/Steps/TestFormGrid.php new file mode 100644 index 0000000000..8862ea7538 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormGrid.php @@ -0,0 +1,45 @@ + 'custom', + '_give_form_grid_redirect_url' => 'https://example.com', + '_give_form_grid_donate_button_text' => 'Donate Now', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormGrid::class); + + // Assert + $this->assertTrue($v3Form->settings->formGridCustomize); + $this->assertEquals('https://example.com', $v3Form->settings->formGridRedirectUrl); + $this->assertEquals('Donate Now', $v3Form->settings->formGridDonateButtonText); + $this->assertTrue($v3Form->settings->formGridHideDocumentationLink); + + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormMeta.php b/tests/Feature/FormMigration/Steps/TestFormMeta.php new file mode 100644 index 0000000000..ccbb238732 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormMeta.php @@ -0,0 +1,43 @@ + true, + '_string_legacy_meta' => 'string', + '_array_legacy_meta' => ['key' => 'value'], + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormMeta::class); + + // Assert + $this->assertTrue((bool) give_get_meta($v3Form->id, '_boolean_legacy_meta', true)); + $this->assertSame('string', give_get_meta($v3Form->id, '_string_legacy_meta', true)); + $this->assertSame(['key' => 'value'], give_get_meta($v3Form->id, '_array_legacy_meta', true)); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestFormTitle.php b/tests/Feature/FormMigration/Steps/TestFormTitle.php new file mode 100644 index 0000000000..e8e92c7b94 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestFormTitle.php @@ -0,0 +1,40 @@ + 'Form Title', + ]; + $v2Form = $this->createSimpleDonationForm(['form' => $form]); + + // Act + $v3Form = $this->migrateForm($v2Form, FormTitle::class); + + // Assert + $this->assertSame($form['post_title'], $v3Form->title); + $this->assertSame($form['post_title'], $v3Form->settings->formTitle); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestMigrateMeta.php b/tests/Feature/FormMigration/Steps/TestMigrateMeta.php new file mode 100644 index 0000000000..e362cae906 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestMigrateMeta.php @@ -0,0 +1,36 @@ +createSimpleDonationForm(); + + // Act + $v3Form = $this->migrateForm($v2Form, MigrateMeta::class); + + // Assert + $this->assertSame($v2Form->id, (int) give_get_meta($v3Form->id, 'migratedFormId', true)); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestOfflineDonations.php b/tests/Feature/FormMigration/Steps/TestOfflineDonations.php new file mode 100644 index 0000000000..a5a67a678c --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestOfflineDonations.php @@ -0,0 +1,61 @@ + 'custom', + '_give_offline_donation_enable_billing_fields_single' => 'enabled', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, OfflineDonations::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp/billing-address'); + $this->assertNotNull($block); + } + + /** + * @unreleased + */ + public function testOfflineDonationsProcessMigratesNotes(): void + { + // Arrange + $instructions = 'Please send a check to 123 Main St.'; + $meta = [ + '_give_customize_offline_donations' => 'custom', + '_give_offline_checkout_notes' => $instructions, + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, OfflineDonations::class); + + // Assert + $this->assertEquals($instructions, $v3Form->settings->offlineDonationInstructions); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestPaymentGateways.php b/tests/Feature/FormMigration/Steps/TestPaymentGateways.php new file mode 100644 index 0000000000..809b1dbb94 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestPaymentGateways.php @@ -0,0 +1,47 @@ + 'enabled', + '_give_stripe_default_account' => 'acct_1', + '_give_customize_offline_donations' => 'enabled', + '_give_offline_checkout_notes' => 'Offline checkout notes', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, PaymentGateways::class); + + // Assert + $block = $v3Form->blocks->findByName('givewp/payment-gateways'); + $this->assertFalse($block->getAttribute('stripeUseGlobalDefault')); + $this->assertSame('acct_1', $block->getAttribute('accountId')); + $this->assertTrue($block->getAttribute('offlineEnabled')); + $this->assertFalse($block->getAttribute('offlineUseGlobalInstructions')); + $this->assertSame('Offline checkout notes', $block->getAttribute('offlineDonationInstructions')); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestPdfSettings.php b/tests/Feature/FormMigration/Steps/TestPdfSettings.php new file mode 100644 index 0000000000..2cd3e364dd --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestPdfSettings.php @@ -0,0 +1,73 @@ + 'enabled', + 'give_pdf_generation_method' => 'auto', + 'give_pdf_colorpicker' => '#FF5733', + 'give_pdf_templates' => 'custom_template', + 'give_pdf_logo_upload' => 'logo.png', + 'give_pdf_company_name' => 'My Company', + 'give_pdf_address_line1' => '123 Main St', + 'give_pdf_address_line2' => 'Apt 4B', + 'give_pdf_address_city_state_zip' => 'New York, NY 10001', + 'give_pdf_url' => 'https://example.com', + 'give_pdf_email_address' => 'info@example.com', + 'give_pdf_header_message' => 'Thank you for your donation!', + 'give_pdf_footer_message' => 'Footer message here.', + 'give_pdf_additional_notes' => 'Additional notes...', + 'give_pdf_receipt_template' => 'custom_template', + 'give_pdf_receipt_template_name' => 'Custom Template Name', + 'give_pdf_builder_page_size' => 'A4', + 'give_pdf_builder' => 'custom_builder', + ]; + $v2Form = $this->createSimpleDonationForm(['meta' => $meta]); + + // Act + $v3Form = $this->migrateForm($v2Form, PdfSettings::class); + + // Assert + $this->assertEquals($meta['give_pdf_receipts_enable_disable'], $v3Form->settings->pdfSettings['enable']); + $this->assertEquals($meta['give_pdf_generation_method'], $v3Form->settings->pdfSettings['generationMethod']); + $this->assertEquals($meta['give_pdf_colorpicker'], $v3Form->settings->pdfSettings['colorPicker']); + $this->assertEquals($meta['give_pdf_templates'], $v3Form->settings->pdfSettings['templateId']); + $this->assertEquals($meta['give_pdf_logo_upload'], $v3Form->settings->pdfSettings['logoUpload']); + $this->assertEquals($meta['give_pdf_company_name'], $v3Form->settings->pdfSettings['name']); + $this->assertEquals($meta['give_pdf_address_line1'], $v3Form->settings->pdfSettings['addressLine1']); + $this->assertEquals($meta['give_pdf_address_line2'], $v3Form->settings->pdfSettings['addressLine2']); + $this->assertEquals($meta['give_pdf_address_city_state_zip'], $v3Form->settings->pdfSettings['cityStateZip']); + $this->assertEquals($meta['give_pdf_url'], $v3Form->settings->pdfSettings['displayWebsiteUrl']); + $this->assertEquals($meta['give_pdf_email_address'], $v3Form->settings->pdfSettings['emailAddress']); + $this->assertEquals($meta['give_pdf_header_message'], $v3Form->settings->pdfSettings['headerMessage']); + $this->assertEquals($meta['give_pdf_footer_message'], $v3Form->settings->pdfSettings['footerMessage']); + $this->assertEquals($meta['give_pdf_additional_notes'], $v3Form->settings->pdfSettings['additionalNotes']); + $this->assertEquals($meta['give_pdf_receipt_template'], $v3Form->settings->pdfSettings['customTemplateId']); + $this->assertEquals($meta['give_pdf_receipt_template_name'], $v3Form->settings->pdfSettings['customTemplateName']); + $this->assertEquals($meta['give_pdf_builder_page_size'], $v3Form->settings->pdfSettings['customPageSize']); + $this->assertEquals($meta['give_pdf_builder'], $v3Form->settings->pdfSettings['customPdfBuilder']); + } +}