newsletter = new NewsletterEntity(); $this->newslettersRepository = $this->diContainer->get(NewslettersRepository::class); $this->newsletter->setSubject('WooCommerce Transactional Email'); $this->newsletter->setType(NewsletterEntity::TYPE_WC_TRANSACTIONAL_EMAIL); $this->newsletter->setPreheader(''); $this->newsletter->setBody([ 'content' => L::col([ L::row([L::col([['type' => 'text', 'text' => 'Some text before heading']])]), ['type' => 'woocommerceHeading'], L::row([L::col([['type' => 'text', 'text' => 'Some text between heading and content']])]), ['type' => 'woocommerceContent'], L::row([L::col([['type' => 'text', 'text' => 'Some text after content']])]), ]), ]); } public function testGetHTMLBeforeContent() { $renderer = $this->getRenderer(); $renderer->render($this->newsletter, 'Heading Text'); $html = $renderer->getHTMLBeforeContent(); verify($html)->stringContainsString('Some text before heading'); verify($html)->stringContainsString('Heading Text'); verify($html)->stringContainsString('Some text between heading and content'); verify($html)->stringNotContainsString('Some text after content'); } public function testGetHTMLAfterContent() { $renderer = $this->getRenderer(); $renderer->render($this->newsletter, 'Heading Text'); $html = $renderer->getHTMLAfterContent(); verify($html)->stringNotContainsString('Some text before heading'); verify($html)->stringNotContainsString('Heading Text'); verify($html)->stringNotContainsString('Some text between heading and content'); verify($html)->stringContainsString('Some text after content'); } public function testRenderHeadingTextWhenHeadingBlockMovedToFooter() { $this->newsletter->setBody([ 'content' => L::col([ L::row([L::col([['type' => 'text', 'text' => 'Some text before heading']])]), L::row([L::col([['type' => 'text', 'text' => 'Some text between heading and content']])]), ['type' => 'woocommerceContent'], ['type' => 'woocommerceHeading'], L::row([L::col([['type' => 'text', 'text' => 'Some text after content']])]), ]), ]); $this->newslettersRepository->persist($this->newsletter); $renderer = $this->getRenderer(); $renderer->render($this->newsletter, 'Heading Text'); $html = $renderer->getHTMLAfterContent(); verify($html)->stringContainsString('Heading Text'); verify($html)->stringContainsString('Some text after content'); } public function testPrefixCss() { $renderer = $this->getRenderer(true); $css = $renderer->enhanceCss(' #some_id {color: black} .some-class {height: 50px; width: 30px} h1 { font-weight:bold; } ', $this->newsletter); verify($css)->stringContainsString("#mailpoet_woocommerce_container #some_id {\ncolor:black\n}"); verify($css)->stringContainsString("#mailpoet_woocommerce_container .some-class {\nheight:50px;\nwidth:30px\n}"); verify($css)->stringContainsString("#mailpoet_woocommerce_container h1 {\nfont-weight:700\n}"); } public function testItReplaceShortcodes() { $this->newsletter->setBody([ 'content' => L::col([ L::row([L::col([['type' => 'text', 'text' => 'Some text before heading']])]), L::row([L::col([['type' => 'text', 'text' => 'Some text between heading and content']])]), ['type' => 'woocommerceContent'], ['type' => 'woocommerceHeading'], L::row([L::col([['type' => 'text', 'text' => 'Some text after content']])]), L::row([L::col([ ['type' => 'text', 'text' => '[site:title]'], ['type' => 'text', 'text' => '[site:homepage_url]'], ['type' => 'text', 'text' => '[date:mtext]'], ['type' => 'text', 'text' => '[date:y]'], ])]), ]), ]); $this->newslettersRepository->persist($this->newsletter); $renderer = $this->getRenderer(); $renderer->render($this->newsletter, 'Heading Text'); $html = $renderer->getHTMLAfterContent(); /** @var string $blogName - for PHPStan */ $blogName = get_option('blogname'); $siteName = strval($blogName); verify($html)->stringContainsString($siteName); // [site:title] /** @var string $home - for PHPStan */ $home = get_option('home'); $siteUrl = strval($home); verify($html)->stringContainsString($siteUrl); // [site:homepage_url] verify($html)->stringContainsString(date_i18n('F', WPFunctions::get()->currentTime('timestamp'))); // [date:mtext] verify($html)->stringContainsString(date_i18n('Y', WPFunctions::get()->currentTime('timestamp'))); // [date:y] } public function testItDoesntChangeFontFamilyWhenNotSaveWithFlag() { $this->newsletter->setBody([ 'globalStyles' => [ 'woocommerce' => [ 'headingFontFamily' => 'Comic Sans MS', ], ], ]); $css = $this->getWooEmailStyles(); $updatedCss = $this->getRenderer(true)->enhanceCss($css, $this->newsletter); verify($updatedCss)->stringNotContainsString('Comic Sans MS'); } public function testItChangesCssForHeadings() { $this->newsletter->setBody([ 'globalStyles' => [ 'h1' => [ 'fontSize' => '1px', ], 'h2' => [ 'fontSize' => '2px', ], 'h3' => [ 'fontSize' => '3px', ], 'woocommerce' => [ 'headingFontFamily' => 'Comic Sans MS', 'contentHeadingFontColor' => '#aaaaaa', 'isSavedWithUpdatedStyles' => true, ], ], ]); $css = $this->getWooEmailStyles(); $updatedCss = $this->getRenderer(true)->enhanceCss($css, $this->newsletter); $h1Styles = $this->getCssDefinitionsForSelector('#mailpoet_woocommerce_container h1', $updatedCss); verify($h1Styles)->stringContainsString('font-family:Comic Sans MS'); verify($h1Styles)->stringContainsString('font-size:1px'); verify($h1Styles)->stringContainsString('color:#aaaaaa'); $h2Styles = $this->getCssDefinitionsForSelector('#mailpoet_woocommerce_container h2', $updatedCss); verify($h2Styles)->stringContainsString('font-family:Comic Sans MS'); verify($h2Styles)->stringContainsString('font-size:2px'); verify($h2Styles)->stringContainsString('color:#aaaaaa'); $h3Styles = $this->getCssDefinitionsForSelector('#mailpoet_woocommerce_container h3', $updatedCss); verify($h3Styles)->stringContainsString('font-family:Comic Sans MS'); verify($h3Styles)->stringContainsString('font-size:3px'); verify($h3Styles)->stringContainsString('color:#aaaaaa'); } public function testItChangesStylesForWooContent() { $this->newsletter->setBody([ 'globalStyles' => [ 'text' => [ 'fontFamily' => 'Comic Sans MS', 'fontSize' => '1px', ], 'woocommerce' => [ 'isSavedWithUpdatedStyles' => true, ], ], ]); $css = $this->getWooEmailStyles(); $updatedCss = $this->getRenderer(true)->enhanceCss($css, $this->newsletter); $contentStyles = $this->getCssDefinitionsForSelector('#mailpoet_woocommerce_container #body_content_inner', $updatedCss); verify($contentStyles)->stringContainsString('font-family:Comic Sans MS'); verify($contentStyles)->stringContainsString('font-size:1px'); } public function testItAddCSSForWooHeading() { $this->newsletter->setBody([ 'globalStyles' => [ 'woocommerce' => [ 'isSavedWithUpdatedStyles' => true, 'headingFontColor' => '#ff0000', ], ], ]); $css = $this->getWooEmailStyles(); $updatedCss = $this->getRenderer(true)->enhanceCss($css, $this->newsletter); $headerStyles = $this->getCssDefinitionsForSelector('#mailpoet-woo-email-header', $updatedCss); verify($headerStyles)->stringContainsString('color: #ff0000 !important'); } public function testItSetsProperColorForHeadingInHeader() { $this->newsletter->setBody([ 'globalStyles' => [ 'woocommerce' => [ 'isSavedWithUpdatedStyles' => true, 'headingFontColor' => '#ff0000', ], ], ]); $css = $this->getWooEmailStyles(); $updatedCss = $this->getRenderer(true)->enhanceCss($css, $this->newsletter); $headerStyles = $this->getCssDefinitionsForSelector('#mailpoet-woo-email-header', $updatedCss); verify($headerStyles)->stringContainsString('color: #ff0000 !important'); } public function testItUpdatesFontFamilyInsideWooContentAndRemovesSeparators() { $emailContent = '
Content
Content