From bf4e6e8296996060206067f7ae5d0b4aef9f4e11 Mon Sep 17 00:00:00 2001 From: Marie Bressy <75746914+Mary-Clb@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:43:12 +0100 Subject: [PATCH] BACKPORT-CONFLICT --- CHANGELOG.md | 6 +++ hook.php | 2 + tests/Units/TagTest.php | 93 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fb592f..5629bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - CI: fix Psalm cache directory, declare a unique composer autoloader suffix +<<<<<<< HEAD +======= +- Fix tags from rules not applied on ticket update +- Fix tags being removed when saving them on a closed ticket +- Fix tag search criterion matching items of other types sharing the same ID +>>>>>>> 4f80737 (FIX / Tag search criterion matching items of other types (#403)) - Fix error when updating a ticket without creation date (e.g. entity transfer) ## [2.14.8] - 2026-09-30 diff --git a/hook.php b/hook.php index 8db6189..c52f3e2 100644 --- a/hook.php +++ b/hook.php @@ -109,6 +109,8 @@ function plugin_tag_getAddSearchOptionsNew($itemtype) 'joinparams' => [ 'jointype' => 'itemtype_item', 'specific_itemtype' => $itemtype, + // Also applied by the core in the `use_subquery` WHERE clause, which ignores `specific_itemtype` + 'condition' => ['NEWTABLE.itemtype' => $itemtype], 'beforejoin' => [ 'table' => getTableForItemType($itemtype), ], diff --git a/tests/Units/TagTest.php b/tests/Units/TagTest.php index d23d0a3..93d5a69 100644 --- a/tests/Units/TagTest.php +++ b/tests/Units/TagTest.php @@ -30,11 +30,24 @@ namespace GlpiPlugin\Tag\Tests\Units; +<<<<<<< HEAD +======= +use CommonITILObject; +use Computer; +>>>>>>> 4f80737 (FIX / Tag search criterion matching items of other types (#403)) use DBmysql; use Glpi\Search\SearchOption; use GlpiPlugin\Tag\Tests\TagTestCase; +use Phone; +use PHPUnit\Framework\Attributes\DataProvider; use PluginTagTag; +<<<<<<< HEAD use Search; +======= +use PluginTagTagItem; +use Search; +use Symfony\Component\DomCrawler\Crawler; +>>>>>>> 4f80737 (FIX / Tag search criterion matching items of other types (#403)) use Ticket; final class TagTest extends TagTestCase @@ -161,4 +174,84 @@ public function testUpdateAcceptsScalarTypeMenu(): void $this->assertSame('["Ticket"]', $tag->fields['type_menu']); } +<<<<<<< HEAD +======= + + public function testSaveButtonOnClosedTicketTargetsTagDropdown(): void + { + $this->loginAs(['login' => 'glpi', 'pass' => 'glpi']); + + $ticket = $this->createItem(Ticket::class, [ + 'name' => 'Closed ticket', + 'content' => 'Closed ticket', + 'entities_id' => $this->getTestRootEntity(true), + ]); + $ticket = $this->updateItem(Ticket::class, $ticket->getID(), ['status' => CommonITILObject::CLOSED]); + + ob_start(); + PluginTagTag::showTagDropdown([ + 'itemtype' => Ticket::class, + 'id' => $ticket->getID(), + ]); + $html = ob_get_clean(); + + $crawler = new Crawler($html); + $this->assertCount(1, $crawler->filter('#save_tag')); + + // The save button JS must read the values from the rendered tags select + $this->assertSame(1, preg_match('/\'_plugin_tag_tag_values\': \$\(\'([^\']+)\'\)\.val\(\)/', $html, $matches)); + $select = $crawler->filter($matches[1]); + $this->assertCount(1, $select); + $this->assertSame('_plugin_tag_tag_values[]', $select->attr('name')); + } + + public static function searchOnTagIgnoresOtherItemtypesProvider(): iterable + { + yield 'equals' => ['equals', true, ['tagged']]; + yield 'notequals' => ['notequals', true, ['untagged']]; + yield 'contains' => ['contains', false, ['tagged']]; + } + + #[DataProvider('searchOnTagIgnoresOtherItemtypesProvider')] + public function testSearchOnTagIgnoresOtherItemtypes(string $searchtype, bool $by_id, array $expected): void + { + /** @var DBmysql $DB */ + global $DB; + + $this->loginAs(['login' => 'glpi', 'pass' => 'glpi']); + $entity = $this->getTestRootEntity(true); + $tag_id = $this->createTag('Search itemtype tag', ['Computer']); + + $prefix = uniqid('tagsearch-'); + $tagged = $this->createItem(Computer::class, ['name' => $prefix . ' tagged', 'entities_id' => $entity]); + $untagged = $this->createItem(Computer::class, ['name' => $prefix . ' untagged', 'entities_id' => $entity]); + $links = [ + [Computer::class, $tagged->getID()], + // Another itemtype sharing the untagged computer ID must not match + [Phone::class, $untagged->getID()], + ]; + foreach ($links as [$itemtype, $items_id]) { + $DB->insert(PluginTagTagItem::getTable(), [ + 'plugin_tag_tags_id' => $tag_id, + 'itemtype' => $itemtype, + 'items_id' => $items_id, + ]); + } + + $data = Search::getDatas(Computer::class, [ + 'criteria' => [ + ['field' => 1, 'searchtype' => 'contains', 'value' => $prefix], + [ + 'link' => 'AND', + 'field' => PluginTagTag::S_OPTION, + 'searchtype' => $searchtype, + 'value' => $by_id ? $tag_id : 'Search itemtype tag', + ], + ], + ], [1]); + + $names = array_column(array_column($data['data']['rows'], 'raw'), 'ITEM_Computer_1'); + $this->assertSame(array_map(fn($name) => sprintf('%s %s', $prefix, $name), $expected), $names); + } +>>>>>>> 4f80737 (FIX / Tag search criterion matching items of other types (#403)) }