Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Double The Donation migration step #7326

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,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'),
Expand Down
16 changes: 16 additions & 0 deletions src/FormMigration/FormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,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
jonwaldstein marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->getMeta('give_dtd_label');
}

/**
* @since 3.5.0
*/
Expand Down
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function register()
Steps\GiftAid::class,
Steps\FormFeaturedImage::class,
Steps\FormExcerpt::class,
Steps\DoubleTheDonation::class,
]);
});
}
Expand Down
41 changes: 41 additions & 0 deletions src/FormMigration/Steps/DoubleTheDonation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Give\FormMigration\Steps;

use Give\FormMigration\Contracts\FormMigrationStep;
use Give\Framework\Blocks\BlockModel;

/**
* @unreleased
*/
class DoubleTheDonation extends FormMigrationStep
jonwaldstein marked this conversation as resolved.
Show resolved Hide resolved
{

/**
* @unreleased
*/
public function canHandle(): bool
{
return $this->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' => '',
jonwaldstein marked this conversation as resolved.
Show resolved Hide resolved
],
],
]);

$this->fieldBlocks->insertAfter('givewp/donation-amount', $block);
}
}
43 changes: 43 additions & 0 deletions tests/Feature/FormMigration/Steps/TestDoubleTheDonation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

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;

/**
* @unreleased
*
* @covers \Give\FormMigration\Steps\DoubleTheDonation
*/
class TestDoubleTheDonation extends TestCase
{
use RefreshDatabase, LegacyDonationFormAdapter;

public function testProcessShouldUpdateDoubleTheDonationBlockAttributes(): void
{
$meta = [
'give_dtd_label' => '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'));
}
}
49 changes: 49 additions & 0 deletions tests/Feature/FormMigration/TestFormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Loading