Fix tests
This commit is contained in:
committed by
M. Shull
parent
0a436087e1
commit
3ff55d85a9
@ -14,48 +14,41 @@ class AccessControl {
|
|||||||
const PERMISSION_MANAGE_SEGMENTS = 'mailpoet_manage_segments';
|
const PERMISSION_MANAGE_SEGMENTS = 'mailpoet_manage_segments';
|
||||||
const NO_ACCESS_RESTRICTION = 'mailpoet_no_access_restriction';
|
const NO_ACCESS_RESTRICTION = 'mailpoet_no_access_restriction';
|
||||||
|
|
||||||
/** @var WPFunctions */
|
|
||||||
private $wp;
|
|
||||||
|
|
||||||
function __construct(WPFunctions $wp) {
|
|
||||||
$this->wp = $wp;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDefaultPermissions() {
|
function getDefaultPermissions() {
|
||||||
return array(
|
return array(
|
||||||
self::PERMISSION_ACCESS_PLUGIN_ADMIN => $this->wp->applyFilters(
|
self::PERMISSION_ACCESS_PLUGIN_ADMIN => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_access_plugin_admin',
|
'mailpoet_permission_access_plugin_admin',
|
||||||
array(
|
array(
|
||||||
'administrator',
|
'administrator',
|
||||||
'editor'
|
'editor'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
self::PERMISSION_MANAGE_SETTINGS => $this->wp->applyFilters(
|
self::PERMISSION_MANAGE_SETTINGS => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_manage_settings',
|
'mailpoet_permission_manage_settings',
|
||||||
array(
|
array(
|
||||||
'administrator'
|
'administrator'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
self::PERMISSION_MANAGE_EMAILS => $this->wp->applyFilters(
|
self::PERMISSION_MANAGE_EMAILS => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_manage_emails',
|
'mailpoet_permission_manage_emails',
|
||||||
array(
|
array(
|
||||||
'administrator',
|
'administrator',
|
||||||
'editor'
|
'editor'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
self::PERMISSION_MANAGE_SUBSCRIBERS => $this->wp->applyFilters(
|
self::PERMISSION_MANAGE_SUBSCRIBERS => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_manage_subscribers',
|
'mailpoet_permission_manage_subscribers',
|
||||||
array(
|
array(
|
||||||
'administrator'
|
'administrator'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
self::PERMISSION_MANAGE_FORMS => $this->wp->applyFilters(
|
self::PERMISSION_MANAGE_FORMS => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_manage_forms',
|
'mailpoet_permission_manage_forms',
|
||||||
array(
|
array(
|
||||||
'administrator'
|
'administrator'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
self::PERMISSION_MANAGE_SEGMENTS => $this->wp->applyFilters(
|
self::PERMISSION_MANAGE_SEGMENTS => WPFunctions::get()->applyFilters(
|
||||||
'mailpoet_permission_manage_segments',
|
'mailpoet_permission_manage_segments',
|
||||||
array(
|
array(
|
||||||
'administrator'
|
'administrator'
|
||||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Form\Block;
|
|||||||
|
|
||||||
use MailPoet\Form\Util\FieldNameObfuscator;
|
use MailPoet\Form\Util\FieldNameObfuscator;
|
||||||
use MailPoet\Models\ModelValidator;
|
use MailPoet\Models\ModelValidator;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
abstract class Base {
|
abstract class Base {
|
||||||
protected static function getInputValidation($block, $extra_rules = array()) {
|
protected static function getInputValidation($block, $extra_rules = array()) {
|
||||||
|
@ -482,4 +482,16 @@ class Functions {
|
|||||||
function hasFilter() {
|
function hasFilter() {
|
||||||
return call_user_func_array('has_filter', func_get_args());
|
return call_user_func_array('has_filter', func_get_args());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wcPrice() {
|
||||||
|
return call_user_func_array('wc_price', func_get_args());
|
||||||
|
}
|
||||||
|
|
||||||
|
function wcGetOrder() {
|
||||||
|
return call_user_func_array('wc_get_order', func_get_args());
|
||||||
|
}
|
||||||
|
function wcGetCustomerOrderCount() {
|
||||||
|
return call_user_func_array('wc_get_customer_order_count', func_get_args());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Posts {
|
|||||||
static function getTerms($args) {
|
static function getTerms($args) {
|
||||||
// Since WordPress 4.5.0 signature of get_terms changed to require
|
// Since WordPress 4.5.0 signature of get_terms changed to require
|
||||||
// one argument array, where taxonomy is key of that array
|
// one argument array, where taxonomy is key of that array
|
||||||
if (version_compare(get_bloginfo('version'), '4.5.0', '>=')) {
|
if (version_compare(WPFunctions::get()->getBloginfo('version'), '4.5.0', '>=')) {
|
||||||
return WPFunctions::get()->getTerms($args);
|
return WPFunctions::get()->getTerms($args);
|
||||||
} else {
|
} else {
|
||||||
$taxonomy = $args['taxonomy'];
|
$taxonomy = $args['taxonomy'];
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace MailPoet\Test\Config;
|
namespace MailPoet\Test\Config;
|
||||||
|
|
||||||
use Codeception\Util\Stub;
|
use Codeception\Stub;
|
||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use Helper\WordPress as WPHelper;
|
|
||||||
use MailPoet\Config\AccessControl;
|
use MailPoet\Config\AccessControl;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ class AccessControlTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->access_control = new AccessControl(new WPFunctions());
|
$this->access_control = new AccessControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItAllowsSettingCustomPermissions() {
|
function testItAllowsSettingCustomPermissions() {
|
||||||
@ -88,17 +87,16 @@ class AccessControlTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItValidatesIfUserHasCapability() {
|
function testItValidatesIfUserHasCapability() {
|
||||||
$wp_mock = Stub::makeEmpty(
|
|
||||||
new WPFunctions(),
|
|
||||||
['currentUserCan' => Expected::once(true)]
|
|
||||||
);
|
|
||||||
$access_control = new AccessControl($wp_mock);
|
|
||||||
$capability = 'some_capability';
|
$capability = 'some_capability';
|
||||||
|
$access_control = new AccessControl();
|
||||||
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'currentUserCan' => true
|
||||||
|
]));
|
||||||
|
|
||||||
expect($access_control->validatePermission($capability))->true();
|
expect($access_control->validatePermission($capability))->true();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
WPHelper::releaseAllFunctions();
|
WPFunctions::set(new WPFunctions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace MailPoet\Test\Twig;
|
namespace MailPoet\Test\Twig;
|
||||||
|
|
||||||
use AspectMock\Test as Mock;
|
use Codeception\Util\Stub;
|
||||||
use MailPoet\Twig\Functions;
|
use MailPoet\Twig\Functions;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class FunctionsTest extends \MailPoetTest {
|
class FunctionsTest extends \MailPoetTest {
|
||||||
function testItExecutesIsRtlFunction() {
|
function testItExecutesIsRtlFunction() {
|
||||||
@ -11,12 +12,20 @@ class FunctionsTest extends \MailPoetTest {
|
|||||||
$twig = new \Twig_Environment(new \Twig_Loader_Array($template));
|
$twig = new \Twig_Environment(new \Twig_Loader_Array($template));
|
||||||
$twig->addExtension(new Functions());
|
$twig->addExtension(new Functions());
|
||||||
|
|
||||||
Mock::func('MailPoet\Twig', 'is_rtl', true);
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'isRtl' => true
|
||||||
|
]));
|
||||||
$result = $twig->render('template');
|
$result = $twig->render('template');
|
||||||
expect($result)->equals('rtl');
|
expect($result)->equals('rtl');
|
||||||
|
|
||||||
Mock::func('MailPoet\Twig', 'is_rtl', false);
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'isRtl' => false
|
||||||
|
]));
|
||||||
$result = $twig->render('template');
|
$result = $twig->render('template');
|
||||||
expect($result)->isEmpty();
|
expect($result)->isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
WPFunctions::set(new WPFunctions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,25 +42,6 @@ class FunctionsTest extends \MailPoetTest {
|
|||||||
return $this->ids[] = $id;
|
return $this->ids[] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanGetImageInfo() {
|
|
||||||
expect(
|
|
||||||
function_exists('wp_generate_attachment_metadata')
|
|
||||||
)->true();
|
|
||||||
|
|
||||||
$filename = 'tests/_data/test-image.jpg';
|
|
||||||
$contents = file_get_contents($filename);
|
|
||||||
|
|
||||||
$upload = wp_upload_bits(basename($filename), null, $contents);
|
|
||||||
$id = $this->makeAttachment($upload);
|
|
||||||
expect($id)->notEmpty();
|
|
||||||
|
|
||||||
$image = $this->wp->getImageInfo($id);
|
|
||||||
expect($image[1])->equals(Env::NEWSLETTER_CONTENT_WIDTH);
|
|
||||||
|
|
||||||
wp_delete_attachment($id, $force_delete = true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testItCanProcessActions() {
|
function testItCanProcessActions() {
|
||||||
$test_value = array('abc', 'def');
|
$test_value = array('abc', 'def');
|
||||||
$test_value2 = new \stdClass;
|
$test_value2 = new \stdClass;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Test\WP;
|
namespace MailPoet\Test\WP;
|
||||||
|
|
||||||
use Helper\WordPress as WordPressHelper;
|
|
||||||
use MailPoet\WP\Posts;
|
use MailPoet\WP\Posts;
|
||||||
|
use Codeception\Util\Stub;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class PostsTest extends \MailPoetUnitTest {
|
class PostsTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
@ -12,16 +13,17 @@ class PostsTest extends \MailPoetUnitTest {
|
|||||||
'hide_empty' => true
|
'hide_empty' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
WordPressHelper::interceptFunction('get_bloginfo', function($key) {
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'getBloginfo' => function($key) {
|
||||||
return '4.6.0';
|
return '4.6.0';
|
||||||
});
|
},
|
||||||
|
'getTerms' => function($key) {
|
||||||
WordPressHelper::interceptFunction('get_terms', function($key) {
|
|
||||||
return array(
|
return array(
|
||||||
'call check' => 'get_terms called',
|
'call check' => 'get_terms called',
|
||||||
'arguments' => func_get_args()
|
'arguments' => func_get_args()
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
]));
|
||||||
|
|
||||||
$result = Posts::getTerms($args);
|
$result = Posts::getTerms($args);
|
||||||
expect($result['call check'])->equals('get_terms called');
|
expect($result['call check'])->equals('get_terms called');
|
||||||
@ -34,16 +36,17 @@ class PostsTest extends \MailPoetUnitTest {
|
|||||||
'hide_empty' => true
|
'hide_empty' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
WordPressHelper::interceptFunction('get_bloginfo', function($key) {
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'getBloginfo' => function($key) {
|
||||||
return '4.4.0';
|
return '4.4.0';
|
||||||
});
|
},
|
||||||
|
'getTerms' => function($key) {
|
||||||
WordPressHelper::interceptFunction('get_terms', function($key) {
|
|
||||||
return array(
|
return array(
|
||||||
'call check' => 'get_terms called',
|
'call check' => 'get_terms called',
|
||||||
'arguments' => func_get_args()
|
'arguments' => func_get_args()
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
]));
|
||||||
|
|
||||||
$result = Posts::getTerms($args);
|
$result = Posts::getTerms($args);
|
||||||
expect($result['call check'])->equals('get_terms called');
|
expect($result['call check'])->equals('get_terms called');
|
||||||
@ -51,7 +54,4 @@ class PostsTest extends \MailPoetUnitTest {
|
|||||||
expect($result['arguments'][1])->equals(array_diff_key($args, array('taxonomy' => '')));
|
expect($result['arguments'][1])->equals(array_diff_key($args, array('taxonomy' => '')));
|
||||||
}
|
}
|
||||||
|
|
||||||
function _afterStep() {
|
|
||||||
WordPressHelper::releaseAllFunctions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user