Skip to content

Commit

Permalink
feature: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ante Laca committed Mar 25, 2024
1 parent 8f15af6 commit 6ea2c6c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
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 6ea2c6c

Please sign in to comment.