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 Constant Contact add-on to the form migration process #7145

Merged
merged 16 commits into from
Apr 10, 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 @@ -334,6 +334,7 @@ public function getSupportedAddons(): array
'Zapier' => defined('GIVE_ZAPIER_VERSION'),
'Salesforce' => defined('GIVE_SALESFORCE_VERSION'),
'Donation Upsells for WooCommerce' => class_exists('Give_WooCommerce'),
'Constant Contact' => class_exists('Give_Constant_Contact'),
'MailChimp' => class_exists('Give_MailChimp'),
// 'Manual Donations' => class_exists('Give_Manual_Donations'),
'Funds' => defined('GIVE_FUNDS_ADDON_NAME'),
Expand All @@ -349,7 +350,6 @@ public function getSupportedAddons(): array
// 'Per Form Confirmations' => class_exists('Per_Form_Confirmations_4_GIVEWP'),
// 'Form Countdown' => class_exists('Give_Form_Countdown'),
// 'ActiveCampaign' => class_exists('Give_ActiveCampaign'),
// 'Constant Contact' => class_exists('Give_Constant_Contact'),
];

$output = [];
Expand Down
49 changes: 48 additions & 1 deletion src/FormMigration/FormMetaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,54 @@ public function getFeeRecoverySettings(): array
];
}

/**
* @unreleased
*/
public function isConstantContactEnabled(): bool
{
$isFormEnabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_enable'),'true');

$isFormDisabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_disable'),'true');

$isGloballyEnabled = give_is_setting_enabled(give_get_option('give_constant_contact_show_checkout_signup'), 'on');

return !($isFormDisabled || ( !$isGloballyEnabled && !$isFormEnabled));
}

/**
* @unreleased
*/
public function getConstantContactLabel(): string
{
$defaultMeta = give_get_option('give_constant_contact_label', __('Subscribe to our newsletter?'));

return $this->getMeta('_give_constant_contact_custom_label', $defaultMeta);
}

/**
* @unreleased
*/
public function getConstantContactDefaultChecked(): bool
{
$defaultMeta = give_is_setting_enabled(
give_get_option('give_constant_contact_checked_default',
true),
'on'
);

return $this->getMeta('_give_constant_contact_checked_default', $defaultMeta);
}

/**
* @unreleased
*/
public function getConstantContactSelectedLists(): array
{
$defaultMeta = give_get_option('give_constant_contact_list', []);

return (array)$this->getMeta('_give_constant_contact', $defaultMeta);
}

/**
* @since 3.3.0
*/
Expand Down Expand Up @@ -542,7 +590,6 @@ public function getMailchimpDefaultChecked(): bool
give_get_option('give_mailchimp_checked_default', true)));
}


/**
* @unreleased add global setting as default.
* @since 3.3.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 @@ -45,6 +45,7 @@ public function register()
Steps\FormMeta::class,
Steps\PdfSettings::class,
Steps\FeeRecovery::class,
Steps\ConstantContact::class,
Steps\PerFormGateways::class,
Steps\Mailchimp::class,
Steps\FundsAndDesignations::class,
Expand Down
37 changes: 37 additions & 0 deletions src/FormMigration/Steps/ConstantContact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Give\FormMigration\Steps;

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

/**
* @unreleased
*/
class ConstantContact extends FormMigrationStep
{
/**
* @unreleased
*/
public function canHandle(): bool
jonwaldstein marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->formV2->isConstantContactEnabled();
}

/**
* @unreleased
*/
public function process(): void
{
$block = BlockModel::make([
'name' => 'givewp/constantcontact',
'attributes' =>[
'label' => $this->formV2->getConstantContactLabel(),
'checked' => $this->formV2->getConstantContactDefaultChecked(),
'selectedEmailLists' => $this->formV2->getConstantContactSelectedLists(),
],
]);

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

namespace Give\Tests\Feature\FormMigration\Steps;

use Give\FormMigration\DataTransferObjects\FormMigrationPayload;
use Give\FormMigration\Steps\ConstantContact;
use Give\Tests\TestCase;
use Give\Tests\TestTraits\RefreshDatabase;
use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter;

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

/**
* @unreleased
*/
public function testProcessShouldUpdateConstantContactBlockAttributesWithV2FormMeta(): void
{
$meta = [
'_give_constant_contact_custom_label' => 'Subscribe to our newsletter?',
'_give_constant_contact_checked_default' => 'on',
'_give_constant_contact' => ['1928414891'],
];

$formV2 = $this->createSimpleDonationForm(['meta' => $meta]);

$payload = FormMigrationPayload::fromFormV2($formV2);

$constantContact = new ConstantContact($payload);

$constantContact->process();

$block = $payload->formV3->blocks->findByName('givewp/constantcontact');

$this->assertTrue(true, $block->getAttribute('checked' === 'on'));
$this->assertSame($meta['_give_constant_contact_custom_label'], $block->getAttribute('label'));
$this->assertSame($meta['_give_constant_contact'], $block->getAttribute('selectedEmailLists'));
}

/**
* @unreleased
*/
public function testProcessShouldUpdateConstantContactBlockAttributesWithGlobalSettings(): void
{
$meta = [
'give_constant_contact_label' => 'Subscribe to our newsletter?',
'give_constant_contact_checked_default' => 'on',
'give_constant_contact_list' => ['1928414891'],
];

$formV2 = $this->createSimpleDonationForm(['meta' => $meta]);

$payload = FormMigrationPayload::fromFormV2($formV2);

foreach ($meta as $key => $value) {
give_update_option($key, $value);
}

$constantContact = new ConstantContact($payload);

$constantContact->process();

$block = $payload->formV3->blocks->findByName('givewp/constantcontact');

$this->assertTrue(true, $block->getAttribute('checked' === 'on'));
$this->assertSame($meta['give_constant_contact_label'], $block->getAttribute('label'));
$this->assertSame($meta['give_constant_contact_list'], $block->getAttribute('selectedEmailLists'));
}

/**
* @unreleased
*/
public function testProcessShouldUpdateConstantContactBlockAttributesWhenNoMeta(): void
{
$formV2 = $this->createSimpleDonationForm();

$payload = FormMigrationPayload::fromFormV2($formV2);

$constantContact = new ConstantContact($payload);

$constantContact->process();

$block = $payload->formV3->blocks->findByName('givewp/constantcontact');

$this->assertTrue(true, $block->getAttribute('checked' === 'on'));
$this->assertSame('Subscribe to our newsletter?', $block->getAttribute('label'));
$this->assertNull(null, $block->getAttribute('selectedEmailLists'));
}
}
Loading