From 49498cfaf9b6f10d993755b47e2cdb3cf256461d Mon Sep 17 00:00:00 2001
From: Dan Brown <ssddanbrown@googlemail.com>
Date: Mon, 16 May 2022 14:05:21 +0100
Subject: [PATCH] Fixed entity-specific tag counts listing

Was reporting wrong due to use of old polymorphic namespace references.
Test was not picking up as assertElementContains had wider scope than
expected, looking within the HTML of the element instead of the text
which you might expect. Updated test helper to look at text instead.
---
 app/Actions/TagRepo.php | 8 ++++----
 tests/TestResponse.php  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/app/Actions/TagRepo.php b/app/Actions/TagRepo.php
index 0acee7486..8cf107601 100644
--- a/app/Actions/TagRepo.php
+++ b/app/Actions/TagRepo.php
@@ -28,10 +28,10 @@ class TagRepo
                 'name',
                 ($searchTerm || $nameFilter) ? 'value' : DB::raw('COUNT(distinct value) as `values`'),
                 DB::raw('COUNT(id) as usages'),
-                DB::raw('SUM(IF(entity_type = \'BookStack\\\\Page\', 1, 0)) as page_count'),
-                DB::raw('SUM(IF(entity_type = \'BookStack\\\\Chapter\', 1, 0)) as chapter_count'),
-                DB::raw('SUM(IF(entity_type = \'BookStack\\\\Book\', 1, 0)) as book_count'),
-                DB::raw('SUM(IF(entity_type = \'BookStack\\\\BookShelf\', 1, 0)) as shelf_count'),
+                DB::raw('SUM(IF(entity_type = \'page\', 1, 0)) as page_count'),
+                DB::raw('SUM(IF(entity_type = \'chapter\', 1, 0)) as chapter_count'),
+                DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'),
+                DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'),
             ])
             ->orderBy($nameFilter ? 'value' : 'name');
 
diff --git a/tests/TestResponse.php b/tests/TestResponse.php
index 4e53aa020..888bacdfc 100644
--- a/tests/TestResponse.php
+++ b/tests/TestResponse.php
@@ -111,7 +111,7 @@ class TestResponse extends BaseTestResponse
 
         foreach ($elements as $element) {
             $element = new Crawler($element);
-            if (preg_match("/$pattern/i", $element->html())) {
+            if (preg_match("/$pattern/i", $element->text())) {
                 $matched = true;
                 break;
             }