feat(wpmc S3): procedural wpmc_* API + smoke test

Also fixes PluginBootTest to be order-independent (reset booted flag)
and to expect ShortcodeDmr hook that boot() now wires.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vladimir Bryzgalov
2026-05-12 20:11:47 +05:00
parent 3dbca34234
commit d8b0d01f1c
4 changed files with 60 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
use WPMultiCity\Helpers;
if (!function_exists('wpmc_current_town')) {
function wpmc_current_town(): ?string
{
return Helpers::current_town();
}
}
if (!function_exists('wpmc_get_term_by_slug')) {
function wpmc_get_term_by_slug(string $slug, string $taxonomy = 'town'): ?\WP_Term
{
return Helpers::get_term_by_slug($slug, $taxonomy);
}
}
if (!function_exists('wpmc_alt_get_field')) {
function wpmc_alt_get_field(string $selector, $post_id = false, bool $format_value = true)
{
return Helpers::alt_get_field($selector, $post_id, $format_value);
}
}
if (!function_exists('wpmc_remove_domain_link')) {
function wpmc_remove_domain_link(string $url): string
{
return Helpers::remove_domain_link($url);
}
}
+13
View File
@@ -197,4 +197,17 @@ final class HelpersTest extends TestCase
self::assertSame('mailto:x@y.com', Helpers::remove_domain_link('mailto:x@y.com')); self::assertSame('mailto:x@y.com', Helpers::remove_domain_link('mailto:x@y.com'));
self::assertSame('not a url', Helpers::remove_domain_link('not a url')); self::assertSame('not a url', Helpers::remove_domain_link('not a url'));
} }
public function test_wpmc_procedural_functions_proxy_to_helpers(): void
{
require_once dirname(__DIR__) . '/includes/wpmc-functions.php';
self::assertTrue(function_exists('wpmc_current_town'));
self::assertTrue(function_exists('wpmc_get_term_by_slug'));
self::assertTrue(function_exists('wpmc_alt_get_field'));
self::assertTrue(function_exists('wpmc_remove_domain_link'));
// remove_domain_link is pure (no WP function dependencies) — exercise the proxy.
self::assertSame('/foo/', wpmc_remove_domain_link('https://site.com/foo/'));
}
} }
+14 -1
View File
@@ -14,7 +14,13 @@ final class PluginBootTest extends TestCase
eval('class ACF {}'); eval('class ACF {}');
} }
Plugin::instance()->boot(); // Reset booted flag so this test is order-independent.
$plugin = Plugin::instance();
$reflection = new \ReflectionClass($plugin);
$prop = $reflection->getProperty('booted');
$prop->setValue($plugin, false);
$plugin->boot();
self::assertNotFalse( self::assertNotFalse(
has_action('init', ['WPMultiCity\\Taxonomy', 'do_register']), has_action('init', ['WPMultiCity\\Taxonomy', 'do_register']),
@@ -28,6 +34,10 @@ final class PluginBootTest extends TestCase
has_action('acf/init', ['WPMultiCity\\FieldGroup', 'do_register']), has_action('acf/init', ['WPMultiCity\\FieldGroup', 'do_register']),
'boot() must register FieldGroup on acf/init' 'boot() must register FieldGroup on acf/init'
); );
self::assertNotFalse(
has_action('init', ['WPMultiCity\\ShortcodeDmr', 'do_register']),
'boot() must register ShortcodeDmr on init'
);
} }
public function test_boot_is_idempotent_when_called_multiple_times(): void public function test_boot_is_idempotent_when_called_multiple_times(): void
@@ -55,6 +65,9 @@ final class PluginBootTest extends TestCase
\Brain\Monkey\Actions\expectAdded('acf/init') \Brain\Monkey\Actions\expectAdded('acf/init')
->with([\WPMultiCity\FieldGroup::class, 'do_register']) ->with([\WPMultiCity\FieldGroup::class, 'do_register'])
->once(); ->once();
\Brain\Monkey\Actions\expectAdded('init')
->with([\WPMultiCity\ShortcodeDmr::class, 'do_register'])
->once();
$plugin->boot(); $plugin->boot();
$plugin->boot(); $plugin->boot();
+1
View File
@@ -21,6 +21,7 @@ defined('WPMC_VERSION') || define('WPMC_VERSION', '0.1.0');
require_once WPMC_PLUGIN_DIR . 'includes/class-plugin.php'; require_once WPMC_PLUGIN_DIR . 'includes/class-plugin.php';
\WPMultiCity\Plugin::register_autoloader(); \WPMultiCity\Plugin::register_autoloader();
require_once WPMC_PLUGIN_DIR . 'includes/wpmc-functions.php';
register_activation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'activate']); register_activation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'activate']);
register_deactivation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'deactivate']); register_deactivation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'deactivate']);