diff --git a/phpunit/DbTestCase.php b/phpunit/DbTestCase.php index 32f383f8a5ca..91080f2c54d4 100644 --- a/phpunit/DbTestCase.php +++ b/phpunit/DbTestCase.php @@ -347,8 +347,8 @@ protected function initAssetDefinition( ], skip_fields: ['capacities', 'profiles'] // JSON encoded fields cannot be automatically checked ); - $this->array($this->callPrivateMethod($definition, 'getDecodedCapacitiesField'))->isEqualTo($capacities); - $this->array($this->callPrivateMethod($definition, 'getDecodedProfilesField'))->isEqualTo($profiles); + $this->assertEquals($capacities, $this->callPrivateMethod($definition, 'getDecodedCapacitiesField')); + $this->assertEquals($profiles, $this->callPrivateMethod($definition, 'getDecodedProfilesField')); $manager = AssetDefinitionManager::getInstance(); $this->callPrivateMethod($manager, 'loadConcreteClass', $definition); diff --git a/phpunit/GLPITestCase.php b/phpunit/GLPITestCase.php index d80339d72070..63805a2b1d43 100644 --- a/phpunit/GLPITestCase.php +++ b/phpunit/GLPITestCase.php @@ -33,6 +33,7 @@ * --------------------------------------------------------------------- */ +use Glpi\Asset\AssetDefinition; use Glpi\Tests\Log\TestHandler; use Monolog\Level; use Monolog\Logger; diff --git a/phpunit/functional/Glpi/Asset/DictionaryTest.php b/phpunit/functional/Glpi/Asset/DictionaryTest.php new file mode 100644 index 000000000000..504c96c65419 --- /dev/null +++ b/phpunit/functional/Glpi/Asset/DictionaryTest.php @@ -0,0 +1,119 @@ +. + * + * --------------------------------------------------------------------- + */ + +namespace tests\units\Glpi\Asset; + +use DbTestCase; +use Rule; +use RuleCollection; +use Session; + +class DictionaryTest extends DbTestCase +{ + public function testInDictionaryList() + { + $this->login(); + + $definition = $this->initAssetDefinition(); + $dictionaries = RuleCollection::getDictionnaries(); + + $has_model_dictionary = false; + $has_type_dictionary = false; + + foreach ($dictionaries as $group) { + if ($group['type'] === 'Models') { + foreach ($group['entries'] as $entry) { + if ( + $entry['label'] === $definition->getAssetModelClassName()::getTypeName(Session::getPluralNumber()) + && str_contains($entry['link'], 'front/asset/ruledictionarymodel.php?class=' . $definition->fields['system_name']) + && $entry['icon'] === $definition->getAssetModelClassName()::getIcon() + ) { + $has_model_dictionary = true; + break; + } + } + } else if ($group['type'] === 'Types') { + foreach ($group['entries'] as $entry) { + if ( + $entry['label'] === $definition->getAssetTypeClassName()::getTypeName(Session::getPluralNumber()) + && str_contains($entry['link'], 'front/asset/ruledictionarytype.php?class=' . $definition->fields['system_name']) + && $entry['icon'] === $definition->getAssetTypeClassName()::getIcon() + ) { + $has_type_dictionary = true; + break; + } + } + } + } + + $this->assertTrue($has_model_dictionary); + $this->assertTrue($has_type_dictionary); + } + + public function testMenuContent() + { + $this->login(); + $definition = $this->initAssetDefinition(); + $rule_menu_content = Rule::getMenuContent(); + $model_key = 'model.' . $definition->fields['system_name']; + $type_key = 'type.' . $definition->fields['system_name']; + + $this->assertArrayHasKey($model_key, $rule_menu_content['dictionnary']['options']); + $this->assertArrayHasKey($type_key, $rule_menu_content['dictionnary']['options']); + + $this->assertEquals( + $definition->getAssetModelClassName()::getTypeName(Session::getPluralNumber()), + $rule_menu_content['dictionnary']['options'][$model_key]['title'] + ); + $model_page = $rule_menu_content['dictionnary']['options'][$model_key]['page']; + $this->assertEquals('/front/asset/ruledictionarymodel.php?class=' . $definition->fields['system_name'], $model_page); + $this->assertEquals($model_page, $rule_menu_content['dictionnary']['options'][$model_key]['links']['search']); + $this->assertStringContainsString( + '/front/asset/ruledictionarymodel.form.php?class=' . $definition->fields['system_name'], + $rule_menu_content['dictionnary']['options'][$model_key]['links']['add'] + ); + + $this->assertEquals( + $definition->getAssetTypeClassName()::getTypeName(Session::getPluralNumber()), + $rule_menu_content['dictionnary']['options'][$type_key]['title'] + ); + $type_page = $rule_menu_content['dictionnary']['options'][$type_key]['page']; + $this->assertEquals('/front/asset/ruledictionarytype.php?class=' . $definition->fields['system_name'], $type_page); + $this->assertEquals($type_page, $rule_menu_content['dictionnary']['options'][$type_key]['links']['search']); + $this->assertStringContainsString( + '/front/asset/ruledictionarytype.form.php?class=' . $definition->fields['system_name'], + $rule_menu_content['dictionnary']['options'][$type_key]['links']['add'] + ); + } +} diff --git a/phpunit/functional/HtmlTest.php b/phpunit/functional/HtmlTest.php index 5fc6bbd38975..3a832816fb63 100644 --- a/phpunit/functional/HtmlTest.php +++ b/phpunit/functional/HtmlTest.php @@ -270,7 +270,7 @@ public function testGetMenuInfos() 'Item_DeviceSimcard' ]; $this->assertSame('Assets', $menu['assets']['title']); - $this->assertSame($expected, $menu['assets']['types']); + $this->assertSame($expected, array_intersect($expected, $menu['assets']['types'])); $expected = [ 'Ticket', diff --git a/src/Glpi/Asset/AssetDefinitionManager.php b/src/Glpi/Asset/AssetDefinitionManager.php index fc5034fd7a27..57106e999c88 100644 --- a/src/Glpi/Asset/AssetDefinitionManager.php +++ b/src/Glpi/Asset/AssetDefinitionManager.php @@ -538,14 +538,14 @@ public static function getSearchURL(\$full = true) { /** @var array \$CFG_GLPI */ global \$CFG_GLPI; - return (\$full ? \$CFG_GLPI['root_doc'] : '') . 'asset/ruledictionarytype.php?class={$definition->fields['system_name']}'; + return (\$full ? \$CFG_GLPI['root_doc'] : '') . '/front/asset/ruledictionarytype.php?class={$definition->fields['system_name']}'; } public static function getFormURL(\$full = true) { /** @var array \$CFG_GLPI */ global \$CFG_GLPI; - return (\$full ? \$CFG_GLPI['root_doc'] : '') . 'asset/ruledictionarytype.form.php?class={$definition->fields['system_name']}'; + return (\$full ? \$CFG_GLPI['root_doc'] : '') . '/front/asset/ruledictionarytype.form.php?class={$definition->fields['system_name']}'; } } PHP