Remove last usages of Subscriber model from the Pages class
[MAILPOET-4020]
This commit is contained in:
@@ -65,7 +65,23 @@ class ManageSubscriptionFormRenderer {
|
||||
$this->subscribersRepository = $subscribersRepository;
|
||||
}
|
||||
|
||||
public function renderForm(Subscriber $subscriber, string $formState = self::FORM_STATE_NOT_SUBMITTED): string {
|
||||
public function renderForm(SubscriberEntity $subscriberEntity, string $formState = self::FORM_STATE_NOT_SUBMITTED): string {
|
||||
// Once the old Subscriber model is removed from this class, the if below can be removed as well and $subscriberEntity
|
||||
// can be used directly (probably worth renaming it to $subscriber). For now this if is needed, as when previewing the
|
||||
// manage subscription page, a demo object is created in Pages::getManageContent() that is not persisted to the database
|
||||
// so $subscriberEntity->getId() is null and thus it is not possible to use Subscriber::findOne() to get the old model.
|
||||
if ($subscriberEntity->getId()) {
|
||||
$subscriber = Subscriber::findOne($subscriberEntity->getId())->withSubscriptions()->withCustomFields();
|
||||
} else {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate([
|
||||
'email' => $subscriberEntity->getEmail(),
|
||||
'first_name' => $subscriberEntity->getFirstName(),
|
||||
'last_name' => $subscriberEntity->getLastName(),
|
||||
'link_token' => $subscriberEntity->getLinkToken(),
|
||||
]);
|
||||
}
|
||||
|
||||
$basicFields = $this->getBasicFields($subscriber);
|
||||
$customFields = $this->getCustomFields($subscriber);
|
||||
$segmentField = $this->getSegmentField($subscriber);
|
||||
|
@@ -8,7 +8,6 @@ use MailPoet\Entities\StatisticsUnsubscribeEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Features\FeaturesController;
|
||||
use MailPoet\Form\AssetsController;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Newsletter\Scheduler\WelcomeScheduler;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Settings\TrackingConfig;
|
||||
@@ -416,18 +415,13 @@ class Pages {
|
||||
|
||||
public function getManageContent() {
|
||||
if ($this->isPreview()) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate([
|
||||
'email' => self::DEMO_EMAIL,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'link_token' => 'bfd0889dbc7f081e171fa0cee7401df2',
|
||||
]);
|
||||
$subscriber = new SubscriberEntity();
|
||||
$subscriber->setEmail(self::DEMO_EMAIL);
|
||||
$subscriber->setFirstName('John');
|
||||
$subscriber->setLastName('Doe');
|
||||
$subscriber->setLinkToken('bfd0889dbc7f081e171fa0cee7401df2');
|
||||
} else if ($this->subscriber !== null) {
|
||||
$subscriberModel = Subscriber::findOne($this->subscriber->getId());
|
||||
$subscriber = $subscriberModel
|
||||
->withCustomFields()
|
||||
->withSubscriptions();
|
||||
$subscriber = $this->subscriber;
|
||||
} else {
|
||||
return $this->wp->__('Subscription management form is only available to mailing lists subscribers.', 'mailpoet');
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ use MailPoet\Entities\SegmentEntity;
|
||||
use MailPoet\Entities\SubscriberCustomFieldEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Entities\SubscriberSegmentEntity;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Test\DataFactories\CustomField as CustomFieldFactory;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
@@ -23,7 +22,7 @@ class ManageSubscriptionFormRendererTest extends \MailPoetTest {
|
||||
|
||||
public function testItGeneratesForm() {
|
||||
$subscriber = $this->getSubscriber($this->getSegment());
|
||||
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId())->withSubscriptions()->withCustomFields());
|
||||
$form = $this->formRenderer->renderForm($subscriber);
|
||||
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=\'\["Please specify a valid name.","Addresses in names are not permitted, please add your name instead\."\]\'\/>/');
|
||||
@@ -50,7 +49,7 @@ class ManageSubscriptionFormRendererTest extends \MailPoetTest {
|
||||
];
|
||||
return $fields;
|
||||
});
|
||||
$form = $this->formRenderer->renderForm(Subscriber::findOne($subscriber->getId())->withSubscriptions()->withCustomFields());
|
||||
$form = $this->formRenderer->renderForm($subscriber);
|
||||
expect($form)->regExp('/<input type="text" class="mailpoet_text" name="data\[[a-zA-Z0-9=_]+\]" title="Additional info" value="" \/>/');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user