-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,10 @@ | |
|
||
namespace GlpiPlugin\Formcreator\Tests; | ||
|
||
use PluginFormcreatorForm; | ||
use PluginFormcreatorFormanswer; | ||
use PluginFormcreatorTarget_Actor; | ||
use Ticket_User; | ||
|
||
abstract class AbstractItilTargetTestCase extends CommonTargetTestCase { | ||
public function beforeTestMethod($method) { | ||
|
@@ -120,4 +123,71 @@ public function testSetTargetPriority($formanswerData, $expected) { | |
$generatedTarget = $formanswer->targetList[0]; // Assume the target has been generated | ||
$generatedTarget->fields['priority'] = $expected; | ||
} | ||
|
||
public function providerSetTargetRequesters() { | ||
$question = $this->getQuestion([ | ||
'fieldtype' => 'email', | ||
]); | ||
$form = PluginFormcreatorForm::getByItem($question); | ||
$target = $this->newTestedInstance(); | ||
$target->add([ | ||
'name' => $this->getUniqueString(), | ||
'plugin_formcreator_forms_id' => $form->getID(), | ||
]); | ||
$targetActor = new PluginFormcreatorTarget_Actor(); | ||
$targetActor->add([ | ||
'itemtype' => $target->getType(), | ||
'items_id' => $target->getID(), | ||
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER, | ||
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON, | ||
'actor_value_4' => $question->getID(), | ||
]); | ||
$this->boolean($targetActor->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); | ||
|
||
$this->login('glpi', 'glpi'); | ||
yield 'One email requester' => [ | ||
'formanswerData' => [ | ||
PluginFormcreatorForm::getForeignKeyField() => $form->getID(), | ||
'formcreator_field_' . $question->getID() => '[email protected]', | ||
], | ||
'expected' => [ | ||
[ | ||
'users_id' => 0, | ||
'alternative_email' => '[email protected]', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerSetTargetRequesters | ||
*/ | ||
public function testSetTargetRequesters($formanswerData, $expected) { | ||
$formanswer = new PluginFormcreatorFormanswer(); | ||
$formanswer->add($formanswerData); | ||
$_SESSION['MESSAGE_AFTER_REDIRECT'] = []; | ||
$this->boolean($formanswer->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); | ||
$generatedTarget = $formanswer->targetList[0]; // Assume the target has been generated | ||
$instance = $this->newTestedInstance(); | ||
$relationClass = $this->callPrivateMethod($instance, 'getItem_User'); | ||
$targetClass = $instance::getTargetItemtypeName(); | ||
$ticketUser = new $relationClass; | ||
if (count($expected) === 0) { | ||
$rows = $ticketUser->find([ | ||
$targetClass::getForeignKeyField() => $generatedTarget->getID(), | ||
'type' => $relationClass::REQUESTER, | ||
]); | ||
$this->array($rows)->hasSize(0); | ||
} else { | ||
foreach ($expected as $searched) { | ||
$rows = $ticketUser->find([ | ||
$targetClass::getForeignKeyField() => $generatedTarget->getID(), | ||
'type' => $relationClass::REQUESTER, | ||
'users_id' => $searched['users_id'], | ||
'alternative_email' => $searched['alternative_email'], | ||
]); | ||
$this->array($rows)->hasSize(1); | ||
} | ||
} | ||
} | ||
} |