Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- CI: fix Psalm cache directory, declare a unique composer autoloader suffix
- 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
- Fix error when updating a ticket without creation date (e.g. entity transfer)

## [2.14.8] - 2026-09-30
Expand Down
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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),
],
Expand Down
54 changes: 54 additions & 0 deletions tests/Units/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
namespace GlpiPlugin\Tag\Tests\Units;

use CommonITILObject;
use Computer;
use DBmysql;
use GlpiPlugin\Tag\Tests\TagTestCase;
use Phone;
use PHPUnit\Framework\Attributes\DataProvider;
use PluginTagTag;
use PluginTagTagItem;
use Search;
use Symfony\Component\DomCrawler\Crawler;
use Ticket;

Expand Down Expand Up @@ -181,4 +186,53 @@ public function testSaveButtonOnClosedTicketTargetsTagDropdown(): void
$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);
}
}
Loading