d8b0d01f1c
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>
80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity\Tests;
|
|
|
|
use WPMultiCity\Plugin;
|
|
|
|
final class PluginBootTest extends TestCase
|
|
{
|
|
public function test_boot_attaches_init_and_acf_init_hooks_when_acf_present(): void
|
|
{
|
|
// Simulate ACF being active so boot() proceeds past the dependency guard.
|
|
if (!class_exists('ACF', false)) {
|
|
eval('class ACF {}');
|
|
}
|
|
|
|
// 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']),
|
|
'boot() must register Taxonomy on init'
|
|
);
|
|
self::assertNotFalse(
|
|
has_action('init', ['WPMultiCity\\PostType', 'do_register']),
|
|
'boot() must register PostType on init'
|
|
);
|
|
self::assertNotFalse(
|
|
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
|
|
{
|
|
if (!class_exists('ACF', false)) {
|
|
eval('class ACF {}');
|
|
}
|
|
|
|
// Reset the singleton's boot flag so this test is independent of
|
|
// whatever previous tests did to the static instance. (We will add
|
|
// the flag in GREEN.)
|
|
$plugin = Plugin::instance();
|
|
$reflection = new \ReflectionClass($plugin);
|
|
if ($reflection->hasProperty('booted')) {
|
|
$prop = $reflection->getProperty('booted');
|
|
$prop->setValue($plugin, false);
|
|
}
|
|
|
|
\Brain\Monkey\Actions\expectAdded('init')
|
|
->with([\WPMultiCity\Taxonomy::class, 'do_register'])
|
|
->once();
|
|
\Brain\Monkey\Actions\expectAdded('init')
|
|
->with([\WPMultiCity\PostType::class, 'do_register'])
|
|
->once();
|
|
\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();
|
|
$plugin->boot();
|
|
|
|
// Mockery verifies ->once() in tearDown.
|
|
self::assertTrue(true);
|
|
}
|
|
}
|