From ba764e7283dcb8794c5f35cd4b991e48a48d6fb3 Mon Sep 17 00:00:00 2001 From: Ante Laca Date: Tue, 16 Apr 2024 19:04:58 +0200 Subject: [PATCH] Feature: Add Double The Donation migration step (#7326) Co-authored-by: Ante Laca Co-authored-by: Jon Waldstein --- .../V2/DonationFormsAdminPage.php | 2 +- src/FormMigration/FormMetaDecorator.php | 16 ++++++ src/FormMigration/ServiceProvider.php | 1 + src/FormMigration/Steps/DoubleTheDonation.php | 41 ++++++++++++++++ .../Steps/TestDoubleTheDonation.php | 43 ++++++++++++++++ .../FormMigration/TestFormMetaDecorator.php | 49 +++++++++++++++++++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/FormMigration/Steps/DoubleTheDonation.php create mode 100644 tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php diff --git a/src/DonationForms/V2/DonationFormsAdminPage.php b/src/DonationForms/V2/DonationFormsAdminPage.php index 06114ead38..f5de6d9bc1 100644 --- a/src/DonationForms/V2/DonationFormsAdminPage.php +++ b/src/DonationForms/V2/DonationFormsAdminPage.php @@ -343,7 +343,7 @@ public function getSupportedAddons(): array // 'MailChimp' => class_exists('Give_MailChimp'), // 'Text-to-Give' => defined('GIVE_TEXT_TO_GIVE_ADDON_NAME'), // 'Donation Block for Stripe' => defined('DONATION_BLOCK_FILE'), - // 'Double the Donation' => defined('GIVE_DTD_NAME'), + 'Double the Donation' => defined('GIVE_DTD_NAME'), // 'Simple Social Shout' => class_exists('SIMPLE_SOCIAL_SHARE_4_GIVEWP'), // 'Receipt Attachments' => defined('GIVERA_VERSION'), 'Per Form Gateways' => class_exists('Give_Per_Form_Gateways'), diff --git a/src/FormMigration/FormMetaDecorator.php b/src/FormMigration/FormMetaDecorator.php index b0a3d0eb71..3f441f16db 100644 --- a/src/FormMigration/FormMetaDecorator.php +++ b/src/FormMigration/FormMetaDecorator.php @@ -809,6 +809,22 @@ public function getGiftAidDeclarationForm(): string return $this->getMeta('give_gift_aid_declaration_form'); } + /** + * @unreleased + */ + public function getDoubleTheDonationStatus(): string + { + return $this->getMeta('dtd_enable_disable'); + } + + /** + * @unreleased + */ + public function getDoubleTheDonationLabel(): string + { + return $this->getMeta('give_dtd_label'); + } + /** * @since 3.5.0 */ diff --git a/src/FormMigration/ServiceProvider.php b/src/FormMigration/ServiceProvider.php index 3af7de2f45..708ee5106b 100644 --- a/src/FormMigration/ServiceProvider.php +++ b/src/FormMigration/ServiceProvider.php @@ -52,6 +52,7 @@ public function register() Steps\GiftAid::class, Steps\FormFeaturedImage::class, Steps\FormExcerpt::class, + Steps\DoubleTheDonation::class, ]); }); } diff --git a/src/FormMigration/Steps/DoubleTheDonation.php b/src/FormMigration/Steps/DoubleTheDonation.php new file mode 100644 index 0000000000..49000c10de --- /dev/null +++ b/src/FormMigration/Steps/DoubleTheDonation.php @@ -0,0 +1,41 @@ +formV2->getDoubleTheDonationStatus() === 'enabled'; + } + + /** + * @unreleased + */ + public function process() + { + $block = BlockModel::make([ + 'name' => 'givewp/dtd', + 'attributes' => [ + 'label' => $this->formV2->getDoubleTheDonationLabel(), + 'company' => [ + 'company_id' => '', + 'company_name' => '', + 'entered_text' => '', + ], + ], + ]); + + $this->fieldBlocks->insertAfter('givewp/donation-amount', $block); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php b/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php new file mode 100644 index 0000000000..b292caa5bf --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php @@ -0,0 +1,43 @@ + 'DTD Label', + ]; + + $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'); + + $this->assertSame($meta['give_dtd_label'], $block->getAttribute('label')); + $this->assertEqualsIgnoringCase($company, $block->getAttribute('company')); + } +} diff --git a/tests/Feature/FormMigration/TestFormMetaDecorator.php b/tests/Feature/FormMigration/TestFormMetaDecorator.php index c5948ce057..77e96e658e 100644 --- a/tests/Feature/FormMigration/TestFormMetaDecorator.php +++ b/tests/Feature/FormMigration/TestFormMetaDecorator.php @@ -265,4 +265,53 @@ private function uploadTestImage() return $this->_make_attachment($upload); } + + + /** + * @unreleased + */ + public function testIsDoubleTheDonationEnabledShouldReturnTrue(): void + { + $formV2 = $this->createSimpleDonationForm([ + 'meta' => [ + 'dtd_enable_disable' => 'enabled', + ], + ]); + + $formMetaDecorator = new FormMetaDecorator($formV2); + + $this->assertTrue($formMetaDecorator->getDoubleTheDonationStatus() === 'enabled'); + } + + /** + * @unreleased + */ + public function testIsDoubleTheDonationDisabledShouldReturnTrue(): void + { + $formV2 = $this->createSimpleDonationForm([ + 'meta' => [ + 'dtd_enable_disable' => 'disabled', + ], + ]); + + $formMetaDecorator = new FormMetaDecorator($formV2); + + $this->assertTrue($formMetaDecorator->getDoubleTheDonationStatus() === 'disabled'); + } + + /** + * @unreleased + */ + public function testIsDoubleTheDonationLabelSetShouldReturnTrue(): void + { + $formV2 = $this->createSimpleDonationForm([ + 'meta' => [ + 'give_dtd_label' => 'DTD Label', + ], + ]); + + $formMetaDecorator = new FormMetaDecorator($formV2); + + $this->assertTrue($formMetaDecorator->getDoubleTheDonationLabel() === 'DTD Label'); + } }