1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Updated tests to use ssddanbrown/asserthtml package

Closes #3519
This commit is contained in:
Dan Brown
2022-07-23 15:10:18 +01:00
parent cf73e5f2c6
commit 72c8b138e1
48 changed files with 869 additions and 1014 deletions

View File

@@ -138,13 +138,11 @@ class EntityPermissionsTest extends TestCase
$book = Book::query()->first();
$bookUrl = $book->getUrl();
$this->actingAs($this->viewer)
->get($bookUrl)
->assertElementNotContains('.actions', 'New Page')
$resp = $this->actingAs($this->viewer)->get($bookUrl);
$this->withHtml($resp)->assertElementNotContains('.actions', 'New Page')
->assertElementNotContains('.actions', 'New Chapter');
$this->actingAs($this->user)
->get($bookUrl)
->assertElementContains('.actions', 'New Page')
$resp = $this->actingAs($this->user)->get($bookUrl);
$this->withHtml($resp)->assertElementContains('.actions', 'New Page')
->assertElementContains('.actions', 'New Chapter');
$this->setRestrictionsForTestRoles($book, ['view', 'delete', 'update']);
@@ -155,8 +153,8 @@ class EntityPermissionsTest extends TestCase
$this->get($bookUrl . '/create-page')->assertRedirect('/');
$this->get('/')->assertSee('You do not have permission');
$this->get($bookUrl)
->assertElementNotContains('.actions', 'New Page')
$resp = $this->get($bookUrl);
$this->withHtml($resp)->assertElementNotContains('.actions', 'New Page')
->assertElementNotContains('.actions', 'New Chapter');
$this->setRestrictionsForTestRoles($book, ['view', 'create']);
@@ -176,8 +174,8 @@ class EntityPermissionsTest extends TestCase
]);
$resp->assertRedirect($book->getUrl('/page/test-page'));
$this->get($bookUrl)
->assertElementContains('.actions', 'New Page')
$resp = $this->get($bookUrl);
$this->withHtml($resp)->assertElementContains('.actions', 'New Page')
->assertElementContains('.actions', 'New Chapter');
}
@@ -262,15 +260,14 @@ class EntityPermissionsTest extends TestCase
$chapter = Chapter::query()->first();
$chapterUrl = $chapter->getUrl();
$this->actingAs($this->user)
->get($chapterUrl)
->assertElementContains('.actions', 'New Page');
$resp = $this->actingAs($this->user)->get($chapterUrl);
$this->withHtml($resp)->assertElementContains('.actions', 'New Page');
$this->setRestrictionsForTestRoles($chapter, ['view', 'delete', 'update']);
$this->get($chapterUrl . '/create-page')->assertRedirect('/');
$this->get('/')->assertSee('You do not have permission');
$this->get($chapterUrl)->assertElementNotContains('.actions', 'New Page');
$this->withHtml($this->get($chapterUrl))->assertElementNotContains('.actions', 'New Page');
$this->setRestrictionsForTestRoles($chapter, ['view', 'create']);
@@ -283,7 +280,7 @@ class EntityPermissionsTest extends TestCase
]);
$resp->assertRedirect($chapter->book->getUrl('/page/test-page'));
$this->get($chapterUrl)->assertElementContains('.actions', 'New Page');
$this->withHtml($this->get($chapterUrl))->assertElementContains('.actions', 'New Page');
}
public function test_chapter_update_restriction()
@@ -356,9 +353,9 @@ class EntityPermissionsTest extends TestCase
$page = Page::query()->first();
$pageUrl = $page->getUrl();
$this->actingAs($this->user)
->get($pageUrl . '/edit')
->assertElementExists('input[name="name"][value="' . $page->name . '"]');
$resp = $this->actingAs($this->user)
->get($pageUrl . '/edit');
$this->withHtml($resp)->assertElementExists('input[name="name"][value="' . $page->name . '"]');
$this->setRestrictionsForTestRoles($page, ['view', 'delete']);
@@ -367,9 +364,9 @@ class EntityPermissionsTest extends TestCase
$this->setRestrictionsForTestRoles($page, ['view', 'update']);
$this->get($pageUrl . '/edit')
->assertOk()
->assertElementExists('input[name="name"][value="' . $page->name . '"]');
$resp = $this->get($pageUrl . '/edit')
->assertOk();
$this->withHtml($resp)->assertElementExists('input[name="name"][value="' . $page->name . '"]');
}
public function test_page_delete_restriction()
@@ -446,9 +443,8 @@ class EntityPermissionsTest extends TestCase
$this->setRestrictionsForTestRoles($page, []);
$this->actingAs($this->user)
->get($page2->getUrl())
->assertElementNotContains('.sidebar-page-list', $page->name);
$resp = $this->actingAs($this->user)->get($page2->getUrl());
$this->withHtml($resp)->assertElementNotContains('.sidebar-page-list', $page->name);
}
public function test_restricted_pages_not_visible_in_book_navigation_on_chapters()
@@ -459,9 +455,8 @@ class EntityPermissionsTest extends TestCase
$this->setRestrictionsForTestRoles($page, []);
$this->actingAs($this->user)
->get($chapter->getUrl())
->assertElementNotContains('.sidebar-page-list', $page->name);
$resp = $this->actingAs($this->user)->get($chapter->getUrl());
$this->withHtml($resp)->assertElementNotContains('.sidebar-page-list', $page->name);
}
public function test_restricted_pages_not_visible_on_chapter_pages()
@@ -538,9 +533,8 @@ class EntityPermissionsTest extends TestCase
$book = Book::query()->first();
$bookUrl = $book->getUrl();
$this->actingAs($this->viewer)
->get($bookUrl)
->assertElementNotContains('.actions', 'New Page')
$resp = $this->actingAs($this->viewer)->get($bookUrl);
$this->withHtml($resp)->assertElementNotContains('.actions', 'New Page')
->assertElementNotContains('.actions', 'New Chapter');
$this->setRestrictionsForTestRoles($book, ['view', 'delete', 'update']);
@@ -549,7 +543,8 @@ class EntityPermissionsTest extends TestCase
$this->get('/')->assertSee('You do not have permission');
$this->get($bookUrl . '/create-page')->assertRedirect('/');
$this->get('/')->assertSee('You do not have permission');
$this->get($bookUrl)->assertElementNotContains('.actions', 'New Page')
$resp = $this->get($bookUrl);
$this->withHtml($resp)->assertElementNotContains('.actions', 'New Page')
->assertElementNotContains('.actions', 'New Chapter');
$this->setRestrictionsForTestRoles($book, ['view', 'create']);
@@ -569,8 +564,8 @@ class EntityPermissionsTest extends TestCase
]);
$resp->assertRedirect($book->getUrl('/page/test-page'));
$this->get($bookUrl)
->assertElementContains('.actions', 'New Page')
$resp = $this->get($bookUrl);
$this->withHtml($resp)->assertElementContains('.actions', 'New Page')
->assertElementContains('.actions', 'New Chapter');
}