Refactor ALC endpoint to follow DI
[MAILPOET-1637]
This commit is contained in:
@ -10,13 +10,14 @@ use MailPoet\WP\Posts as WPPosts;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class AutomatedLatestContent extends APIEndpoint {
|
class AutomatedLatestContent extends APIEndpoint {
|
||||||
|
/** @var \MailPoet\Newsletter\AutomatedLatestContent */
|
||||||
public $ALC;
|
public $ALC;
|
||||||
public $permissions = array(
|
public $permissions = array(
|
||||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
|
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
|
||||||
);
|
);
|
||||||
|
|
||||||
function __construct() {
|
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc) {
|
||||||
$this->ALC = new \MailPoet\Newsletter\AutomatedLatestContent();
|
$this->ALC = $alc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPostTypes() {
|
function getPostTypes() {
|
||||||
@ -74,14 +75,12 @@ class AutomatedLatestContent extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getBulkTransformedPosts($data = array()) {
|
function getBulkTransformedPosts($data = array()) {
|
||||||
$alc = new \MailPoet\Newsletter\AutomatedLatestContent();
|
|
||||||
|
|
||||||
$used_posts = array();
|
$used_posts = array();
|
||||||
$rendered_posts = array();
|
$rendered_posts = array();
|
||||||
|
|
||||||
foreach($data['blocks'] as $block) {
|
foreach($data['blocks'] as $block) {
|
||||||
$posts = $alc->getPosts($block, $used_posts);
|
$posts = $this->ALC->getPosts($block, $used_posts);
|
||||||
$rendered_posts[] = $alc->transformPosts($block, $posts);
|
$rendered_posts[] = $this->ALC->transformPosts($block, $posts);
|
||||||
|
|
||||||
foreach($posts as $post) {
|
foreach($posts as $post) {
|
||||||
$used_posts[] = $post->ID;
|
$used_posts[] = $post->ID;
|
||||||
|
@ -81,6 +81,8 @@ class ContainerFactory {
|
|||||||
$container->autowire(\MailPoet\Subscribers\NewSubscriberNotificationMailer::class)->setPublic(true);
|
$container->autowire(\MailPoet\Subscribers\NewSubscriberNotificationMailer::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Subscribers\ConfirmationEmailMailer::class)->setPublic(true);
|
$container->autowire(\MailPoet\Subscribers\ConfirmationEmailMailer::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Subscribers\RequiredCustomFieldValidator::class)->setPublic(true);
|
$container->autowire(\MailPoet\Subscribers\RequiredCustomFieldValidator::class)->setPublic(true);
|
||||||
|
// Newsletter
|
||||||
|
$container->autowire(\MailPoet\Newsletter\AutomatedLatestContent::class)->setPublic(true);
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ use MailPoet\API\JSON\v1\AutomatedLatestContent;
|
|||||||
|
|
||||||
class AutomatedLatestContentTest extends \MailPoetTest {
|
class AutomatedLatestContentTest extends \MailPoetTest {
|
||||||
function testItGetsPostTypes() {
|
function testItGetsPostTypes() {
|
||||||
$router = new AutomatedLatestContent();
|
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent());
|
||||||
$response = $router->getPostTypes();
|
$response = $endpoint->getPostTypes();
|
||||||
expect($response->data)->notEmpty();
|
expect($response->data)->notEmpty();
|
||||||
foreach($response->data as $post_type) {
|
foreach($response->data as $post_type) {
|
||||||
expect($post_type)->count(2);
|
expect($post_type)->count(2);
|
||||||
@ -17,8 +17,8 @@ class AutomatedLatestContentTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItDoesNotGetPostTypesExludedFromSearch() {
|
function testItDoesNotGetPostTypesExludedFromSearch() {
|
||||||
$router = new AutomatedLatestContent();
|
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent());
|
||||||
$response = $router->getPostTypes();
|
$response = $endpoint ->getPostTypes();
|
||||||
// WP's default post type 'revision' is excluded from search
|
// WP's default post type 'revision' is excluded from search
|
||||||
// https://codex.wordpress.org/Post_Types
|
// https://codex.wordpress.org/Post_Types
|
||||||
$revision_post_type = get_post_type_object('revision');
|
$revision_post_type = get_post_type_object('revision');
|
||||||
|
Reference in New Issue
Block a user