107 lines
2.2 KiB
PHP
107 lines
2.2 KiB
PHP
<?php
|
|
namespace MailPoet\Test\DataFactories;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class Newsletter {
|
|
|
|
/** @var array */
|
|
private $data;
|
|
|
|
/** @var array */
|
|
private $options;
|
|
|
|
public function __construct() {
|
|
$this->data = [
|
|
'subject' => 'Some subject',
|
|
'preheader' => 'Some preheader',
|
|
'type' => 'standard',
|
|
'status' => 'draft',
|
|
];
|
|
$this->options = [];
|
|
$this->loadBodyFrom('newsletterWithALC.json');
|
|
}
|
|
|
|
/**
|
|
* @return Newsletter
|
|
*/
|
|
public function loadBodyFrom($filename) {
|
|
$this->data['body'] = json_decode(file_get_contents(__DIR__ . '/../_data/' . $filename), true);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Newsletter
|
|
*/
|
|
public function withSubject($subject) {
|
|
$this->data['subject'] = $subject;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Newsletter
|
|
*/
|
|
public function withPostNotificationsType() {
|
|
$this->data['type'] = 'notification';
|
|
$this->withOptions([
|
|
8 => 'daily', # intervalType
|
|
9 => '0', # timeOfDay
|
|
10 => '1', # intervalType
|
|
11 => '0', # monthDay
|
|
12 => '1', # nthWeekDay
|
|
13 => '0 0 * * *', # schedule
|
|
]);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Newsletter
|
|
*/
|
|
public function withWelcomeType() {
|
|
$this->data['type'] = 'welcome';
|
|
$this->withOptions([
|
|
3 => 'segment', // event
|
|
4 => '2', // segment
|
|
5 => 'subscriber', // role
|
|
6 => '1', // afterTimeNumber
|
|
7 => 'immediate', // afterTimeType
|
|
]);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param array $options
|
|
*
|
|
* @return Newsletter
|
|
*/
|
|
private function withOptions(array $options) {
|
|
$this->options = $options;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Newsletter
|
|
*/
|
|
public function withDeleted() {
|
|
$this->data['deleted_at'] = Carbon::now();
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return \MailPoet\Models\Newsletter
|
|
*/
|
|
public function create() {
|
|
$newsletter = \MailPoet\Models\Newsletter::createOrUpdate($this->data);
|
|
foreach($this->options as $option_id => $option_value) {
|
|
\MailPoet\Models\NewsletterOption::createOrUpdate(
|
|
[
|
|
'newsletter_id' => $newsletter->id,
|
|
'option_field_id' => $option_id,
|
|
'value' => $option_value,
|
|
]
|
|
);
|
|
}
|
|
return $newsletter;
|
|
}
|
|
}
|