-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: add activecampaign add-on to the form migration process (#7336)
Co-authored-by: Jon Waldstein <[email protected]>
- Loading branch information
1 parent
07afc8d
commit beec47e
Showing
5 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Give\FormMigration\Steps; | ||
|
||
use Give\FormMigration\Contracts\FormMigrationStep; | ||
use Give\Framework\Blocks\BlockModel; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class ActiveCampaign extends FormMigrationStep | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function canHandle(): bool | ||
{ | ||
return $this->formV2->isActiveCampaignEnabled(); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function process(): void | ||
{ | ||
$block = BlockModel::make([ | ||
'name' => 'give-activecampaign/activecampaign', | ||
'attributes' => $this->getAttributes() | ||
]); | ||
|
||
$this->fieldBlocks->insertAfter('givewp/email', $block); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
private function getAttributes(): array | ||
{ | ||
return [ | ||
'label' => $this->formV2->getActiveCampaignLabel() , | ||
'defaultChecked' => $this->formV2->getActiveCampaignDefaultChecked(), | ||
'selectedLists' => $this->formV2->getActiveCampaignSelectedLists(), | ||
'selectedTags' => $this->formV2->getActiveCampaignTags() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Feature\FormMigration\Steps; | ||
|
||
namespace Give\Tests\Feature\FormMigration\Steps; | ||
|
||
use Give\FormMigration\DataTransferObjects\FormMigrationPayload; | ||
use Give\FormMigration\Steps\ActiveCampaign; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; | ||
|
||
class TestActiveCampaign extends TestCase | ||
{ | ||
use RefreshDatabase, LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateActiveCampaignBlockAttributesFromV2FormMeta(): void | ||
{ | ||
$meta = [ | ||
'give_activecampaign_label' => __('Subscribe to our newsletter?'), | ||
'give_activecampaign_lists' => ['1', '2'], | ||
'give_activecampaign_tags' => ['tag 1', 'tag 2'], | ||
'give_activecampaign_checkbox_default' => true, | ||
]; | ||
|
||
$formV2 = $this->createSimpleDonationForm(['meta' => $meta]); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$mailchimp = new ActiveCampaign($payload); | ||
|
||
$mailchimp->process(); | ||
|
||
$block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); | ||
|
||
$this->assertSame($meta['give_activecampaign_label'], $block->getAttribute('label')); | ||
$this->assertSame($meta['give_activecampaign_lists'], $block->getAttribute('selectedLists')); | ||
$this->assertSame($meta['give_activecampaign_tags'], $block->getAttribute('selectedTags')); | ||
$this->assertTrue(true, $block->getAttribute('defaultChecked')); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateActiveCampaignBlockAttributesFromGlobalSettings(): void | ||
{ | ||
$meta = [ | ||
'give_activecampaign_label' => __('Subscribe to our newsletter?'), | ||
'give_activecampaign_lists' => ['1', '2'], | ||
'give_activecampaign_tags' => ['tag 1', 'tag 2'], | ||
'give_activecampaign_checkbox_default' => true, | ||
]; | ||
|
||
foreach ($meta as $key => $value) { | ||
give_update_option($key, $value); | ||
} | ||
|
||
$formV2 = $this->createSimpleDonationForm(['meta' => $meta]); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$mailchimp = new ActiveCampaign($payload); | ||
|
||
$mailchimp->process(); | ||
|
||
$block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); | ||
|
||
$this->assertSame($meta['give_activecampaign_label'], $block->getAttribute('label')); | ||
$this->assertSame($meta['give_activecampaign_lists'], $block->getAttribute('selectedLists')); | ||
$this->assertSame($meta['give_activecampaign_tags'], $block->getAttribute('selectedTags')); | ||
$this->assertTrue(true, $block->getAttribute('defaultChecked')); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateActiveCampaignBlockAttributesWhenNoMeta(): void | ||
{ | ||
$formV2 = $this->createSimpleDonationForm(); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$mailchimp = new ActiveCampaign($payload); | ||
|
||
$mailchimp->process(); | ||
|
||
$block = $payload->formV3->blocks->findByName('give-activecampaign/activecampaign'); | ||
|
||
$this->assertSame(__('Subscribe to our newsletter?'), $block->getAttribute('label')); | ||
$this->assertSame([], $block->getAttribute('selectedLists')); | ||
$this->assertNull(null, $block->getAttribute('selectedTags')); | ||
$this->assertTrue(true, $block->getAttribute('defaultChecked')); | ||
} | ||
} |