Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions src/Utils/Testing/SharpAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Code16\Sharp\Http\Context\SharpBreadcrumb;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
use Code16\Sharp\Utils\Links\BreadcrumbBuilder;

trait SharpAssertions
Expand Down Expand Up @@ -39,8 +40,10 @@ public function withSharpBreadcrumb(Closure $callback): self
return $this;
}

public function deleteFromSharpShow(string $entityKey, $instanceId)
public function deleteFromSharpShow(string $entityClassNameOrKey, $instanceId)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->delete(
route(
Expand All @@ -54,8 +57,10 @@ public function deleteFromSharpShow(string $entityKey, $instanceId)
);
}

public function deleteFromSharpList(string $entityKey, $instanceId)
public function deleteFromSharpList(string $entityClassNameOrKey, $instanceId)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->withHeader(
SharpBreadcrumb::CURRENT_PAGE_URL_HEADER,
Expand All @@ -66,8 +71,10 @@ public function deleteFromSharpList(string $entityKey, $instanceId)
->delete(route('code16.sharp.api.list.delete', [$entityKey, $instanceId]));
}

public function getSharpForm(string $entityKey, $instanceId = null)
public function getSharpForm(string $entityClassNameOrKey, $instanceId = null)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->get(
$instanceId
Expand All @@ -91,8 +98,10 @@ public function getSharpForm(string $entityKey, $instanceId = null)
);
}

public function getSharpSingleForm(string $entityKey)
public function getSharpSingleForm(string $entityClassNameOrKey)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->get(
route(
Expand All @@ -106,8 +115,10 @@ public function getSharpSingleForm(string $entityKey)
);
}

public function updateSharpForm(string $entityKey, $instanceId, array $data)
public function updateSharpForm(string $entityClassNameOrKey, $instanceId, array $data)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->post(
route(
Expand All @@ -122,8 +133,10 @@ public function updateSharpForm(string $entityKey, $instanceId, array $data)
);
}

public function updateSharpSingleForm(string $entityKey, array $data)
public function updateSharpSingleForm(string $entityClassNameOrKey, array $data)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->post(
route(
Expand All @@ -137,8 +150,10 @@ public function updateSharpSingleForm(string $entityKey, array $data)
);
}

public function getSharpShow(string $entityKey, $instanceId)
public function getSharpShow(string $entityClassNameOrKey, $instanceId)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->get(
route(
Expand All @@ -153,8 +168,10 @@ public function getSharpShow(string $entityKey, $instanceId)
);
}

public function storeSharpForm(string $entityKey, array $data)
public function storeSharpForm(string $entityClassNameOrKey, array $data)
{
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

return $this
->post(
route(
Expand All @@ -170,12 +187,14 @@ public function storeSharpForm(string $entityKey, array $data)
}

public function callSharpInstanceCommandFromList(
string $entityKey,
string $entityClassNameOrKey,
$instanceId,
string $commandKeyOrClassName,
array $data = [],
?string $commandStep = null
) {
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

$commandKey = class_exists($commandKeyOrClassName)
? class_basename($commandKeyOrClassName)
: $commandKeyOrClassName;
Expand All @@ -197,12 +216,14 @@ public function callSharpInstanceCommandFromList(
}

public function callSharpInstanceCommandFromShow(
string $entityKey,
string $entityClassNameOrKey,
$instanceId,
string $commandKeyOrClassName,
array $data = [],
?string $commandStep = null
) {
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

$commandKey = class_exists($commandKeyOrClassName)
? class_basename($commandKeyOrClassName)
: $commandKeyOrClassName;
Expand All @@ -224,11 +245,13 @@ public function callSharpInstanceCommandFromShow(
}

public function callSharpEntityCommandFromList(
string $entityKey,
string $entityClassNameOrKey,
string $commandKeyOrClassName,
array $data = [],
?string $commandStep = null
) {
$entityKey = $this->resolveEntityKey($entityClassNameOrKey);

$commandKey = class_exists($commandKeyOrClassName)
? class_basename($commandKeyOrClassName)
: $commandKeyOrClassName;
Expand Down Expand Up @@ -272,4 +295,9 @@ private function buildCurrentPageUrl(BreadcrumbBuilder $builder): string
)
);
}

private function resolveEntityKey(string $entityClassNameOrKey): string
{
return app(SharpEntityManager::class)->entityKeyFor($entityClassNameOrKey);
}
}
Loading