From 6ea2c6cac6c50c811dc61fa8035a64cee686a663 Mon Sep 17 00:00:00 2001 From: Ante Laca Date: Mon, 25 Mar 2024 13:32:03 +0100 Subject: [PATCH] feature: add tests --- .../Steps/TestDoubleTheDonation.php | 43 ++++++++++++++++ .../FormMigration/TestFormMetaDecorator.php | 49 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php 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'); + } }