Files
wp-multi-city/tests/acf-stubs.php
T
Vladimir Bryzgalov fc21fd1f06 feat(wpmc S4): OptionsPage::do_register registers routing field group
Also: add acf_add_options_page to acf-stubs.php; add translation-function
stubs to acf-stubs.php; fix TestCase::tearDown to call Patchwork::restoreAll()
in a finally block so that when('function_exists') routes are always cleaned up
even when Mockery::close() throws InvalidCountException.
2026-05-16 19:54:23 +05:00

76 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
/**
* Minimal ACF function stubs for the test suite.
*
* This file is required from TestCase::setUp() AFTER Brain\Monkey\setUp() so
* that Patchwork's stream wrapper instruments these functions and can redefine
* them across successive test classes in the same PHP process.
*
* Functions declared via eval() cannot be re-intercepted by Patchwork after
* restoreAll(); functions from a real file loaded through Patchwork's stream
* wrapper can.
*/
if (!function_exists('acf_add_local_field_group')) {
function acf_add_local_field_group($field_group): void {}
}
if (!function_exists('acf_add_options_page')) {
function acf_add_options_page($args): void {}
}
// Translation function stubs — declared here (via Patchwork's stream wrapper) so that
// Brain\Monkey\Functions\stubTranslationFunctions() finds them via function_exists() and
// never falls back to eval(), which would cause "Cannot redeclare" fatals across tests
// that use when('function_exists')->alias(...).
if (!function_exists('__')) {
function __($text, $domain = 'default') { return $text; }
}
if (!function_exists('_x')) {
function _x($text, $context, $domain = 'default') { return $text; }
}
if (!function_exists('translate')) {
function translate($text, $domain = 'default') { return $text; }
}
if (!function_exists('_n')) {
function _n($single, $plural, $number, $domain = 'default') { return $number === 1 ? $single : $plural; }
}
if (!function_exists('_nx')) {
function _nx($single, $plural, $number, $context, $domain = 'default') { return $number === 1 ? $single : $plural; }
}
if (!function_exists('_e')) {
function _e($text, $domain = 'default') { echo $text; }
}
if (!function_exists('_ex')) {
function _ex($text, $context, $domain = 'default') { echo $text; }
}
if (!function_exists('esc_html__')) {
function esc_html__($text, $domain = 'default') { return $text; }
}
if (!function_exists('esc_html_x')) {
function esc_html_x($text, $context, $domain = 'default') { return $text; }
}
if (!function_exists('esc_attr__')) {
function esc_attr__($text, $domain = 'default') { return $text; }
}
if (!function_exists('esc_attr_x')) {
function esc_attr_x($text, $context, $domain = 'default') { return $text; }
}
if (!function_exists('esc_html_e')) {
function esc_html_e($text, $domain = 'default') { echo $text; }
}
if (!function_exists('esc_attr_e')) {
function esc_attr_e($text, $domain = 'default') { echo $text; }
}
if (!function_exists('_n_noop')) {
function _n_noop($singular, $plural, $domain = 'default') { return compact('singular', 'plural'); }
}
if (!function_exists('_nx_noop')) {
function _nx_noop($singular, $plural, $context, $domain = 'default') { return compact('singular', 'plural'); }
}
if (!function_exists('translate_nooped_plural')) {
function translate_nooped_plural($nooped_plural, $count, $domain = 'default') { return $count === 1 ? $nooped_plural['singular'] : $nooped_plural['plural']; }
}