Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
test(entityconfig): add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 19, 2018
1 parent 1f70611 commit a151acc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/suite-unit/PluginFlyvemdmEntityConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PluginFlyvemdmEntityConfig extends CommonTestCase {
public function beforeTestMethod($method) {
switch ($method) {
case 'testCanAddAgent':
case 'testHook_entity_add':
$this->login('glpi', 'glpi');
break;
}
Expand Down Expand Up @@ -150,4 +151,39 @@ public function testPrepareInputForUpdate(array $credentials, array $input, $out
$this->array($actualOutput)->containsValues($output);
}
}

public function testHook_entity_add() {
$config = \Config::getConfigurationValues('flyvemdm', ['default_device_limit']);
$defaultDeviceLimit = $config['default_device_limit'];

// Create an entity in DB
// This must run hook_entity_add
$entity = new \Entity();
$entityId = $entity->import([
'name' => __FUNCTION__,
'entities_id' => 0
]);
// The root entity (id 0) already exists then it cannot be returned or retrieved
$this->integer($entityId)->isGreaterThan(0);

$instance = $this->newTestedInstance();
$instance->getFromDBByCrit([
\Entity::getForeignKeyField() => $entityId
]);
$this->boolean($instance->isNewItem())->isFalse();
$this->string($instance->getField('agent_token'))->isNotEmpty();
$this->string($instance->getField('agent_token_life'))->isEqualTo('P7D');
$this->string($instance->getField('support_name'))->isEqualTo('');
$this->string($instance->getField('support_phone'))->isEqualTo('');
$this->string($instance->getField('support_website'))->isEqualTo('');
$this->string($instance->getField('support_email'))->isEqualTo('');
$this->string($instance->getField('support_address'))->isEqualTo('');
$this->integer((int) $instance->getField('managed'))->isEqualTo(0);
$this->string($instance->getField('download_url'))->isEqualTo(PLUGIN_FLYVEMDM_AGENT_DOWNLOAD_URL);
$this->integer((int) $instance->getField('device_limit'))->isEqualTo((int) $defaultDeviceLimit);

// Test directories are created
$this->boolean(is_dir(FLYVEMDM_PACKAGE_PATH . '/' . $entityId));
$this->boolean(is_dir(FLYVEMDM_FILE_PATH . '/' . $entityId));
}
}

0 comments on commit a151acc

Please sign in to comment.