feat(wpmc S2): Taxonomy::register() attaches init hook
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WPMultiCity;
|
||||||
|
|
||||||
|
final class Taxonomy
|
||||||
|
{
|
||||||
|
public const SLUG = 'town';
|
||||||
|
|
||||||
|
public static function register(): void
|
||||||
|
{
|
||||||
|
add_action('init', [self::class, 'do_register']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function do_register(): void
|
||||||
|
{
|
||||||
|
// Implementation filled in Task 5.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WPMultiCity\Tests;
|
||||||
|
|
||||||
|
use Brain\Monkey\Actions;
|
||||||
|
use WPMultiCity\Taxonomy;
|
||||||
|
|
||||||
|
final class TaxonomyTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_register_attaches_init_action(): void
|
||||||
|
{
|
||||||
|
Taxonomy::register();
|
||||||
|
|
||||||
|
self::assertNotFalse(
|
||||||
|
has_action('init', [Taxonomy::class, 'do_register']),
|
||||||
|
'Taxonomy::register() must attach init action with do_register handler'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_do_register_calls_register_taxonomy_town_with_required_args(): void
|
||||||
|
{
|
||||||
|
$captured = null;
|
||||||
|
\Brain\Monkey\Functions\expect('register_taxonomy')
|
||||||
|
->once()
|
||||||
|
->with('town', ['shortcode-town'], \Mockery::on(function ($args) use (&$captured) {
|
||||||
|
$captured = $args;
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Taxonomy::do_register();
|
||||||
|
|
||||||
|
self::assertFalse($captured['hierarchical'], 'town must be flat');
|
||||||
|
self::assertFalse($captured['public'], 'town must not be public');
|
||||||
|
self::assertTrue($captured['show_ui'], 'town must show in admin UI');
|
||||||
|
self::assertTrue($captured['show_in_rest'], 'town must be REST-exposed');
|
||||||
|
self::assertFalse($captured['publicly_queryable']);
|
||||||
|
self::assertFalse($captured['query_var']);
|
||||||
|
self::assertFalse($captured['rewrite']);
|
||||||
|
self::assertFalse($captured['meta_box_cb']);
|
||||||
|
self::assertSame('Города', $captured['labels']['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user