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

Commit

Permalink
fix(tests): restore disabled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Mar 17, 2017
1 parent 31568b8 commit 47395ce
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 50 deletions.
Expand Up @@ -31,7 +31,7 @@

use Flyvemdm\Test\ApiRestTestCase;

class CreateInvitationSendsAnEmail extends ApiRestTestCase {
class CreateInvitationSendsAnEmailTest extends ApiRestTestCase {

protected static $sessionToken;

Expand Down
Expand Up @@ -29,7 +29,7 @@
------------------------------------------------------------------------------
*/

class DeviceCountLimit extends RegisteredUserTestCase {
class DeviceCountLimitTest extends RegisteredUserTestCase {

protected static $deviceLimit = 5;

Expand Down
Expand Up @@ -29,14 +29,14 @@
------------------------------------------------------------------------------
*/

class PolicyNotification extends RegisteredUserTestCase
class PolicyNotificationTest extends RegisteredUserTestCase
{

public function testInitCreateFleet() {
$fleet = new PluginFlyvemdmFleet();
$fleet->add([
'name' => 'test fleet',
'entities_id' => $entityId
'entities_id' => $_SESSION['glpiactive_entity']
]);
$this->assertFalse($fleet->isNewItem());

Expand All @@ -53,51 +53,21 @@ public function testApplyPolicy($fleet) {
$policyFactory = new PluginFlyvemdmPolicyFactory();
$policy = $policyFactory->createFromDBByID($policyData->getID());

// Prepare subscriber
$mqttSubscriber = new MqttClientHandler();
$publishedMessage = null;

// Contains true if the ploicy successfully applied to the fleet
$fleetPolicyId = null;

// function to trigger the mqtt message
$sendMqttMessageCallback = function () use (&$fleetPolicy, &$fleetPolicyId, &$fleet, &$policyData) {
// Apply the policy to a fleet
$fleetPolicy = new PluginFlyvemdmFleet_Policy();
$fleetPolicyId = $fleetPolicy->add([
'plugin_flyvemdm_fleets_id' => $fleet->getID(),
'plugin_flyvemdm_policies_id' => $policyData->getID(),
'value' => 'PASSWORD_NONE'
]);
};

// Callback each time the mqtt broker sends a pingresp
$callback = function () use (&$publishedMessage, &$mqttSubscriber) {
$publishedMessage = $mqttSubscriber->getPublishedMessage();
};

$mqttSubscriber->setSendMqttMessageCallback($sendMqttMessageCallback);
$mqttSubscriber->setPingCallback($callback);
$topic = $fleet->getTopic();
$mqttSubscriber->subscribe("$topic/Command");

$this->assertGreaterThan(0, $fleetPolicyId, "Failed to apply the policy");
$this->assertInstanceOf('\sskaje\mqtt\Message\PUBLISH', $publishedMessage);

$data = array();
$data['publishedMessage'] = $publishedMessage;

return $data;
}
// Apply the policy to a fleet
$fleetPolicy = new PluginFlyvemdmFleet_Policy();
$fleetPolicyId = $fleetPolicy->add([
'plugin_flyvemdm_fleets_id' => $fleet->getID(),
'plugin_flyvemdm_policies_id' => $policyData->getID(),
'value' => 'PASSWORD_NONE'
]);

/**
* @depends testApplyPolicy
* @param array $data
*/
public function testPolicyApplyMessageIsValid($data) {
$published = $data['publishedMessage'];
$json = $published->getMessage();
$this->assertJson($json);
$groupName = $policyData->getField('group');
$fleetId = $fleet->getID();
$mqttUpdateQueue = new PluginFlyvemdmMqttupdatequeue();
$rows = $mqttUpdateQueue->find("`group` = '$groupName'
AND `plugin_flyvemdm_fleets_id` = '$fleetId'
AND `status` = 'queued'");
$this->assertCount(1, $rows);
}

}
2 changes: 1 addition & 1 deletion tests/inc/GuestUserTestCase.php
Expand Up @@ -29,7 +29,7 @@
------------------------------------------------------------------------------
*/

use Glpi\test\CommonTestCase;
use Glpi\Test\CommonTestCase;

class GuestUserTestCase extends CommonTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/inc/RegisteredUserTestCase.php
Expand Up @@ -29,7 +29,7 @@
------------------------------------------------------------------------------
*/

use Glpi\test\CommonTestCase;
use Glpi\Test\CommonTestCase;

class RegisteredUserTestCase extends CommonTestCase
{
Expand Down

0 comments on commit 47395ce

Please sign in to comment.