Skip to content

Commit

Permalink
Tags: Stopped recycle bin tags being counted on index
Browse files Browse the repository at this point in the history
For #4892
Added test to cover.
  • Loading branch information
ssddanbrown committed Apr 15, 2024
1 parent d9ff001 commit f05ec4c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/Activity/TagRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilt
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($sort, $listOptions->getOrder());
->orderBy($sort, $listOptions->getOrder())
->whereHas('entity');

if ($nameFilter) {
$query->where('name', '=', $nameFilter);
Expand Down
20 changes: 19 additions & 1 deletion tests/Entity/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TagTest extends TestCase
{
protected $defaultTagCount = 20;
protected int $defaultTagCount = 20;

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

public function test_tag_index_does_not_include_tags_on_recycle_bin_items()
{
$page = $this->entities->page();
$page->tags()->create(['name' => 'DeleteRecord', 'value' => 'itemToDeleteTest']);

$resp = $this->asEditor()->get('/tags');
$resp->assertSee('DeleteRecord');
$resp = $this->asEditor()->get('/tags?name=DeleteRecord');
$resp->assertSee('itemToDeleteTest');

$this->entities->sendToRecycleBin($page);

$resp = $this->asEditor()->get('/tags');
$resp->assertDontSee('DeleteRecord');
$resp = $this->asEditor()->get('/tags?name=DeleteRecord');
$resp->assertDontSee('itemToDeleteTest');
}

public function test_tag_classes_visible_on_entities()
{
$this->asEditor();
Expand Down
23 changes: 23 additions & 0 deletions tests/Helpers/EntityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ public function newDraftPage(array $input = ['name' => 'test page', 'html' => 'M
return $draftPage;
}

/**
* Send an entity to the recycle bin.
*/
public function sendToRecycleBin(Entity $entity)
{
$trash = app()->make(TrashCan::class);

if ($entity instanceof Page) {
$trash->softDestroyPage($entity);
} elseif ($entity instanceof Chapter) {
$trash->softDestroyChapter($entity);
} elseif ($entity instanceof Book) {
$trash->softDestroyBook($entity);
} elseif ($entity instanceof Bookshelf) {
$trash->softDestroyBookshelf($entity);
}

$entity->refresh();
if (is_null($entity->deleted_at)) {
throw new \Exception("Could not send entity type [{$entity->getMorphClass()}] to the recycle bin");
}
}

/**
* Fully destroy the given entity from the system, bypassing the recycle bin
* stage. Still runs through main app deletion logic.
Expand Down

0 comments on commit f05ec4c

Please sign in to comment.