Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 10, 2024
1 parent 3768f42 commit 0fb66c0
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions tests/Menu/Matcher/Voter/AdminVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function provideMatchingCases(): iterable
yield 'has admin' => [$this->getAdmin('_sonata_admin', true, true), '_sonata_admin', null, true];
yield 'has child admin' => [$this->getChildAdmin('_sonata_admin', '_sonata_child_admin', true, true), '_sonata_admin|_sonata_child_admin', null, true];
yield 'has bad child admin' => [$this->getChildAdmin('_sonata_admin', '_sonata_child_admin', true, true), '_sonata_admin|_sonata_child_admin_unexpected', null, null];
yield 'has nested child admin' => [$this->getNestedChildAdmin('_sonata_admin', '_sonata_child_admin', '_sonata_nested_child_admin', true, true), '_sonata_admin|_sonata_child_admin|_sonata_nested_child_admin', null, true];
yield 'has bad nested child admin' => [$this->getNestedChildAdmin('_sonata_admin', '_sonata_child_admin', '_sonata_nested_child_admin', true, true), '_sonata_admin|_sonata_child_admin|_sonata_nested_child_admin_unexpected', null, null];
yield 'direct link' => ['admin_post', null, 'admin_post', true];
yield 'no direct link' => ['admin_post', null, 'admin_blog', null];
}
Expand All @@ -81,7 +83,7 @@ private function getAdmin(string $code, bool $list = false, bool $granted = fals
->with('list')
->willReturn($granted);
$admin
->method('getCode')
->method('getBaseCodeRoute')
->willReturn($code);
$admin
->method('getChildren')
Expand Down Expand Up @@ -109,7 +111,7 @@ private function getChildAdmin(
->with('list')
->willReturn($granted);
$parentAdmin
->method('getCode')
->method('getBaseCodeRoute')
->willReturn($parentCode);

$childAdmin = $this->createMock(AdminInterface::class);
Expand All @@ -123,4 +125,48 @@ private function getChildAdmin(

return $parentAdmin;
}

/**
* @return AdminInterface<object>
*/
private function getNestedChildAdmin(
string $grandParentCode,
string $parentCode,
string $childCode,
bool $list = false,
bool $granted = false
): AdminInterface {
$grandParentAdmin = $this->createMock(AdminInterface::class);
$grandParentAdmin
->method('hasRoute')
->with('list')
->willReturn($list);
$grandParentAdmin
->method('hasAccess')
->with('list')
->willReturn($granted);
$grandParentAdmin
->method('getBaseCodeRoute')
->willReturn($grandParentCode);

$parentAdmin = $this->createMock(AdminInterface::class);
$parentAdmin
->method('getBaseCodeRoute')
->willReturn(sprintf('%s|%s', $grandParentCode, $parentCode));

$grandParentAdmin
->method('getChildren')
->willReturn([$parentAdmin]);

$childAdmin = $this->createMock(AdminInterface::class);
$childAdmin
->method('getBaseCodeRoute')
->willReturn(sprintf('%s|%s|%s', $grandParentCode, $parentCode, $childCode));

$parentAdmin
->method('getChildren')
->willReturn([$childAdmin]);

return $grandParentAdmin;
}
}

0 comments on commit 0fb66c0

Please sign in to comment.