Skip to content

Commit f05ec4c

Browse files
committed
Tags: Stopped recycle bin tags being counted on index
For #4892 Added test to cover.
1 parent d9ff001 commit f05ec4c

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

app/Activity/TagRepo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilt
3838
DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'),
3939
DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'),
4040
])
41-
->orderBy($sort, $listOptions->getOrder());
41+
->orderBy($sort, $listOptions->getOrder())
42+
->whereHas('entity');
4243

4344
if ($nameFilter) {
4445
$query->where('name', '=', $nameFilter);

tests/Entity/TagTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class TagTest extends TestCase
1111
{
12-
protected $defaultTagCount = 20;
12+
protected int $defaultTagCount = 20;
1313

1414
/**
1515
* Get an instance of a page that has many tags.
@@ -193,6 +193,24 @@ public function test_tag_index_shows_message_on_no_results()
193193
$resp->assertSee('Tags can be assigned via the page editor sidebar');
194194
}
195195

196+
public function test_tag_index_does_not_include_tags_on_recycle_bin_items()
197+
{
198+
$page = $this->entities->page();
199+
$page->tags()->create(['name' => 'DeleteRecord', 'value' => 'itemToDeleteTest']);
200+
201+
$resp = $this->asEditor()->get('/tags');
202+
$resp->assertSee('DeleteRecord');
203+
$resp = $this->asEditor()->get('/tags?name=DeleteRecord');
204+
$resp->assertSee('itemToDeleteTest');
205+
206+
$this->entities->sendToRecycleBin($page);
207+
208+
$resp = $this->asEditor()->get('/tags');
209+
$resp->assertDontSee('DeleteRecord');
210+
$resp = $this->asEditor()->get('/tags?name=DeleteRecord');
211+
$resp->assertDontSee('itemToDeleteTest');
212+
}
213+
196214
public function test_tag_classes_visible_on_entities()
197215
{
198216
$this->asEditor();

tests/Helpers/EntityProvider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ public function newDraftPage(array $input = ['name' => 'test page', 'html' => 'M
207207
return $draftPage;
208208
}
209209

210+
/**
211+
* Send an entity to the recycle bin.
212+
*/
213+
public function sendToRecycleBin(Entity $entity)
214+
{
215+
$trash = app()->make(TrashCan::class);
216+
217+
if ($entity instanceof Page) {
218+
$trash->softDestroyPage($entity);
219+
} elseif ($entity instanceof Chapter) {
220+
$trash->softDestroyChapter($entity);
221+
} elseif ($entity instanceof Book) {
222+
$trash->softDestroyBook($entity);
223+
} elseif ($entity instanceof Bookshelf) {
224+
$trash->softDestroyBookshelf($entity);
225+
}
226+
227+
$entity->refresh();
228+
if (is_null($entity->deleted_at)) {
229+
throw new \Exception("Could not send entity type [{$entity->getMorphClass()}] to the recycle bin");
230+
}
231+
}
232+
210233
/**
211234
* Fully destroy the given entity from the system, bypassing the recycle bin
212235
* stage. Still runs through main app deletion logic.

0 commit comments

Comments
 (0)