11bfaa08a0
Re-add ->never() to both noop tests so Brain Monkey/Mockery actively asserts
acf_add_local_field_group is never called when ACF is absent. Order matters:
expect() must precede when('function_exists')->alias() so FunctionStub sees the
real function_exists and skips the eval() path (function already declared in
acf-stubs.php). Also tighten stub signature to match real ACF ($field_group,
no type hint, no default).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity\Tests;
|
|
|
|
use WPMultiCity\TermMeta;
|
|
|
|
final class TermMetaTest extends TestCase
|
|
{
|
|
public function test_register_attaches_acf_init_action(): void
|
|
{
|
|
TermMeta::register();
|
|
|
|
self::assertNotFalse(
|
|
has_action('acf/init', [TermMeta::class, 'do_register']),
|
|
'TermMeta::register() must hook acf/init'
|
|
);
|
|
}
|
|
|
|
public function test_do_register_is_noop_when_acf_missing(): void
|
|
{
|
|
// Set up the ->never() expectation BEFORE aliasing function_exists, so that
|
|
// FunctionStub::__construct() sees the real function_exists and skips the
|
|
// eval() path (the function is already declared in acf-stubs.php).
|
|
\Brain\Monkey\Functions\expect('acf_add_local_field_group')->never();
|
|
\Brain\Monkey\Functions\when('function_exists')->alias(function ($name) {
|
|
return $name !== 'acf_add_local_field_group';
|
|
});
|
|
|
|
TermMeta::do_register();
|
|
|
|
// ->never() above is the actual guard assertion; assertTrue keeps
|
|
// PHPUnit happy under failOnRisky.
|
|
self::assertTrue(true);
|
|
}
|
|
|
|
public function test_do_register_registers_main_page_alt_field_group(): void
|
|
{
|
|
\Brain\Monkey\Functions\when('function_exists')->alias(function ($name) {
|
|
return $name === 'acf_add_local_field_group';
|
|
});
|
|
|
|
$captured = null;
|
|
\Brain\Monkey\Functions\expect('acf_add_local_field_group')
|
|
->once()
|
|
->with(\Mockery::on(function ($group) use (&$captured) {
|
|
$captured = $group;
|
|
return true;
|
|
}));
|
|
|
|
TermMeta::do_register();
|
|
|
|
self::assertSame('group_wpmc_town_main_page', $captured['key']);
|
|
self::assertSame(
|
|
[[['param' => 'taxonomy', 'operator' => '==', 'value' => 'town']]],
|
|
$captured['location']
|
|
);
|
|
self::assertCount(1, $captured['fields']);
|
|
self::assertSame('field_wpmc_main_page_alt', $captured['fields'][0]['key']);
|
|
self::assertSame('main_page_alt', $captured['fields'][0]['name']);
|
|
self::assertSame('post_object', $captured['fields'][0]['type']);
|
|
self::assertSame('id', $captured['fields'][0]['return_format']);
|
|
self::assertSame(['page'], $captured['fields'][0]['post_type']);
|
|
}
|
|
}
|