Fix a bug in ManageSubscriptionFormRendererTest

The test class ManageSubscriptionFormRendererTest creates a subscriber
with a segment. But when calling $this->formRenderer->renderForm(), it
was passing the subscriber without information about its segments. This
meant that the output returned by renderForm() wrongly had the list of
segments without the subscriber segment checked.

This commit fixes this problem by passing the subscriber with the
segments to renderForm() and changing the expected HTML that should be
returned.

[MAILPOET-4020]
This commit is contained in:
Rodrigo Primo
2022-03-24 10:58:13 -03:00
committed by Veljko V
parent bb47db85b8
commit ee4df28cc3

View File

@@ -20,12 +20,12 @@ class ManageSubscriptionFormRendererTest extends \MailPoetTest {
public function testItGeneratesForm() {
$subscriber = $this->getSubscriber($this->getSegment());
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId()));
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId())->withSubscriptions());
expect($form)->regExp('/<form class="mailpoet-manage-subscription" method="post" action="[a-z0-9:\/\._]+wp-admin\/admin-post.php" novalidate>/');
expect($form)->stringContainsString('<input type="hidden" name="data[email]" value="subscriber@test.com" />');
expect($form)->regExp('/<input type="text" class="mailpoet_text" name="data\[[a-zA-Z0-9=_]+\]" title="First name" value="Fname" data-automation-id="form_first_name" data-parsley-names=\'\[&quot;Please specify a valid name.&quot;,&quot;Addresses in names are not permitted, please add your name instead\.&quot;\]\'\/>/');
expect($form)->regExp('/<input type="text" class="mailpoet_text" name="data\[[a-zA-Z0-9=_]+\]" title="Last name" value="Lname" data-automation-id="form_last_name" data-parsley-names=\'\[&quot;Please specify a valid name.&quot;,&quot;Addresses in names are not permitted, please add your name instead\.&quot;\]\'\/>/');
expect($form)->regExp('/<input type="checkbox" class="mailpoet_checkbox" name="data\[[a-zA-Z0-9=_]+\]\[\]" value="1" data-parsley-required="true" data-parsley-group="segments" data-parsley-errors-container="\.mailpoet_error_segments" data-parsley-required-message="Please select a list." \/> Test segment/');
expect($form)->regExp('/<input type="checkbox" class="mailpoet_checkbox" name="data\[[a-zA-Z0-9=_]+\]\[\]" value="1" checked="checked" data-parsley-required="true" data-parsley-group="segments" data-parsley-errors-container="\.mailpoet_error_segments" data-parsley-required-message="Please select a list." \/> Test segment/');
expect($form)->stringContainsString('Need to change your email address? Unsubscribe using the form below, then simply sign up again.');
}
@@ -43,7 +43,7 @@ class ManageSubscriptionFormRendererTest extends \MailPoetTest {
];
return $fields;
});
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId()));
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId())->withSubscriptions());
expect($form)->regExp('/<input type="text" class="mailpoet_text" name="data\[[a-zA-Z0-9=_]+\]" title="Additional info" value="" \/>/');
}