]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/TagTest.php
Updated tests to use ssddanbrown/asserthtml package
[bookstack] / tests / Entity / TagTest.php
index 160dd62d8181c7f08a361502295755b47da02e23..6d03ed95ab24962fccb53b3d457ae94cc7036efa 100644 (file)
@@ -94,10 +94,10 @@ class TagTest extends TestCase
         $page = $this->getEntityWithTags(Page::class, $tags);
         $resp = $this->asEditor()->get('/search?term=[category]');
         $resp->assertSee($page->name);
-        $resp->assertElementContains('[href="' . $page->getUrl() . '"]', 'category');
-        $resp->assertElementContains('[href="' . $page->getUrl() . '"]', 'buckets');
-        $resp->assertElementContains('[href="' . $page->getUrl() . '"]', 'color');
-        $resp->assertElementContains('[href="' . $page->getUrl() . '"]', 'red');
+        $this->withHtml($resp)->assertElementContains('[href="' . $page->getUrl() . '"]', 'category');
+        $this->withHtml($resp)->assertElementContains('[href="' . $page->getUrl() . '"]', 'buckets');
+        $this->withHtml($resp)->assertElementContains('[href="' . $page->getUrl() . '"]', 'color');
+        $this->withHtml($resp)->assertElementContains('[href="' . $page->getUrl() . '"]', 'red');
     }
 
     public function test_tags_index_shows_tag_name_as_expected_with_right_counts()
@@ -109,23 +109,24 @@ class TagTest extends TestCase
 
         $resp = $this->asEditor()->get('/tags');
         $resp->assertSee('Category');
-        $resp->assertElementCount('.tag-item', 1);
+        $html = $this->withHtml($resp);
+        $html->assertElementCount('.tag-item', 1);
         $resp->assertDontSee('GreatTestContent');
         $resp->assertDontSee('OtherTestContent');
-        $resp->assertElementContains('a[title="Total tag usages"]', '2');
-        $resp->assertElementContains('a[title="Assigned to Pages"]', '2');
-        $resp->assertElementContains('a[title="Assigned to Books"]', '0');
-        $resp->assertElementContains('a[title="Assigned to Chapters"]', '0');
-        $resp->assertElementContains('a[title="Assigned to Shelves"]', '0');
-        $resp->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values');
+        $html->assertElementContains('a[title="Total tag usages"]', '2');
+        $html->assertElementContains('a[title="Assigned to Pages"]', '2');
+        $html->assertElementContains('a[title="Assigned to Books"]', '0');
+        $html->assertElementContains('a[title="Assigned to Chapters"]', '0');
+        $html->assertElementContains('a[title="Assigned to Shelves"]', '0');
+        $html->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values');
 
         /** @var Book $book */
         $book = Book::query()->first();
         $book->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
         $resp = $this->asEditor()->get('/tags');
-        $resp->assertElementContains('a[title="Total tag usages"]', '3');
-        $resp->assertElementContains('a[title="Assigned to Books"]', '1');
-        $resp->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values');
+        $this->withHtml($resp)->assertElementContains('a[title="Total tag usages"]', '3');
+        $this->withHtml($resp)->assertElementContains('a[title="Assigned to Books"]', '1');
+        $this->withHtml($resp)->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values');
     }
 
     public function test_tag_index_can_be_searched()
@@ -135,14 +136,14 @@ class TagTest extends TestCase
         $page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
 
         $resp = $this->asEditor()->get('/tags?search=cat');
-        $resp->assertElementContains('.tag-item .tag-name', 'Category');
+        $this->withHtml($resp)->assertElementContains('.tag-item .tag-name', 'Category');
 
         $resp = $this->asEditor()->get('/tags?search=content');
-        $resp->assertElementContains('.tag-item .tag-name', 'Category');
-        $resp->assertElementContains('.tag-item .tag-value', 'GreatTestContent');
+        $this->withHtml($resp)->assertElementContains('.tag-item .tag-name', 'Category');
+        $this->withHtml($resp)->assertElementContains('.tag-item .tag-value', 'GreatTestContent');
 
         $resp = $this->asEditor()->get('/tags?search=other');
-        $resp->assertElementNotExists('.tag-item .tag-name');
+        $this->withHtml($resp)->assertElementNotExists('.tag-item .tag-name');
     }
 
     public function test_tag_index_search_will_show_mulitple_values_of_a_single_tag_name()
@@ -153,8 +154,8 @@ class TagTest extends TestCase
         $page->tags()->create(['name' => 'Animal', 'value' => 'Catdog']);
 
         $resp = $this->asEditor()->get('/tags?search=cat');
-        $resp->assertElementContains('.tag-item .tag-value', 'Catfish');
-        $resp->assertElementContains('.tag-item .tag-value', 'Catdog');
+        $this->withHtml($resp)->assertElementContains('.tag-item .tag-value', 'Catfish');
+        $this->withHtml($resp)->assertElementContains('.tag-item .tag-value', 'Catdog');
     }
 
     public function test_tag_index_can_be_scoped_to_specific_tag_name()
@@ -170,9 +171,9 @@ class TagTest extends TestCase
         $resp->assertSee('GreatTestContent');
         $resp->assertSee('OtherTestContent');
         $resp->assertDontSee('OtherTagName');
-        $resp->assertElementCount('table .tag-item', 2);
         $resp->assertSee('Active Filter:');
-        $resp->assertElementContains('form[action$="/tags"]', 'Clear Filter');
+        $this->withHtml($resp)->assertElementCount('table .tag-item', 2);
+        $this->withHtml($resp)->assertElementContains('form[action$="/tags"]', 'Clear Filter');
     }
 
     public function test_tags_index_adheres_to_page_permissions()