Skip to content

Commit

Permalink
test(issue): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 11, 2022
1 parent efdcc66 commit b483113
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"php": "7.2"
},
"optimize-autoloader": true,
"apcu-autoloader": true
"apcu-autoloader": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require": {
"php": ">= 7.2",
Expand Down
95 changes: 95 additions & 0 deletions tests/3-unit/PluginFormcreatorIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

namespace tests\units;
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
use PluginFormcreatorFormAnswer;
use RuleAction;
use User;
use Rule;
use RuleTicket;
use RuleCriteria;
use CommonITILObject;

class PluginFormcreatorIssue extends CommonTestCase {
public function beforeTestMethod($method) {
Expand Down Expand Up @@ -128,6 +135,7 @@ public function providerGetsyncIssuesRequest_simpleFormanswers() {
}

public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() {
// case 1
$form = $this->getForm();
$targetTicket1 = new \PluginFormcreatorTargetTicket();
$targetTicket1->add([
Expand All @@ -145,6 +153,46 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() {
$ticket = array_shift($formAnswer->targetList);
$this->object($ticket)->isInstanceOf(\Ticket::getType());

// case 2
// Add business rules to add 2 validators
$rule = $this->getGlpiCoreItem(Rule::class, [
'sub_type' => RuleTicket::class,
'name' => 'add validators',
'match' => 'AND',
'is_active' => 1,
'condition' => 1,
]);
$ruleCriteria = $this->getGlpiCoreItem(RuleCriteria::class, [
$rule::getForeignKeyField() => $rule->getID(),
'criteria' => '_groups_id_of_requester',
'condition' => 1,
'pattern' => User::getIdByName('normal'),
]);
$ruleAction = $this->getGlpiCoreItem(RuleAction::class, [
$rule::getForeignKeyField() => $rule->getID(),
'action_type' => 'add_validation',
'field' => 'users_id_validate',
'value' => User::getIdByName('glpi'),
]);
$ruleAction = $this->getGlpiCoreItem(RuleAction::class, [
$rule::getForeignKeyField() => $rule->getID(),
'action_type' => 'add_validation',
'field' => 'users_id_validate',
'value' => User::getIdByName('normal'),
]);
$formAnswer = new \PluginFormcreatorFormAnswer();
$formAnswer->add([
'plugin_formcreator_forms_id' => $form->getID(),
]);
$rule->update([
'id' => $rule->getID(),
'is_active' => 0,
]);
$this->boolean($formAnswer->isNewItem())->isFalse();
$formAnswer->getFromDB($formAnswer->getID());
$ticket2 = array_shift($formAnswer->targetList);
$this->object($ticket)->isInstanceOf(\Ticket::getType());

return [
'formAnswerWithOneTicket' => [
'item' => $ticket,
Expand All @@ -161,6 +209,19 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() {
'groups_id_validator' => '0',
],
],
'formAnswer With One Ticket Having several validators' => [
'item' => $ticket2,
'expected' => [
'itemtype' => \Ticket::getType(),
'items_id' => $ticket2->getID(),
'display_id' => 't_' . $ticket2->getID(),
'name' => $ticket2->fields['name'],
'status' => CommonITILObject::ASSIGNED,
'requester_id' => $ticket2->fields['users_id_recipient'],
'date_creation' => $ticket2->fields['date'],
'date_mod' => $ticket2->fields['date_mod'],
],
],
];
}

Expand Down Expand Up @@ -327,6 +388,27 @@ public function providerGetsyncIssuesRequest_validatedTicket() {
'status' => \TicketValidation::ACCEPTED
]);

$ticket2 = new \Ticket();
$ticket2->add([
'name' => 'a ticket',
'content' => 'foo',
'status' => \Ticket::INCOMING,
'_add_validation' => '0',
'validatortype' => User::class,
'users_id_validate' => [User::getIdByName('tech'), User::getIdByName('normal')], // Tech
'_actors' => [
'requester' => [
0 => ['itemtype' => \User::class,
'items_id' => User::getIdByName('glpi'), // glpi
'use_notification' => 1,
'alternative_email' => '',
]
]
]
]);
$this->boolean($ticket2->isNewItem())->isFalse();
$ticket2->getFromDB($ticket2->getID());

return [
'validatedTicket' => [
'item' => $ticket,
Expand All @@ -341,6 +423,19 @@ public function providerGetsyncIssuesRequest_validatedTicket() {
'date_mod' => $ticket->fields['date_mod'],
],
],
'ticket with multiple validators' => [
'item' => $ticket2,
'expected' => [
'itemtype' => \Ticket::getType(),
'items_id' => $ticket2->getID(),
'display_id' => 't_' . $ticket2->getID(),
'name' => $ticket2->fields['name'],
'status' => PluginFormcreatorFormAnswer::STATUS_WAITING,
'requester_id' => $ticket2->fields['users_id_recipient'],
'date_creation' => $ticket2->fields['date'],
'date_mod' => $ticket2->fields['date_mod'],
],
]
];
}

Expand Down

0 comments on commit b483113

Please sign in to comment.