Refactor WPFunctions to property in Twig Functions class
[MAILPOET-2182]
This commit is contained in:
committed by
M. Shull
parent
a23bc07349
commit
72aa4a5fb8
@@ -21,9 +21,13 @@ class Functions extends AbstractExtension {
|
|||||||
/** @var WooCommerceHelper */
|
/** @var WooCommerceHelper */
|
||||||
private $woocommerce_helper;
|
private $woocommerce_helper;
|
||||||
|
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
$this->woocommerce_helper = new WooCommerceHelper();
|
$this->woocommerce_helper = new WooCommerceHelper();
|
||||||
|
$this->wp = WPFunctions::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFunctions() {
|
function getFunctions() {
|
||||||
@@ -157,10 +161,10 @@ class Functions extends AbstractExtension {
|
|||||||
|
|
||||||
$label = null;
|
$label = null;
|
||||||
$labels = [
|
$labels = [
|
||||||
'minute' => WPFunctions::get()->__('every minute', 'mailpoet'),
|
'minute' => $this->wp->__('every minute', 'mailpoet'),
|
||||||
'minutes' => WPFunctions::get()->__('every %1$d minutes', 'mailpoet'),
|
'minutes' => $this->wp->__('every %1$d minutes', 'mailpoet'),
|
||||||
'hour' => WPFunctions::get()->__('every hour', 'mailpoet'),
|
'hour' => $this->wp->__('every hour', 'mailpoet'),
|
||||||
'hours' => WPFunctions::get()->__('every %1$d hours', 'mailpoet'),
|
'hours' => $this->wp->__('every %1$d hours', 'mailpoet'),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($value >= 60) {
|
if ($value >= 60) {
|
||||||
@@ -188,11 +192,11 @@ class Functions extends AbstractExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWPDateFormat() {
|
function getWPDateFormat() {
|
||||||
return WPFunctions::get()->getOption('date_format') ?: 'F j, Y';
|
return $this->wp->getOption('date_format') ?: 'F j, Y';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWPStartOfWeek() {
|
function getWPStartOfWeek() {
|
||||||
return WPFunctions::get()->getOption('start_of_week') ?: 0;
|
return $this->wp->getOption('start_of_week') ?: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMailPoetVersion() {
|
function getMailPoetVersion() {
|
||||||
@@ -204,7 +208,7 @@ class Functions extends AbstractExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWPTimeFormat() {
|
function getWPTimeFormat() {
|
||||||
return WPFunctions::get()->getOption('time_format') ?: 'g:i a';
|
return $this->wp->getOption('time_format') ?: 'g:i a';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWPDateTimeFormat() {
|
function getWPDateTimeFormat() {
|
||||||
@@ -212,7 +216,7 @@ class Functions extends AbstractExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function params($key = null) {
|
function params($key = null) {
|
||||||
$args = WPFunctions::get()->stripslashesDeep($_GET);
|
$args = $this->wp->stripslashesDeep($_GET);
|
||||||
if (array_key_exists($key, $args)) {
|
if (array_key_exists($key, $args)) {
|
||||||
return $args[$key];
|
return $args[$key];
|
||||||
}
|
}
|
||||||
@@ -231,11 +235,11 @@ class Functions extends AbstractExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isRtl() {
|
function isRtl() {
|
||||||
return WPFunctions::get()->isRtl();
|
return $this->wp->isRtl();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTwoLettersLocale() {
|
function getTwoLettersLocale() {
|
||||||
return explode('_', WPFunctions::get()->getLocale())[0];
|
return explode('_', $this->wp->getLocale())[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFreeDomains() {
|
function getFreeDomains() {
|
||||||
|
@@ -10,19 +10,15 @@ class FunctionsTest extends \MailPoetTest {
|
|||||||
function testItExecutesIsRtlFunction() {
|
function testItExecutesIsRtlFunction() {
|
||||||
$template = ['template' => '{% if is_rtl() %}rtl{% endif %}'];
|
$template = ['template' => '{% if is_rtl() %}rtl{% endif %}'];
|
||||||
$twig = new \MailPoetVendor\Twig_Environment(new \MailPoetVendor\Twig_Loader_Array($template));
|
$twig = new \MailPoetVendor\Twig_Environment(new \MailPoetVendor\Twig_Loader_Array($template));
|
||||||
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'isRtl' => Stub::consecutive(true, false),
|
||||||
|
]));
|
||||||
|
|
||||||
$twig->addExtension(new Functions());
|
$twig->addExtension(new Functions());
|
||||||
|
$result_rtl = $twig->render('template');
|
||||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
expect($result_rtl)->equals('rtl');
|
||||||
'isRtl' => true,
|
$result_no_rtl = $twig->render('template');
|
||||||
]));
|
expect($result_no_rtl)->isEmpty();
|
||||||
$result = $twig->render('template');
|
|
||||||
expect($result)->equals('rtl');
|
|
||||||
|
|
||||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
|
||||||
'isRtl' => false,
|
|
||||||
]));
|
|
||||||
$result = $twig->render('template');
|
|
||||||
expect($result)->isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
|
Reference in New Issue
Block a user