diff --git a/src/Utils/Testing/EntityList/PendingEntityList.php b/src/Utils/Testing/EntityList/PendingEntityList.php index b5d075fb5..dbf0f287b 100644 --- a/src/Utils/Testing/EntityList/PendingEntityList.php +++ b/src/Utils/Testing/EntityList/PendingEntityList.php @@ -182,13 +182,15 @@ public function instanceCommand(string $commandKeyOrClassName, int|string $insta protected function entityListShowField(): ?SharpShowEntityListField { - /** @noinspection PhpIncompatibleReturnTypeInspection */ - return $this->parent instanceof PendingShow - ? $this->parent->show->getBuiltFields() + if ($this->parent instanceof PendingShow) { + /** @noinspection PhpIncompatibleReturnTypeInspection */ + return $this->parent->show->getBuiltFields() ->first(fn (SharpShowField $field) => $field instanceof SharpShowEntityListField && $field->toArray()['entityListKey'] === $this->entityKey - ) - : null; + ); + } + + return null; } protected function entityListQueryParams(): array diff --git a/src/Utils/Testing/GeneratesCurrentPageUrl.php b/src/Utils/Testing/GeneratesCurrentPageUrl.php index 6bb9c58d0..72c1d4ef7 100644 --- a/src/Utils/Testing/GeneratesCurrentPageUrl.php +++ b/src/Utils/Testing/GeneratesCurrentPageUrl.php @@ -2,18 +2,16 @@ namespace Code16\Sharp\Utils\Testing; -use Code16\Sharp\Utils\Links\BreadcrumbBuilder; - trait GeneratesCurrentPageUrl { - private function buildCurrentPageUrl(BreadcrumbBuilder $builder): string + private function buildCurrentPageUrl(string $breadcrumbUri): string { return url( sprintf( '/%s/%s/%s', sharp()->config()->get('custom_url_segment'), sharp()->context()->globalFilterUrlSegmentValue(), - $builder->generateUri() + $breadcrumbUri ) ); } diff --git a/src/Utils/Testing/IsPendingComponent.php b/src/Utils/Testing/IsPendingComponent.php index 6f150da56..ced8f7fef 100644 --- a/src/Utils/Testing/IsPendingComponent.php +++ b/src/Utils/Testing/IsPendingComponent.php @@ -18,9 +18,14 @@ protected function getParentUri(): string return $this->breadcrumbBuilder($this->parents())->generateUri(); } + protected function getCurrentUri(): string + { + return $this->breadcrumbBuilder([...$this->parents(), $this])->generateUri(); + } + protected function getCurrentPageUrlFromParents(): string { - return $this->buildCurrentPageUrl($this->breadcrumbBuilder([...$this->parents(), $this])); + return $this->buildCurrentPageUrl($this->getCurrentUri()); } protected function breadcrumbBuilder(array $components): BreadcrumbBuilder diff --git a/src/Utils/Testing/SharpAssertions.php b/src/Utils/Testing/SharpAssertions.php index e5709258e..f5d8c4897 100644 --- a/src/Utils/Testing/SharpAssertions.php +++ b/src/Utils/Testing/SharpAssertions.php @@ -103,7 +103,7 @@ public function deleteFromSharpList(string $entityClassNameOrKey, mixed $instanc ->withHeader( SharpBreadcrumb::CURRENT_PAGE_URL_HEADER, $this->buildCurrentPageUrl( - $this->breadcrumbBuilder($entityKey) + $this->breadcrumbBuilder($entityKey)->generateUri() ), ) ->delete( @@ -253,7 +253,7 @@ public function callSharpInstanceCommandFromList( ->withHeader( SharpBreadcrumb::CURRENT_PAGE_URL_HEADER, $this->buildCurrentPageUrl( - $this->breadcrumbBuilder($entityKey) + $this->breadcrumbBuilder($entityKey)->generateUri() ), ) ->postJson( @@ -284,7 +284,7 @@ public function callSharpInstanceCommandFromShow( ->withHeader( SharpBreadcrumb::CURRENT_PAGE_URL_HEADER, $this->buildCurrentPageUrl( - $this->breadcrumbBuilder($entityKey, $instanceId) + $this->breadcrumbBuilder($entityKey, $instanceId)->generateUri() ), ) ->postJson( @@ -313,7 +313,7 @@ public function callSharpEntityCommandFromList( return $this ->withHeader( SharpBreadcrumb::CURRENT_PAGE_URL_HEADER, - $this->buildCurrentPageUrl($this->breadcrumbBuilder($entityKey)) + $this->buildCurrentPageUrl($this->breadcrumbBuilder($entityKey)->generateUri()) ) ->postJson( route('code16.sharp.api.list.command.entity', compact('entityKey', 'commandKey')), diff --git a/src/Utils/Testing/Show/PendingShow.php b/src/Utils/Testing/Show/PendingShow.php index dc1d49c37..5d67aa517 100644 --- a/src/Utils/Testing/Show/PendingShow.php +++ b/src/Utils/Testing/Show/PendingShow.php @@ -32,6 +32,9 @@ public function __construct( ) { $this->entityKey = app(SharpEntityManager::class)->entityKeyFor($entityKey); $this->show = app(SharpEntityManager::class)->entityFor($this->entityKey)->getShowOrFail(); + sharp()->context()->breadcrumb()->forceRequestSegments( + explode('/', $this->getCurrentUri()) + ); } public function sharpForm(string $entityClassNameOrKey): PendingForm