Create WC transactional email

[MAILPOET-2280]
This commit is contained in:
Amine Ben hammou
2019-09-17 03:05:01 +01:00
committed by Jack Kitterhing
parent 1dd8c7c1be
commit 5e5c744c3d
9 changed files with 925 additions and 6 deletions

View File

@ -31,6 +31,7 @@ use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Subscribers\Source;
use MailPoet\Subscription\Captcha;
use MailPoet\Util\Helpers;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions;
class Populator {
@ -50,12 +51,16 @@ class Populator {
/** @var FeaturesController */
private $flags_controller;
/** @var TransactionalEmails */
private $wc_transactional_emails;
function __construct(
SettingsController $settings,
WPFunctions $wp,
Captcha $captcha,
ReferralDetector $referralDetector,
FeaturesController $flags_controller
FeaturesController $flags_controller,
TransactionalEmails $wc_transactional_emails
) {
$this->settings = $settings;
$this->wp = $wp;
@ -143,6 +148,7 @@ class Populator {
'FarmersMarket',
];
$this->flags_controller = $flags_controller;
$this->wc_transactional_emails = $wc_transactional_emails;
}
function up() {
@ -169,6 +175,7 @@ class Populator {
$this->scheduleSubscriberLinkTokens();
$this->detectReferral();
$this->updateFormsSuccessMessages();
$this->initWooCommerceTransactionalEmails();
}
private function createMailPoetPage() {
@ -674,4 +681,11 @@ class Populator {
private function detectReferral() {
$this->referralDetector->detect();
}
private function initWooCommerceTransactionalEmails() {
$feature_enabled = $this->flags_controller->isSupported(FeaturesController::WC_TRANSACTIONAL_EMAILS_CUSTOMIZER);
if ($feature_enabled) {
$this->wc_transactional_emails->init();
}
}
}

View File

@ -193,6 +193,7 @@ class ContainerConfigurator implements IContainerConfigurator {
// WooCommerce
$container->autowire(\MailPoet\WooCommerce\Helper::class)->setPublic(true);
$container->autowire(\MailPoet\WooCommerce\Subscription::class)->setPublic(true);
$container->autowire(\MailPoet\WooCommerce\TransactionalEmails::class);
// WordPress
$container->autowire(\MailPoet\WP\Functions::class)->setPublic(true);
return $container;

View File

@ -0,0 +1,833 @@
<?php
namespace MailPoet\WooCommerce;
use MailPoet\Config\Env;
use MailPoet\Models\Newsletter;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
class TransactionalEmails {
const SETTING_EMAIL_ID = 'woocommerce.transactional_email_id';
/** @var WPFunctions */
private $wp;
/** @var SettingsController */
private $settings;
function __construct(WPFunctions $wp, SettingsController $settings) {
$this->wp = $wp;
$this->settings = $settings;
}
function init() {
$saved_email_id = (bool)$this->settings->get(self::SETTING_EMAIL_ID, false);
if (!$saved_email_id) {
$email = Newsletter::createOrUpdate([
'type' => Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL,
'subject' => 'WooCommerce Transactional Email',
'preheader' => '',
'body' => json_encode($this->getBody()),
]);
$this->settings->set(self::SETTING_EMAIL_ID, $email->id);
}
}
private function getBody() {
$social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons';
$wc_header_image = $this->wp->getOption('woocommerce_email_header_image', '');
return [
'content' =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => '#eeeeee',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'spacer',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
],
1 =>
[
'type' => 'image',
'link' => '',
'src' => $wc_header_image,
'alt' => 'mailpoet-logo',
'fullWidth' => false,
'width' => '160px',
'height' => '490px',
'styles' =>
[
'block' =>
[
'textAlign' => 'center',
],
],
],
2 =>
[
'type' => 'spacer',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
],
],
],
],
],
1 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'text',
'text' => '<p style="text-align: center;"><strong>WIDGET "WC HEADING" GOES HERE</strong></p>
<p style="text-align: center;"><strong>(instead of the column)</strong></p>',
],
],
],
],
],
2 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'spacer',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
],
],
],
],
],
3 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'text',
'text' => '<p style="text-align: center;"><strong>WIDGET "WC CONTENT" GOES HERE</strong></p>
<p style="text-align: center;"><strong>(instead of the column)</strong></p>',
],
],
],
],
],
4 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => '#ffffff',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'spacer',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
],
],
],
],
],
5 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'horizontal',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => '#eeeeee',
],
],
'blocks' =>
[
0 =>
[
'type' => 'container',
'columnLayout' => false,
'orientation' => 'vertical',
'image' =>
[
'src' => null,
'display' => 'scale',
],
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
],
'blocks' =>
[
0 =>
[
'type' => 'spacer',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
],
1 =>
[
'type' => 'text',
'text' => '<p style="text-align: center;"><span style="color: #fe5301;">Footer text</span></p>',
],
],
],
],
],
],
],
'globalStyles' =>
[
'text' =>
[
'fontColor' => '#111111',
'fontFamily' => 'Arial',
'fontSize' => '16px',
'lineHeight' => '1.6',
],
'h1' =>
[
'fontColor' => '#333333',
'fontFamily' => 'Source Sans Pro',
'fontSize' => '36px',
'lineHeight' => '1.6',
],
'h2' =>
[
'fontColor' => '#222222',
'fontFamily' => 'Verdana',
'fontSize' => '24px',
'lineHeight' => '1.6',
],
'h3' =>
[
'fontColor' => '#333333',
'fontFamily' => 'Trebuchet MS',
'fontSize' => '22px',
'lineHeight' => '1.6',
],
'link' =>
[
'fontColor' => '#21759B',
'textDecoration' => 'underline',
],
'wrapper' =>
[
'backgroundColor' => '#ffffff',
],
'body' =>
[
'backgroundColor' => '#eeeeee',
],
],
'blockDefaults' =>
[
'automatedLatestContent' =>
[
'amount' => '5',
'withLayout' => false,
'contentType' => 'post',
'inclusionType' => 'include',
'displayType' => 'excerpt',
'titleFormat' => 'h1',
'titleAlignment' => 'left',
'titleIsLink' => false,
'imageFullWidth' => false,
'featuredImagePosition' => 'belowTitle',
'showAuthor' => 'no',
'authorPrecededBy' => 'Author:',
'showCategories' => 'no',
'categoriesPrecededBy' => 'Categories:',
'readMoreType' => 'button',
'readMoreText' => 'Read more',
'readMoreButton' =>
[
'text' => 'Read more',
'url' => '[postLink]',
'context' => 'automatedLatestContent.readMoreButton',
'styles' =>
[
'block' =>
[
'backgroundColor' => '#2ea1cd',
'borderColor' => '#0074a2',
'borderWidth' => '1px',
'borderRadius' => '5px',
'borderStyle' => 'solid',
'width' => '180px',
'lineHeight' => '40px',
'fontColor' => '#ffffff',
'fontFamily' => 'Verdana',
'fontSize' => '18px',
'fontWeight' => 'normal',
'textAlign' => 'center',
],
],
],
'sortBy' => 'newest',
'showDivider' => true,
'divider' =>
[
'context' => 'automatedLatestContent.divider',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'padding' => '13px',
'borderStyle' => 'solid',
'borderWidth' => '3px',
'borderColor' => '#aaaaaa',
],
],
],
'backgroundColor' => '#ffffff',
'backgroundColorAlternate' => '#eeeeee',
],
'automatedLatestContentLayout' =>
[
'amount' => '5',
'withLayout' => true,
'contentType' => 'post',
'inclusionType' => 'include',
'displayType' => 'excerpt',
'titleFormat' => 'h1',
'titleAlignment' => 'left',
'titleIsLink' => false,
'imageFullWidth' => false,
'featuredImagePosition' => 'alternate',
'showAuthor' => 'no',
'authorPrecededBy' => 'Author:',
'showCategories' => 'no',
'categoriesPrecededBy' => 'Categories:',
'readMoreType' => 'button',
'readMoreText' => 'Read more',
'readMoreButton' =>
[
'text' => 'Read more',
'url' => '[postLink]',
'context' => 'automatedLatestContentLayout.readMoreButton',
'styles' =>
[
'block' =>
[
'backgroundColor' => '#2ea1cd',
'borderColor' => '#0074a2',
'borderWidth' => '1px',
'borderRadius' => '5px',
'borderStyle' => 'solid',
'width' => '180px',
'lineHeight' => '40px',
'fontColor' => '#ffffff',
'fontFamily' => 'Verdana',
'fontSize' => '18px',
'fontWeight' => 'normal',
'textAlign' => 'center',
],
],
],
'sortBy' => 'newest',
'showDivider' => true,
'divider' =>
[
'context' => 'automatedLatestContentLayout.divider',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'padding' => '13px',
'borderStyle' => 'solid',
'borderWidth' => '3px',
'borderColor' => '#aaaaaa',
],
],
],
'backgroundColor' => '#ffffff',
'backgroundColorAlternate' => '#eeeeee',
],
'button' =>
[
'text' => 'Button',
'url' => '',
'styles' =>
[
'block' =>
[
'backgroundColor' => '#2ea1cd',
'borderColor' => '#0074a2',
'borderWidth' => '1px',
'borderRadius' => '5px',
'borderStyle' => 'solid',
'width' => '180px',
'lineHeight' => '40px',
'fontColor' => '#ffffff',
'fontFamily' => 'Verdana',
'fontSize' => '18px',
'fontWeight' => 'normal',
'textAlign' => 'center',
],
],
],
'divider' =>
[
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'padding' => '13px',
'borderStyle' => 'solid',
'borderWidth' => '3px',
'borderColor' => '#aaaaaa',
],
],
],
'footer' =>
[
'text' => '<p><a href="[link:subscription_unsubscribe_url]">Unsubscribe</a> | <a href="[link:subscription_manage_url]">Manage subscription</a><br />Add your postal address here!</p>',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
'text' =>
[
'fontColor' => '#222222',
'fontFamily' => 'Arial',
'fontSize' => '12px',
'textAlign' => 'center',
],
'link' =>
[
'fontColor' => '#6cb7d4',
'textDecoration' => 'none',
],
],
],
'posts' =>
[
'amount' => '10',
'withLayout' => true,
'contentType' => 'post',
'postStatus' => 'publish',
'inclusionType' => 'include',
'displayType' => 'excerpt',
'titleFormat' => 'h1',
'titleAlignment' => 'left',
'titleIsLink' => false,
'imageFullWidth' => false,
'featuredImagePosition' => 'alternate',
'showAuthor' => 'no',
'authorPrecededBy' => 'Author:',
'showCategories' => 'no',
'categoriesPrecededBy' => 'Categories:',
'readMoreType' => 'link',
'readMoreText' => 'Read more',
'readMoreButton' =>
[
'text' => 'Read more',
'url' => '[postLink]',
'context' => 'posts.readMoreButton',
'styles' =>
[
'block' =>
[
'backgroundColor' => '#2ea1cd',
'borderColor' => '#0074a2',
'borderWidth' => '1px',
'borderRadius' => '5px',
'borderStyle' => 'solid',
'width' => '180px',
'lineHeight' => '40px',
'fontColor' => '#ffffff',
'fontFamily' => 'Verdana',
'fontSize' => '18px',
'fontWeight' => 'normal',
'textAlign' => 'center',
],
],
],
'sortBy' => 'newest',
'showDivider' => true,
'divider' =>
[
'context' => 'posts.divider',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'padding' => '13px',
'borderStyle' => 'solid',
'borderWidth' => '3px',
'borderColor' => '#aaaaaa',
],
],
],
'backgroundColor' => '#ffffff',
'backgroundColorAlternate' => '#eeeeee',
],
'products' =>
[
'amount' => '10',
'withLayout' => true,
'contentType' => 'product',
'postStatus' => 'publish',
'inclusionType' => 'include',
'displayType' => 'excerpt',
'titleFormat' => 'h1',
'titleAlignment' => 'left',
'titleIsLink' => false,
'imageFullWidth' => false,
'featuredImagePosition' => 'alternate',
'pricePosition' => 'below',
'readMoreType' => 'link',
'readMoreText' => 'Buy now',
'readMoreButton' =>
[
'text' => 'Buy now',
'url' => '[postLink]',
'context' => 'posts.readMoreButton',
'styles' =>
[
'block' =>
[
'backgroundColor' => '#2ea1cd',
'borderColor' => '#0074a2',
'borderWidth' => '1px',
'borderRadius' => '5px',
'borderStyle' => 'solid',
'width' => '180px',
'lineHeight' => '40px',
'fontColor' => '#ffffff',
'fontFamily' => 'Verdana',
'fontSize' => '18px',
'fontWeight' => 'normal',
'textAlign' => 'center',
],
],
],
'sortBy' => 'newest',
'showDivider' => true,
'divider' =>
[
'context' => 'posts.divider',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'padding' => '13px',
'borderStyle' => 'solid',
'borderWidth' => '3px',
'borderColor' => '#aaaaaa',
],
],
],
'backgroundColor' => '#ffffff',
'backgroundColorAlternate' => '#eeeeee',
],
'social' =>
[
'iconSet' => 'default',
'styles' =>
[
'block' =>
[
'textAlign' => 'center',
],
],
'icons' =>
[
0 =>
[
'type' => 'socialIcon',
'iconType' => 'facebook',
'link' => 'http://www.facebook.com',
'image' => $social_icon_url . '/01-social/Facebook.png',
'height' => '32px',
'width' => '32px',
'text' => 'Facebook',
],
1 =>
[
'type' => 'socialIcon',
'iconType' => 'twitter',
'link' => 'http://www.twitter.com',
'image' => $social_icon_url . '/01-social/Twitter.png',
'height' => '32px',
'width' => '32px',
'text' => 'Twitter',
],
],
],
'spacer' =>
[
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
'height' => '20px',
],
],
'type' => 'spacer',
],
'header' =>
[
'text' => 'Display problems?&nbsp;<a href="[link:newsletter_view_in_browser_url]">Open this email in your web browser.</a>',
'styles' =>
[
'block' =>
[
'backgroundColor' => 'transparent',
],
'text' =>
[
'fontColor' => '#222222',
'fontFamily' => 'Arial',
'fontSize' => '12px',
'textAlign' => 'center',
],
'link' =>
[
'fontColor' => '#6cb7d4',
'textDecoration' => 'underline',
],
],
],
],
];
}
}

View File

@ -13,6 +13,7 @@ use Helper\WordPressHooks as WPHooksHelper;
use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Captcha;
use MailPoet\WooCommerce\TransactionalEmails;
class SetupTest extends \MailPoetTest {
function _before() {
@ -30,7 +31,8 @@ class SetupTest extends \MailPoetTest {
$settings = new SettingsController();
$referral_detector = new ReferralDetector($wp, $settings);
$populator = new Populator($settings, $wp, new Captcha(), $referral_detector, $features_controller);
$wc_transactional_emails = new TransactionalEmails($wp, $settings);
$populator = new Populator($settings, $wp, new Captcha(), $referral_detector, $features_controller, $wc_transactional_emails);
$router = new Setup($wp, new Activator($settings, $populator));
$response = $router->reset();
expect($response->status)->equals(APIResponse::STATUS_OK);

View File

@ -34,6 +34,7 @@ use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Captcha;
use MailPoet\Subscription\Url;
use MailPoet\Tasks\Sending as SendingTask;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions;
class SendingQueueTest extends \MailPoetTest {
@ -51,7 +52,8 @@ class SendingQueueTest extends \MailPoetTest {
$this->settings = new SettingsController();
$referral_detector = new ReferralDetector(WPFunctions::get(), $this->settings);
$features_controller = Stub::makeEmpty(FeaturesController::class);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller);
$wc_transactional_emails = new TransactionalEmails(WPFunctions::get(), $this->settings);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller, $wc_transactional_emails);
$populator->up();
$this->subscriber = Subscriber::create();
$this->subscriber->email = 'john@doe.com';

View File

@ -12,6 +12,7 @@ use MailPoet\Models\Subscriber;
use MailPoet\Referrals\ReferralDetector;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Captcha;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions;
class MailerTest extends \MailPoetTest {
@ -28,7 +29,8 @@ class MailerTest extends \MailPoetTest {
$this->settings = new SettingsController();
$referral_detector = new ReferralDetector(WPFunctions::get(), $this->settings);
$features_controller = Stub::makeEmpty(FeaturesController::class);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller);
$wc_transactional_emails = new TransactionalEmails(WPFunctions::get(), $this->settings);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller, $wc_transactional_emails);
$populator->up();
$this->mailer_task = new MailerTask();
$this->sender = $this->settings->get('sender');

View File

@ -15,6 +15,7 @@ use MailPoet\Referrals\ReferralDetector;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Captcha;
use MailPoet\Subscription\Url as SubscriptionUrl;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions;
require_once(ABSPATH . 'wp-admin/includes/user.php');
@ -31,7 +32,8 @@ class ShortcodesTest extends \MailPoetTest {
$this->settings = new SettingsController();
$referral_detector = new ReferralDetector(WPFunctions::get(), $this->settings);
$features_controller = Stub::makeEmpty(FeaturesController::class);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller);
$wc_transactional_emails = new TransactionalEmails(WPFunctions::get(), $this->settings);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller, $wc_transactional_emails);
$populator->up();
$this->WP_user = $this->_createWPUser();
$this->WP_post = $this->_createWPPost();

View File

@ -11,6 +11,7 @@ use MailPoet\Models\Setting;
use MailPoet\Config\Populator;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Captcha;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions;
class UrlTest extends \MailPoetTest {
@ -19,7 +20,8 @@ class UrlTest extends \MailPoetTest {
$this->settings = new SettingsController;
$referral_detector = new ReferralDetector(WPFunctions::get(), $this->settings);
$features_controller = Stub::makeEmpty(FeaturesController::class);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller);
$wc_transactional_emails = new TransactionalEmails(WPFunctions::get(), $this->settings);
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller, $wc_transactional_emails);
$populator->up();
}

View File

@ -0,0 +1,61 @@
<?php
namespace MailPoet\WooCommerce;
use Codeception\Stub;
use MailPoet\Models\Newsletter;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
class TransactionalEmailsTest extends \MailPoetTest {
/** @var WPFunctions */
private $wp;
/** @var SettingsController */
private $settings;
/** @var array */
private $original_wc_settings;
/** @var TransactionalEmails */
private $transactional_emails;
function _before() {
$this->wp = new WPFunctions();
$this->settings = new SettingsController();
$this->original_wc_settings = $this->settings->get('woocommerce');
$this->transactional_emails = new TransactionalEmails($this->wp, $this->settings);
}
function testInitCreatesTransactionalEmailAndSavesItsId() {
$this->transactional_emails->init();
$email = Newsletter::where('type', Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL)->findOne();
$id = $this->settings->get(TransactionalEmails::SETTING_EMAIL_ID, null);
expect($email)->notEmpty();
expect($id)->notNull();
expect($email->id)->equals($id);
}
function testInitDoesntCreateTransactionalEmailIfSettingAlreadySet() {
$this->settings->set(TransactionalEmails::SETTING_EMAIL_ID, 1);
$this->transactional_emails->init();
$email = Newsletter::where('type', Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL)->findOne();
expect($email)->equals(null);
}
function testInitUsesImageFromWCSettings() {
$wp = Stub::make(new WPFunctions, ['getOption' => function($name) {
expect($name)->equals('woocommerce_email_header_image');
return 'my-awesome-image-url';
}]);
$transactional_emails = new TransactionalEmails($wp, $this->settings);
$transactional_emails->init();
$email = Newsletter::where('type', Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL)->findOne();
expect($email)->notEmpty();
expect($email->body)->contains('my-awesome-image-url');
}
function _after() {
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
$this->settings->set('woocommerce', $this->original_wc_settings);
}
}