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:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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('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,7 +14,13 @@ final class PluginBootTest extends TestCase
|
||||
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(
|
||||
has_action('init', ['WPMultiCity\\Taxonomy', 'do_register']),
|
||||
@@ -28,6 +34,10 @@ final class PluginBootTest extends TestCase
|
||||
has_action('acf/init', ['WPMultiCity\\FieldGroup', 'do_register']),
|
||||
'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
|
||||
@@ -55,6 +65,9 @@ final class PluginBootTest extends TestCase
|
||||
\Brain\Monkey\Actions\expectAdded('acf/init')
|
||||
->with([\WPMultiCity\FieldGroup::class, 'do_register'])
|
||||
->once();
|
||||
\Brain\Monkey\Actions\expectAdded('init')
|
||||
->with([\WPMultiCity\ShortcodeDmr::class, 'do_register'])
|
||||
->once();
|
||||
|
||||
$plugin->boot();
|
||||
$plugin->boot();
|
||||
|
||||
@@ -21,6 +21,7 @@ defined('WPMC_VERSION') || define('WPMC_VERSION', '0.1.0');
|
||||
|
||||
require_once WPMC_PLUGIN_DIR . 'includes/class-plugin.php';
|
||||
\WPMultiCity\Plugin::register_autoloader();
|
||||
require_once WPMC_PLUGIN_DIR . 'includes/wpmc-functions.php';
|
||||
|
||||
register_activation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'activate']);
|
||||
register_deactivation_hook(__FILE__, ['\\WPMultiCity\\Activator', 'deactivate']);
|
||||
|
||||
Reference in New Issue
Block a user