@@ -153,7 +153,7 @@ class Export {
|
|||||||
}
|
}
|
||||||
if($this->exportConfirmedOption) {
|
if($this->exportConfirmedOption) {
|
||||||
$subscribers =
|
$subscribers =
|
||||||
$subscribers->where(Subscriber::$_table . '.status', 'confirmed');
|
$subscribers->where(Subscriber::$_table . '.status', 'subscribed');
|
||||||
}
|
}
|
||||||
return $subscribers->findArray();
|
return $subscribers->findArray();
|
||||||
}
|
}
|
||||||
|
@@ -9,19 +9,27 @@ use MailPoet\Models\SubscriberSegment;
|
|||||||
use MailPoet\Subscribers\ImportExport\Export\Export;
|
use MailPoet\Subscribers\ImportExport\Export\Export;
|
||||||
|
|
||||||
class ExportCest {
|
class ExportCest {
|
||||||
function __construct() {
|
function _before() {
|
||||||
$this->JSONdata = json_decode(file_get_contents(dirname(__FILE__) . '/ExportTestData.json'), true);
|
$this->JSONdata = json_decode(file_get_contents(dirname(__FILE__) . '/ExportTestData.json'), true);
|
||||||
|
$this->subscriberFields = array(
|
||||||
|
'first_name' => 'First name',
|
||||||
|
'last_name' => 'Last name',
|
||||||
|
'email' => 'Email',
|
||||||
|
1 => 'Country'
|
||||||
|
);
|
||||||
|
|
||||||
$this->subscribersData = array(
|
$this->subscribersData = array(
|
||||||
array(
|
array(
|
||||||
'first_name' => 'Adam',
|
'first_name' => 'Adam',
|
||||||
'last_name' => 'Smith',
|
'last_name' => 'Smith',
|
||||||
'email' => 'adam@smith.com',
|
'email' => 'adam@smith.com'
|
||||||
1 => 'Brazil'
|
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'first_name' => 'Mary',
|
'first_name' => 'Mary',
|
||||||
'last_name' => 'Jane',
|
'last_name' => 'Jane',
|
||||||
'email' => 'mary@jane.com'
|
'email' => 'mary@jane.com',
|
||||||
|
'status' => 'subscribed',
|
||||||
|
1 => 'Brazil'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'first_name' => 'John',
|
'first_name' => 'John',
|
||||||
@@ -49,6 +57,9 @@ class ExportCest {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
foreach ($this->subscribersData as $subscriber) {
|
foreach ($this->subscribersData as $subscriber) {
|
||||||
|
if(isset($subscriber[1])) {
|
||||||
|
unset($subscriber[1]);
|
||||||
|
}
|
||||||
$entity = Subscriber::create();
|
$entity = Subscriber::create();
|
||||||
$entity->hydrate($subscriber);
|
$entity->hydrate($subscriber);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
@@ -63,26 +74,42 @@ class ExportCest {
|
|||||||
$entity->hydrate($customField);
|
$entity->hydrate($customField);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
|
$entity = SubscriberCustomField::create();
|
||||||
|
$entity->subscriber_id = 2;
|
||||||
|
$entity->custom_field_id = 1;
|
||||||
|
$entity->value = $this->subscribersData[1][1];
|
||||||
|
$entity->save();
|
||||||
|
$entity = SubscriberSegment::create();
|
||||||
|
$entity->subscriber_id = 1;
|
||||||
|
$entity->segment_id = 1;
|
||||||
|
$entity->save();
|
||||||
|
$entity = SubscriberSegment::create();
|
||||||
|
$entity->subscriber_id = 1;
|
||||||
|
$entity->segment_id = 2;
|
||||||
|
$entity->save();
|
||||||
|
$entity = SubscriberSegment::create();
|
||||||
|
$entity->subscriber_id = 2;
|
||||||
|
$entity->segment_id = 1;
|
||||||
|
$entity->save();
|
||||||
|
$entity = SubscriberSegment::create();
|
||||||
|
$entity->subscriber_id = 3;
|
||||||
|
$entity->segment_id = 2;
|
||||||
|
$entity->save();
|
||||||
$this->export = new Export($this->JSONdata);
|
$this->export = new Export($this->JSONdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function _before() {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
function itCanConstruct() {
|
function itCanConstruct() {
|
||||||
expect($this->export->exportConfirmedOption)
|
expect($this->export->exportConfirmedOption)
|
||||||
->equals(false);
|
->equals(false);
|
||||||
expect($this->export->exportFormatOption)
|
expect($this->export->exportFormatOption)
|
||||||
->equals('csv');
|
->equals('csv');
|
||||||
expect($this->export->groupBySegmentOption)
|
expect($this->export->groupBySegmentOption)
|
||||||
->equals(true);
|
->equals(false);
|
||||||
expect($this->export->segments)
|
expect($this->export->segments)
|
||||||
->equals(
|
->equals(
|
||||||
array(
|
array(
|
||||||
0,
|
1,
|
||||||
1
|
2
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
expect($this->export->subscribersWithoutSegment)
|
expect($this->export->subscribersWithoutSegment)
|
||||||
@@ -113,41 +140,98 @@ class ExportCest {
|
|||||||
)->equals(1);
|
)->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanGetSubscribers() {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function itCanGetSubscriberCustomFields() {
|
function itCanGetSubscriberCustomFields() {
|
||||||
$customFields = $this->export->getSubscriberCustomFields();
|
$source = CustomField::where('name', $this->customFieldsData[0]['name'])
|
||||||
expect($customFields)->equals(
|
->findOne();
|
||||||
array(
|
$target = $this->export->getSubscriberCustomFields();
|
||||||
1 => $this->customFieldsData[0]['name']
|
expect($target)->equals(array($source->id => $source->name));
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanFormatSubscriberFields() {
|
function itCanFormatSubscriberFields() {
|
||||||
$formattedSubscriberFields = $this->export->formatSubscriberFields(
|
$formattedSubscriberFields = $this->export->formatSubscriberFields(
|
||||||
$this->subscriberFields,
|
array_keys($this->subscriberFields),
|
||||||
$this->export->getSubscriberCustomFields()
|
$this->export->getSubscriberCustomFields()
|
||||||
);
|
);
|
||||||
|
expect($formattedSubscriberFields)
|
||||||
|
->equals(array_values($this->subscriberFields));
|
||||||
|
}
|
||||||
|
|
||||||
!d($formattedSubscriberFields);exit;
|
function itProperlyReturnsSubscriberCustomFields() {
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
foreach ($subscribers as $subscriber) {
|
||||||
|
if($subscriber['email'] === $this->subscribersData[1]) {
|
||||||
|
expect($subscriber['Country'])
|
||||||
|
->equals($this->subscribersData[1][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSubscribers() {
|
||||||
|
$this->export->segments = array(1);
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(2);
|
||||||
|
$this->export->segments = array(2);
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(2);
|
||||||
|
$this->export->segments = array(
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGroupSubscribersBySegments() {
|
||||||
|
$this->export->groupBySegmentOption = true;
|
||||||
|
$this->export->subscribersWithoutSegment = true;
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSubscribersOnlyWithoutSegments() {
|
||||||
|
$this->export->segments = array(0);
|
||||||
|
$this->export->subscribersWithoutSegment = true;
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(1);
|
||||||
|
expect($subscribers[0]['segment_name'])->equals('Not In List');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetOnlyConfirmedSubscribers() {
|
||||||
|
$this->export->exportConfirmedOption = true;
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(1);
|
||||||
|
expect($subscribers[0]['email'])
|
||||||
|
->equals($this->subscribersData[1]['email']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetSubscribersOnlyInSegments() {
|
||||||
|
SubscriberSegment::where('subscriber_id', 3)
|
||||||
|
->findOne()
|
||||||
|
->delete();
|
||||||
|
$subscribers = $this->export->getSubscribers();
|
||||||
|
expect(count($subscribers))->equals(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function itCanProcess() {
|
function itCanProcess() {
|
||||||
|
$this->export->exportFile = $this->export->getExportFile('csv');
|
||||||
|
$this->export->exportFormatOption = 'csv';
|
||||||
|
$this->export->process();
|
||||||
|
$CSVFileSize = filesize($this->export->exportFile);
|
||||||
|
$this->export->exportFile = $this->export->getExportFile('xls');
|
||||||
|
$this->export->exportFormatOption = 'xls';
|
||||||
|
$this->export->process();
|
||||||
|
$XLSFileSize = filesize($this->export->exportFile);
|
||||||
|
expect($CSVFileSize)->greaterThan(0);
|
||||||
|
expect($XLSFileSize)->greaterThan(0);
|
||||||
|
expect($XLSFileSize)->greaterThan($CSVFileSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
ORM::forTable(Subscriber::$_table)
|
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||||
->deleteMany();
|
ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
||||||
ORM::forTable(SubscriberCustomField::$_table)
|
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table);
|
||||||
->deleteMany();
|
ORM::raw_execute('TRUNCATE ' . CustomField::$_table);
|
||||||
ORM::forTable(SubscriberSegment::$_table)
|
ORM::raw_execute('TRUNCATE ' . SubscriberCustomField::$_table);
|
||||||
->deleteMany();
|
|
||||||
ORM::forTable(Segment::$_table)
|
|
||||||
->deleteMany();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"exportConfirmedOption": false,
|
"exportConfirmedOption": false,
|
||||||
"exportFormatOption": "csv",
|
"exportFormatOption": "csv",
|
||||||
"groupBySegmentOption": true,
|
"groupBySegmentOption": false,
|
||||||
"segments": [
|
"segments": [
|
||||||
"0",
|
"1",
|
||||||
"1"
|
"2"
|
||||||
],
|
],
|
||||||
"subscriberFields": [
|
"subscriberFields": [
|
||||||
"email",
|
"email",
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MailPoet\Subscribers\ImportExport\Import\Import;
|
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberCustomField;
|
use MailPoet\Models\SubscriberCustomField;
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
|
use MailPoet\Subscribers\ImportExport\Import\Import;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
class ImportCest {
|
class ImportCest {
|
||||||
@@ -108,38 +108,39 @@ class ImportCest {
|
|||||||
function itCanFilterSubscriberState() {
|
function itCanFilterSubscriberState() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'status' => array(
|
'status' => array(
|
||||||
'confirmed',
|
//subscribed
|
||||||
'subscribed',
|
|
||||||
'subscribed',
|
'subscribed',
|
||||||
'confirmed',
|
'confirmed',
|
||||||
1,
|
1,
|
||||||
'1',
|
'1',
|
||||||
'true',
|
'true',
|
||||||
|
//unconfirmed
|
||||||
|
'unconfirmed',
|
||||||
|
0,
|
||||||
|
"0",
|
||||||
|
//unsubscribed
|
||||||
'unsubscribed',
|
'unsubscribed',
|
||||||
-1,
|
-1,
|
||||||
'-1',
|
'-1',
|
||||||
'false',
|
'false'
|
||||||
'something',
|
|
||||||
'else'
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$statuses = $this->import->filterSubscriberStatus($data);
|
$statuses = $this->import->filterSubscriberStatus($data);
|
||||||
expect($statuses)->equals(
|
expect($statuses)->equals(
|
||||||
array(
|
array(
|
||||||
'status' => array(
|
'status' => array(
|
||||||
'confirmed',
|
'subscribed',
|
||||||
'confirmed',
|
'subscribed',
|
||||||
'confirmed',
|
'subscribed',
|
||||||
'confirmed',
|
'subscribed',
|
||||||
'confirmed',
|
'subscribed',
|
||||||
'confirmed',
|
'unconfirmed',
|
||||||
'confirmed',
|
'unconfirmed',
|
||||||
|
'unconfirmed',
|
||||||
'unsubscribed',
|
'unsubscribed',
|
||||||
'unsubscribed',
|
'unsubscribed',
|
||||||
'unsubscribed',
|
'unsubscribed',
|
||||||
'unsubscribed',
|
'unsubscribed'
|
||||||
'confirmed',
|
|
||||||
'confirmed'
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user