X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/7d94da10fbb0fa6de6f24878ea5984f8de6a031c..refs/pull/3593/head:/tests/FavouriteTest.php diff --git a/tests/FavouriteTest.php b/tests/FavouriteTest.php index 7209063c9..017dd889f 100644 --- a/tests/FavouriteTest.php +++ b/tests/FavouriteTest.php @@ -9,27 +9,26 @@ use Tests\TestCase; class FavouriteTest extends TestCase { - public function test_page_add_favourite_flow() { $page = Page::query()->first(); $editor = $this->getEditor(); $resp = $this->actingAs($editor)->get($page->getUrl()); - $resp->assertElementContains('button', 'Favourite'); - $resp->assertElementExists('form[method="POST"][action$="/favourites/add"]'); + $this->withHtml($resp)->assertElementContains('button', 'Favourite'); + $this->withHtml($resp)->assertElementExists('form[method="POST"][action$="/favourites/add"]'); $resp = $this->post('/favourites/add', [ 'type' => get_class($page), - 'id' => $page->id, + 'id' => $page->id, ]); $resp->assertRedirect($page->getUrl()); $resp->assertSessionHas('success', "\"{$page->name}\" has been added to your favourites"); $this->assertDatabaseHas('favourites', [ - 'user_id' => $editor->id, + 'user_id' => $editor->id, 'favouritable_type' => $page->getMorphClass(), - 'favouritable_id' => $page->id, + 'favouritable_id' => $page->id, ]); } @@ -38,18 +37,18 @@ class FavouriteTest extends TestCase $page = Page::query()->first(); $editor = $this->getEditor(); Favourite::query()->forceCreate([ - 'user_id' => $editor->id, - 'favouritable_id' => $page->id, + 'user_id' => $editor->id, + 'favouritable_id' => $page->id, 'favouritable_type' => $page->getMorphClass(), ]); $resp = $this->actingAs($editor)->get($page->getUrl()); - $resp->assertElementContains('button', 'Unfavourite'); - $resp->assertElementExists('form[method="POST"][action$="/favourites/remove"]'); + $this->withHtml($resp)->assertElementContains('button', 'Unfavourite'); + $this->withHtml($resp)->assertElementExists('form[method="POST"][action$="/favourites/remove"]'); $resp = $this->post('/favourites/remove', [ 'type' => get_class($page), - 'id' => $page->id, + 'id' => $page->id, ]); $resp->assertRedirect($page->getUrl()); $resp->assertSessionHas('success', "\"{$page->name}\" has been removed from your favourites"); @@ -70,15 +69,17 @@ class FavouriteTest extends TestCase foreach ($entities as $entity) { $resp = $this->get($entity->getUrl()); - $resp->assertElementExists('form[method="POST"][action$="/favourites/add"]'); + $this->withHtml($resp)->assertElementExists('form[method="POST"][action$="/favourites/add"]'); } } public function test_header_contains_link_to_favourites_page_when_logged_in() { $this->setSettings(['app-public' => 'true']); - $this->get('/')->assertElementNotContains('header', 'My Favourites'); - $this->actingAs($this->getViewer())->get('/')->assertElementContains('header a', 'My Favourites'); + $resp = $this->get('/'); + $this->withHtml($resp)->assertElementNotContains('header', 'My Favourites'); + $resp = $this->actingAs($this->getViewer())->get('/'); + $this->withHtml($resp)->assertElementContains('header a', 'My Favourites'); } public function test_favourites_shown_on_homepage() @@ -86,15 +87,15 @@ class FavouriteTest extends TestCase $editor = $this->getEditor(); $resp = $this->actingAs($editor)->get('/'); - $resp->assertElementNotExists('#top-favourites'); + $this->withHtml($resp)->assertElementNotExists('#top-favourites'); /** @var Page $page */ $page = Page::query()->first(); - $page->favourites()->save((new Favourite)->forceFill(['user_id' => $editor->id])); + $page->favourites()->save((new Favourite())->forceFill(['user_id' => $editor->id])); $resp = $this->get('/'); - $resp->assertElementExists('#top-favourites'); - $resp->assertElementContains('#top-favourites', $page->name); + $this->withHtml($resp)->assertElementExists('#top-favourites'); + $this->withHtml($resp)->assertElementContains('#top-favourites', $page->name); } public function test_favourites_list_page_shows_favourites_and_has_working_pagination() @@ -106,7 +107,7 @@ class FavouriteTest extends TestCase $resp = $this->actingAs($editor)->get('/favourites'); $resp->assertDontSee($page->name); - $page->favourites()->save((new Favourite)->forceFill(['user_id' => $editor->id])); + $page->favourites()->save((new Favourite())->forceFill(['user_id' => $editor->id])); $resp = $this->get('/favourites'); $resp->assertSee($page->name); @@ -114,5 +115,4 @@ class FavouriteTest extends TestCase $resp = $this->get('/favourites?page=2'); $resp->assertDontSee($page->name); } - -} \ No newline at end of file +}