Skip to content

Commit 083350e

Browse files
committed
add another test
1 parent f2d9870 commit 083350e

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

phpunit/functional/Glpi/Asset/CustomFieldDefinitionTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
use Glpi\Asset\CustomFieldType\URLType;
5050
use Glpi\DBAL\QueryExpression;
5151
use Glpi\DBAL\QueryFunction;
52+
use Glpi\Search\SearchEngine;
53+
use Glpi\Search\SearchOption;
5254
use PHPUnit\Framework\Attributes\DataProvider;
5355

5456
class CustomFieldDefinitionTest extends DbTestCase
@@ -631,4 +633,70 @@ public function testTypeUpdate(): void
631633
$this->assertFalse($updated);
632634
$this->hasSessionMessages(ERROR, ['The field type cannot be changed.']);
633635
}
636+
637+
public function testSearchDropdownField(): void
638+
{
639+
$this->login();
640+
641+
$opts = SearchOption::getOptionsForItemtype('Glpi\\CustomAsset\\Test01Asset');
642+
$single_dropdown_opt = null;
643+
$multiple_dropdown_opt = null;
644+
645+
foreach ($opts as $num => $opt) {
646+
if (!is_array($opt)) {
647+
continue;
648+
}
649+
if ($opt['name'] === 'Single Custom Tag') {
650+
$single_dropdown_opt = $num;
651+
} elseif ($opt['name'] === 'Multi Custom Tag') {
652+
$multiple_dropdown_opt = $num;
653+
}
654+
}
655+
$this->assertNotNull($single_dropdown_opt);
656+
$this->assertNotNull($multiple_dropdown_opt);
657+
658+
$this->createItem('Glpi\\CustomAsset\\Test01Asset', [
659+
'entities_id' => $this->getTestRootEntity(true),
660+
'name' => __FUNCTION__,
661+
'custom_customtagsingle' => getItemByTypeName('Glpi\\CustomDropdown\\CustomTagDropdown', 'Tag01', true),
662+
'custom_customtagmulti' => [
663+
getItemByTypeName('Glpi\\CustomDropdown\\CustomTagDropdown', 'Tag01', true),
664+
getItemByTypeName('Glpi\\CustomDropdown\\CustomTagDropdown', 'Tag02', true)
665+
],
666+
], ['custom_customtagsingle', 'custom_customtagmulti']);
667+
668+
$data = SearchEngine::getData('Glpi\\CustomAsset\\Test01Asset', [
669+
'criteria' => [
670+
[
671+
'link' => 'AND',
672+
'field' => 'name',
673+
'searchtype' => 'equals',
674+
'value' => __FUNCTION__,
675+
],
676+
[
677+
'link' => 'OR',
678+
'field' => $single_dropdown_opt,
679+
'searchtype' => 'contains',
680+
'value' => 'Tag',
681+
],
682+
[
683+
'link' => 'OR',
684+
'field' => $multiple_dropdown_opt,
685+
'searchtype' => 'contains',
686+
'value' => 'Tag',
687+
]
688+
]
689+
], [$single_dropdown_opt, $multiple_dropdown_opt]);
690+
691+
$this->assertCount(1, $data['data']['rows']);
692+
$row = reset($data['data']['rows'])['raw'];
693+
$this->assertEquals(
694+
'Tag01',
695+
$row['ITEM_Glpi\\CustomAsset\\Test01Asset_' . $single_dropdown_opt]
696+
);
697+
$this->assertEquals(
698+
'Tag01$#$1$$##$$Tag02$#$2',
699+
$row['ITEM_Glpi\\CustomAsset\\Test01Asset_' . $multiple_dropdown_opt]
700+
);
701+
}
634702
}

tests/src/autoload/functions.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,12 @@ function loadDataset()
732732
],
733733
'Glpi\\CustomDropdown\\CustomTagDropdown' => [
734734
[
735+
'id' => 1,
735736
'name' => 'Tag01',
736737
'entities_id' => '_test_root_entity',
737738
],
738739
[
740+
'id' => 2,
739741
'name' => 'Tag02',
740742
'entities_id' => '_test_root_entity',
741743
],
@@ -766,37 +768,37 @@ function loadDataset()
766768
'assets_assetdefinitions_id' => 'Test01',
767769
'label' => 'Test String',
768770
'type' => 'Glpi\\Asset\\CustomFieldType\\StringType',
769-
'field_options' => '{"full_width":"0","readonly":"0","required":"0"}',
771+
'field_options' => ["full_width" => "0", "readonly" => "0", "required" => "0"],
770772
],
771773
[
772774
'system_name' => 'customtagsingle',
773775
'assets_assetdefinitions_id' => 'Test01',
774776
'label' => 'Single Custom Tag',
775777
'type' => 'Glpi\\Asset\\CustomFieldType\\DropdownType',
776778
'itemtype' => 'Glpi\\CustomDropdown\\CustomTagDropdown',
777-
'field_options' => '{"full_width":"0","readonly":"0","required":"0"}',
779+
'field_options' => ["full_width" => "0", "readonly" => "0", "required" => "0"],
778780
],
779781
[
780782
'system_name' => 'customtagmulti',
781783
'assets_assetdefinitions_id' => 'Test01',
782784
'label' => 'Multi Custom Tag',
783785
'type' => 'Glpi\\Asset\\CustomFieldType\\DropdownType',
784786
'itemtype' => 'Glpi\\CustomDropdown\\CustomTagDropdown',
785-
'field_options' => '{"full_width":"0","readonly":"0","required":"0","multiple":"1"}',
787+
'field_options' => ["full_width" => "0", "readonly" => "0", "required" => "0", "multiple" => "1"],
786788
],
787789
],
788790
'Glpi\\CustomAsset\\Test01Asset' => [
789791
[
790792
'name' => 'TestA',
791793
'entities_id' => '_test_root_entity',
792794
'custom_teststring' => 'Test String A',
793-
'custom_customtagsingle' => 'Tag01',
795+
'custom_customtagsingle' => "1"
794796
],
795797
[
796798
'name' => 'TestB',
797799
'entities_id' => '_test_root_entity',
798800
'custom_teststring' => 'Test String B',
799-
'custom_customtagmulti' => ['Tag01', 'Tag02'],
801+
'custom_customtagmulti' => [0 => "1", 1 => "2"],
800802
],
801803
],
802804
'Glpi\\CustomAsset\\Test02Asset' => [

0 commit comments

Comments
 (0)