Move Send_Preview_Email class to Engine folder and update tests

MAILPOET-6092
This commit is contained in:
Oluwaseun Olorunsola
2024-11-15 16:01:20 +01:00
committed by Rostislav Wolný
parent 33031f3fbd
commit 58f1af7920
7 changed files with 73 additions and 21 deletions

View File

@ -343,6 +343,7 @@ class ContainerConfigurator implements IContainerConfigurator {
$container->autowire(\MailPoet\EmailEditor\Engine\Email_Api_Controller::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Settings_Controller::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Theme_Controller::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Send_Preview_Email::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Highlighting_Postprocessor::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Variables_Postprocessor::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Blocks_Width_Preprocessor::class)->setPublic(true);
@ -350,7 +351,6 @@ class ContainerConfigurator implements IContainerConfigurator {
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Spacing_Preprocessor::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Typography_Preprocessor::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\Renderer::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Integrations\Utils\Send_Preview_Email::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Templates\Templates::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Templates\Utils::class)->setPublic(true);
$container->autowire(\MailPoet\EmailEditor\Engine\Templates\Template_Preview::class)->setPublic(true);

View File

@ -25,17 +25,18 @@ Please use with caution.
### Actions
| Name | Argument | Description |
| -------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------- |
|----------------------------------------|------------------|----------------------------------------------------------------------------------------------------|
| `mailpoet_email_editor_initialized` | `null` | Called when the Email Editor is initialized |
| `mailpoet_blocks_renderer_initialized` | `BlocksRegistry` | Called when the block content renderer is initialized. You may use this to add a new BlockRenderer |
### Filters
| Name | Argument | Return | Description |
| ---------------------------------------- | ----------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|--------------------------------------------|-------------------------------------------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mailpoet_email_editor_post_types` | `Array` $postTypes | `Array` EmailPostType | Applied to the list of post types used by the `getPostTypes` method |
| `mailpoet_email_editor_theme_json` | `WP_Theme_JSON` $coreThemeData | `WP_Theme_JSON` $themeJson | Applied to the theme json data. This theme json data is created from the merging of the `WP_Theme_JSON_Resolver::get_core_data` and MailPoet owns `theme.json` file |
| `mailpoet_email_renderer_styles` | `string` $templateStyles, `WP_Post` $post | `string` $templateStyles | Applied to the email editor template styles. |
| `mailpoet_blocks_renderer_parsed_blocks` | `WP_Block_Parser_Block[]` $output | `WP_Block_Parser_Block[]` $output | Applied to the result of parsed blocks created by the BlocksParser. |
| `mailpoet_email_content_renderer_styles` | `string` $contentStyles, `WP_Post` $post | `string` $contentStyles | Applied to the inline content styles prior to use by the CSS Inliner. |
| `mailpoet_is_email_editor_page` | `boolean` $isEditorPage | `boolean` | Check current page is the email editor page |
| `mailpoet_email_editor_send_preview_email` | `Array` $postData | `boolean` Result of processing. Was email sent successfully? | Allows override of the send preview mail function. Folks may choose to use custom implementation |

View File

@ -45,6 +45,14 @@ class Email_Api_Controller {
* @return WP_REST_Response
*/
public function send_preview_email_data( WP_REST_Request $request ): WP_REST_Response {
/**
* $data - Post Data
* format
* [_locale] => user
* [newsletterId] => NEWSLETTER_ID
* [email] => Provided email address
* [postId] => POST_ID
*/
$data = $request->get_params();
try {
$result = apply_filters( 'mailpoet_email_editor_send_preview_email', $data );

View File

@ -11,7 +11,6 @@ namespace MailPoet\EmailEditor\Engine;
use MailPoet\EmailEditor\Engine\Patterns\Patterns;
use MailPoet\EmailEditor\Engine\Templates\Template_Preview;
use MailPoet\EmailEditor\Engine\Templates\Templates;
use MailPoet\EmailEditor\Integrations\Utils\Send_Preview_Email;
use WP_Post;
use WP_Theme_JSON;

View File

@ -7,7 +7,7 @@
declare( strict_types = 1 );
namespace MailPoet\EmailEditor\Integrations\Utils;
namespace MailPoet\EmailEditor\Engine;
use MailPoet\EmailEditor\Engine\Renderer\Renderer;

View File

@ -6,9 +6,11 @@
*/
declare(strict_types = 1);
namespace MailPoet\EmailEditor\Integrations\Utils;
namespace MailPoet\EmailEditor\Engine;
use Codeception\Stub\Expected;
use MailPoet\EmailEditor\Engine\Renderer\Renderer;
use MailPoet\WP\Functions as WPFunctions;
/**
* Unit test for Send_Preview_Email_Test class.
@ -22,14 +24,21 @@ class Send_Preview_Email_Test extends \MailPoetTest {
*/
private $send_preview_email;
/**
* Instance of Renderer
*
* @var Renderer
*/
private $renderer_mock;
/**
* Set up before each test
*/
public function _before() {
parent::_before();
$renderer_mock = $this->createMock( Renderer::class );
$renderer_mock->method( 'render' )->willReturn(
$this->renderer_mock = $this->createMock( Renderer::class );
$this->renderer_mock->method( 'render' )->willReturn(
array(
'html' => 'test html',
'text' => 'test text',
@ -39,7 +48,7 @@ class Send_Preview_Email_Test extends \MailPoetTest {
$this->send_preview_email = $this->getServiceWithOverrides(
Send_Preview_Email::class,
array(
'renderer' => $renderer_mock,
'renderer' => $this->renderer_mock,
)
);
}
@ -48,9 +57,13 @@ class Send_Preview_Email_Test extends \MailPoetTest {
* Test it sends preview email.
*/
public function testItSendsPreviewEmail(): void {
$this->send_preview_email->send_email = function () {
return true;
};
$spe = $this->make(
Send_Preview_Email::class,
array(
'renderer' => $this->renderer_mock,
'send_email' => Expected::once( true ),
)
);
$email_post = $this->tester->create_post(
array(
@ -64,11 +77,42 @@ class Send_Preview_Email_Test extends \MailPoetTest {
'postId' => $email_post->ID,
);
$result = $this->send_preview_email->send_preview_email( $post_data );
$result = $spe->send_preview_email( $post_data );
verify( $result )->equals( true );
}
/**
* Test it returns the status of send_mail.
*/
public function testItReturnsTheStatusOfSendMail(): void {
$mailing_status = false;
$spe = $this->make(
Send_Preview_Email::class,
array(
'renderer' => $this->renderer_mock,
'send_email' => Expected::once( $mailing_status ),
)
);
$email_post = $this->tester->create_post(
array(
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
)
);
$post_data = array(
'newsletterId' => 2,
'email' => 'hello@example.com',
'postId' => $email_post->ID,
);
$result = $spe->send_preview_email( $post_data );
verify( $result )->equals( $mailing_status );
}
/**
* Test it throws an exception with invalid email
*/

View File

@ -29,7 +29,7 @@ use MailPoet\EmailEditor\Engine\Templates\Utils;
use MailPoet\EmailEditor\Engine\Theme_Controller;
use MailPoet\EmailEditor\Integrations\Core\Initializer;
use MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController;
use MailPoet\EmailEditor\Integrations\Utils\Send_Preview_Email;
use MailPoet\EmailEditor\Engine\Send_Preview_Email;
use MailPoet\EmailEditor\Utils\Cdn_Asset_Url;
if ( (bool) getenv( 'MULTISITE' ) === true ) {