From 519e436337e8d6c2aa81b61636b93423332a8514 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Tue, 12 May 2026 17:47:57 +0500 Subject: [PATCH] feat(wpmc S2): register ACF group list_shortcode for shortcode-town Co-Authored-By: Claude Sonnet 4.6 --- includes/class-field-group.php | 49 +++++++++++++++++++++++++++++++++- tests/FieldGroupTest.php | 43 +++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/includes/class-field-group.php b/includes/class-field-group.php index 7a25626..7b36421 100644 --- a/includes/class-field-group.php +++ b/includes/class-field-group.php @@ -15,6 +15,53 @@ final class FieldGroup public static function do_register(): void { - // Implementation filled in Tasks 13 and 14. + if (!function_exists('acf_add_local_field_group')) { + return; + } + + acf_add_local_field_group([ + 'key' => self::GROUP_KEY, + 'title' => 'WPMultiCity / Shortcode rows', + 'fields' => [ + [ + 'key' => self::REPEATER_KEY, + 'label' => __('Подстановки по городам', 'wp-multi-city'), + 'name' => 'list_shortcode', + 'type' => 'repeater', + 'layout' => 'table', + 'button_label' => __('Добавить город', 'wp-multi-city'), + 'sub_fields' => [ + [ + 'key' => 'field_wpmc_list_shortcode_town', + 'label' => __('Город', 'wp-multi-city'), + 'name' => 'town', + 'type' => 'taxonomy', + 'taxonomy' => 'town', + 'field_type' => 'select', + 'return_format' => 'id', + 'allow_null' => 0, + 'multiple' => 0, + 'add_term' => 0, + ], + [ + 'key' => 'field_wpmc_list_shortcode_text', + 'label' => __('Значение', 'wp-multi-city'), + 'name' => 'text', + 'type' => 'textarea', + 'rows' => 4, + ], + ], + ], + ], + 'location' => [ + [ + ['param' => 'post_type', 'operator' => '==', 'value' => 'shortcode-town'], + ], + ], + 'menu_order' => 0, + 'position' => 'normal', + 'style' => 'default', + 'active' => true, + ]); } } diff --git a/tests/FieldGroupTest.php b/tests/FieldGroupTest.php index 5f587f6..b8f0639 100644 --- a/tests/FieldGroupTest.php +++ b/tests/FieldGroupTest.php @@ -26,4 +26,47 @@ final class FieldGroupTest extends TestCase 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'] + ); + } }