-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: scaffold v2 to v3 donation form migration tests (#7216)
Co-authored-by: Jon Waldstein <[email protected]>
- Loading branch information
1 parent
a785ee0
commit c11d821
Showing
6 changed files
with
375 additions
and
23 deletions.
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
63 changes: 63 additions & 0 deletions
63
tests/Feature/FormMigration/Controllers/TestMigrationController.php
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,63 @@ | ||
<?php | ||
|
||
namespace Give\Tests\Feature\FormMigration\Controllers; | ||
|
||
use Give\FormMigration\Actions\GetMigratedFormId; | ||
use Give\FormMigration\Controllers\MigrationController; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; | ||
use WP_REST_Request; | ||
use WP_REST_Response; | ||
use WP_REST_Server; | ||
|
||
|
||
/** | ||
* @unreleased | ||
* | ||
* @covers \Give\FormMigration\Controllers\MigrationController | ||
*/ | ||
class TestMigrationController extends TestCase | ||
{ | ||
use RefreshDatabase, LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testShouldMigrateFormV2ToV3(): void | ||
{ | ||
$formV2 = $this->createSimpleDonationForm(); | ||
|
||
$request = $this->getMockRequest(WP_REST_Server::CREATABLE); | ||
|
||
$controller = new MigrationController($request); | ||
|
||
$response = $controller($formV2); | ||
|
||
$formV3Id = (int)(new GetMigratedFormId)($formV2->id); | ||
|
||
$this->assertInstanceOf(WP_REST_Response::class, $response); | ||
|
||
$this->assertSame($response->data, [ | ||
'v2FormId' => $formV2->id, | ||
'v3FormId' => $formV3Id, | ||
'redirect' => add_query_arg([ | ||
'post_type' => 'give_forms', | ||
'page' => 'givewp-form-builder', | ||
'donationFormID' => $formV3Id, | ||
], admin_url('edit.php')) | ||
]); | ||
} | ||
|
||
/** | ||
* | ||
* @unreleased | ||
*/ | ||
public function getMockRequest(string $method): WP_REST_Request | ||
{ | ||
return new WP_REST_Request( | ||
$method, | ||
'/wp/v2/' . 'admin/forms/migrate/(?P<id>\d+)' | ||
); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace Give\Tests\Feature\FormMigration\Steps; | ||
|
||
use Give\FormMigration\DataTransferObjects\FormMigrationPayload; | ||
use Give\FormMigration\Steps\DonationGoal; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @covers \Give\FormMigration\Steps\DonationGoal | ||
*/ | ||
class TestDonationGoal extends TestCase | ||
{ | ||
use RefreshDatabase, LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateDonationFormDonationGoalSettings(): void | ||
{ | ||
$meta = [ | ||
'_give_goal_option' => 'enabled', | ||
'_give_goal_setting' => 'enabled', | ||
'_give_goal_format' => 'amount', | ||
'_give_set_goal' => 5000, | ||
'_give_close_form_when_goal_achieved' => 'enabled', | ||
'_give_form_goal_achieved_message' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), | ||
]; | ||
|
||
$formV2 = $this->createSimpleDonationForm(['meta' => $meta]); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$donationGoal = new DonationGoal($payload); | ||
|
||
$donationGoal->process(); | ||
|
||
$settings = $payload->formV3->settings; | ||
|
||
$this->assertTrue(true, $settings->enableDonationGoal); | ||
$this->assertTrue($settings->goalType->isAmount()); | ||
$this->assertSame((string)$meta['_give_set_goal'], $settings->goalAmount); | ||
$this->assertTrue(true, $settings->enableAutoClose); | ||
$this->assertSame($meta['_give_form_goal_achieved_message'], $settings->goalAchievedMessage); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace Give\Tests\Feature\FormMigration\Steps; | ||
|
||
use Give\FormMigration\DataTransferObjects\FormMigrationPayload; | ||
use Give\FormMigration\Steps\DonationOptions; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
use Give\Tests\Unit\DonationForms\TestTraits\LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @covers \Give\FormMigration\Steps\DonationOptions | ||
*/ | ||
class TestDonationOptions extends TestCase { | ||
use RefreshDatabase, LegacyDonationFormAdapter; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateDonationAmountBlockAttributes(): void | ||
{ | ||
$meta = [ | ||
'_give_price_option' => 'set', | ||
'_give_set_price' => '100', | ||
'_give_custom_amount' => 'enabled', | ||
'_give_custom_amount_range_minimum' => '1', | ||
'_give_custom_amount_range_maximum' => '1000', | ||
]; | ||
|
||
$formV2 = $this->createSimpleDonationForm(['meta' => $meta]); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$donationOptions = new DonationOptions($payload); | ||
|
||
$donationOptions->process(); | ||
|
||
$block = $payload->formV3->blocks->findByName('givewp/donation-amount'); | ||
|
||
$this->assertSame($meta['_give_price_option'], $block->getAttribute('priceOption')); | ||
$this->assertSame($meta['_give_set_price'], $block->getAttribute('setPrice')); | ||
$this->assertTrue($block->getAttribute('customAmount')); | ||
$this->assertSame((float)$meta['_give_custom_amount_range_minimum'], $block->getAttribute('customAmountMin')); | ||
$this->assertSame((float)$meta['_give_custom_amount_range_maximum'], $block->getAttribute('customAmountMax')); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonationLevels(): void | ||
{ | ||
$meta = [ | ||
'_give_custom_amount' => 'enabled', | ||
'_give_custom_amount_range_minimum' => '1', | ||
'_give_custom_amount_range_maximum' => '1000', | ||
]; | ||
|
||
$formV2 = $this->createMultiLevelDonationForm(['meta' => $meta]); | ||
|
||
$payload = FormMigrationPayload::fromFormV2($formV2); | ||
|
||
$donationOptions = new DonationOptions($payload); | ||
|
||
$donationOptions->process(); | ||
|
||
$block = $payload->formV3->blocks->findByName('givewp/donation-amount'); | ||
|
||
$this->assertSame([10.00, 25.00, 50.00, 100.00], $block->getAttribute('levels')); | ||
$this->assertTrue($block->getAttribute('customAmount')); | ||
$this->assertSame((float)$meta['_give_custom_amount_range_minimum'], $block->getAttribute('customAmountMin')); | ||
$this->assertSame((float)$meta['_give_custom_amount_range_maximum'], $block->getAttribute('customAmountMax')); | ||
} | ||
} |
Oops, something went wrong.