-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathPluginFormcreatorTargetTicket.php
More file actions
175 lines (159 loc) · 6.8 KB
/
Copy pathPluginFormcreatorTargetTicket.php
File metadata and controls
175 lines (159 loc) · 6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/
namespace tests\units;
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
use Entity;
/**
* @engine inline
*/
class PluginFormcreatorTargetTicket extends CommonTestCase {
public function beforeTestMethod($method) {
parent::beforeTestMethod($method);
$this->login('glpi', 'glpi');
}
public function testTargetTicketActors() {
// Create a form with a target ticket
$form = $this->getForm();
$instance = new \PluginFormcreatorTargetTicket();
$instance->add([
'name' => 'a target',
'plugin_formcreator_forms_id' => $form->getID()
]);
$instance->getFromDB($instance->getID());
$this->boolean($instance->isNewItem())->isFalse();
// find the actors created by default
$requesterActor = new \PluginFormcreatorTarget_Actor();
$observerActor = new \PluginFormcreatorTarget_Actor();
$instanceId = $instance->getID();
$requesterActor->getFromDBByCrit([
'AND' => [
'itemtype' => $instance->getType(),
'items_id' => $instanceId,
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_AUTHOR,
]
]);
$observerActor->getFromDBByCrit([
'AND' => [
'itemtype' => $instance->getType(),
'items_id' => $instanceId,
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR
]
]);
$this->boolean($requesterActor->isNewItem())->isFalse();
$this->boolean($observerActor->isNewItem())->isFalse();
// check the settings of the default actors
$this->integer((int) $requesterActor->getField('use_notification'))
->isEqualTo(1);
$this->integer((int) $observerActor->getField('use_notification'))
->isEqualTo(1);
}
public function testUrgency() {
global $DB;
// Create a form with a urgency question and 2 target tickets
$form = $this->getForm([
'entities_id' => $_SESSION['glpiactive_entity'],
'name' => __METHOD__,
'description' => 'form description',
'content' => 'a content',
'is_active' => 1,
'validation_required' => 0
]);
$this->boolean($form->isNewItem())->isFalse();
$section = $this->getSection([
'plugin_formcreator_forms_id' => $form->getID(),
'name' => 'a section',
]);
$this->boolean($section->isNewItem())->isFalse();
$question = $this->getQuestion([
'plugin_formcreator_sections_id' => $section->getID(),
'name' => 'custom urgency',
'fieldtype' => 'urgency',
'default_values' => '3',
]);
$this->boolean($question->isNewItem())->isFalse();
$targetTicket1 = $this->getTargetTicket([
'plugin_formcreator_forms_id' => $form->getID(),
'name' => 'urgency from answer',
'target_name' => 'urgency from answer',
'content' => '##FULLFORM##',
'itemtype' => \PluginFormcreatorTargetTicket::class,
'urgency_rule' => \PluginFormcreatorAbstractItilTarget::URGENCY_RULE_ANSWER,
'urgency_question' => $question->getID(),
]);
$this->boolean($targetTicket1->isNewItem())->isFalse();
$targetTicket2 = $this->getTargetTicket([
'plugin_formcreator_forms_id' => $form->getID(),
'name' => 'default urgency',
'target_name' => 'default urgency',
'content' => '##FULLFORM##',
'itemtype' => \PluginFormcreatorTargetTicket::class,
'urgency_rule' => \PluginFormcreatorAbstractItilTarget::URGENCY_RULE_NONE,
'urgency_question' => '0',
]);
$this->boolean($targetTicket2->isNewItem())->isFalse();
// create a formanswer
$saveFormData = [
'plugin_formcreator_forms_id' => $form->getID(),
'formcreator_field_' . $question->getID() => '5',
];
$formAnswer = new \PluginFormcreatorFormAnswer();
$form->getFromDB($form->getID());
$formAnswer->add($saveFormData);
// Let's assume thre are no previous formanswers for this foreign key
$formAnswer->getFromDbByCrit([
'plugin_formcreator_forms_id' => $form->getID(),
]);
$rows = $DB->request([
'SELECT' => ['tickets_id'],
'FROM' => \Item_Ticket::getTable(),
'WHERE' => [
'itemtype' => \PluginFormcreatorFormAnswer::class,
'items_id' => $formAnswer->getID(),
]
]);
$this->variable($rows)->isNotNull();
foreach ($rows as $row) {
$ticket = new \Ticket();
$ticket->getFromDB($row['tickets_id']);
$this->boolean($ticket->isNewItem())->isFalse();
if ($ticket->fields['name'] == 'urgency from answer') {
$this->integer((int) $ticket->fields['urgency'])->isEqualTo(5);
} else if ($ticket->fields['name'] == 'default urgency') {
// expected medium urgency
$this->integer((int) $ticket->fields['urgency'])->isEqualTo(3);
} else {
throw new \RuntimeException('Unexpected ticket');
}
}
}
}