Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use manager for adding items in tests #226

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,10 @@ public function testGetRole(): void

public function testAdd(): void
{
$time = time();
$newItem = (new Permission('Delete post'))->withCreatedAt($time)->withUpdatedAt($time);

$storage = $this->getItemsStorage();
$newItem = new Permission('Delete post');
$storage->add($newItem);

$this->assertInstanceOf(Permission::class, $storage->get('Delete post'));
Expand Down
33 changes: 13 additions & 20 deletions tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,15 @@ public function testCanAddChildPermissionToRole(): void
public function testCanAddChildToNonExistingItem(): void
{
$itemsStorage = $this->createItemsStorage();
$itemsStorage->add(new Role('author'));

$manager = $this->createManager($itemsStorage);
$manager = $this->createManager($itemsStorage)->addRole(new Role('author'));

$this->assertFalse($manager->canAddChild('admin', 'author'));
}

public function testCanAddNonExistingChild(): void
{
$itemsStorage = $this->createItemsStorage();
$itemsStorage->add(new Role('author'));

$manager = $this->createManager($itemsStorage);
$manager = $this->createManager($itemsStorage)->addRole(new Role('author'));

$this->assertFalse($manager->canAddChild('author', 'reader'));
}
Expand Down Expand Up @@ -449,21 +445,15 @@ public function testHasChild(): void
public function testAssign(): void
{
$itemsStorage = $this->createItemsStorage();
$itemsStorage->add(new Role('author'));
$itemsStorage->add(new Role('reader'));
$itemsStorage->add(new Role('writer'));
$itemsStorage->add(new Role('default-role'));

$assignmentsStorage = $this->createAssignmentsStorage();

$manager = $this->createManager($itemsStorage, $assignmentsStorage);
$manager->setDefaultRoleNames(['default-role']);

$manager->assign('reader', 'readingAuthor');
$readerAssignment = $assignmentsStorage->get('reader', 'readingAuthor');

$manager->assign('author', 'readingAuthor');
$authorAssignment = $assignmentsStorage->get('author', 'readingAuthor');
$manager = $this->createManager($itemsStorage, $assignmentsStorage)
->addRole(new Role('author'))
->addRole(new Role('reader'))
->addRole(new Role('writer'))
->addRole(new Role('default-role'))
->setDefaultRoleNames(['default-role'])
->assign('reader', 'readingAuthor')
->assign('author', 'readingAuthor');

$this->assertEqualsCanonicalizing(
[
Expand All @@ -475,11 +465,14 @@ public function testAssign(): void
);

$createdAt = 1_683_707_079;
$readerAssignment = $assignmentsStorage->get('reader', 'readingAuthor');

$this->assertSame('readingAuthor', $readerAssignment->getUserId());
$this->assertSame('reader', $readerAssignment->getItemName());
$this->assertSame($createdAt, $readerAssignment->getCreatedAt());

$authorAssignment = $assignmentsStorage->get('author', 'readingAuthor');

$this->assertSame('readingAuthor', $authorAssignment->getUserId());
$this->assertSame('author', $authorAssignment->getItemName());
$this->assertSame($createdAt, $authorAssignment->getCreatedAt());
Expand Down
Loading