519e436337
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
73 lines
2.4 KiB
PHP
73 lines
2.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity\Tests;
|
|
|
|
use WPMultiCity\FieldGroup;
|
|
|
|
final class FieldGroupTest extends TestCase
|
|
{
|
|
public function test_register_attaches_acf_init_action(): void
|
|
{
|
|
FieldGroup::register();
|
|
|
|
self::assertNotFalse(
|
|
has_action('acf/init', [FieldGroup::class, 'do_register']),
|
|
'FieldGroup::register() must hook acf/init'
|
|
);
|
|
}
|
|
|
|
public function test_do_register_is_noop_when_acf_missing(): void
|
|
{
|
|
\Brain\Monkey\Functions\when('function_exists')->justReturn(false);
|
|
\Brain\Monkey\Functions\expect('acf_add_local_field_group')->never();
|
|
|
|
FieldGroup::do_register();
|
|
|
|
self::assertTrue(true, 'do_register must not call acf_add_local_field_group when ACF is missing');
|
|
}
|
|
|
|
public function test_do_register_calls_acf_add_local_field_group_with_expected_structure(): 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;
|
|
}));
|
|
|
|
FieldGroup::do_register();
|
|
|
|
self::assertSame('group_wpmc_shortcode_rows', $captured['key']);
|
|
self::assertSame('WPMultiCity / Shortcode rows', $captured['title']);
|
|
|
|
self::assertCount(1, $captured['fields']);
|
|
$repeater = $captured['fields'][0];
|
|
|
|
self::assertSame('field_wpmc_list_shortcode', $repeater['key']);
|
|
self::assertSame('list_shortcode', $repeater['name']);
|
|
self::assertSame('repeater', $repeater['type']);
|
|
self::assertCount(2, $repeater['sub_fields']);
|
|
|
|
[$town, $text] = $repeater['sub_fields'];
|
|
self::assertSame('town', $town['name']);
|
|
self::assertSame('taxonomy', $town['type']);
|
|
self::assertSame('town', $town['taxonomy']);
|
|
self::assertSame('id', $town['return_format']);
|
|
self::assertSame(0, $town['allow_null']);
|
|
|
|
self::assertSame('text', $text['name']);
|
|
self::assertSame('textarea', $text['type']);
|
|
|
|
self::assertSame(
|
|
[[['param' => 'post_type', 'operator' => '==', 'value' => 'shortcode-town']]],
|
|
$captured['location']
|
|
);
|
|
}
|
|
}
|