Skip to content

Commit

Permalink
test(entityconfig): enyhance tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Jan 7, 2021
1 parent 80ff1c7 commit a7264d3
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions tests/3-unit/PluginFormcreatorEntityConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,108 @@ public function testGetTabNameForItem($item, $expected) {

public function testGetUsedConfig() {
$this->login('glpi', 'glpi');

// Create an entity with 2 sub entities
$base = 'Root entity > ' . $this->getUniqueString();
$entity = new \Entity();
$entityId = $entity->add([
'name' => $this->getUniqueString(),
'entities_id' => '0',
]);
$this->boolean($entity->isNewID($entityId))->isFalse();

$entityId1 = $entity->add([
'name' => "$base > a",
'entities_id' => $entityId,
]);
$this->boolean($entity->isNewID($entityId1))->isFalse();

$entityId2 = $entity->add([
'name' => "b",
'entities_id' => $entityId1,
]);
$this->boolean($entity->isNewID($entityId2))->isFalse();

$entityId3 = $entity->add([
'name' => "c",
'entities_id' => $entityId,
]);
$this->boolean($entity->isNewID($entityId3))->isFalse();

// Set configuration for the 2 sub entities
$instance = $this->newTestedInstance();
$instance->add([
'id' => $entityId,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_EXTENDED_SERVICE_CATALOG,
'is_kb_separated' => \PluginFormcreatorEntityconfig::CONFIG_KB_MERGED,
'sort_order' => \PluginFormcreatorEntityconfig::CONFIG_SORT_ALPHABETICAL,
]);
$this->boolean($instance->isNewItem())->isFalse();

$instance = $this->newTestedInstance();
$instance->add([
'id' => $entityId1,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG,
'is_kb_separated' => \PluginFormcreatorEntityconfig::CONFIG_KB_MERGED,
'sort_order' => \PluginFormcreatorEntityconfig::CONFIG_SORT_ALPHABETICAL,
]);
$this->boolean($instance->isNewItem())->isFalse();

$instance = $this->newTestedInstance();
$instance->add([
'id' => $entityId2,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_EXTENDED_SERVICE_CATALOG,
'is_kb_separated' => \PluginFormcreatorEntityconfig::CONFIG_KB_DISTINCT,
'sort_order' => \PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY,
]);
$this->boolean($instance->isNewItem())->isFalse();

$instance = $this->newTestedInstance();
$instance->add([
'id' => $entityId3,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_PARENT,
'is_kb_separated' => \PluginFormcreatorEntityconfig::CONFIG_PARENT,
'sort_order' => \PluginFormcreatorEntityconfig::CONFIG_PARENT,
]);
$this->boolean($instance->isNewItem())->isFalse();

// Test settings of entities
$output = $instance::getUsedConfig('replace_helpdesk', $entityId1);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG);
$output = $instance::getUsedConfig('is_kb_separated', $entityId1);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_KB_MERGED);
$output = $instance::getUsedConfig('sort_order', $entityId1);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SORT_ALPHABETICAL);

$output = $instance::getUsedConfig('replace_helpdesk', $entityId2);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_EXTENDED_SERVICE_CATALOG);
$output = $instance::getUsedConfig('is_kb_separated', $entityId2);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_KB_DISTINCT);
$output = $instance::getUsedConfig('sort_order', $entityId2);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY);

$output = $instance::getUsedConfig('replace_helpdesk', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_EXTENDED_SERVICE_CATALOG);
$output = $instance::getUsedConfig('is_kb_separated', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_KB_MERGED);
$output = $instance::getUsedConfig('sort_order', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SORT_ALPHABETICAL);

// Check change on parent entity propagates to child with inherited settings
$instance = $this->newTestedInstance();
$instance->update([
'id' => $entityId2,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_PARENT,
'id' => $entityId,
'replace_helpdesk' => \PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG,
'is_kb_separated' => \PluginFormcreatorEntityconfig::CONFIG_KB_DISTINCT,
'sort_order' => \PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY,
]);
$output = $instance::getUsedConfig('replace_helpdesk', $entityId2);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG);

$output = $instance::getUsedConfig('replace_helpdesk', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG);
$output = $instance::getUsedConfig('is_kb_separated', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_KB_DISTINCT);
$output = $instance::getUsedConfig('sort_order', $entityId3);
$this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY);
}

public function testgetEnumHelpdeskMode() {
Expand Down

0 comments on commit a7264d3

Please sign in to comment.