<?php namespace Tests;
use BookStack\Book;
+use BookStack\Chapter;
use BookStack\Page;
use BookStack\Repos\EntityRepo;
public function setUp()
{
parent::setUp();
- $this->book = \BookStack\Book::first();
+ $this->book = Book::first();
}
public function test_drafts_do_not_show_up()
public function test_page_move()
{
- $page = \BookStack\Page::first();
+ $page = Page::first();
$currentBook = $page->book;
- $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
+ $newBook = Book::where('id', '!=', $currentBook->id)->first();
- $resp = $this->asAdmin()->get($page->getUrl() . '/move');
+ $resp = $this->asEditor()->get($page->getUrl('/move'));
$resp->assertSee('Move Page');
- $movePageResp = $this->put($page->getUrl() . '/move', [
+ $movePageResp = $this->put($page->getUrl('/move'), [
'entity_selection' => 'book:' . $newBook->id
]);
- $page = \BookStack\Page::find($page->id);
+ $page = Page::find($page->id);
$movePageResp->assertRedirect($page->getUrl());
$this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book');
$newBookResp->assertSee($page->name);
}
+ public function test_page_move_requires_create_permissions_on_parent()
+ {
+ $page = Page::first();
+ $currentBook = $page->book;
+ $newBook = Book::where('id', '!=', $currentBook->id)->first();
+ $editor = $this->getEditor();
+
+ $this->setEntityRestrictions($newBook, ['view', 'edit', 'delete'], $editor->roles);
+
+ $movePageResp = $this->actingAs($editor)->put($page->getUrl('/move'), [
+ 'entity_selection' => 'book:' . $newBook->id
+ ]);
+ $this->assertPermissionError($movePageResp);
+
+ $this->setEntityRestrictions($newBook, ['view', 'edit', 'delete', 'create'], $editor->roles);
+ $movePageResp = $this->put($page->getUrl('/move'), [
+ 'entity_selection' => 'book:' . $newBook->id
+ ]);
+
+ $page = Page::find($page->id);
+ $movePageResp->assertRedirect($page->getUrl());
+
+ $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book');
+ }
+
public function test_chapter_move()
{
- $chapter = \BookStack\Chapter::first();
+ $chapter = Chapter::first();
$currentBook = $chapter->book;
$pageToCheck = $chapter->pages->first();
- $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
+ $newBook = Book::where('id', '!=', $currentBook->id)->first();
- $chapterMoveResp = $this->asAdmin()->get($chapter->getUrl() . '/move');
+ $chapterMoveResp = $this->asEditor()->get($chapter->getUrl('/move'));
$chapterMoveResp->assertSee('Move Chapter');
- $moveChapterResp = $this->put($chapter->getUrl() . '/move', [
+ $moveChapterResp = $this->put($chapter->getUrl('/move'), [
'entity_selection' => 'book:' . $newBook->id
]);
- $chapter = \BookStack\Chapter::find($chapter->id);
+ $chapter = Chapter::find($chapter->id);
$moveChapterResp->assertRedirect($chapter->getUrl());
$this->assertTrue($chapter->book->id === $newBook->id, 'Chapter Book is now the new book');
$newBookResp->assertSee('moved chapter');
$newBookResp->assertSee($chapter->name);
- $pageToCheck = \BookStack\Page::find($pageToCheck->id);
+ $pageToCheck = Page::find($pageToCheck->id);
$this->assertTrue($pageToCheck->book_id === $newBook->id, 'Chapter child page\'s book id has changed to the new book');
$pageCheckResp = $this->get($pageToCheck->getUrl());
$pageCheckResp->assertSee($newBook->name);
];
}
- $sortResp = $this->asAdmin()->put($newBook->getUrl() . '/sort', ['sort-tree' => json_encode($reqData)]);
+ $sortResp = $this->asEditor()->put($newBook->getUrl() . '/sort', ['sort-tree' => json_encode($reqData)]);
$sortResp->assertRedirect($newBook->getUrl());
$sortResp->assertStatus(302);
$this->assertDatabaseHas('chapters', [
$checkResp->assertSee($newBook->name);
}
+ public function test_page_copy()
+ {
+ $page = Page::first();
+ $currentBook = $page->book;
+ $newBook = Book::where('id', '!=', $currentBook->id)->first();
+
+ $resp = $this->asEditor()->get($page->getUrl('/copy'));
+ $resp->assertSee('Copy Page');
+
+ $movePageResp = $this->post($page->getUrl('/copy'), [
+ 'entity_selection' => 'book:' . $newBook->id,
+ 'name' => 'My copied test page'
+ ]);
+
+ $pageCopy = Page::where('name', '=', 'My copied test page')->first();
+
+ $movePageResp->assertRedirect($pageCopy->getUrl());
+ $this->assertTrue($pageCopy->book->id == $newBook->id, 'Page was copied to correct book');
+ }
+
+ public function test_page_copy_with_no_destination()
+ {
+ $page = Page::first();
+ $currentBook = $page->book;
+
+ $resp = $this->asEditor()->get($page->getUrl('/copy'));
+ $resp->assertSee('Copy Page');
+
+ $movePageResp = $this->post($page->getUrl('/copy'), [
+ 'name' => 'My copied test page'
+ ]);
+
+ $pageCopy = Page::where('name', '=', 'My copied test page')->first();
+
+ $movePageResp->assertRedirect($pageCopy->getUrl());
+ $this->assertTrue($pageCopy->book->id == $currentBook->id, 'Page was copied to correct book');
+ $this->assertTrue($pageCopy->id !== $page->id, 'Page copy is not the same instance');
+ }
+
}
\ No newline at end of file