diff --git a/tests/src/Flyvemdm/Tests/CommonTestCase.php b/tests/src/Flyvemdm/Tests/CommonTestCase.php index f9897124..3534c249 100644 --- a/tests/src/Flyvemdm/Tests/CommonTestCase.php +++ b/tests/src/Flyvemdm/Tests/CommonTestCase.php @@ -144,4 +144,18 @@ protected function agentFromInvitation( return $this->enrollFromInvitation($user, $input); } -} \ No newline at end of file + + /** + * @return object PluginFlyvemdmFleet mocked + * + * @param array $input input data + */ + protected function createFleet($input) { + $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); + $fleet->getMockController()->post_addItem = function () {}; + $fleet->add($input); + $this->boolean($fleet->isNewItem())->isFalse(); + + return $fleet; + } +} diff --git a/tests/suite-integration/PluginFlyvemdmAgent.php b/tests/suite-integration/PluginFlyvemdmAgent.php index 1204f0b6..ed968917 100644 --- a/tests/suite-integration/PluginFlyvemdmAgent.php +++ b/tests/suite-integration/PluginFlyvemdmAgent.php @@ -751,7 +751,10 @@ public function testMoveBetweenFleets() { $this->boolean($agent->isNewItem()) ->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); $fleetFk = $fleet::getForeignKeyField(); // add the agent in the fleet @@ -789,22 +792,6 @@ public function testMoveBetweenFleets() { } - /** - * @return object PluginFlyvemdmFleet mocked - * @tags createFleet - */ - private function createFleet() { - $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => $this->getUniqueString(), - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } - /** * Lock or unlock device and check the expected status * @param \PluginFlyvemdmAgent $agent diff --git a/tests/suite-integration/PluginFlyvemdmFile.php b/tests/suite-integration/PluginFlyvemdmFile.php index d44a0757..a20461ae 100644 --- a/tests/suite-integration/PluginFlyvemdmFile.php +++ b/tests/suite-integration/PluginFlyvemdmFile.php @@ -58,7 +58,10 @@ public function testApplyPolicy() { // Applya a policy on a file $deployPolicyData = $this->getFileDeploymentPolicy(); - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); $fleet_policy = $this->ApplyAddFilePolicy($deployPolicyData, $file, $fleet, $fileDestination); $this->boolean($fleet_policy->isNewItem()) @@ -136,21 +139,6 @@ private function getFileRemovalPolicy() { return $policyData; } - /** - * @return object PluginFlyvemdmFleet mocked - */ - private function createFleet() { - $fleet = $this->newMockInstance(PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => $this->getUniqueString(), - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } - /** * @param PluginFlyvemdmPolicy $policyData * @param FlyvemdmFile $file diff --git a/tests/suite-integration/PluginFlyvemdmPackage.php b/tests/suite-integration/PluginFlyvemdmPackage.php index 40098392..aa0c345f 100644 --- a/tests/suite-integration/PluginFlyvemdmPackage.php +++ b/tests/suite-integration/PluginFlyvemdmPackage.php @@ -87,7 +87,10 @@ public function testCreateApplication() { $policyDataRemove = new \PluginFlyvemdmPolicy(); $this->boolean($policyDataRemove->getFromDBBySymbol('removeApp'))->isTrue(); - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); $task = $this->applyAddPackagePolicy($policyDataDeploy, $package, $fleet); $this->boolean($task->isNewItem())->isFalse(); @@ -112,21 +115,6 @@ public function testCreateApplication() { $this->boolean($task->isNewItem())->isTrue(); } - /** - * @return object \PluginFlyvemdmFleet mocked - */ - private function createFleet() { - $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a fleet', - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } - /** * @param \PluginFlyvemdmPolicy $policyData * @param \PluginFlyvemdmPackage $package diff --git a/tests/suite-integration/PluginFlyvemdmPolicyDeployFile.php b/tests/suite-integration/PluginFlyvemdmPolicyDeployFile.php index 740cbe6b..86a8c482 100644 --- a/tests/suite-integration/PluginFlyvemdmPolicyDeployFile.php +++ b/tests/suite-integration/PluginFlyvemdmPolicyDeployFile.php @@ -69,7 +69,10 @@ public function testApplyPolicy() { $policyDataDeploy = new \PluginFlyvemdmPolicy(); $this->boolean($policyDataDeploy->getFromDBBySymbol('deployFile'))->isTrue(); - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $this->defaultEntity, + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); $fleetFk = \PluginFlyvemdmFleet::getForeignKeyField(); $policyFk = \PluginFlyvemdmPolicy::getForeignKeyField(); @@ -170,21 +173,6 @@ public function testApplyPolicy() { ]))->isTrue(); } - /** - * @return object PluginFlyvemdmFleet mocked - */ - private function createFleet() { - $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $this->defaultEntity, - 'name' => 'a fleet', - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } - /** * @param \PluginFlyvemdmPolicy $policyData * @param PluginFlyvemdmFile $file diff --git a/tests/suite-integration/PluginFlyvemdmPolicyRemoveFile.php b/tests/suite-integration/PluginFlyvemdmPolicyRemoveFile.php index 77f0c7c8..ca81a167 100644 --- a/tests/suite-integration/PluginFlyvemdmPolicyRemoveFile.php +++ b/tests/suite-integration/PluginFlyvemdmPolicyRemoveFile.php @@ -66,7 +66,10 @@ public function testDeployRemoveFilePolicy() { $this->boolean($file->isNewItem())->isFalse($mysqlError); // Create a fleet - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $this->defaultEntity, + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); $policyData = new \PluginFlyvemdmPolicy(); $this->boolean($policyData->getFromDBBySymbol('removeFile'))->isTrue(); @@ -106,19 +109,4 @@ public function testDeployRemoveFilePolicy() { $this->boolean($task->isNewItem())->isFalse(); } - - /** - * @return object PluginFlyvemdmFleet mocked - */ - private function createFleet() { - $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $this->defaultEntity, - 'name' => 'a fleet', - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } } diff --git a/tests/suite-integration/PluginFlyvemdmTask.php b/tests/suite-integration/PluginFlyvemdmTask.php index 043c2916..d0fa3740 100644 --- a/tests/suite-integration/PluginFlyvemdmTask.php +++ b/tests/suite-integration/PluginFlyvemdmTask.php @@ -76,7 +76,10 @@ public function testApplyPolicy() { ->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); // Create a fleet - $fleet = $this->createFleet(); + $fleet = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __FUNCTION__ + ]); // Move the agent to the fleet $this->boolean($agent->update([ @@ -158,7 +161,10 @@ public function testApplyPolicy() { // Test tassk status is created when an agent joins a fleet having policies // Create a 2nd fleet - $fleet2 = $this->createFleet(); + $fleet2 = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __FUNCTION__ + ]); // Apply a policy $policy = new \PluginFlyvemdmPolicy(); @@ -191,7 +197,10 @@ public function testApplyPolicy() { } // Create a 3rd fleet - $fleet3 = $this->createFleet(); + $fleet3 = $this->createFleet([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __CLASS__ . '::'. __FUNCTION__, + ]); // Apply a policy $policy = new \PluginFlyvemdmPolicy(); @@ -228,19 +237,4 @@ public function testApplyPolicy() { $this->string($row['status'])->isEqualTo('canceled'); } } - - /** - * @return object PluginFlyvemdmFleet mocked - */ - private function createFleet() { - $fleet = $this->newMockInstance(\PluginFlyvemdmFleet::class, '\MyMock'); - $fleet->getMockController()->post_addItem = function () {}; - $fleet->add([ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => $this->getUniqueString(), - ]); - $this->boolean($fleet->isNewItem())->isFalse(); - - return $fleet; - } } diff --git a/tests/suite-unit/PluginFlyvemdmPolicyRemoveapplication.php b/tests/suite-unit/PluginFlyvemdmPolicyRemoveapplication.php index 83d580b8..86f3da38 100644 --- a/tests/suite-unit/PluginFlyvemdmPolicyRemoveapplication.php +++ b/tests/suite-unit/PluginFlyvemdmPolicyRemoveapplication.php @@ -199,28 +199,4 @@ private function createAppInDB() { return $file; } - - /** - * Create an application (directly in DB) because we are not uploading any file - * @return \PluginFlyvemdmPackage - */ - private function createFleetInDB() { - global $DB; - - $uniqid = 'packages_fleet_' . uniqid(); - $table_file = \PluginFlyvemdmFleet::getTable(); - $query = "INSERT INTO `$table_file` ( - `name` - ) VALUES ( - '" . $uniqid . "' - )"; - $result = $DB->query($query); - $this->boolean($result)->isTrue(); - - $itemType = new \PluginFlyvemdmFleet(); - $itemType->getFromDB($DB->insert_id()); - $this->boolean($itemType->isNewItem())->isFalse(); - - return $itemType; - } } \ No newline at end of file