|
35 | 35 | namespace tests\units\Glpi\Form;
|
36 | 36 |
|
37 | 37 | use CommonGLPI;
|
| 38 | +use CommonITILActor; |
38 | 39 | use DbTestCase;
|
39 | 40 | use Glpi\Form\Answer;
|
40 | 41 | use Glpi\Form\AnswersHandler\AnswersHandler;
|
|
46 | 47 | use Glpi\Form\QuestionType\QuestionTypeShortText;
|
47 | 48 | use Glpi\Tests\FormBuilder;
|
48 | 49 | use Glpi\Tests\FormTesterTrait;
|
| 50 | +use Group; |
| 51 | +use Group_User; |
49 | 52 | use Ticket;
|
| 53 | +use User; |
50 | 54 |
|
51 | 55 | class AnswersSetTest extends DbTestCase
|
52 | 56 | {
|
@@ -135,6 +139,113 @@ public function testGetLinksToCreatedItemssForEndUser()
|
135 | 139 | $this->assertCount(1, $answers->getLinksToCreatedItems());
|
136 | 140 | }
|
137 | 141 |
|
| 142 | + public function testGetDelegationWihoutRights() |
| 143 | + { |
| 144 | + $this->login("post-only", "postonly"); |
| 145 | + $form = $this->createForm(new FormBuilder()); |
| 146 | + |
| 147 | + $answers_handler = AnswersHandler::getInstance(); |
| 148 | + $answers = $answers_handler->saveAnswers( |
| 149 | + $form, |
| 150 | + [], |
| 151 | + \Session::getLoginUserID(), |
| 152 | + [], |
| 153 | + [ |
| 154 | + 'users_id' => getitemByTypeName(User::class, 'glpi')->getID(), |
| 155 | + 'use_notification' => true, |
| 156 | + 'alternative_email' => '' |
| 157 | + ] |
| 158 | + ); |
| 159 | + |
| 160 | + /** @var Ticket $ticket */ |
| 161 | + $ticket = current($answers->getCreatedItems()); |
| 162 | + $this->assertInstanceOf(Ticket::class, $ticket); |
| 163 | + $requesters = $ticket->getActorsForType(CommonITILActor::REQUESTER); |
| 164 | + $this->assertCount(1, $requesters); |
| 165 | + $this->assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys( |
| 166 | + [ |
| 167 | + 'itemtype' => User::class, |
| 168 | + 'items_id' => getitemByTypeName(User::class, 'post-only')->getID(), |
| 169 | + 'use_notification' => 1, |
| 170 | + 'alternative_email' => '', |
| 171 | + ], |
| 172 | + current($requesters), |
| 173 | + [ |
| 174 | + 'itemtype', |
| 175 | + 'items_id', |
| 176 | + 'use_notification', |
| 177 | + 'alternative_email', |
| 178 | + ] |
| 179 | + ); |
| 180 | + } |
| 181 | + |
| 182 | + public function testGetDelegation() |
| 183 | + { |
| 184 | + $this->login("post-only", "postonly"); |
| 185 | + |
| 186 | + // Create a group |
| 187 | + $group = $this->createItem( |
| 188 | + Group::class, |
| 189 | + [ |
| 190 | + 'name' => 'Test group', |
| 191 | + 'entities_id' => 0 |
| 192 | + ] |
| 193 | + ); |
| 194 | + |
| 195 | + // Add users to the group |
| 196 | + $this->createItem( |
| 197 | + Group_User::class, |
| 198 | + [ |
| 199 | + 'groups_id' => $group->getID(), |
| 200 | + 'users_id' => getItemByTypeName(User::class, 'post-only')->getID(), |
| 201 | + 'is_userdelegate' => 1 |
| 202 | + ] |
| 203 | + ); |
| 204 | + $this->createItem( |
| 205 | + Group_User::class, |
| 206 | + [ |
| 207 | + 'groups_id' => $group->getID(), |
| 208 | + 'users_id' => getItemByTypeName(User::class, 'glpi')->getID() |
| 209 | + ] |
| 210 | + ); |
| 211 | + |
| 212 | + $form = $this->createForm(new FormBuilder()); |
| 213 | + |
| 214 | + $answers_handler = AnswersHandler::getInstance(); |
| 215 | + $answers = $answers_handler->saveAnswers( |
| 216 | + $form, |
| 217 | + [], |
| 218 | + \Session::getLoginUserID(), |
| 219 | + [], |
| 220 | + [ |
| 221 | + 'users_id' => getitemByTypeName(User::class, 'glpi')->getID(), |
| 222 | + 'use_notification' => true, |
| 223 | + 'alternative_email' => '' |
| 224 | + ] |
| 225 | + ); |
| 226 | + |
| 227 | + /** @var Ticket $ticket */ |
| 228 | + $ticket = current($answers->getCreatedItems()); |
| 229 | + $this->assertInstanceOf(Ticket::class, $ticket); |
| 230 | + $requesters = $ticket->getActorsForType(CommonITILActor::REQUESTER); |
| 231 | + $this->assertCount(1, $requesters); |
| 232 | + $this->assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys( |
| 233 | + [ |
| 234 | + 'itemtype' => User::class, |
| 235 | + 'items_id' => getitemByTypeName(User::class, 'glpi')->getID(), |
| 236 | + 'use_notification' => 1, |
| 237 | + 'alternative_email' => '', |
| 238 | + ], |
| 239 | + current($requesters), |
| 240 | + [ |
| 241 | + 'itemtype', |
| 242 | + 'items_id', |
| 243 | + 'use_notification', |
| 244 | + 'alternative_email', |
| 245 | + ] |
| 246 | + ); |
| 247 | + } |
| 248 | + |
138 | 249 | private function createAndGetFormWithTwoAnswers(): Form
|
139 | 250 | {
|
140 | 251 | $form = $this->createForm(
|
|
0 commit comments