Add tests to import for new properties
Fixes:#2968 [MAILPOET-2957]
This commit is contained in:
@@ -482,7 +482,6 @@ class SubscriberTest extends \MailPoetTest {
|
|||||||
expect($subscribers[1]['status'])->equals($values[1]['status']);
|
expect($subscribers[1]['status'])->equals($values[1]['status']);
|
||||||
|
|
||||||
$values[0]['first_name'] = 'John';
|
$values[0]['first_name'] = 'John';
|
||||||
$values[0]['status'] = 'subscribed';
|
|
||||||
Subscriber::updateMultiple($columns, $values);
|
Subscriber::updateMultiple($columns, $values);
|
||||||
$subscribers = Subscriber::findArray();
|
$subscribers = Subscriber::findArray();
|
||||||
expect($subscribers[0]['first_name'])->equals($values[0]['first_name']);
|
expect($subscribers[0]['first_name'])->equals($values[0]['first_name']);
|
||||||
|
@@ -52,6 +52,8 @@ class ImportTest extends \MailPoetTest {
|
|||||||
$this->segment1->id,
|
$this->segment1->id,
|
||||||
],
|
],
|
||||||
'timestamp' => time(),
|
'timestamp' => time(),
|
||||||
|
'newSubscribersStatus' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
|
'existingSubscribersStatus' => Import::STATUS_DONT_UPDATE,
|
||||||
'updateSubscribers' => true,
|
'updateSubscribers' => true,
|
||||||
];
|
];
|
||||||
$this->subscribersFields = [
|
$this->subscribersFields = [
|
||||||
@@ -139,6 +141,8 @@ class ImportTest extends \MailPoetTest {
|
|||||||
],
|
],
|
||||||
'segments' => [],
|
'segments' => [],
|
||||||
'timestamp' => time(),
|
'timestamp' => time(),
|
||||||
|
'newSubscribersStatus' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
|
'existingSubscribersStatus' => Import::STATUS_DONT_UPDATE,
|
||||||
'updateSubscribers' => true,
|
'updateSubscribers' => true,
|
||||||
];
|
];
|
||||||
$import = new Import($data);
|
$import = new Import($data);
|
||||||
@@ -211,6 +215,8 @@ class ImportTest extends \MailPoetTest {
|
|||||||
],
|
],
|
||||||
'segments' => [1],
|
'segments' => [1],
|
||||||
'timestamp' => time(),
|
'timestamp' => time(),
|
||||||
|
'newSubscribersStatus' => Subscriber::STATUS_SUBSCRIBED,
|
||||||
|
'existingSubscribersStatus' => Import::STATUS_DONT_UPDATE,
|
||||||
'updateSubscribers' => true,
|
'updateSubscribers' => true,
|
||||||
];
|
];
|
||||||
$import = new Import($data);
|
$import = new Import($data);
|
||||||
@@ -426,26 +432,6 @@ class ImportTest extends \MailPoetTest {
|
|||||||
expect($updatedSubscriber->status)->equals('unsubscribed');
|
expect($updatedSubscriber->status)->equals('unsubscribed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItDoesNotUpdateExistingSubscribersStatusWhenStatusColumnIsPresent() {
|
|
||||||
$data = $this->testData;
|
|
||||||
$data['columns']['status'] = ['index' => 4];
|
|
||||||
$data['subscribers'][0][] = 'subscribed';
|
|
||||||
$data['subscribers'][1][] = 'subscribed';
|
|
||||||
$import = new Import($data);
|
|
||||||
$existingSubscriber = Subscriber::create();
|
|
||||||
$existingSubscriber->hydrate(
|
|
||||||
[
|
|
||||||
'first_name' => 'Adam',
|
|
||||||
'last_name' => 'Smith',
|
|
||||||
'email' => 'Adam@Smith.com',
|
|
||||||
'status' => 'unsubscribed',
|
|
||||||
]);
|
|
||||||
$existingSubscriber->save();
|
|
||||||
$result = $import->process();
|
|
||||||
$updatedSubscriber = Subscriber::where('email', $existingSubscriber->email)->findOne();
|
|
||||||
expect($updatedSubscriber->status)->equals('unsubscribed');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testItImportsNewsSubscribersWithAllAdditionalParameters() {
|
public function testItImportsNewsSubscribersWithAllAdditionalParameters() {
|
||||||
$data = $this->testData;
|
$data = $this->testData;
|
||||||
$data['columns']['status'] = ['index' => 4];
|
$data['columns']['status'] = ['index' => 4];
|
||||||
@@ -490,6 +476,35 @@ class ImportTest extends \MailPoetTest {
|
|||||||
expect($updatedSubscriber->lastSubscribedAt)->equals('2017-12-12 12:12:00');
|
expect($updatedSubscriber->lastSubscribedAt)->equals('2017-12-12 12:12:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItDoesUpdateStatusExistingSubscriberWhenExistingSubscribersStatusIsSet() {
|
||||||
|
$data = $this->testData;
|
||||||
|
$data['existingSubscribersStatus'] = Subscriber::STATUS_SUBSCRIBED;
|
||||||
|
$existingSubscriber = Subscriber::create();
|
||||||
|
$existingSubscriber->hydrate(
|
||||||
|
[
|
||||||
|
'first_name' => 'Adam',
|
||||||
|
'last_name' => 'Smith',
|
||||||
|
'email' => 'Adam@Smith.com',
|
||||||
|
'status' => Subscriber::STATUS_UNSUBSCRIBED,
|
||||||
|
'last_subscribed_at' => '2020-08-08 08:08:00',
|
||||||
|
]);
|
||||||
|
$import = new Import($data);
|
||||||
|
$import->process();
|
||||||
|
$updatedSubscriber = Subscriber::where('email', $existingSubscriber->email)->findOne();
|
||||||
|
expect($updatedSubscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItDoesStatusNewSubscriberWhenNewSubscribersStatusIsSet() {
|
||||||
|
$data = $this->testData;
|
||||||
|
$data['newSubscribersStatus'] = Subscriber::STATUS_UNSUBSCRIBED;
|
||||||
|
$import = new Import($data);
|
||||||
|
$import->process();
|
||||||
|
$newSubscriber = Subscriber::where('email', 'Adam@Smith.com')->findOne();
|
||||||
|
expect($newSubscriber->status)->equals(Subscriber::STATUS_UNSUBSCRIBED);
|
||||||
|
$newSubscriber = Subscriber::where('email', 'mary@jane.com')->findOne();
|
||||||
|
expect($newSubscriber->status)->equals(Subscriber::STATUS_UNSUBSCRIBED);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItRunsImport() {
|
public function testItRunsImport() {
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['created'])->equals(2);
|
expect($result['created'])->equals(2);
|
||||||
|
Reference in New Issue
Block a user