Skip to content
Draft
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down
93 changes: 93 additions & 0 deletions tests/Units/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,24 @@

namespace GlpiPlugin\Tag\Tests\Units;

<<<<<<< HEAD

Check failure on line 33 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_SL on line 33

Check failure on line 33 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_SL on line 33
=======
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
Expand Down Expand Up @@ -137,12 +150,12 @@
$data = Search::getDatas(Ticket::class, ['criteria' => []], [PluginTagTag::S_OPTION + 1]);

$this->assertArrayHasKey('sql', $data);
$this->assertStringContainsString('glpi_plugin_tag_tags', $data['sql']['search']);

Check failure on line 153 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting '-' or T_STRING or T_VARIABLE or T_NUM_STRING on line 153

Check failure on line 153 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting '-' or T_STRING or T_VARIABLE or T_NUM_STRING on line 153
}

public function testUpdateAcceptsScalarTypeMenu(): void
{
$tag = $this->createItem(

Check failure on line 158 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 158

Check failure on line 158 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 158
PluginTagTag::class,
[
'name' => 'Massive update test',
Expand All @@ -152,13 +165,93 @@
['type_menu'],
);

$tag = $this->updateItem(

Check failure on line 168 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 168

Check failure on line 168 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 168
PluginTagTag::class,
$tag->getID(),

Check failure on line 170 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 170

Check failure on line 170 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 170
['type_menu' => 'Ticket'],
['type_menu'],
);

$this->assertSame('["Ticket"]', $tag->fields['type_menu']);

Check failure on line 175 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 175

Check failure on line 175 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 175
}
<<<<<<< HEAD
=======

public function testSaveButtonOnClosedTicketTargetsTagDropdown(): void
{
$this->loginAs(['login' => 'glpi', 'pass' => 'glpi']);

Check failure on line 182 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 182

Check failure on line 182 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 182

$ticket = $this->createItem(Ticket::class, [

Check failure on line 184 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 184

Check failure on line 184 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 184
'name' => 'Closed ticket',
'content' => 'Closed ticket',
'entities_id' => $this->getTestRootEntity(true),

Check failure on line 187 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 187

Check failure on line 187 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 187
]);
$ticket = $this->updateItem(Ticket::class, $ticket->getID(), ['status' => CommonITILObject::CLOSED]);

Check failure on line 189 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 189

Check failure on line 189 in tests/Units/TagTest.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 189

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))
}
Loading