Skip to content

Commit

Permalink
Merge branch 'develop' into release/3.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Apr 16, 2024
2 parents a5733b9 + ba764e7 commit 11eba0a
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
16 changes: 16 additions & 0 deletions src/FormMigration/FormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
{

/**
* @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' => '',
],
],
]);

$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');
}
}

0 comments on commit 11eba0a

Please sign in to comment.