- Adds new ConflictResolver class
- Executes URL query parameter conflict resolver action in Router class - Adds unit tests
This commit is contained in:
@ -4,6 +4,7 @@ namespace MailPoet\Config;
|
||||
use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\Router;
|
||||
use MailPoet\API;
|
||||
use MailPoet\Util\ConflictResolver;
|
||||
use MailPoet\WP\Notice as WPNotice;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -112,6 +113,7 @@ class Initializer {
|
||||
$this->setupShortcodes();
|
||||
$this->setupImages();
|
||||
$this->setupCronTrigger();
|
||||
$this->setupConflictResolver();
|
||||
|
||||
$this->plugin_initialized = true;
|
||||
} catch(\Exception $e) {
|
||||
@ -222,6 +224,11 @@ class Initializer {
|
||||
add_image_size('mailpoet_newsletter_max', 1320);
|
||||
}
|
||||
|
||||
function setupConflictResolver() {
|
||||
$conflict_resolver = new ConflictResolver();
|
||||
$conflict_resolver->init();
|
||||
}
|
||||
|
||||
function handleFailedInitialization($message) {
|
||||
return WPNotice::displayError($message);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class Router {
|
||||
if(!method_exists($endpoint, $this->action) || !in_array($this->action, $endpoint->allowed_actions)) {
|
||||
return $this->terminateRequest(self::RESPONSE_ERROR, __('Invalid router endpoint action.', 'mailpoet'));
|
||||
}
|
||||
do_action('mailpoet_conflict_url_query_parameters');
|
||||
return call_user_func(
|
||||
array(
|
||||
$endpoint,
|
||||
|
13
lib/Util/ConflictResolver.php
Normal file
13
lib/Util/ConflictResolver.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace MailPoet\Util;
|
||||
|
||||
class ConflictResolver {
|
||||
function init() {
|
||||
add_action('mailpoet_conflict_url_query_parameters', array($this, 'resolveRouterUrlQueryParametersConflict'));
|
||||
}
|
||||
|
||||
function resolveRouterUrlQueryParametersConflict() {
|
||||
// prevents other plugins from overtaking URL query parameters 'action=' and 'endpoint='
|
||||
unset($_GET['endpoint'], $_GET['action']);
|
||||
}
|
||||
}
|
@ -96,6 +96,12 @@ class FrontRouterTest extends MailPoetTest {
|
||||
expect($result)->equals($data);
|
||||
}
|
||||
|
||||
function testItExecutesUrlParameterConflictResolverAction() {
|
||||
$data = array('data' => 'dummy data');
|
||||
$result = $this->router->init();
|
||||
expect((boolean) did_action('mailpoet_conflict_url_query_parameters'))->true();
|
||||
}
|
||||
|
||||
function testItCanEncodeRequestData() {
|
||||
$data = array('data' => 'dummy data');
|
||||
$result = Router::encodeRequestData($data);
|
||||
|
24
tests/unit/Util/ConflictResolverTest.php
Normal file
24
tests/unit/Util/ConflictResolverTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use MailPoet\Util\ConflictResolver;
|
||||
|
||||
class ConflictResolverTest extends MailPoetTest {
|
||||
public $conflict_resolver;
|
||||
public $wp_filter;
|
||||
|
||||
function __construct() {
|
||||
$this->conflict_resolver = new ConflictResolver();
|
||||
$this->conflict_resolver = $this->conflict_resolver->init();
|
||||
global $wp_filter;
|
||||
$this->wp_filter = $wp_filter;
|
||||
}
|
||||
|
||||
function testItResolvesRouterUrlQueryParametersConflict() {
|
||||
expect(!empty($this->wp_filter['mailpoet_conflict_url_query_parameters']))->true();
|
||||
// it should unset action & endpoint GET variables
|
||||
$_GET['endpoint'] = $_GET['action'] = $_GET['test'] = 'test';
|
||||
do_action('mailpoet_conflict_url_query_parameters');
|
||||
expect(empty($_GET['endpoint']))->true();
|
||||
expect(empty($_GET['action']))->true();
|
||||
expect(empty($_GET['test']))->false();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user