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