From ee7c9a01a12f255bc2f6a713532e35ed4dacb7c9 Mon Sep 17 00:00:00 2001 From: Paulo Iankoski Date: Tue, 23 Apr 2024 18:06:39 -0300 Subject: [PATCH] fix: update tests to reflect changes to donation levels schema --- src/FormMigration/Steps/DonationOptions.php | 2 +- .../Steps/TestDonationOptions.php | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/FormMigration/Steps/DonationOptions.php b/src/FormMigration/Steps/DonationOptions.php index d1b78ffe6b..97b691131e 100644 --- a/src/FormMigration/Steps/DonationOptions.php +++ b/src/FormMigration/Steps/DonationOptions.php @@ -31,7 +31,7 @@ public function process() return [ 'value' => $this->roundAmount($donationLevel['_give_amount']), 'label' => $donationLevel['_give_text'], - 'checked' => $donationLevel['_give_default'] === 'default' ?? false, + 'checked' => isset($donationLevel['_give_default']) && $donationLevel['_give_default'] === 'default', ]; }, $donationLevels) ); diff --git a/tests/Feature/FormMigration/Steps/TestDonationOptions.php b/tests/Feature/FormMigration/Steps/TestDonationOptions.php index 59a0315d17..d79e9c1548 100644 --- a/tests/Feature/FormMigration/Steps/TestDonationOptions.php +++ b/tests/Feature/FormMigration/Steps/TestDonationOptions.php @@ -47,6 +47,7 @@ public function testProcessShouldUpdateDonationAmountBlockAttributes(): void } /** + * @unreleased Updated test to include donation levels with descriptions * @since 3.4.0 */ public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonationLevels(): void @@ -67,7 +68,29 @@ public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonation $block = $payload->formV3->blocks->findByName('givewp/donation-amount'); - $this->assertSame([10.00, 25.00, 50.00, 100.00], $block->getAttribute('levels')); + $expectedLevels = [ + [ + 'value' => 10.00, + 'label' => 'Small Gift', + 'checked' => false, + ], + [ + 'value' => 25.00, + 'label' => 'Mid-size Gift', + 'checked' => true, + ], + [ + 'value' => 50.00, + 'label' => 'Large Gift', + 'checked' => false, + ], + [ + 'value' => 100.00, + 'label' => 'Big Gift', + 'checked' => false, + ], + ]; + $this->assertSame($expectedLevels, $block->getAttribute('levels')); $this->assertTrue($block->getAttribute('customAmount')); $this->assertSame((float)$meta['_give_custom_amount_range_minimum'], $block->getAttribute('customAmountMin')); $this->assertSame((float)$meta['_give_custom_amount_range_maximum'], $block->getAttribute('customAmountMax'));