X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/21f2a7087c7ef1af1e30e1997bce77cc64ede76e..refs/pull/5280/head:/tests/Entity/ChapterTest.php
diff --git a/tests/Entity/ChapterTest.php b/tests/Entity/ChapterTest.php
index 1d28ec839..1577cee76 100644
--- a/tests/Entity/ChapterTest.php
+++ b/tests/Entity/ChapterTest.php
@@ -11,25 +11,35 @@ class ChapterTest extends TestCase
{
public function test_create()
{
- /** @var Book $book */
- $book = Book::query()->first();
+ $book = $this->entities->book();
$chapter = Chapter::factory()->make([
'name' => 'My First Chapter',
]);
$resp = $this->asEditor()->get($book->getUrl());
- $resp->assertElementContains('a[href="' . $book->getUrl('/create-chapter') . '"]', 'New Chapter');
+ $this->withHtml($resp)->assertElementContains('a[href="' . $book->getUrl('/create-chapter') . '"]', 'New Chapter');
$resp = $this->get($book->getUrl('/create-chapter'));
- $resp->assertElementContains('form[action="' . $book->getUrl('/create-chapter') . '"][method="POST"]', 'Save Chapter');
+ $this->withHtml($resp)->assertElementContains('form[action="' . $book->getUrl('/create-chapter') . '"][method="POST"]', 'Save Chapter');
- $resp = $this->post($book->getUrl('/create-chapter'), $chapter->only('name', 'description'));
+ $resp = $this->post($book->getUrl('/create-chapter'), $chapter->only('name', 'description_html'));
$resp->assertRedirect($book->getUrl('/chapter/my-first-chapter'));
$resp = $this->get($book->getUrl('/chapter/my-first-chapter'));
$resp->assertSee($chapter->name);
- $resp->assertSee($chapter->description);
+ $resp->assertSee($chapter->description_html, false);
+ }
+
+ public function test_show_view_displays_description_if_no_description_html_set()
+ {
+ $chapter = $this->entities->chapter();
+ $chapter->description_html = '';
+ $chapter->description = "My great\ndescription\n\nwith newlines";
+ $chapter->save();
+
+ $resp = $this->asEditor()->get($chapter->getUrl());
+ $resp->assertSee("
My great
\ndescription
\n
\nwith newlines
", false);
}
public function test_delete()
@@ -53,28 +63,26 @@ class ChapterTest extends TestCase
$this->assertTrue($chapter->deletions()->count() === 1);
$redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
- $redirectReq->assertNotificationContains('Chapter Successfully Deleted');
+ $this->assertNotificationContains($redirectReq, 'Chapter Successfully Deleted');
}
public function test_show_view_has_copy_button()
{
- /** @var Chapter $chapter */
- $chapter = Chapter::query()->first();
+ $chapter = $this->entities->chapter();
$resp = $this->asEditor()->get($chapter->getUrl());
- $resp->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy');
+ $this->withHtml($resp)->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy');
}
public function test_copy_view()
{
- /** @var Chapter $chapter */
- $chapter = Chapter::query()->first();
+ $chapter = $this->entities->chapter();
$resp = $this->asEditor()->get($chapter->getUrl('/copy'));
$resp->assertOk();
$resp->assertSee('Copy Chapter');
- $resp->assertElementExists("input[name=\"name\"][value=\"{$chapter->name}\"]");
- $resp->assertElementExists("input[name=\"entity_selection\"]");
+ $this->withHtml($resp)->assertElementExists("input[name=\"name\"][value=\"{$chapter->name}\"]");
+ $this->withHtml($resp)->assertElementExists('input[name="entity_selection"]');
}
public function test_copy()
@@ -85,7 +93,7 @@ class ChapterTest extends TestCase
$otherBook = Book::query()->where('id', '!=', $chapter->book_id)->first();
$resp = $this->asEditor()->post($chapter->getUrl('/copy'), [
- 'name' => 'My copied chapter',
+ 'name' => 'My copied chapter',
'entity_selection' => 'book:' . $otherBook->id,
]);
@@ -99,15 +107,12 @@ class ChapterTest extends TestCase
public function test_copy_does_not_copy_non_visible_pages()
{
- /** @var Chapter $chapter */
- $chapter = Chapter::query()->whereHas('pages')->first();
+ $chapter = $this->entities->chapterHasPages();
// Hide pages to all non-admin roles
/** @var Page $page */
foreach ($chapter->pages as $page) {
- $page->restricted = true;
- $page->save();
- $this->regenEntityPermissions($page);
+ $this->permissions->setEntityPermissions($page, [], []);
}
$this->asEditor()->post($chapter->getUrl('/copy'), [
@@ -121,10 +126,9 @@ class ChapterTest extends TestCase
public function test_copy_does_not_copy_pages_if_user_cant_page_create()
{
- /** @var Chapter $chapter */
- $chapter = Chapter::query()->whereHas('pages')->first();
- $viewer = $this->getViewer();
- $this->giveUserPermissions($viewer, ['chapter-create-all']);
+ $chapter = $this->entities->chapterHasPages();
+ $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'), [
@@ -135,7 +139,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'), [
@@ -146,4 +150,15 @@ class ChapterTest extends TestCase
$newChapter2 = Chapter::query()->where('name', '=', 'My copied again chapter')->first();
$this->assertEquals($chapter->pages()->count(), $newChapter2->pages()->count());
}
+
+ public function test_sort_book_action_visible_if_permissions_allow()
+ {
+ $chapter = $this->entities->chapter();
+
+ $resp = $this->actingAs($this->users->viewer())->get($chapter->getUrl());
+ $this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort'));
+
+ $resp = $this->asEditor()->get($chapter->getUrl());
+ $this->withHtml($resp)->assertLinkExists($chapter->book->getUrl('sort'));
+ }
}