diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index ac7819ece5..28c55cd6c3 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -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(); + } + } } diff --git a/lib/DI/ContainerConfigurator.php b/lib/DI/ContainerConfigurator.php index d5b701d70e..3e7789166e 100644 --- a/lib/DI/ContainerConfigurator.php +++ b/lib/DI/ContainerConfigurator.php @@ -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; diff --git a/lib/WooCommerce/TransactionalEmails.php b/lib/WooCommerce/TransactionalEmails.php new file mode 100644 index 0000000000..239120dbdf --- /dev/null +++ b/lib/WooCommerce/TransactionalEmails.php @@ -0,0 +1,833 @@ +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' => '

WIDGET "WC HEADING" GOES HERE

+

(instead of the column)

', + ], + ], + ], + ], + ], + 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' => '

WIDGET "WC CONTENT" GOES HERE

+

(instead of the column)

', + ], + ], + ], + ], + ], + 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' => '

Footer text

', + ], + ], + ], + ], + ], + ], + ], + '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' => '

Unsubscribe | Manage subscription
Add your postal address here!

', + '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? Open this email in your web browser.', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + 'text' => + [ + 'fontColor' => '#222222', + 'fontFamily' => 'Arial', + 'fontSize' => '12px', + 'textAlign' => 'center', + ], + 'link' => + [ + 'fontColor' => '#6cb7d4', + 'textDecoration' => 'underline', + ], + ], + ], + ], + ]; + } +} \ No newline at end of file diff --git a/tests/integration/API/JSON/v1/SetupTest.php b/tests/integration/API/JSON/v1/SetupTest.php index 83f496c0c0..033cfafe38 100644 --- a/tests/integration/API/JSON/v1/SetupTest.php +++ b/tests/integration/API/JSON/v1/SetupTest.php @@ -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); diff --git a/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php b/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php index 9fb8046e60..fa0cda6d41 100644 --- a/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php +++ b/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php @@ -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'; diff --git a/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php b/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php index 6badc97c24..5e775c042f 100644 --- a/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php +++ b/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php @@ -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'); diff --git a/tests/integration/Newsletter/ShortcodesTest.php b/tests/integration/Newsletter/ShortcodesTest.php index b4b2e0ad4f..21ea3b38b9 100644 --- a/tests/integration/Newsletter/ShortcodesTest.php +++ b/tests/integration/Newsletter/ShortcodesTest.php @@ -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(); diff --git a/tests/integration/Subscription/UrlTest.php b/tests/integration/Subscription/UrlTest.php index 146d67da7f..739444f73a 100644 --- a/tests/integration/Subscription/UrlTest.php +++ b/tests/integration/Subscription/UrlTest.php @@ -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(); } diff --git a/tests/integration/WooCommerce/TransactionalEmailsTest.php b/tests/integration/WooCommerce/TransactionalEmailsTest.php new file mode 100644 index 0000000000..a1ea4e46b1 --- /dev/null +++ b/tests/integration/WooCommerce/TransactionalEmailsTest.php @@ -0,0 +1,61 @@ +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); + } +}