Skip to content

Commit

Permalink
test(category): refactor class expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 23, 2023
1 parent 238b4fc commit f30c28e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/3-unit/PluginFormcreatorCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
namespace tests\units;
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
use Entity;
use PluginFormcreatorForm;
use Session;

class PluginFormcreatorCategory extends CommonTestCase {
public function providerGetTypeName() {
Expand Down Expand Up @@ -80,15 +83,15 @@ public function testGetCategoryTree() {

// create a sub entity which will take in the forms and cateory for this test
// and not conflict with previous data
$entity = new \Entity();
$entity = new Entity();
$rand = mt_rand();
$entities_id = $entity->add([
'name' => "test formcreator sub entity $rand",
'entities_id' => 0
]);

// create some categories for forms
$category = new \PluginFormcreatorCategory;
$category = $this->newTestedInstance();
$categories = [];
for ($i = 0; $i < 5; $i++) {
$root_cat = $category->add([
Expand All @@ -104,7 +107,7 @@ public function testGetCategoryTree() {
}

// create some forms
$form = new \PluginFormcreatorForm;
$form = new PluginFormcreatorForm;
for ($i = 0; $i < 10; $i++) {
$form->add([
'name' => "testgetCategoryTree form $i",
Expand All @@ -116,10 +119,11 @@ public function testGetCategoryTree() {
}

// Set active entity
\Session::changeActiveEntities($entities_id, true);
Session::changeActiveEntities($entities_id, true);

//test method
$tree = \PluginFormcreatorCategory::getCategoryTree();
$testedClassName = $this->getTestedClassName();
$tree = $testedClassName::getCategoryTree();
$this->array($tree)
->isNotEmpty()
->child['subcategories'](function($child) {
Expand All @@ -132,6 +136,6 @@ public function testGetCategoryTree() {
}

// return to root entity
\Session::changeActiveEntities(0, true);
Session::changeActiveEntities(0, true);
}
}

0 comments on commit f30c28e

Please sign in to comment.