1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

Rolled out reference pages to all entities, added testing

Including testing to check permissions applied to listed references.
This commit is contained in:
Dan Brown
2022-08-19 22:40:44 +01:00
parent d5465726e2
commit d198332d3c
9 changed files with 182 additions and 19 deletions

View File

@@ -54,6 +54,46 @@ class ReferencesTest extends TestCase
$this->assertDatabaseMissing('references', ['to_id' => $pageA->id, 'to_type' => $pageA->getMorphClass()]);
}
public function test_references_to_visible_on_references_page()
{
$entities = $this->getEachEntityType();
$this->asEditor();
foreach ($entities as $entity) {
$this->createReference($entities['page'], $entity);
}
foreach ($entities as $entity) {
$resp = $this->get($entity->getUrl('/references'));
$resp->assertSee('References');
$resp->assertSee($entities['page']->name);
$resp->assertDontSee('There are no tracked references');
}
}
public function test_reference_not_visible_if_view_permission_does_not_permit()
{
/** @var Page $page */
/** @var Page $pageB */
$page = Page::query()->first();
$pageB = Page::query()->where('id', '!=', $page->id)->first();
$this->createReference($pageB, $page);
$this->setEntityRestrictions($pageB);
$this->asEditor()->get($page->getUrl('/references'))->assertDontSee($pageB->name);
$this->asAdmin()->get($page->getUrl('/references'))->assertSee($pageB->name);
}
public function test_reference_page_shows_empty_state_with_no_references()
{
/** @var Page $page */
$page = Page::query()->first();
$this->asEditor()
->get($page->getUrl('/references'))
->assertSee('There are no tracked references');
}
protected function createReference(Model $from, Model $to)
{
(new Reference())->forceFill([

View File

@@ -430,7 +430,7 @@ abstract class TestCase extends BaseTestCase
}
/**
* @return Entity[]
* @return array{page: Page, chapter: Chapter, book: Book, bookshelf: Bookshelf}
*/
protected function getEachEntityType(): array
{