mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Copied over work from user_permissions branch
Only that relevant to the additional testing work.
This commit is contained in:
@@ -16,21 +16,20 @@ class BookShelfTest extends TestCase
|
||||
|
||||
public function test_shelves_shows_in_header_if_have_view_permissions()
|
||||
{
|
||||
$viewer = $this->getViewer();
|
||||
$viewer = $this->users->viewer();
|
||||
$resp = $this->actingAs($viewer)->get('/');
|
||||
$this->withHtml($resp)->assertElementContains('header', 'Shelves');
|
||||
|
||||
$viewer->roles()->delete();
|
||||
$this->giveUserPermissions($viewer);
|
||||
$resp = $this->actingAs($viewer)->get('/');
|
||||
$this->withHtml($resp)->assertElementNotContains('header', 'Shelves');
|
||||
|
||||
$this->giveUserPermissions($viewer, ['bookshelf-view-all']);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['bookshelf-view-all']);
|
||||
$resp = $this->actingAs($viewer)->get('/');
|
||||
$this->withHtml($resp)->assertElementContains('header', 'Shelves');
|
||||
|
||||
$viewer->roles()->delete();
|
||||
$this->giveUserPermissions($viewer, ['bookshelf-view-own']);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['bookshelf-view-own']);
|
||||
$resp = $this->actingAs($viewer)->get('/');
|
||||
$this->withHtml($resp)->assertElementContains('header', 'Shelves');
|
||||
}
|
||||
@@ -38,14 +37,14 @@ class BookShelfTest extends TestCase
|
||||
public function test_shelves_shows_in_header_if_have_any_shelve_view_permission()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$this->giveUserPermissions($user, ['image-create-all']);
|
||||
$this->permissions->grantUserRolePermissions($user, ['image-create-all']);
|
||||
$shelf = $this->entities->shelf();
|
||||
$userRole = $user->roles()->first();
|
||||
|
||||
$resp = $this->actingAs($user)->get('/');
|
||||
$this->withHtml($resp)->assertElementNotContains('header', 'Shelves');
|
||||
|
||||
$this->entities->setPermissions($shelf, ['view'], [$userRole]);
|
||||
$this->permissions->setEntityPermissions($shelf, ['view'], [$userRole]);
|
||||
|
||||
$resp = $this->get('/');
|
||||
$this->withHtml($resp)->assertElementContains('header', 'Shelves');
|
||||
@@ -69,7 +68,7 @@ class BookShelfTest extends TestCase
|
||||
$resp->assertSee($book->name);
|
||||
$resp->assertSee($book->getUrl());
|
||||
|
||||
$this->entities->setPermissions($book, []);
|
||||
$this->permissions->setEntityPermissions($book, []);
|
||||
|
||||
$resp = $this->asEditor()->get('/shelves');
|
||||
$resp->assertDontSee($book->name);
|
||||
@@ -93,7 +92,7 @@ class BookShelfTest extends TestCase
|
||||
],
|
||||
]));
|
||||
$resp->assertRedirect();
|
||||
$editorId = $this->getEditor()->id;
|
||||
$editorId = $this->users->editor()->id;
|
||||
$this->assertDatabaseHas('bookshelves', array_merge($shelfInfo, ['created_by' => $editorId, 'updated_by' => $editorId]));
|
||||
|
||||
$shelf = Bookshelf::where('name', '=', $shelfInfo['name'])->first();
|
||||
@@ -186,13 +185,13 @@ class BookShelfTest extends TestCase
|
||||
$this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(1)', $books[0]->name);
|
||||
$this->withHtml($resp)->assertElementNotContains('.book-content a.grid-card:nth-child(3)', $books[0]->name);
|
||||
|
||||
setting()->putUser($this->getEditor(), 'shelf_books_sort_order', 'desc');
|
||||
setting()->putUser($this->users->editor(), 'shelf_books_sort_order', 'desc');
|
||||
$resp = $this->asEditor()->get($shelf->getUrl());
|
||||
$this->withHtml($resp)->assertElementNotContains('.book-content a.grid-card:nth-child(1)', $books[0]->name);
|
||||
$this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(3)', $books[0]->name);
|
||||
|
||||
setting()->putUser($this->getEditor(), 'shelf_books_sort_order', 'desc');
|
||||
setting()->putUser($this->getEditor(), 'shelf_books_sort', 'name');
|
||||
setting()->putUser($this->users->editor(), 'shelf_books_sort_order', 'desc');
|
||||
setting()->putUser($this->users->editor(), 'shelf_books_sort', 'name');
|
||||
$resp = $this->asEditor()->get($shelf->getUrl());
|
||||
$this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(1)', 'hdgfgdfg');
|
||||
$this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(2)', 'bsfsdfsdfsd');
|
||||
@@ -224,7 +223,7 @@ class BookShelfTest extends TestCase
|
||||
$resp->assertRedirect($shelf->getUrl());
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
$editorId = $this->getEditor()->id;
|
||||
$editorId = $this->users->editor()->id;
|
||||
$this->assertDatabaseHas('bookshelves', array_merge($shelfInfo, ['id' => $shelf->id, 'created_by' => $editorId, 'updated_by' => $editorId]));
|
||||
|
||||
$shelfPage = $this->get($shelf->getUrl());
|
||||
@@ -294,11 +293,11 @@ class BookShelfTest extends TestCase
|
||||
$resp->assertSee("action=\"{$shelf->getUrl('/copy-permissions')}\"", false);
|
||||
|
||||
$child = $shelf->books()->first();
|
||||
$editorRole = $this->getEditor()->roles()->first();
|
||||
$editorRole = $this->users->editor()->roles()->first();
|
||||
$this->assertFalse($child->hasPermissions(), 'Child book should not be restricted by default');
|
||||
$this->assertTrue($child->permissions()->count() === 0, 'Child book should have no permissions by default');
|
||||
|
||||
$this->entities->setPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$this->permissions->setEntityPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$resp = $this->post($shelf->getUrl('/copy-permissions'));
|
||||
$child = $shelf->books()->first();
|
||||
|
||||
|
@@ -221,7 +221,7 @@ class BookTest extends TestCase
|
||||
public function test_books_view_shows_view_toggle_option()
|
||||
{
|
||||
/** @var Book $book */
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
setting()->putUser($editor, 'books_view_type', 'list');
|
||||
|
||||
$resp = $this->actingAs($editor)->get('/books');
|
||||
@@ -304,7 +304,7 @@ class BookTest extends TestCase
|
||||
// Hide child content
|
||||
/** @var BookChild $page */
|
||||
foreach ($book->getDirectChildren() as $child) {
|
||||
$this->entities->setPermissions($child, [], []);
|
||||
$this->permissions->setEntityPermissions($child, [], []);
|
||||
}
|
||||
|
||||
$this->asEditor()->post($book->getUrl('/copy'), ['name' => 'My copy book']);
|
||||
@@ -318,8 +318,8 @@ class BookTest extends TestCase
|
||||
{
|
||||
/** @var Book $book */
|
||||
$book = Book::query()->whereHas('chapters')->whereHas('directPages')->whereHas('chapters')->first();
|
||||
$viewer = $this->getViewer();
|
||||
$this->giveUserPermissions($viewer, ['book-create-all']);
|
||||
$viewer = $this->users->viewer();
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['book-create-all']);
|
||||
|
||||
$this->actingAs($viewer)->post($book->getUrl('/copy'), ['name' => 'My copy book']);
|
||||
/** @var Book $copy */
|
||||
@@ -354,9 +354,9 @@ class BookTest extends TestCase
|
||||
$shelfA->appendBook($book);
|
||||
$shelfB->appendBook($book);
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$this->giveUserPermissions($viewer, ['book-update-all', 'book-create-all', 'bookshelf-update-all']);
|
||||
$this->entities->setPermissions($shelfB);
|
||||
$viewer = $this->users->viewer();
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['book-update-all', 'book-create-all', 'bookshelf-update-all']);
|
||||
$this->permissions->setEntityPermissions($shelfB);
|
||||
|
||||
|
||||
$this->asEditor()->post($book->getUrl('/copy'), ['name' => 'My copy book']);
|
||||
|
@@ -101,7 +101,7 @@ class ChapterTest extends TestCase
|
||||
// Hide pages to all non-admin roles
|
||||
/** @var Page $page */
|
||||
foreach ($chapter->pages as $page) {
|
||||
$this->entities->setPermissions($page, [], []);
|
||||
$this->permissions->setEntityPermissions($page, [], []);
|
||||
}
|
||||
|
||||
$this->asEditor()->post($chapter->getUrl('/copy'), [
|
||||
@@ -116,8 +116,8 @@ class ChapterTest extends TestCase
|
||||
public function test_copy_does_not_copy_pages_if_user_cant_page_create()
|
||||
{
|
||||
$chapter = $this->entities->chapterHasPages();
|
||||
$viewer = $this->getViewer();
|
||||
$this->giveUserPermissions($viewer, ['chapter-create-all']);
|
||||
$viewer = $this->users->viewer();
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['chapter-create-all']);
|
||||
|
||||
// Lacking permission results in no copied pages
|
||||
$this->actingAs($viewer)->post($chapter->getUrl('/copy'), [
|
||||
@@ -128,7 +128,7 @@ class ChapterTest extends TestCase
|
||||
$newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first();
|
||||
$this->assertEquals(0, $newChapter->pages()->count());
|
||||
|
||||
$this->giveUserPermissions($viewer, ['page-create-all']);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['page-create-all']);
|
||||
|
||||
// Having permission rules in copied pages
|
||||
$this->actingAs($viewer)->post($chapter->getUrl('/copy'), [
|
||||
@@ -144,7 +144,7 @@ class ChapterTest extends TestCase
|
||||
{
|
||||
$chapter = $this->entities->chapter();
|
||||
|
||||
$resp = $this->actingAs($this->getViewer())->get($chapter->getUrl());
|
||||
$resp = $this->actingAs($this->users->viewer())->get($chapter->getUrl());
|
||||
$this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort'));
|
||||
|
||||
$resp = $this->asEditor()->get($chapter->getUrl());
|
||||
|
@@ -49,16 +49,16 @@ class ConvertTest extends TestCase
|
||||
public function test_convert_chapter_to_book_requires_permissions()
|
||||
{
|
||||
$chapter = $this->entities->chapter();
|
||||
$user = $this->getViewer();
|
||||
$user = $this->users->viewer();
|
||||
|
||||
$permissions = ['chapter-delete-all', 'book-create-all', 'chapter-update-all'];
|
||||
$this->giveUserPermissions($user, $permissions);
|
||||
$this->permissions->grantUserRolePermissions($user, $permissions);
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
$this->removePermissionFromUser($user, $permission);
|
||||
$this->permissions->removeUserRolePermissions($user, [$permission]);
|
||||
$resp = $this->actingAs($user)->post($chapter->getUrl('/convert-to-book'));
|
||||
$this->assertPermissionError($resp);
|
||||
$this->giveUserPermissions($user, [$permission]);
|
||||
$this->permissions->grantUserRolePermissions($user, [$permission]);
|
||||
}
|
||||
|
||||
$resp = $this->actingAs($user)->post($chapter->getUrl('/convert-to-book'));
|
||||
@@ -122,16 +122,16 @@ class ConvertTest extends TestCase
|
||||
public function test_book_convert_to_shelf_requires_permissions()
|
||||
{
|
||||
$book = $this->entities->book();
|
||||
$user = $this->getViewer();
|
||||
$user = $this->users->viewer();
|
||||
|
||||
$permissions = ['book-delete-all', 'bookshelf-create-all', 'book-update-all', 'book-create-all'];
|
||||
$this->giveUserPermissions($user, $permissions);
|
||||
$this->permissions->grantUserRolePermissions($user, $permissions);
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
$this->removePermissionFromUser($user, $permission);
|
||||
$this->permissions->removeUserRolePermissions($user, [$permission]);
|
||||
$resp = $this->actingAs($user)->post($book->getUrl('/convert-to-shelf'));
|
||||
$this->assertPermissionError($resp);
|
||||
$this->giveUserPermissions($user, [$permission]);
|
||||
$this->permissions->grantUserRolePermissions($user, [$permission]);
|
||||
}
|
||||
|
||||
$resp = $this->actingAs($user)->post($book->getUrl('/convert-to-shelf'));
|
||||
|
@@ -11,8 +11,8 @@ class EntityAccessTest extends TestCase
|
||||
public function test_entities_viewable_after_creator_deletion()
|
||||
{
|
||||
// Create required assets and revisions
|
||||
$creator = $this->getEditor();
|
||||
$updater = $this->getViewer();
|
||||
$creator = $this->users->editor();
|
||||
$updater = $this->users->viewer();
|
||||
$entities = $this->entities->createChainBelongingToUser($creator, $updater);
|
||||
app()->make(UserRepo::class)->destroy($creator);
|
||||
$this->entities->updatePage($entities['page'], ['html' => '<p>hello!</p>>']);
|
||||
@@ -23,8 +23,8 @@ class EntityAccessTest extends TestCase
|
||||
public function test_entities_viewable_after_updater_deletion()
|
||||
{
|
||||
// Create required assets and revisions
|
||||
$creator = $this->getViewer();
|
||||
$updater = $this->getEditor();
|
||||
$creator = $this->users->viewer();
|
||||
$updater = $this->users->editor();
|
||||
$entities = $this->entities->createChainBelongingToUser($creator, $updater);
|
||||
app()->make(UserRepo::class)->destroy($updater);
|
||||
$this->entities->updatePage($entities['page'], ['html' => '<p>Hello there!</p>']);
|
||||
|
@@ -132,7 +132,7 @@ class EntitySearchTest extends TestCase
|
||||
public function test_search_filters()
|
||||
{
|
||||
$page = $this->entities->newPage(['name' => 'My new test quaffleachits', 'html' => 'this is about an orange donkey danzorbhsing']);
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
// Viewed filter searches
|
||||
@@ -171,7 +171,7 @@ class EntitySearchTest extends TestCase
|
||||
|
||||
// Restricted filter
|
||||
$this->get('/search?term=' . urlencode('danzorbhsing {is_restricted}'))->assertDontSee($page->name);
|
||||
$this->entities->setPermissions($page, ['view'], [$editor->roles->first()]);
|
||||
$this->permissions->setEntityPermissions($page, ['view'], [$editor->roles->first()]);
|
||||
$this->get('/search?term=' . urlencode('danzorbhsing {is_restricted}'))->assertSee($page->name);
|
||||
|
||||
// Date filters
|
||||
@@ -235,7 +235,7 @@ class EntitySearchTest extends TestCase
|
||||
$this->withHtml($resp)->assertElementContains($baseSelector, $page->name);
|
||||
$this->withHtml($resp)->assertElementNotContains($baseSelector, "You don't have the required permissions to select this item");
|
||||
|
||||
$resp = $this->actingAs($this->getViewer())->get($searchUrl);
|
||||
$resp = $this->actingAs($this->users->viewer())->get($searchUrl);
|
||||
$this->withHtml($resp)->assertElementContains($baseSelector, $page->name);
|
||||
$this->withHtml($resp)->assertElementContains($baseSelector, "You don't have the required permissions to select this item");
|
||||
}
|
||||
@@ -246,7 +246,7 @@ class EntitySearchTest extends TestCase
|
||||
$this->assertGreaterThan(2, count($chapter->pages), 'Ensure we\'re testing with at least 1 sibling');
|
||||
$page = $chapter->pages->first();
|
||||
|
||||
$search = $this->actingAs($this->getViewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
||||
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
||||
$search->assertSuccessful();
|
||||
foreach ($chapter->pages as $page) {
|
||||
$search->assertSee($page->name);
|
||||
@@ -261,7 +261,7 @@ class EntitySearchTest extends TestCase
|
||||
$bookChildren = $page->book->getDirectChildren();
|
||||
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
|
||||
|
||||
$search = $this->actingAs($this->getViewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
||||
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
||||
$search->assertSuccessful();
|
||||
foreach ($bookChildren as $child) {
|
||||
$search->assertSee($child->name);
|
||||
@@ -276,7 +276,7 @@ class EntitySearchTest extends TestCase
|
||||
$bookChildren = $chapter->book->getDirectChildren();
|
||||
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
|
||||
|
||||
$search = $this->actingAs($this->getViewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter");
|
||||
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter");
|
||||
$search->assertSuccessful();
|
||||
foreach ($bookChildren as $child) {
|
||||
$search->assertSee($child->name);
|
||||
@@ -291,7 +291,7 @@ class EntitySearchTest extends TestCase
|
||||
$book = $books->first();
|
||||
$this->assertGreaterThan(2, count($books), 'Ensure we\'re testing with at least 1 sibling');
|
||||
|
||||
$search = $this->actingAs($this->getViewer())->get("/search/entity/siblings?entity_id={$book->id}&entity_type=book");
|
||||
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$book->id}&entity_type=book");
|
||||
$search->assertSuccessful();
|
||||
foreach ($books as $expectedBook) {
|
||||
$search->assertSee($expectedBook->name);
|
||||
@@ -304,7 +304,7 @@ class EntitySearchTest extends TestCase
|
||||
$shelf = $shelves->first();
|
||||
$this->assertGreaterThan(2, count($shelves), 'Ensure we\'re testing with at least 1 sibling');
|
||||
|
||||
$search = $this->actingAs($this->getViewer())->get("/search/entity/siblings?entity_id={$shelf->id}&entity_type=bookshelf");
|
||||
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$shelf->id}&entity_type=bookshelf");
|
||||
$search->assertSuccessful();
|
||||
foreach ($shelves as $expectedShelf) {
|
||||
$search->assertSee($expectedShelf->name);
|
||||
|
@@ -275,7 +275,7 @@ class ExportTest extends TestCase
|
||||
|
||||
public function test_page_export_with_deleted_creator_and_updater()
|
||||
{
|
||||
$user = $this->getViewer(['name' => 'ExportWizardTheFifth']);
|
||||
$user = $this->users->viewer(['name' => 'ExportWizardTheFifth']);
|
||||
$page = $this->entities->page();
|
||||
$page->created_by = $user->id;
|
||||
$page->updated_by = $user->id;
|
||||
@@ -409,7 +409,7 @@ class ExportTest extends TestCase
|
||||
$chapter = $book->chapters()->first();
|
||||
$page = $chapter->pages()->first();
|
||||
$entities = [$book, $chapter, $page];
|
||||
$user = $this->getViewer();
|
||||
$user = $this->users->viewer();
|
||||
$this->actingAs($user);
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
@@ -417,8 +417,7 @@ class ExportTest extends TestCase
|
||||
$resp->assertSee('/export/pdf');
|
||||
}
|
||||
|
||||
/** @var Role $role */
|
||||
$this->removePermissionFromUser($user, 'content-export');
|
||||
$this->permissions->removeUserRolePermissions($user, ['content-export']);
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$resp = $this->get($entity->getUrl());
|
||||
|
@@ -483,7 +483,7 @@ class PageContentTest extends TestCase
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
|
||||
$this->actingAs($this->getAdmin())
|
||||
$this->actingAs($this->users->admin())
|
||||
->put($page->getUrl(''), [
|
||||
'name' => 'Testing',
|
||||
'html' => '<p>"Hello & welcome"</p>',
|
||||
|
@@ -39,7 +39,7 @@ class PageDraftTest extends TestCase
|
||||
$this->withHtml($resp)->assertElementNotContains('[name="html"]', $addedContent);
|
||||
|
||||
$newContent = $this->page->html . $addedContent;
|
||||
$newUser = $this->getEditor();
|
||||
$newUser = $this->users->editor();
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
|
||||
$resp = $this->actingAs($newUser)->get($this->page->getUrl('/edit'));
|
||||
@@ -62,7 +62,7 @@ class PageDraftTest extends TestCase
|
||||
$this->withHtml($resp)->assertElementNotContains('[name="html"]', $addedContent);
|
||||
|
||||
$newContent = $this->page->html . $addedContent;
|
||||
$newUser = $this->getEditor();
|
||||
$newUser = $this->users->editor();
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
|
||||
$this->actingAs($newUser)
|
||||
@@ -75,8 +75,8 @@ class PageDraftTest extends TestCase
|
||||
|
||||
public function test_draft_save_shows_alert_if_draft_older_than_last_page_update()
|
||||
{
|
||||
$admin = $this->getAdmin();
|
||||
$editor = $this->getEditor();
|
||||
$admin = $this->users->admin();
|
||||
$editor = $this->users->editor();
|
||||
$page = $this->entities->page();
|
||||
|
||||
$this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [
|
||||
@@ -109,8 +109,8 @@ class PageDraftTest extends TestCase
|
||||
|
||||
public function test_draft_save_shows_alert_if_draft_edit_started_by_someone_else()
|
||||
{
|
||||
$admin = $this->getAdmin();
|
||||
$editor = $this->getEditor();
|
||||
$admin = $this->users->admin();
|
||||
$editor = $this->users->editor();
|
||||
$page = $this->entities->page();
|
||||
|
||||
$this->actingAs($admin)->put('/ajax/page/' . $page->id . '/save-draft', [
|
||||
@@ -143,7 +143,7 @@ class PageDraftTest extends TestCase
|
||||
{
|
||||
$book = $this->entities->book();
|
||||
$chapter = $book->chapters->first();
|
||||
$newUser = $this->getEditor();
|
||||
$newUser = $this->users->editor();
|
||||
|
||||
$this->actingAs($newUser)->get($book->getUrl('/create-page'));
|
||||
$this->get($chapter->getUrl('/create-page'));
|
||||
|
@@ -208,13 +208,13 @@ class PageRevisionTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$this->createRevisions($page, 2);
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$viewer = $this->users->viewer();
|
||||
$this->actingAs($viewer);
|
||||
$respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
|
||||
$respHtml->assertElementNotContains('.actions a', 'Restore');
|
||||
$respHtml->assertElementNotExists('form[action$="/restore"]');
|
||||
|
||||
$this->giveUserPermissions($viewer, ['page-update-all']);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['page-update-all']);
|
||||
|
||||
$respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
|
||||
$respHtml->assertElementContains('.actions a', 'Restore');
|
||||
@@ -226,13 +226,13 @@ class PageRevisionTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$this->createRevisions($page, 2);
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$viewer = $this->users->viewer();
|
||||
$this->actingAs($viewer);
|
||||
$respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
|
||||
$respHtml->assertElementNotContains('.actions a', 'Delete');
|
||||
$respHtml->assertElementNotExists('form[action$="/delete"]');
|
||||
|
||||
$this->giveUserPermissions($viewer, ['page-delete-all']);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['page-delete-all']);
|
||||
|
||||
$respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
|
||||
$respHtml->assertElementContains('.actions a', 'Delete');
|
||||
|
@@ -25,7 +25,7 @@ class PageTemplateTest extends TestCase
|
||||
public function test_manage_templates_permission_required_to_change_page_template_status()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$pageUpdateData = [
|
||||
@@ -40,7 +40,7 @@ class PageTemplateTest extends TestCase
|
||||
'template' => false,
|
||||
]);
|
||||
|
||||
$this->giveUserPermissions($editor, ['templates-manage']);
|
||||
$this->permissions->grantUserRolePermissions($editor, ['templates-manage']);
|
||||
|
||||
$this->put($page->getUrl(), $pageUpdateData);
|
||||
$this->assertDatabaseHas('pages', [
|
||||
@@ -53,7 +53,7 @@ class PageTemplateTest extends TestCase
|
||||
{
|
||||
$content = '<div>my_custom_template_content</div>';
|
||||
$page = $this->entities->page();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$templateFetch = $this->get('/templates/' . $page->id);
|
||||
@@ -73,7 +73,7 @@ class PageTemplateTest extends TestCase
|
||||
|
||||
public function test_template_endpoint_returns_paginated_list_of_templates()
|
||||
{
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$toBeTemplates = Page::query()->orderBy('name', 'asc')->take(12)->get();
|
||||
|
@@ -38,8 +38,8 @@ class PageTest extends TestCase
|
||||
public function test_page_view_when_creator_is_deleted_but_owner_exists()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
$user = $this->getViewer();
|
||||
$owner = $this->getEditor();
|
||||
$user = $this->users->viewer();
|
||||
$owner = $this->users->editor();
|
||||
$page->created_by = $user->id;
|
||||
$page->owned_by = $owner->id;
|
||||
$page->save();
|
||||
@@ -190,15 +190,15 @@ class PageTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$currentBook = $page->book;
|
||||
$newBook = Book::where('id', '!=', $currentBook->id)->first();
|
||||
$viewer = $this->getViewer();
|
||||
$viewer = $this->users->viewer();
|
||||
|
||||
$resp = $this->actingAs($viewer)->get($page->getUrl());
|
||||
$resp->assertDontSee($page->getUrl('/copy'));
|
||||
|
||||
$newBook->owned_by = $viewer->id;
|
||||
$newBook->save();
|
||||
$this->giveUserPermissions($viewer, ['page-create-own']);
|
||||
$this->entities->regenPermissions($newBook);
|
||||
$this->permissions->grantUserRolePermissions($viewer, ['page-create-own']);
|
||||
$this->permissions->regenerateForEntity($newBook);
|
||||
|
||||
$resp = $this->actingAs($viewer)->get($page->getUrl());
|
||||
$resp->assertSee($page->getUrl('/copy'));
|
||||
@@ -249,7 +249,7 @@ class PageTest extends TestCase
|
||||
|
||||
public function test_recently_updated_pages_view()
|
||||
{
|
||||
$user = $this->getEditor();
|
||||
$user = $this->users->editor();
|
||||
$content = $this->entities->createChainBelongingToUser($user);
|
||||
|
||||
$resp = $this->asAdmin()->get('/pages/recently-updated');
|
||||
@@ -258,7 +258,7 @@ class PageTest extends TestCase
|
||||
|
||||
public function test_recently_updated_pages_view_shows_updated_by_details()
|
||||
{
|
||||
$user = $this->getEditor();
|
||||
$user = $this->users->editor();
|
||||
$page = $this->entities->page();
|
||||
|
||||
$this->actingAs($user)->put($page->getUrl(), [
|
||||
@@ -272,7 +272,7 @@ class PageTest extends TestCase
|
||||
|
||||
public function test_recently_updated_pages_view_shows_parent_chain()
|
||||
{
|
||||
$user = $this->getEditor();
|
||||
$user = $this->users->editor();
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
|
||||
$this->actingAs($user)->put($page->getUrl(), [
|
||||
@@ -287,7 +287,7 @@ class PageTest extends TestCase
|
||||
|
||||
public function test_recently_updated_pages_view_does_not_show_parent_if_not_visible()
|
||||
{
|
||||
$user = $this->getEditor();
|
||||
$user = $this->users->editor();
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
|
||||
$this->actingAs($user)->put($page->getUrl(), [
|
||||
@@ -295,8 +295,8 @@ class PageTest extends TestCase
|
||||
'html' => '<p>Updated content</p>',
|
||||
]);
|
||||
|
||||
$this->entities->setPermissions($page->book);
|
||||
$this->entities->setPermissions($page, ['view'], [$user->roles->first()]);
|
||||
$this->permissions->setEntityPermissions($page->book);
|
||||
$this->permissions->setEntityPermissions($page, ['view'], [$user->roles->first()]);
|
||||
|
||||
$resp = $this->get('/pages/recently-updated');
|
||||
$resp->assertDontSee($page->book->getShortName(42));
|
||||
|
@@ -53,7 +53,7 @@ class SortTest extends TestCase
|
||||
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||
$newChapter = $newBook->chapters()->first();
|
||||
|
||||
$movePageResp = $this->actingAs($this->getEditor())->put($page->getUrl('/move'), [
|
||||
$movePageResp = $this->actingAs($this->users->editor())->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'chapter:' . $newChapter->id,
|
||||
]);
|
||||
$page->refresh();
|
||||
@@ -71,7 +71,7 @@ class SortTest extends TestCase
|
||||
$page = $oldChapter->pages()->first();
|
||||
$newBook = Book::query()->where('id', '!=', $oldChapter->book_id)->first();
|
||||
|
||||
$movePageResp = $this->actingAs($this->getEditor())->put($page->getUrl('/move'), [
|
||||
$movePageResp = $this->actingAs($this->users->editor())->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
$page->refresh();
|
||||
@@ -89,16 +89,16 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$currentBook = $page->book;
|
||||
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'delete'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete'], $editor->roles->all());
|
||||
|
||||
$movePageResp = $this->actingAs($editor)->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
$this->assertPermissionError($movePageResp);
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'delete', 'create'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete', 'create'], $editor->roles->all());
|
||||
$movePageResp = $this->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
@@ -114,10 +114,10 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$currentBook = $page->book;
|
||||
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->entities->setPermissions($page, ['view', 'update', 'create'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($page, ['view', 'update', 'create'], $editor->roles->all());
|
||||
|
||||
$movePageResp = $this->actingAs($editor)->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
@@ -126,7 +126,7 @@ class SortTest extends TestCase
|
||||
$pageView = $this->get($page->getUrl());
|
||||
$pageView->assertDontSee($page->getUrl('/move'));
|
||||
|
||||
$this->entities->setPermissions($page, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($page, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$movePageResp = $this->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
@@ -169,10 +169,10 @@ class SortTest extends TestCase
|
||||
$chapter = $this->entities->chapter();
|
||||
$currentBook = $chapter->book;
|
||||
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->entities->setPermissions($chapter, ['view', 'update', 'create'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create'], $editor->roles->all());
|
||||
|
||||
$moveChapterResp = $this->actingAs($editor)->put($chapter->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
@@ -181,7 +181,7 @@ class SortTest extends TestCase
|
||||
$pageView = $this->get($chapter->getUrl());
|
||||
$pageView->assertDontSee($chapter->getUrl('/move'));
|
||||
|
||||
$this->entities->setPermissions($chapter, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create', 'delete'], $editor->roles->all());
|
||||
$moveChapterResp = $this->put($chapter->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
@@ -196,17 +196,17 @@ class SortTest extends TestCase
|
||||
$chapter = $this->entities->chapter();
|
||||
$currentBook = $chapter->book;
|
||||
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$editor = $this->users->editor();
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'delete'], [$editor->roles->first()]);
|
||||
$this->entities->setPermissions($chapter, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete'], [$editor->roles->first()]);
|
||||
$this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
|
||||
|
||||
$moveChapterResp = $this->actingAs($editor)->put($chapter->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
$this->assertPermissionError($moveChapterResp);
|
||||
|
||||
$this->entities->setPermissions($newBook, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
|
||||
$this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
|
||||
$moveChapterResp = $this->put($chapter->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
]);
|
||||
@@ -313,7 +313,7 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
/** @var Chapter $otherChapter */
|
||||
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
|
||||
$this->entities->setPermissions($otherChapter);
|
||||
$this->permissions->setEntityPermissions($otherChapter);
|
||||
|
||||
$sortData = [
|
||||
'id' => $page->id,
|
||||
@@ -334,8 +334,8 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
/** @var Chapter $otherChapter */
|
||||
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$this->entities->setPermissions($otherChapter->book, ['update', 'delete'], [$editor->roles()->first()]);
|
||||
$editor = $this->users->editor();
|
||||
$this->permissions->setEntityPermissions($otherChapter->book, ['update', 'delete'], [$editor->roles()->first()]);
|
||||
|
||||
$sortData = [
|
||||
'id' => $page->id,
|
||||
@@ -356,8 +356,8 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
/** @var Chapter $otherChapter */
|
||||
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$this->entities->setPermissions($otherChapter, ['view', 'delete'], [$editor->roles()->first()]);
|
||||
$editor = $this->users->editor();
|
||||
$this->permissions->setEntityPermissions($otherChapter, ['view', 'delete'], [$editor->roles()->first()]);
|
||||
|
||||
$sortData = [
|
||||
'id' => $page->id,
|
||||
@@ -378,8 +378,8 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
/** @var Chapter $otherChapter */
|
||||
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$this->entities->setPermissions($page, ['view', 'delete'], [$editor->roles()->first()]);
|
||||
$editor = $this->users->editor();
|
||||
$this->permissions->setEntityPermissions($page, ['view', 'delete'], [$editor->roles()->first()]);
|
||||
|
||||
$sortData = [
|
||||
'id' => $page->id,
|
||||
@@ -400,8 +400,8 @@ class SortTest extends TestCase
|
||||
$page = $this->entities->pageWithinChapter();
|
||||
/** @var Chapter $otherChapter */
|
||||
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
|
||||
$editor = $this->getEditor();
|
||||
$this->entities->setPermissions($page, ['view', 'update'], [$editor->roles()->first()]);
|
||||
$editor = $this->users->editor();
|
||||
$this->permissions->setEntityPermissions($page, ['view', 'update'], [$editor->roles()->first()]);
|
||||
|
||||
$sortData = [
|
||||
'id' => $page->id,
|
||||
|
@@ -75,7 +75,7 @@ class TagTest extends TestCase
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country']);
|
||||
|
||||
// Set restricted permission the page
|
||||
$this->entities->setPermissions($page, [], []);
|
||||
$this->permissions->setEntityPermissions($page, [], []);
|
||||
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country']);
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson([]);
|
||||
@@ -178,7 +178,7 @@ class TagTest extends TestCase
|
||||
$resp = $this->get('/tags?name=SuperCategory');
|
||||
$resp->assertSee('GreatTestContent');
|
||||
|
||||
$this->entities->setPermissions($page, [], []);
|
||||
$this->permissions->setEntityPermissions($page, [], []);
|
||||
|
||||
$resp = $this->asEditor()->get('/tags');
|
||||
$resp->assertDontSee('SuperCategory');
|
||||
|
Reference in New Issue
Block a user