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 NO_ACCESS_RESTRICTION = 'mailpoet_no_access_restriction';
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
function __construct(WPFunctions $wp) {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getDefaultPermissions() {
|
||||
return array(
|
||||
self::PERMISSION_ACCESS_PLUGIN_ADMIN => $this->wp->applyFilters(
|
||||
self::PERMISSION_ACCESS_PLUGIN_ADMIN => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_access_plugin_admin',
|
||||
array(
|
||||
'administrator',
|
||||
'editor'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SETTINGS => $this->wp->applyFilters(
|
||||
self::PERMISSION_MANAGE_SETTINGS => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_manage_settings',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_EMAILS => $this->wp->applyFilters(
|
||||
self::PERMISSION_MANAGE_EMAILS => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_manage_emails',
|
||||
array(
|
||||
'administrator',
|
||||
'editor'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SUBSCRIBERS => $this->wp->applyFilters(
|
||||
self::PERMISSION_MANAGE_SUBSCRIBERS => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_manage_subscribers',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_FORMS => $this->wp->applyFilters(
|
||||
self::PERMISSION_MANAGE_FORMS => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_manage_forms',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SEGMENTS => $this->wp->applyFilters(
|
||||
self::PERMISSION_MANAGE_SEGMENTS => WPFunctions::get()->applyFilters(
|
||||
'mailpoet_permission_manage_segments',
|
||||
array(
|
||||
'administrator'
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Form\Block;
|
||||
|
||||
use MailPoet\Form\Util\FieldNameObfuscator;
|
||||
use MailPoet\Models\ModelValidator;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
abstract class Base {
|
||||
protected static function getInputValidation($block, $extra_rules = array()) {
|
||||
|
@ -482,4 +482,16 @@ class Functions {
|
||||
function hasFilter() {
|
||||
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) {
|
||||
// Since WordPress 4.5.0 signature of get_terms changed to require
|
||||
// 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);
|
||||
} else {
|
||||
$taxonomy = $args['taxonomy'];
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace MailPoet\Test\Config;
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use Codeception\Stub;
|
||||
use Codeception\Stub\Expected;
|
||||
use Helper\WordPress as WPHelper;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
@ -15,7 +14,7 @@ class AccessControlTest extends \MailPoetTest {
|
||||
|
||||
function _before() {
|
||||
parent::_before();
|
||||
$this->access_control = new AccessControl(new WPFunctions());
|
||||
$this->access_control = new AccessControl;
|
||||
}
|
||||
|
||||
function testItAllowsSettingCustomPermissions() {
|
||||
@ -88,17 +87,16 @@ class AccessControlTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItValidatesIfUserHasCapability() {
|
||||
$wp_mock = Stub::makeEmpty(
|
||||
new WPFunctions(),
|
||||
['currentUserCan' => Expected::once(true)]
|
||||
);
|
||||
$access_control = new AccessControl($wp_mock);
|
||||
$capability = 'some_capability';
|
||||
$access_control = new AccessControl();
|
||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||
'currentUserCan' => true
|
||||
]));
|
||||
|
||||
expect($access_control->validatePermission($capability))->true();
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHelper::releaseAllFunctions();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
namespace MailPoet\Test\Twig;
|
||||
|
||||
use AspectMock\Test as Mock;
|
||||
use Codeception\Util\Stub;
|
||||
use MailPoet\Twig\Functions;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class FunctionsTest extends \MailPoetTest {
|
||||
function testItExecutesIsRtlFunction() {
|
||||
@ -11,12 +12,20 @@ class FunctionsTest extends \MailPoetTest {
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_Array($template));
|
||||
$twig->addExtension(new Functions());
|
||||
|
||||
Mock::func('MailPoet\Twig', 'is_rtl', true);
|
||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||
'isRtl' => true
|
||||
]));
|
||||
$result = $twig->render('template');
|
||||
expect($result)->equals('rtl');
|
||||
|
||||
Mock::func('MailPoet\Twig', 'is_rtl', false);
|
||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||
'isRtl' => false
|
||||
]));
|
||||
$result = $twig->render('template');
|
||||
expect($result)->isEmpty();
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -42,25 +42,6 @@ class FunctionsTest extends \MailPoetTest {
|
||||
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() {
|
||||
$test_value = array('abc', 'def');
|
||||
$test_value2 = new \stdClass;
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\WP;
|
||||
|
||||
use Helper\WordPress as WordPressHelper;
|
||||
use MailPoet\WP\Posts;
|
||||
use Codeception\Util\Stub;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class PostsTest extends \MailPoetUnitTest {
|
||||
|
||||
@ -12,16 +13,17 @@ class PostsTest extends \MailPoetUnitTest {
|
||||
'hide_empty' => true
|
||||
);
|
||||
|
||||
WordPressHelper::interceptFunction('get_bloginfo', function($key) {
|
||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||
'getBloginfo' => function($key) {
|
||||
return '4.6.0';
|
||||
});
|
||||
|
||||
WordPressHelper::interceptFunction('get_terms', function($key) {
|
||||
},
|
||||
'getTerms' => function($key) {
|
||||
return array(
|
||||
'call check' => 'get_terms called',
|
||||
'arguments' => func_get_args()
|
||||
);
|
||||
});
|
||||
}
|
||||
]));
|
||||
|
||||
$result = Posts::getTerms($args);
|
||||
expect($result['call check'])->equals('get_terms called');
|
||||
@ -34,16 +36,17 @@ class PostsTest extends \MailPoetUnitTest {
|
||||
'hide_empty' => true
|
||||
);
|
||||
|
||||
WordPressHelper::interceptFunction('get_bloginfo', function($key) {
|
||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||
'getBloginfo' => function($key) {
|
||||
return '4.4.0';
|
||||
});
|
||||
|
||||
WordPressHelper::interceptFunction('get_terms', function($key) {
|
||||
},
|
||||
'getTerms' => function($key) {
|
||||
return array(
|
||||
'call check' => 'get_terms called',
|
||||
'arguments' => func_get_args()
|
||||
);
|
||||
});
|
||||
}
|
||||
]));
|
||||
|
||||
$result = Posts::getTerms($args);
|
||||
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' => '')));
|
||||
}
|
||||
|
||||
function _afterStep() {
|
||||
WordPressHelper::releaseAllFunctions();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user