From bae9cd0b958301924abe7804714487e6834c8e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Franco?= Date: Sun, 22 Nov 2026 07:19:48 +0100 Subject: [PATCH] feat(panel): web_ui.header_actions page_actions puts the header actions in the page-actions menu --- docs/CHANGELOG.md | 4 + docs/CONFIGURATION.md | 1 + docs/USAGE.md | 4 +- src/Controller/RoutingPanelController.php | 2 +- src/Controller/UrlRedirectPanelController.php | 4 +- src/DependencyInjection/Configuration.php | 6 ++ .../RoutingKitExtension.php | 1 + src/Panel/HeaderActionsPlacement.php | 89 +++++++++++++++++++ src/Panel/PanelView.php | 13 +++ .../config/packages/nowo_routing_kit.yaml | 1 + .../Integration/Contract/PageContractTest.php | 45 ++++++++++ tests/Support/PanelPageFixtures.php | 14 +-- .../PanelChromeConfigTest.php | 9 ++ .../RoutingKitExtensionTest.php | 2 + .../Unit/Panel/HeaderActionsPlacementTest.php | 62 +++++++++++++ 15 files changed, 246 insertions(+), 11 deletions(-) create mode 100644 src/Panel/HeaderActionsPlacement.php create mode 100644 tests/Unit/Panel/HeaderActionsPlacementTest.php diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1e3396b..fc47f53 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -62,6 +62,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `web_ui.header_actions` (`buttons` | `page_actions`, default `buttons`): with `page_actions` the header actions of the paths and redirects lists (New, Export, Clear routing cache, Import) are UiKit `View\Action` items of the square page-actions menu (the page header uses UiKit's split layout and no action stays a filled primary button), instead of a row of header buttons. The actions keep their kind, target, POST + CSRF form and dialog opener, and `PageHeader::$actions` is the same list a host compact header reads for its own page-actions menu. Needs UiKit 2.21+ (an older UiKit keeps the buttons). Nothing changes with the default. `Nowo\RoutingKitBundle\Panel\HeaderActionsPlacement`, `PanelView::listHeader()`. + ### Changed - Demo: runs in UiKit's demo platform shell (`nowo-tech/ui-kit-bundle` ^2.60); the demo's own header is gone and the pages use the shell page headers and section cards. Demo only, no bundle change. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index c38cdad..172eab3 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -26,6 +26,7 @@ Root key: `nowo_routing_kit`. | `web_ui.import_display` | `modal` | Signed JSON import: `modal` (UiKit `dialog` `#modal-routing-import`, opened from the "Import" page action; needs `js/nowo-ui-dialog.js`, loaded by the UiKit document layout; default since 1.9.1) or `inline` (card under the paths table) | | `web_ui.show_row_count` | `false` | "N row(s)" caption of the tables (default `false` since 1.9.1: the pagination summary already shows the count) | | `web_ui.primary_action_last` | `false` | Render "New path" after Export / Clear cache / Import | +| `web_ui.header_actions` | `buttons` | `buttons`: one button per header action. `page_actions`: the header actions (New, Export, Clear cache, Import; New redirect) are items of UiKit's page-actions menu (split header, no filled primary button); a host compact header reads the same `PageHeader::$actions`. UiKit 2.21+ | | `security.access_roles` | `[ROLE_ADMIN]` | At least one role required; **empty** = fail-closed (every panel request is denied). Still firewall the prefix | | `security.access_checker` | `null` | Custom `RoutingKitAccessCheckerInterface` service id (`null` = Configurable by roles) | | `security.allow_unauthenticated` | `false` | DEV/DEMO only — skip in-bundle role check (AllowAll) and show the **UNSAFE** banner on every panel page; panel requires SecurityBundle when `false` | diff --git a/docs/USAGE.md b/docs/USAGE.md index b15acfa..641bcff 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -210,7 +210,9 @@ UiKit and the panel inherits it — no RoutingKit-specific chrome configuration 3. **Scaffolds** — `templates/bundles/NowoUiKitBundle/page/list.html.twig` (or `form`, `confirm`) re-skins every list / form / confirm page of every bundle. 4. **Options** — `web_ui.import_display: inline` (card instead of the default dialog), `web_ui.show_row_count: true`, - `web_ui.primary_action_last: true`. Row actions follow `nowo_ui_kit.row_actions_display` / `icon_set`. + `web_ui.primary_action_last: true`, `web_ui.header_actions: page_actions` (New / Export / Clear cache / Import as + UiKit `View\Action` items of the page-actions menu instead of header buttons; default `buttons`). + Row actions follow `nowo_ui_kit.row_actions_display` / `icon_set`. 5. **One page** — `web_ui.templates.` with a template that extends `@!NowoRoutingKitBundle/…` and redefines a data block ([TEMPLATES.md](TEMPLATES.md)). diff --git a/src/Controller/RoutingPanelController.php b/src/Controller/RoutingPanelController.php index dcc8269..9d4d37f 100644 --- a/src/Controller/RoutingPanelController.php +++ b/src/Controller/RoutingPanelController.php @@ -106,7 +106,7 @@ public function index(Request $request): Response $actions = $this->view->primaryActionLast ? [...$actions, $create] : [$create, ...$actions]; $listPage = new ListPage( - new PageHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => $this->locales->getDefaultLocale()]), $actions, tabs: $this->view->nav('routes')), + $this->view->listHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => $this->locales->getDefaultLocale()]), $actions, $this->view->nav('routes')), [ new Column('routeName', PanelView::label('panel.col.route'), required: true), new Column('locale', PanelView::label('panel.col.locale')), diff --git a/src/Controller/UrlRedirectPanelController.php b/src/Controller/UrlRedirectPanelController.php index 556db76..65aea03 100644 --- a/src/Controller/UrlRedirectPanelController.php +++ b/src/Controller/UrlRedirectPanelController.php @@ -107,9 +107,9 @@ public function index(Request $request): Response return $this->view->render('redirects_index', 'redirects', [ 'page' => new ListPage( - new PageHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [ + $this->view->listHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [ new Action('create', PanelView::label('redirects.new'), $prefix . '/redirects/new', variant: 'primary', attributes: ['data-testid' => 'redirect-new']), - ], tabs: $this->view->nav('redirects')), + ], $this->view->nav('redirects')), [ new Column('sourcePath', PanelView::label('redirects.col.source'), required: true), new Column('targetUrl', PanelView::label('redirects.col.target'), required: true), diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 5d46052..14c25de 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -5,6 +5,7 @@ namespace Nowo\RoutingKitBundle\DependencyInjection; use InvalidArgumentException; +use Nowo\RoutingKitBundle\Panel\HeaderActionsPlacement; use Nowo\RoutingKitBundle\Panel\PanelChrome; use Nowo\RoutingKitBundle\Panel\PanelView; use Nowo\RoutingKitBundle\Redirect\ProtectedPaths; @@ -279,6 +280,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->info('Render the primary "New" action after the secondary page actions.') ->defaultFalse() ->end() + ->enumNode('header_actions') + ->info('Where the header actions (New, Export, Clear cache, Import) go: "buttons" (default) = one button per action in the page header; "page_actions" = UiKit View\\Action items in the square page-actions menu (UiKit split header; the compact header of the host reads the same PageHeader actions). Needs UiKit 2.21+.') + ->values(HeaderActionsPlacement::MODES) + ->defaultValue(HeaderActionsPlacement::BUTTONS) + ->end() ->booleanNode('main_landmark') ->info('Deprecated, no effect: the layout (UiKit or host) owns the
landmark.') ->setDeprecated(self::DEPRECATION_PACKAGE, self::DEPRECATION_VERSION, 'The "%path%.%node%" option is deprecated and has no effect: the layout owns the
landmark.') diff --git a/src/DependencyInjection/RoutingKitExtension.php b/src/DependencyInjection/RoutingKitExtension.php index ee72fef..e506b54 100644 --- a/src/DependencyInjection/RoutingKitExtension.php +++ b/src/DependencyInjection/RoutingKitExtension.php @@ -594,6 +594,7 @@ private function configurePanel(ContainerBuilder $container, array $config): voi ->setArgument('$showRowCount', (bool) $webUi['show_row_count']) ->setArgument('$primaryActionLast', (bool) $webUi['primary_action_last']) ->setArgument('$urlRedirectsEnabled', (bool) $config['url_redirects']['enabled']) + ->setArgument('$headerActions', (string) $webUi['header_actions']) // Shows panel.role_gate_warning: the in-bundle role check is skipped (AllowAll checker). ->setArgument('$roleGateDisabled', (bool) $config['security']['allow_unauthenticated']); diff --git a/src/Panel/HeaderActionsPlacement.php b/src/Panel/HeaderActionsPlacement.php new file mode 100644 index 0000000..fb0ea19 --- /dev/null +++ b/src/Panel/HeaderActionsPlacement.php @@ -0,0 +1,89 @@ +actions === [] || !property_exists(PageHeader::class, 'actionsLayout')) { + return $header; + } + + return new PageHeader($header->title, $header->intro, self::menuActions($header->actions), $header->breadcrumbs, $header->breadcrumbCollection, $header->tabs, $header->breadcrumbsMode, $header->back, $header->status, 'split'); + } + + /** + * The same actions with the filled variant removed from the create / save ones, so none of them is the header's + * primary button; destructive actions keep their variant (UiKit puts them last, in red). + * + * @param list $actions + * + * @return list + */ + public static function menuActions(array $actions): array + { + $menu = []; + foreach ($actions as $action) { + $menu[] = $action->resolvedVariant() === 'primary' ? self::withVariant($action, 'secondary') : $action; + } + + return $menu; + } + + private static function withVariant(Action $action, string $variant): Action + { + return new Action( + kind: $action->kind, + label: $action->label, + href: $action->href, + route: $action->route, + params: $action->params, + method: $action->method, + csrfToken: $action->csrfToken, + confirm: $action->confirm, + icon: $action->icon, + variant: $variant, + attributes: $action->attributes, + form: $action->form, + csrfField: $action->csrfField, + modalId: $action->modalId, + disabled: $action->disabled, + visible: $action->visible, + display: $action->display, + confirmScope: $action->confirmScope, + fallbackHref: $action->fallbackHref, + dialogId: $action->dialogId, + title: $action->title, + ); + } +} diff --git a/src/Panel/PanelView.php b/src/Panel/PanelView.php index 37df1e4..f0a18ee 100644 --- a/src/Panel/PanelView.php +++ b/src/Panel/PanelView.php @@ -11,6 +11,7 @@ use Nowo\UiKitBundle\View\AreaNav; use Nowo\UiKitBundle\View\AreaNavItem; use Nowo\UiKitBundle\View\Label; +use Nowo\UiKitBundle\View\PageHeader; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; @@ -78,6 +79,7 @@ public function __construct( public bool $primaryActionLast = false, public bool $urlRedirectsEnabled = false, public bool $roleGateDisabled = false, + public string $headerActions = HeaderActionsPlacement::BUTTONS, ) { } @@ -104,6 +106,17 @@ public static function importDialogAction(): Action ]); } + /** + * Page header of the list pages: the header actions as buttons or, with {@code web_ui.header_actions: page_actions}, + * in the page-actions menu ({@see HeaderActionsPlacement}). + * + * @param list $actions + */ + public function listHeader(Label $title, Label $intro, array $actions, ?AreaNav $tabs): PageHeader + { + return HeaderActionsPlacement::apply($this->headerActions, new PageHeader($title, $intro, $actions, tabs: $tabs)); + } + public function template(string $page): string { if (!array_key_exists($page, self::TEMPLATES)) { diff --git a/src/Resources/config/packages/nowo_routing_kit.yaml b/src/Resources/config/packages/nowo_routing_kit.yaml index 2914a1c..6b2bfaa 100644 --- a/src/Resources/config/packages/nowo_routing_kit.yaml +++ b/src/Resources/config/packages/nowo_routing_kit.yaml @@ -24,6 +24,7 @@ nowo_routing_kit: import_display: modal # modal (dialog from the Import action) | inline (card under the table) show_row_count: false # the pagination summary already shows the count primary_action_last: false + header_actions: buttons # buttons | page_actions (UiKit View\Action items in the page-actions menu, UiKit 2.21+) security: access_roles: [ROLE_ADMIN] allow_unauthenticated: false diff --git a/tests/Integration/Contract/PageContractTest.php b/tests/Integration/Contract/PageContractTest.php index 743c626..17e3c16 100644 --- a/tests/Integration/Contract/PageContractTest.php +++ b/tests/Integration/Contract/PageContractTest.php @@ -9,6 +9,7 @@ use Nowo\UiKitBundle\Test\PageContractTestCase; use Nowo\UiKitBundle\Test\PageFixture; use Nowo\UiKitBundle\View\ConfirmPage; +use Nowo\UiKitBundle\View\PageHeader; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bridge\Twig\Extension\TranslationExtension; use Symfony\Component\Translation\DataCollectorTranslator; @@ -38,6 +39,8 @@ public static function pageFixtures(): iterable yield 'path form (edit)' => new PageFixture('@NowoRoutingKitBundle/panel/form.html.twig', PanelPageFixtures::form($definitions[2])); yield 'path form (create, controller override)' => new PageFixture('@NowoRoutingKitBundle/panel/form.html.twig', PanelPageFixtures::form(null, controllerOverride: true)); yield 'path delete (no-JS confirm)' => new PageFixture('@NowoRoutingKitBundle/panel/delete.html.twig', PanelPageFixtures::delete($definitions[2])); + yield 'paths list (header actions in the page-actions menu)' => new PageFixture('@NowoRoutingKitBundle/panel/index.html.twig', PanelPageFixtures::index($definitions, headerActions: 'page_actions')); + yield 'redirects list (header actions in the page-actions menu)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, headerActions: 'page_actions')); yield 'redirects list' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, 'created')); yield 'redirects list (row count)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, rowCount: true)); yield 'redirects list (empty)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex([])); @@ -110,6 +113,48 @@ public function testListRowsRenderTheBundleCellsAndTheConfirmDialogs(): void self::assertStringNotContainsString('routing-kit-role-gate-warning', $html); } + public function testHeaderActionsGoToThePageActionsMenuOnRequest(): void + { + $header = PanelPageFixtures::index(PanelPageFixtures::definitions(), headerActions: 'page_actions')['page']->header; + self::assertSame('split', $header->actionsLayout); + $html = $this->headerHtml($header); + + self::assertStringContainsString('data-nowo-ui-header-more', $html, 'The square page-actions menu replaces the buttons.'); + self::assertStringContainsString('href="/_routing/new"', $html, 'New path is a menu item.'); + self::assertStringContainsString('action="/_routing/export"', $html, 'Export keeps its POST form.'); + self::assertStringContainsString('action="/_routing/clear-cache"', $html); + self::assertStringContainsString('data-testid="routing-kit-import-open"', $html, 'Import keeps its dialog opener.'); + self::assertStringNotContainsString('nowo-ui-btn--primary', substr($html, 0, (int) strpos($html, 'data-nowo-ui-header-more')), 'No filled primary button in the header.'); + } + + public function testHeaderActionsStayButtonsInTheKitHeaderByDefault(): void + { + $header = PanelPageFixtures::index(PanelPageFixtures::definitions())['page']->header; + + self::assertSame('toolbar', $header->actionsLayout); + self::assertSame('primary', $header->actions[0]->resolvedVariant(), 'New path stays the primary button.'); + } + + public function testRedirectsHeaderActionsGoToThePageActionsMenuOnRequest(): void + { + $header = PanelPageFixtures::redirectsIndex(PanelPageFixtures::redirects(), headerActions: 'page_actions')['page']->header; + self::assertSame('split', $header->actionsLayout); + $html = $this->headerHtml($header); + + self::assertStringContainsString('data-nowo-ui-header-more', $html); + self::assertStringContainsString('data-testid="redirect-new"', $html); + self::assertStringContainsString('href="/_routing/redirects/new"', $html); + } + + /** + * The header actions the way UiKit's page header draws a split header (the contract test's stub theme replaces the + * page header partial, so the real `header_actions` partial is rendered on the header's actions). + */ + private function headerHtml(PageHeader $header): string + { + return $this->renderPage(new PageFixture('@NowoUiKitBundle/partials/_header_actions.html.twig', ['actions' => $header->actions, 'bundle' => PanelView::BUNDLE]))->html; + } + public function testRouteDeleteConfirmPagePostsWithCsrf(): void { $html = $this->renderPage(new PageFixture('@NowoRoutingKitBundle/panel/delete.html.twig', PanelPageFixtures::delete(PanelPageFixtures::definitions()[2])))->html; diff --git a/tests/Support/PanelPageFixtures.php b/tests/Support/PanelPageFixtures.php index 63ad2df..89b587c 100644 --- a/tests/Support/PanelPageFixtures.php +++ b/tests/Support/PanelPageFixtures.php @@ -70,7 +70,7 @@ public static function redirects(): array * * @return array */ - public static function index(array $rows, string $importDisplay = 'modal', bool $roleGateDisabled = false, bool $redirects = true, bool $rowCount = false): array + public static function index(array $rows, string $importDisplay = 'modal', bool $roleGateDisabled = false, bool $redirects = true, bool $rowCount = false, string $headerActions = 'buttons'): array { $rowActions = []; foreach ($rows as $key => $row) { @@ -90,7 +90,7 @@ public static function index(array $rows, string $importDisplay = 'modal', bool return [ 'page' => new ListPage( - new PageHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => 'en']), $actions, tabs: self::view($redirects)->nav('routes')), + self::view($redirects, $headerActions)->listHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => 'en']), $actions, self::view($redirects)->nav('routes')), [ new Column('routeName', PanelView::label('panel.col.route'), required: true), new Column('locale', PanelView::label('panel.col.locale')), @@ -155,7 +155,7 @@ public static function form(?RoutePathDefinition $existing, array $conflicts = [ * * @return array */ - public static function redirectsIndex(array $rows, ?string $status = null, bool $rowCount = false): array + public static function redirectsIndex(array $rows, ?string $status = null, bool $rowCount = false, string $headerActions = 'buttons'): array { $rowActions = []; foreach ($rows as $key => $redirect) { @@ -167,9 +167,9 @@ public static function redirectsIndex(array $rows, ?string $status = null, bool return [ 'page' => new ListPage( - new PageHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [ + self::view(true, $headerActions)->listHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [ new Action('create', PanelView::label('redirects.new'), self::PREFIX . '/redirects/new', variant: 'primary', attributes: ['data-testid' => 'redirect-new']), - ], tabs: self::view()->nav('redirects')), + ], self::view()->nav('redirects')), [ new Column('sourcePath', PanelView::label('redirects.col.source'), required: true), new Column('targetUrl', PanelView::label('redirects.col.target'), required: true), @@ -271,9 +271,9 @@ public static function shared(string $section, bool $roleGateDisabled = false): ]; } - public static function view(bool $redirects = true): PanelView + public static function view(bool $redirects = true, string $headerActions = 'buttons'): PanelView { - return new PanelView(new Environment(new ArrayLoader()), self::PREFIX, urlRedirectsEnabled: $redirects); + return new PanelView(new Environment(new ArrayLoader()), self::PREFIX, urlRedirectsEnabled: $redirects, headerActions: $headerActions); } public static function factory(): FormFactoryInterface diff --git a/tests/Unit/DependencyInjection/PanelChromeConfigTest.php b/tests/Unit/DependencyInjection/PanelChromeConfigTest.php index b79e790..7b3c31c 100644 --- a/tests/Unit/DependencyInjection/PanelChromeConfigTest.php +++ b/tests/Unit/DependencyInjection/PanelChromeConfigTest.php @@ -28,10 +28,19 @@ public function testDefaultsKeepTheLegacyChrome(): void self::assertSame('modal', $webUi['import_display'], 'Import dialog by default since 1.9.1.'); self::assertFalse($webUi['show_row_count'], 'No row-count caption by default since 1.9.1.'); self::assertFalse($webUi['primary_action_last']); + self::assertSame('buttons', $webUi['header_actions'], 'Header actions stay buttons by default.'); self::assertSame([], $webUi['delete_confirm_attr']); self::assertArrayNotHasKey('main_landmark', $webUi); } + public function testHeaderActionsAcceptsOnlyKnownModes(): void + { + self::assertSame('page_actions', $this->process(['web_ui' => ['header_actions' => 'page_actions']])['web_ui']['header_actions']); + + $this->expectException(InvalidConfigurationException::class); + $this->process(['web_ui' => ['header_actions' => 'toolbar']]); + } + public function testUnknownClassKeyIsRejected(): void { $this->expectException(InvalidConfigurationException::class); diff --git a/tests/Unit/DependencyInjection/RoutingKitExtensionTest.php b/tests/Unit/DependencyInjection/RoutingKitExtensionTest.php index 5da9c8f..3304e5b 100644 --- a/tests/Unit/DependencyInjection/RoutingKitExtensionTest.php +++ b/tests/Unit/DependencyInjection/RoutingKitExtensionTest.php @@ -733,6 +733,7 @@ public function testPanelViewReceivesTheWebUiSettings(): void 'import_display' => 'modal', 'show_row_count' => false, 'primary_action_last' => true, + 'header_actions' => 'page_actions', ], ]], $container); @@ -743,6 +744,7 @@ public function testPanelViewReceivesTheWebUiSettings(): void self::assertSame('modal', $view->getArgument('$importDisplay')); self::assertFalse($view->getArgument('$showRowCount')); self::assertTrue($view->getArgument('$primaryActionLast')); + self::assertSame('page_actions', $view->getArgument('$headerActions')); self::assertFalse($view->getArgument('$urlRedirectsEnabled')); self::assertSame('/admin/routing', $container->getParameter('nowo.routing_kit.web_ui.path_prefix')); self::assertSame('ROLE_ROUTES', $container->getParameter('nowo.routing_kit.panel.role')); diff --git a/tests/Unit/Panel/HeaderActionsPlacementTest.php b/tests/Unit/Panel/HeaderActionsPlacementTest.php new file mode 100644 index 0000000..84264cd --- /dev/null +++ b/tests/Unit/Panel/HeaderActionsPlacementTest.php @@ -0,0 +1,62 @@ +actions); + self::assertSame('toolbar', $header->actionsLayout); + } + + public function testPageActionsUseTheSplitLayoutWithoutAPrimaryButton(): void + { + $dialog = new Action('import', PanelView::label('panel.import'), '#modal', attributes: ['data-nowo-ui-dialog-open' => 'modal'], dialogId: 'modal'); + $delete = new Action('delete', 'Delete', '/x', method: 'POST', confirm: new Confirm('Sure?')); + $header = HeaderActionsPlacement::apply(HeaderActionsPlacement::PAGE_ACTIONS, new PageHeader('T', 'intro', [Action::create('/new', 'New'), $dialog, $delete], [new Crumb('C')], tabs: new AreaNav([], 'nav'))); + + self::assertSame('split', $header->actionsLayout); + self::assertSame('intro', $header->intro); + self::assertCount(1, $header->breadcrumbs); + self::assertNotNull($header->tabs); + self::assertCount(3, $header->actions); + self::assertSame('create', $header->actions[0]->kind); + self::assertSame('secondary', $header->actions[0]->resolvedVariant()); + self::assertSame('/new', $header->actions[0]->href); + self::assertSame($dialog, $header->actions[1], 'Non-primary actions are the same objects.'); + self::assertSame($delete, $header->actions[2]); + } + + public function testAHeaderWithoutActionsIsLeftAlone(): void + { + $header = new PageHeader('T'); + + self::assertSame($header, HeaderActionsPlacement::apply(HeaderActionsPlacement::PAGE_ACTIONS, $header)); + } + + public function testDemotedActionKeepsEverythingElse(): void + { + $confirm = new Confirm('Sure?'); + $source = new Action('create', 'New', '/new', method: 'post', csrfToken: 't', confirm: $confirm, icon: 'plus', variant: 'primary', attributes: ['data-testid' => 'x'], csrfField: '_c', modalId: 'm', disabled: true, visible: false, display: 'icon_text', confirmScope: 's', fallbackHref: '/fb', title: 'tip'); + + $copy = HeaderActionsPlacement::menuActions([$source])[0]; + + self::assertSame('secondary', $copy->variant); + self::assertSame(['create', 'POST', 't', $confirm, 'plus', ['data-testid' => 'x'], '_c', 'm', true, false, 'icon_text', 's', '/fb', 'tip'], [$copy->kind, $copy->method, $copy->csrfToken, $copy->confirm, $copy->icon, $copy->attributes, $copy->csrfField, $copy->modalId, $copy->disabled, $copy->visible, $copy->display, $copy->confirmScope, $copy->fallbackHref, $copy->title]); + } +}