$this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book');
}
+ public function test_chapter_move_requires_create_permissions_in_new_book()
+ {
+ $chapter = Chapter::query()->first();
+ $currentBook = $chapter->book;
+ $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
+ $editor = $this->getEditor();
+
+ $this->setEntityRestrictions($newBook, ['view', 'update', 'delete'], [$editor->roles->first()]);
+ $this->setEntityRestrictions($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->setEntityRestrictions($newBook, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
+ $moveChapterResp = $this->put($chapter->getUrl('/move'), [
+ 'entity_selection' => 'book:' . $newBook->id,
+ ]);
+
+ $chapter = Chapter::query()->find($chapter->id);
+ $moveChapterResp->assertRedirect($chapter->getUrl());
+ $this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book');
+ }
+
public function test_chapter_move_changes_book_for_deleted_pages_within()
{
/** @var Chapter $chapter */
// Create request data
$reqData = [
[
- 'id' => $chapterToMove->id,
- 'sort' => 0,
+ 'id' => $chapterToMove->id,
+ 'sort' => 0,
'parentChapter' => false,
- 'type' => 'chapter',
- 'book' => $newBook->id,
+ 'type' => 'chapter',
+ 'book' => $newBook->id,
],
];
foreach ($pagesToMove as $index => $page) {
$reqData[] = [
- 'id' => $page->id,
- 'sort' => $index,
+ 'id' => $page->id,
+ 'sort' => $index,
'parentChapter' => $index === count($pagesToMove) - 1 ? $chapterToMove->id : false,
- 'type' => 'page',
- 'book' => $newBook->id,
+ 'type' => 'page',
+ 'book' => $newBook->id,
];
}
$sortResp->assertRedirect($newBook->getUrl());
$sortResp->assertStatus(302);
$this->assertDatabaseHas('chapters', [
- 'id' => $chapterToMove->id,
- 'book_id' => $newBook->id,
+ 'id' => $chapterToMove->id,
+ 'book_id' => $newBook->id,
'priority' => 0,
]);
$this->assertTrue($newBook->chapters()->count() === 1);
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $page->book_id,
+ 'type' => 'page',
+ 'book' => $page->book_id,
];
$this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter->book, ['update', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter, ['view', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($page, ['view', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($page, ['view', 'update'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
]);
}
-
public function test_book_sort_item_returns_book_content()
{
$books = Book::all();