How to use isNotFalse method of variable class

Best Atoum code snippet using variable.isNotFalse

APIBaseClass.php

Source:APIBaseClass.php Github

copy

Full Screen

...74 $token = $user->getAuthToken('api_token');75 }76 $data = $this->query('initSession',77 ['query' => ['user_token' => $token]]);78 $this->variable($data)->isNotFalse();79 $this->array($data)->hasKey('session_token');80 }81 /**82 * @tags api83 * @covers API::initSession84 */85 public function testAppToken() {86 $apiclient = new APIClient;87 $this->integer(88 (int)$apiclient->add([89 'name' => 'test app token',90 'is_active' => 1,91 'ipv4_range_start' => '127.0.0.1',92 'ipv4_range_end' => '127.0.0.1',93 '_reset_app_token' => true,94 ])95 )->isGreaterThan(0);96 $app_token = $apiclient->fields['app_token'];97 $this->string($app_token)->isNotEmpty()->hasLength(40);98 // test valid app token -> expect ok session99 $data = $this->query('initSession',100 ['query' => [101 'login' => TU_USER,102 'password' => TU_PASS,103 'app_token' => $app_token]]);104 $this->variable($data)->isNotFalse();105 $this->array($data)->hasKey('session_token');106 // test invalid app token -> expect error 400 and a specific code107 $data = $this->query('initSession',108 ['query' => [109 'login' => TU_USER,110 'password' => TU_PASS,111 'app_token' => "test_invalid_token"]],112 400, 'ERROR_WRONG_APP_TOKEN_PARAMETER');113 }114 /**115 * @tags api116 * @covers API::changeActiveEntities117 */118 public function testChangeActiveEntities() {119 $res = $this->query('changeActiveEntities',120 ['verb' => 'POST',121 'headers' => ['Session-Token' => $this->session_token],122 'json' => [123 'entities_id' => 'all',124 'is_recursive' => true]],125 200);126 }127 /**128 * @tags api129 * @covers API::getMyEntities130 */131 public function testGetMyEntities() {132 $data = $this->query('getMyEntities',133 ['headers' => ['Session-Token' => $this->session_token]]);134 $this->variable($data)->isNotFalse();135 $this->array($data)136 ->hasKey('myentities')137 ->array['myentities']138 ->array[0] // check presence of first entity139 ->variable['id']140 ->isEqualTo(0); // check presence of root entity141 }142 /**143 * @tags api144 * @covers API::getActiveEntities145 */146 public function testGetActiveEntities() {147 $data = $this->query('getActiveEntities',148 ['headers' => ['Session-Token' => $this->session_token]]);149 $this->variable($data)->isNotFalse();150 $this->array($data)151 ->array['active_entity'];152 $this->array($data['active_entity'])153 ->hasKey('id')154 ->hasKey('active_entity_recursive')155 ->hasKey('active_entities')156 ->array['active_entities'];157 }158 /**159 * @tags api160 * @covers API::changeActiveProfile161 */162 public function testChangeActiveProfile() {163 // test change to an existing and available profile164 $data = $this->query('changeActiveProfile',165 ['verb' => 'POST',166 'headers' => ['Session-Token' => $this->session_token],167 'json' => ['profiles_id' => 4]]);168 // test change to a non existing profile169 $data = $this->query('changeActiveProfile',170 ['verb' => 'POST',171 'headers' => ['Session-Token' => $this->session_token],172 'json' => ['profiles_id' => 9999]],173 404,174 'ERROR_ITEM_NOT_FOUND');175 // test a bad request176 $data = $this->query('changeActiveProfile',177 ['verb' => 'POST',178 'headers' => ['Session-Token' => $this->session_token],179 'json' => ['something_bad' => 4]],180 400,181 'ERROR');182 }183 /**184 * @tags api185 * @covers API::getMyProfiles186 */187 public function testGetMyProfiles() {188 $data = $this->query('getMyProfiles',189 ['headers' => ['Session-Token' => $this->session_token]]);190 $this->variable($data)->isNotFalse();191 $this->array($data)192 ->hasKey('myprofiles'); // check presence of root key193 $this->array($data['myprofiles'][0])194 ->hasKey('id'); // check presence of id key in first profile195 }196 /**197 * @tags api198 * @covers API::getActiveProfile199 */200 public function testGetActiveProfile() {201 $data = $this->query('getActiveProfile',202 ['headers' => ['Session-Token' => $this->session_token]]);203 $this->variable($data)->isNotFalse();204 $this->array($data)205 ->hasKey('active_profile');206 $this->array($data['active_profile'])207 ->hasKey('id')208 ->hasKey('name')209 ->hasKey('interface');210 }211 /**212 * @tags api213 * @covers API::getFullSession214 */215 public function testGetFullSession() {216 $data = $this->query('getFullSession',217 ['headers' => ['Session-Token' => $this->session_token]]);218 $this->variable($data)->isNotFalse();219 $this->array($data)->hasKey('session');220 $this->array($data['session'])221 ->hasKey('glpiID')222 ->hasKey('glpiname')223 ->hasKey('glpiroot')224 ->hasKey('glpilanguage')225 ->hasKey('glpilist_limit');226 }227 /**228 * @tags api229 * @covers API::getMultipleItems230 */231 public function testGetMultipleItems() {232 // Get the User TU_USER and the entity in the same query233 $uid = getItemByTypeName('User', TU_USER, true);234 $eid = getItemByTypeName('Entity', '_test_root_entity', true);235 $data = $this->query('getMultipleItems',236 ['headers' => ['Session-Token' => $this->session_token],237 'query' => [238 'items' => [['itemtype' => 'User',239 'items_id' => $uid],240 ['itemtype' => 'Entity',241 'items_id' => $eid]],242 'with_logs' => true,243 'expand_dropdowns' => true]]);244 unset($data['headers']);245 $this->array($data)246 ->hasSize(2);247 foreach ($data as $item) {248 $this->array($item)249 ->hasKey('id')250 ->hasKey('name')251 ->hasKey('entities_id')252 ->hasKey('links')253 ->hasKey('_logs') // with_logs == true254 ->notHasKey('password');255 $this->boolean(is_numeric($item['entities_id']))->isFalse(); // for expand_dropdowns256 }257 }258 /**259 * @tags api260 * @covers API::listSearchOptions261 */262 public function testListSearchOptions() {263 // test retrieve all users264 $data = $this->query('listSearchOptions',265 ['itemtype' => 'Computer',266 'headers' => ['Session-Token' => $this->session_token]]);267 $this->variable($data)->isNotFalse();268 $this->array($data)269 ->size->isGreaterThanOrEqualTo(128);270 $this->array($data[1])271 ->string['name']->isIdenticalTo('Name')272 ->string['table']->isIdenticalTo('glpi_computers')273 ->string['field']->isIdenticalTo('name')274 ->array['available_searchtypes'];275 $this->array($data[1]['available_searchtypes'])276 ->isIdenticalTo(['contains', 'notcontains', 'equals', 'notequals']);277 }278 /**279 * @tags api280 * @covers API::searchItems281 */282 public function testListSearch() {283 // test retrieve all users284 $data = $this->query('search',285 ['itemtype' => 'User',286 'headers' => ['Session-Token' => $this->session_token],287 'query' => [288 'sort' => 19,289 'order' => 'DESC',290 'range' => '0-10',291 'forcedisplay' => '81',292 'rawdata' => true]]);293 $this->array($data)294 ->hasKey('headers')295 ->hasKey('totalcount')296 ->hasKey('count')297 ->hasKey('sort')298 ->hasKey('order')299 ->hasKey('rawdata');300 $headers = $data['headers'];301 $this->array($data['headers'])302 ->hasKey('Accept-Range');303 $this->string($headers['Accept-Range'][0])304 ->startWith('User');305 $this->array($data['rawdata'])306 ->hasSize(9);307 $first_user = array_shift($data['data']);308 $second_user = array_shift($data['data']);309 $this->array($first_user)->hasKey(81);310 $this->array($second_user)->hasKey(81);311 $this->checkContentRange($data, $headers);312 }313 /**314 * @tags api315 * @covers API::searchItems316 */317 public function testListSearchPartial() {318 // test retrieve partial users319 $data = $this->query('search',320 ['itemtype' => 'User',321 'headers' => ['Session-Token' => $this->session_token],322 'query' => [323 'sort' => 19,324 'order' => 'DESC',325 'range' => '0-2',326 'forcedisplay' => '81',327 'rawdata' => true]],328 206);329 $this->variable($data)->isNotFalse();330 $this->array($data)331 ->hasKey('totalcount')332 ->hasKey('count')333 ->hasKey('sort')334 ->hasKey('order')335 ->hasKey('rawdata');336 $this->array($data['rawdata'])337 ->hasSize(9);338 $first_user = array_shift($data['data']);339 $second_user = array_shift($data['data']);340 $this->array($first_user)->hasKey(81);341 $this->array($second_user)->hasKey(81);342 $this->checkContentRange($data, $data['headers']);343 }344 /**345 * @tags api346 * @covers API::searchItems347 */348 public function testListSearchEmpty() {349 // test retrieve partial users350 $data = $this->query('search',351 ['itemtype' => 'User',352 'headers' => ['Session-Token' => $this->session_token],353 'query' => [354 'sort' => 19,355 'order' => 'DESC',356 'range' => '0-100',357 'forcedisplay' => '81',358 'rawdata' => true,359 'criteria' => [360 [361 'field' => 1,362 'searchtype' => 'contains',363 'value' => 'nonexistent',364 ]365 ]]]);366 $this->variable($data)->isNotFalse();367 $this->array($data)368 ->hasKey('headers')369 ->hasKey('totalcount')370 ->hasKey('count')371 ->hasKey('sort')372 ->hasKey('order')373 ->hasKey('rawdata');374 $this->array($data['headers'])375 ->hasKey('Accept-Range');376 $this->string($data['headers']['Accept-Range'][0])377 ->startWith('User');378 $this->array($data['rawdata'])379 ->hasSize(9);380 $this->checkEmptyContentRange($data, $data['headers']);381 }382 /**383 * @tags api384 * @covers API::searchItems385 */386 public function testSearchWithBadCriteria() {387 // test retrieve all users388 // multidimensional array of vars in query string not supported ?389 // test a non existing search option ID390 $data = $this->query('search',391 ['itemtype' => 'User',392 'headers' => ['Session-Token' => $this->session_token],393 'query' => [394 'reset' => 'reset',395 'criteria' => [[396 'field' => '134343',397 'searchtype' => 'contains',398 'value' => 'dsadasd',399 ]]400 ]],401 400, // 400 code expected (error, bad request)402 'ERROR');403 // test a non numeric search option ID404 $data = $this->query('search',405 ['itemtype' => 'User',406 'headers' => ['Session-Token' => $this->session_token],407 'query' => [408 'reset' => 'reset',409 'criteria' => [[410 'field' => '\134343',411 'searchtype' => 'contains',412 'value' => 'dsadasd',413 ]]414 ]],415 400, // 400 code expected (error, bad request)416 'ERROR');417 // test an incomplete criteria418 $data = $this->query('search',419 ['itemtype' => 'User',420 'headers' => ['Session-Token' => $this->session_token],421 'query' => [422 'reset' => 'reset',423 'criteria' => [[424 'field' => '134343',425 'searchtype' => 'contains',426 ]]427 ]],428 400, // 400 code expected (error, bad request)429 'ERROR');430 }431 /**432 * @tags api433 */434 protected function badEndpoint($expected_code = null, $expected_symbol = null) {435 $data = $this->query('badEndpoint',436 ['headers' => [437 'Session-Token' => $this->session_token]],438 $expected_code,439 $expected_symbol);440 }441 /**442 * Create a computer443 *444 * @return Computer445 */446 protected function createComputer() {447 $data = $this->query('createItems',448 ['verb' => 'POST',449 'itemtype' => 'Computer',450 'headers' => ['Session-Token' => $this->session_token],451 'json' => ['input' => ['name' => "My single computer "]]],452 201);453 $this->variable($data)454 ->isNotFalse();455 $this->array($data)456 ->hasKey('id')457 ->hasKey('message');458 $computers_id = $data['id'];459 $this->boolean(is_numeric($computers_id))->isTrue();460 $this->integer((int)$computers_id)->isGreaterThanOrEqualTo(0);461 $computer = new Computer;462 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();463 return $computer;464 }465 /**466 * Create a network port467 *468 * @param integer $computers_id Computer ID469 *470 * @return void471 */472 protected function createNetworkPort($computers_id) {473 $data = $this->query('createItems',474 ['verb' => 'POST',475 'itemtype' => 'NetworkPort',476 'headers' => ['Session-Token' => $this->session_token],477 'json' => [478 'input' => [479 'instantiation_type' => "NetworkPortEthernet",480 'name' => "test port",481 'logical_number' => 1,482 'items_id' => $computers_id,483 'itemtype' => "Computer",484 'NetworkName_name' => "testname",485 'NetworkName_fqdns_id' => 0,486 // add an aditionnal key to the next array487 // to avoid xmlrpc losing -1 key.488 // see https://bugs.php.net/bug.php?id=37746489 'NetworkName__ipaddresses' => ['-1' => "1.2.3.4",490 '_xmlrpc_fckng_fix' => ''],491 '_create_children' => true]]],492 201);493 $this->variable($data)->isNotFalse();494 $this->array($data)495 ->hasKey('id')496 ->hasKey('message');497 }498 /**499 * Create a note500 *501 * @param integer $computers_id Computer ID502 *503 * @return void504 */505 protected function createNote($computers_id) {506 $data = $this->query('createItems',507 ['verb' => 'POST',508 'itemtype' => 'Notepad',509 'headers' => ['Session-Token' => $this->session_token],510 'json' => [511 'input' => [512 'itemtype' => 'Computer',513 'items_id' => $computers_id,514 'content' => 'note about a computer']]],515 201);516 $this->variable($data)->isNotFalse();517 $this->array($data)518 ->hasKey('id')519 ->hasKey('message');520 }521 /**522 * @tags api523 * @covers API::CreateItems524 */525 public function testCreateItem() {526 $computer = $this->createComputer();527 $computers_id = $computer->getID();528 // create a network port for the previous computer529 $this->createNetworkPort($computers_id);530 // try to create a new note531 $this->createNote($computers_id);532 }533 /**534 * @tags api535 * @covers API::CreateItems536 */537 public function testCreateItems() {538 $data = $this->query('createItems',539 ['verb' => 'POST',540 'itemtype' => 'Computer',541 'headers' => ['Session-Token' => $this->session_token],542 'json' => [543 'input' => [[544 'name' => "My computer 2"545 ],[546 'name' => "My computer 3"547 ],[548 'name' => "My computer 4"]]]],549 201);550 $this->variable($data)->isNotFalse();551 $first_computer = $data[0];552 $second_computer = $data[1];553 $this->array($first_computer)554 ->hasKey('id')555 ->hasKey('message');556 $this->array($second_computer)557 ->hasKey('id')558 ->hasKey('message');559 $this->boolean(is_numeric($first_computer['id']))->isTrue();560 $this->boolean(is_numeric($second_computer['id']))->isTrue();561 $this->integer((int)$first_computer['id'])->isGreaterThanOrEqualTo(0);562 $this->integer((int)$second_computer['id'])->isGreaterThanOrEqualTo(0);563 $computer = new Computer;564 $this->boolean((bool)$computer->getFromDB($first_computer['id']))->isTrue();565 $this->boolean((bool)$computer->getFromDB($second_computer['id']))->isTrue();566 unset($data['headers']);567 return $data;568 }569 /**570 * @tags apit571 * @covers API::getItem572 */573 public function testGetItem() {574 $computer = $this->createComputer();575 $computers_id = $computer->getID();576 // create a network port for the previous computer577 $this->createNetworkPort($computers_id);578 // Get the User TU_USER579 $uid = getItemByTypeName('User', TU_USER, true);580 $data = $this->query('getItem',581 ['itemtype' => 'User',582 'id' => $uid,583 'headers' => ['Session-Token' => $this->session_token],584 'query' => [585 'expand_dropdowns' => true,586 'with_logs' => true]]);587 $this->variable($data)->isNotFalse();588 $this->array($data)589 ->hasKey('id')590 ->hasKey('name')591 ->hasKey('entities_id')592 ->hasKey('links')593 ->hasKey('_logs') // with_logs == true594 ->notHasKey('password');595 $this->boolean(is_numeric($data['entities_id']))->isFalse(); // for expand_dropdowns596 // Get user's entity597 $eid = getItemByTypeName('Entity', '_test_root_entity', true);598 $data = $this->query('getItem',599 ['itemtype' => 'Entity',600 'id' => $eid,601 'headers' => ['Session-Token' => $this->session_token],602 'query' => ['get_hateoas' => false]]);603 $this->variable($data)->isNotFalse();604 $this->array($data)605 ->hasKey('id')606 ->hasKey('name')607 ->hasKey('completename')608 ->notHasKey('links'); // get_hateoas == false609 // Get the previously created 'computer 1'610 $data = $this->query('getItem',611 ['itemtype' => 'Computer',612 'id' => $computers_id,613 'headers' => ['Session-Token' => $this->session_token],614 'query' => ['with_networkports' => true]]);615 $this->variable($data)->isNotFalse();616 $this->array($data)617 ->hasKey('id')618 ->hasKey('name')619 ->hasKey('_networkports');620 $this->array($data['_networkports'])621 ->hasKey('NetworkPortEthernet');622 $this->array($data['_networkports']['NetworkPortEthernet'][0])->hasKey('NetworkName');623 $networkname = $data['_networkports']['NetworkPortEthernet'][0]['NetworkName'];624 $this->array($networkname)625 ->hasKey('IPAddress')626 ->hasKey('FQDN')627 ->hasKey('id')628 ->hasKey('name');629 $this->array($networkname['IPAddress'][0])630 ->hasKey('name')631 ->hasKey('IPNetwork');632 $this->string($networkname['IPAddress'][0]['name'])->isIdenticalTo('1.2.3.4');633 }634 /**635 * @tags api636 * @covers API::getItem637 */638 public function testGetItemWithNotes() {639 $computer = $this->createComputer();640 $computers_id = $computer->getID();641 // try to create a new note642 $this->createNote($computers_id);643 // Get the previously created 'computer 1'644 $data = $this->query('getItem',645 ['itemtype' => 'Computer',646 'id' => $computers_id,647 'headers' => ['Session-Token' => $this->session_token],648 'query' => ['with_notes' => true]]);649 $this->variable($data)->isNotFalse();650 $this->array($data)651 ->hasKey('id')652 ->hasKey('name')653 ->hasKey('_notes');654 $this->array($data['_notes'][0])655 ->hasKey('id')656 ->hasKey('itemtype')657 ->hasKey('items_id')658 ->hasKey('users_id')659 ->hasKey('content');660 }661 /**662 * @tags api663 * @covers API::getItem664 */665 public function testGetItems() {666 // test retrieve all users667 $data = $this->query('getItems',668 ['itemtype' => 'User',669 'headers' => ['Session-Token' => $this->session_token],670 'query' => [671 'expand_dropdowns' => true]]);672 $this->variable($data)->isNotFalse();673 $this->array($data)674 ->hasKey('headers')675 ->hasKey(0)676 ->size->isGreaterThanOrEqualTo(4);677 unset($data['headers']);678 $this->array($data[0])679 ->hasKey('id')680 ->hasKey('name')681 ->hasKey('is_active')682 ->hasKey('entities_id')683 ->notHasKey('password');684 $this->boolean(is_numeric($data[0]['entities_id']))->isFalse(); // for expand_dropdowns685 // test retrieve partial users686 $data = $this->query('getItems',687 ['itemtype' => 'User',688 'headers' => ['Session-Token' => $this->session_token],689 'query' => [690 'range' => '0-1',691 'expand_dropdowns' => true]],692 206);693 $this->variable($data)->isNotFalse();694 $this->array($data)695 ->hasKey('headers')696 ->hasSize(3);697 unset($data['headers']);698 $this->array($data[0])699 ->hasKey('id')700 ->hasKey('name')701 ->hasKey('is_active')702 ->hasKey('entities_id')703 ->notHasKey('password');704 $this->boolean(is_numeric($data[0]['entities_id']))->isFalse(); // for expand_dropdowns705 // test retrieve 1 user with a text filter706 $data = $this->query('getItems',707 ['itemtype' => 'User',708 'headers' => ['Session-Token' => $this->session_token],709 'query' => ['searchText' => ['name' => 'gl']]]);710 $this->variable($data)->isNotFalse();711 $this->array($data)712 ->hasKey('headers')713 ->hasSize(2);714 unset($data['headers']);715 $this->array($data[0])716 ->hasKey('id')717 ->hasKey('name');718 $this->string($data[0]['name'])->isIdenticalTo('glpi');719 // Test only_id param720 $data = $this->query('getItems',721 ['itemtype' => 'User',722 'headers' => ['Session-Token' => $this->session_token],723 'query' => ['only_id' => true]]);724 $this->variable($data)->isNotFalse();725 $this->array($data)726 ->hasKey('headers')727 ->size->isGreaterThanOrEqualTo(5);728 $this->array($data[0])729 ->hasKey('id')730 ->notHasKey('name')731 ->notHasKey('is_active')732 ->notHasKey('password');733 // test retrieve all config734 $data = $this->query('getItems',735 ['itemtype' => 'Config',736 'headers' => ['Session-Token' => $this->session_token],737 'query' => ['expand_dropdowns' => true]], 206);738 $this->variable($data)->isNotFalse();739 $this->array($data)->hasKey('headers');740 unset($data['headers']);741 foreach ($data as $config_row) {742 $this->string($config_row['name'])743 ->isNotEqualTo('smtp_passwd')744 ->isNotEqualTo('proxy_passwd');745 }746 }747 /**748 * try to retrieve invalid range of users749 * We expect a http code 400750 *751 * @tags api752 * @covers API::getItem753 */754 public function testgetItemsInvalidRange() {755 $data = $this->query('getItems',756 ['itemtype' => 'User',757 'headers' => ['Session-Token' => $this->session_token],758 'query' => [759 'range' => '100-105',760 'expand_dropdowns' => true]],761 400,762 'ERROR_RANGE_EXCEED_TOTAL');763 }764 /**765 * This function test https://github.com/glpi-project/glpi/issues/1103766 * A post-only user could retrieve tickets of others users when requesting itemtype767 * without first letter in uppercase768 *769 * @tags api770 * @covers API::getItem771 */772 public function testgetItemsForPostonly() {773 // init session for postonly774 $data = $this->query('initSession',775 ['query' => [776 'login' => 'post-only',777 'password' => 'postonly']]);778 // create a ticket for another user (glpi - super-admin)779 $ticket = new \Ticket;780 $tickets_id = $ticket->add(['name' => 'test post-only',781 'content' => 'test post-only',782 '_users_id_requester' => 2]);783 $this->integer((int)$tickets_id)->isGreaterThan(0);784 // try to access this ticket with post-only785 $this->query('getItem',786 ['itemtype' => 'Ticket',787 'id' => $tickets_id,788 'headers' => [789 'Session-Token' => $data['session_token']]],790 403,791 'ERROR_RIGHT_MISSING');792 // try to access ticket list (we should get empty return)793 $data = $this->query('getItems',794 ['itemtype' => 'Ticket',795 'headers' => ['Session-Token' => $data['session_token'],796 'query' => [797 'expand_dropdowns' => true]]]);798 $this->variable($data)->isNotFalse();799 $this->array($data)800 ->hasKey('headers')801 ->hasSize(1);802 // delete ticket803 $ticket->delete(['id' => $tickets_id], true);804 }805 /**806 * @tags api807 * @covers API::updateItems808 */809 public function testUpdateItem() {810 $computer = $this->createComputer();811 $computers_id = $computer->getID();812 $data = $this->query('updateItems',813 ['itemtype' => 'Computer',814 'verb' => 'PUT',815 'headers' => ['Session-Token' => $this->session_token],816 'json' => [817 'input' => [818 'id' => $computers_id,819 'serial' => "abcdef"]]]);820 $this->variable($data)->isNotFalse();821 $computer = array_shift($data);822 $this->array($computer)823 ->hasKey($computers_id)824 ->hasKey('message');825 $this->boolean((bool)$computer[$computers_id])->isTrue();826 $computer = new Computer;827 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();828 $this->string($computer->fields['serial'])->isIdenticalTo('abcdef');829 }830 /**831 * @tags api832 * @covers API::updateItems833 */834 public function testUpdateItems() {835 $computers_id_collection = $this->testCreateItems();836 $input = [];837 $computer = new Computer;838 foreach ($computers_id_collection as $key => $computers_id) {839 $input[] = ['id' => $computers_id['id'],840 'otherserial' => "abcdef"];841 }842 $data = $this->query('updateItems',843 ['itemtype' => 'Computer',844 'verb' => 'PUT',845 'headers' => ['Session-Token' => $this->session_token],846 'json' => ['input' => $input]]);847 $this->variable($data)->isNotFalse();848 $this->array($data)->hasKey('headers');849 unset($data['headers']);850 foreach ($data as $index => $row) {851 $computers_id = $computers_id_collection[$index]['id'];852 $this->array($row)853 ->hasKey($computers_id)854 ->hasKey('message');855 $this->boolean(true, (bool) $row[$computers_id])->isTrue();856 $this->boolean((bool)$computer->getFromDB($computers_id))->isTrue();857 $this->string($computer->fields['otherserial'])->isIdenticalTo('abcdef');858 }859 }860 /**861 * @tags api862 * @covers API::deleteItems863 */864 public function testDeleteItem() {865 $eid = getItemByTypeName('Entity', '_test_root_entity', true);866 $_SESSION['glpiactive_entity'] = $eid;867 $computer = new \Computer();868 $this->integer(869 $computer->add([870 'name' => 'A computer to delete',871 'entities_id' => $eid872 ])873 )->isGreaterThan(0);874 $computers_id = $computer->getID();875 $data = $this->query('deleteItems',876 ['itemtype' => 'Computer',877 'id' => $computers_id,878 'verb' => 'DELETE',879 'headers' => ['Session-Token' => $this->session_token],880 'query' => ['force_purge' => "true"]]);881 $this->variable($data)->isNotFalse();882 $this->array($data)->hasKey('headers');883 unset($data['headers']);884 $computer = array_shift($data);885 $this->array($computer)886 ->hasKey($computers_id)887 ->hasKey('message');888 $computer = new \Computer;889 $this->boolean((bool)$computer->getFromDB($computers_id))->isFalse();890 }891 /**892 * @tags api893 * @covers API::deleteItems894 */895 public function testDeleteItems() {896 $computers_id_collection = $this->testCreateItems();897 $input = [];898 $computer = new Computer;899 $lastComputer = array_pop($computers_id_collection);900 foreach ($computers_id_collection as $key => $computers_id) {901 $input[] = ['id' => $computers_id['id']];902 }903 $data = $this->query('deleteItems',904 ['itemtype' => 'Computer',905 'verb' => 'DELETE',906 'headers' => ['Session-Token' => $this->session_token],907 'json' => [908 'input' => $input,909 'force_purge' => true]]);910 $this->variable($data)->isNotFalse();911 unset($data['headers']);912 foreach ($data as $index => $row) {913 $computers_id = $computers_id_collection[$index]['id'];914 $this->array($row)915 ->hasKey($computers_id)916 ->hasKey('message');917 $this->boolean((bool)$row[$computers_id])->isTrue();918 $this->boolean((bool)$computer->getFromDB($computers_id))->isFalse();919 }920 // Test multiple delete with multi-status921 $input = [];922 $computers_id_collection = [923 ['id' => $lastComputer['id']],924 ['id' => $lastComputer['id'] + 1] // Non existing computer id925 ];926 foreach ($computers_id_collection as $key => $computers_id) {927 $input[] = ['id' => $computers_id['id']];928 }929 $data = $this->query('deleteItems',930 ['itemtype' => 'Computer',931 'verb' => 'DELETE',932 'headers' => ['Session-Token' => $this->session_token],933 'json' => [934 'input' => $input,935 'force_purge' => true]],936 207);937 $this->variable($data)->isNotFalse();938 $this->boolean($data[1][0][$computers_id_collection[0]['id']])->isTrue();939 $this->array($data[1][0])->hasKey('message');940 $this->boolean($data[1][1][$computers_id_collection[1]['id']])->isFalse();941 $this->array($data[1][1])->hasKey('message');942 }943 /**944 * @tags api945 */946 public function testInjection() {947 $data = $this->query('createItems',948 ['itemtype' => 'Computer',949 'verb' => 'POST',950 'headers' => ['Session-Token' => $this->session_token],951 'json' => [952 'input' => [953 'name' => "my computer', (SELECT `password` from `glpi_users` as `otherserial` WHERE `id`=2), '0 ' , '2016-10-26 00:00:00', '2016-10-26 00 :00 :00')#",954 'otherserial' => "Not hacked"]]],955 201);956 $this->array($data)957 ->hasKey('id');958 $new_id = $data['id'];959 $computer = new Computer();960 $this->boolean((bool)$computer->getFromDB($new_id))->isTrue();961 //Add SQL injection spotted!962 $this->boolean($computer->fields['otherserial'] != 'Not hacked')->isFalse();963 $data = $this->query('updateItems',964 ['itemtype' => 'Computer',965 'verb' => 'PUT',966 'headers' => ['Session-Token' => $this->session_token],967 'json' => [968 'input' => [969 'id' => $new_id,970 'serial' => "abcdef', `otherserial`='injected"]]]);971 $this->boolean((bool)$computer->getFromDB($new_id))->isTrue();972 //Update SQL injection spotted!973 $this->boolean($computer->fields['otherserial'] === 'injected')->isFalse();974 $computer = new Computer();975 $computer->delete(['id' => $new_id], true);976 }977 /**978 * @tags api979 */980 public function testProtectedConfigSettings() {981 $sensitiveSettings = [982 'proxy_passwd',983 'smtp_passwd',984 ];985 // set a non empty value to the sessionts to check986 foreach ($sensitiveSettings as $name) {987 Config::setConfigurationValues('core', [$name => 'not_empty_password']);988 $value = Config::getConfigurationValues('core', [$name]);989 $this->array($value)->hasKey($name);990 $this->string($value[$name])->isNotEmpty();991 }992 $config = new Config();993 $rows = $config->find(['context' => 'core', 'name' => $sensitiveSettings]);994 $this->array($rows)995 ->hasSize(count($sensitiveSettings));996 // Check the value is not retrieved for sensitive settings997 foreach ($rows as $row) {998 $data = $this->query('getItem',999 ['itemtype' => 'Config',1000 'id' => $row['id'],1001 'headers' => ['Session-Token' => $this->session_token]]);1002 $this->array($data)->notHasKey('value');1003 }1004 // Check an other setting is disclosed (when not empty)1005 $config = new Config();1006 $config->getFromDBByCrit(['context' => 'core', 'name' => 'admin_email']);1007 $data = $this->query('getItem',1008 ['itemtype' => 'Config',1009 'id' => $config->getID(),1010 'headers' => ['Session-Token' => $this->session_token]]);1011 $this->variable($data['value'])->isNotEqualTo('');1012 // Check a search does not disclose sensitive values1013 $criteria = [];1014 $queryString = "";1015 foreach ($rows as $row) {1016 $queryString = "&criteria[0][link]=or&criteria[0][field]=1&criteria[0][searchtype]=equals&criteria[0][value]=".$row['name'];1017 }1018 $data = $this->query('search',1019 ['itemtype' => 'Config',1020 'headers' => ['Session-Token' => $this->session_token],1021 'query' => []],1022 206);1023 foreach ($data['data'] as $row) {1024 foreach ($row as $col) {1025 $this->variable($col)->isNotEqualTo('not_empty_password');1026 }1027 }1028 }1029 /**1030 * @tags api1031 */1032 public function testProtectedDeviceSimcardFields() {1033 global $DB;1034 $sensitiveFields = [1035 'pin',1036 'pin2',1037 'puk',1038 'puk2',1039 ];1040 $obj = new \Item_DeviceSimcard();1041 // Add1042 $computer = getItemByTypeName('Computer', '_test_pc01');1043 $this->object($computer)->isInstanceOf('\Computer');1044 $deviceSimcard = getItemByTypeName('DeviceSimcard', '_test_simcard_1');1045 $this->integer((int) $deviceSimcard->getID())->isGreaterThan(0);1046 $this->object($deviceSimcard)->isInstanceOf('\DeviceSimcard');1047 $input = [1048 'itemtype' => 'Computer',1049 'items_id' => $computer->getID(),1050 'devicesimcards_id' => $deviceSimcard->getID(),1051 'entities_id' => 0,1052 'pin' => '1234',1053 'pin2' => '2345',1054 'puk' => '3456',1055 'puk2' => '4567',1056 ];1057 $id = $obj->add($input);1058 $this->integer($id)->isGreaterThan(0);1059 //drop update access on item_devicesimcard1060 $DB->update(1061 'glpi_profilerights',1062 ['rights' => 2], [1063 'profiles_id' => 4,1064 'name' => 'devicesimcard_pinpuk'1065 ]1066 );1067 // Profile changed then login1068 $backupSessionToken = $this->session_token;1069 $this->initSessionCredentials();1070 $limitedSessionToken = $this->session_token;1071 //reset rights. Done here so ACLs are reset even if tests fails.1072 $DB->update(1073 'glpi_profilerights',1074 ['rights' => 3], [1075 'profiles_id' => 4,1076 'name' => 'devicesimcard_pinpuk'1077 ]1078 );1079 $this->session_token = $backupSessionToken;1080 // test getItem does not disclose sensitive fields when READ disabled1081 $data = $this->query('getItem',1082 ['itemtype' => 'Item_DeviceSimcard',1083 'id' => $id,1084 'headers' => ['Session-Token' => $limitedSessionToken]]);1085 foreach ($sensitiveFields as $field) {1086 $this->array($data)->notHasKey($field);1087 }1088 // test getItem discloses sensitive fields when READ enabled1089 $data = $this->query('getItem',1090 ['itemtype' => 'Item_DeviceSimcard',1091 'id' => $id,1092 'headers' => ['Session-Token' => $this->session_token]]);1093 foreach ($sensitiveFields as $field) {1094 $this->array($data)->hasKey($field);1095 }1096 // test searching a sensitive field as criteria id forbidden1097 $data = $this->query('search',1098 ['itemtype' => 'Item_DeviceSimcard',1099 'headers' => ['Session-Token' => $this->session_token],1100 'query' => ['criteria' => [1101 0 => ['field' => 15,1102 'searchtype' => 'equals',1103 'value' => $input['pin']1104 ]1105 ]1106 ]1107 ],1108 400,1109 'ERROR');1110 // test forcing display of a sensitive field1111 $data = $this->query('search',1112 ['itemtype' => 'Item_DeviceSimcard',1113 'headers' => ['Session-Token' => $this->session_token],1114 'query' => [1115 'forcedisplay' => [15]1116 ]1117 ],1118 400,1119 'ERROR');1120 }1121 /**1122 * @tags api1123 * @covers API::getGlpiConfig1124 */1125 public function testGetGlpiConfig() {1126 $data = $this->query('getGlpiConfig',1127 ['headers' => ['Session-Token' => $this->session_token]]);1128 // Test a disclosed data1129 $this->array($data)1130 ->hasKey('cfg_glpi');1131 $this->array($data['cfg_glpi'])1132 ->hasKey('infocom_types');1133 }1134 public function testUndisclosedField() {1135 // test common cases1136 $itemtypes = [1137 'APIClient', 'AuthLDAP', 'MailCollector', 'User'1138 ];1139 foreach ($itemtypes as $itemtype) {1140 $data = $this->query(1141 'getItems',1142 [1143 'itemtype' => $itemtype,1144 'headers' => ['Session-Token' => $this->session_token]1145 ]1146 );1147 $this->array($itemtype::$undisclosedFields)1148 ->size->isGreaterThan(0);1149 foreach ($itemtype::$undisclosedFields as $key) {1150 $this->array($data);1151 unset($data['headers']);1152 foreach ($data as $item) {1153 $this->array($item)->notHasKey($key);1154 }1155 }1156 }1157 // test specific cases1158 // Config1159 $data = $this->query('getGlpiConfig', [1160 'headers' => ['Session-Token' => $this->session_token]1161 ]);1162 // Test undisclosed data are actually not disclosed1163 $this->array(Config::$undisclosedFields)1164 ->size->isGreaterThan(0);1165 foreach (Config::$undisclosedFields as $key) {1166 $this->array($data['cfg_glpi'])->notHasKey($key);1167 }1168 }1169 /**1170 * @tags api1171 * @covers API::killSession1172 */1173 public function testKillSession() {1174 // test retrieve all users1175 $res = $this->query('killSession',1176 ['headers' => ['Session-Token' => $this->session_token]]);1177 $res = $this->query('getFullSession',1178 ['headers' => ['Session-Token' => $this->session_token]],1179 401,1180 'ERROR_SESSION_TOKEN_INVALID');1181 }1182 /**1183 * @tags api1184 * @engine inline1185 */1186 public function testLostPasswordRequest() {1187 global $CFG_GLPI;1188 $user = getItemByTypeName('User', TU_USER);1189 $email = $user->getDefaultEmail();1190 // Test the verb POST is not alloxed1191 $res = $this->query('lostPassword',1192 ['verb' => 'POST',1193 ],1194 400,1195 'ERROR');1196 // Test the verb GET is not alloxed1197 $res = $this->query('lostPassword',1198 ['verb' => 'GET',1199 ],1200 400,1201 'ERROR');1202 // Test the verb DELETE is not allowed1203 $res = $this->query('lostPassword',1204 ['verb' => 'DELETE',1205 ],1206 400,1207 'ERROR');1208 $this->array($CFG_GLPI)1209 ->variable['use_notifications']->isEqualTo(0)1210 ->variable['notifications_mailing']->isEqualTo(0);1211 // Test disabled notifications make this fail1212 $res = $this->query('lostPassword',1213 ['verb' => 'PUT',1214 'json' => [1215 'email' => $email1216 ]1217 ],1218 400,1219 'ERROR');1220 //enable notifications1221 Config::setConfigurationValues('core', [1222 'use_notifications' => '1',1223 'notifications_mailing' => '1'1224 ]);1225 // Test an unknown email is rejected1226 $res = $this->query('lostPassword',1227 ['verb' => 'PUT',1228 'json' => [1229 'email' => 'nonexistent@localhost.local'1230 ]1231 ],1232 400,1233 'ERROR');1234 // Test a valid email is accepted1235 $res = $this->query('lostPassword',1236 ['verb' => 'PATCH',1237 'json' => [1238 'email' => $email1239 ]1240 ],1241 200);1242 // get the password recovery token1243 $user = getItemByTypeName('User', TU_USER);1244 $token = $user->getField('password_forget_token');1245 // Test reset password with a bad token1246 $res = $this->query('lostPassword',1247 ['verb' => 'PUT',1248 'json' => [1249 'email' => $email,1250 'password_forget_token' => $token . 'bad',1251 'password' => 'NewPassword',1252 ]1253 ],1254 400,1255 'ERROR');1256 // Test reset password with the good token1257 $res = $this->query('lostPassword',1258 ['verb' => 'PATCH',1259 'json' => [1260 'email' => $email,1261 'password_forget_token' => $token,1262 'password' => 'NewPassword',1263 ]1264 ],1265 200);1266 // Refresh the in-memory instance of user and get the password1267 $user->getFromDB($user->getID());1268 $newHash = $user->getField('password');1269 // Restore the initial password in the DB1270 $updateSuccess = $user->update([1271 'id' => $user->getID(),1272 'password' => TU_PASS,1273 'password2' => TU_PASS1274 ]);1275 $this->variable($updateSuccess)->isNotFalse('password update failed');1276 // Test the new password was saved1277 $this->variable(\Auth::checkPassword('NewPassword', $newHash))->isNotFalse();1278 //diable notifications1279 Config::setConfigurationValues('core', [1280 'use_notifications' => '0',1281 'notifications_mailing' => '0'1282 ]);1283 }1284 /**1285 * Check consistency of Content-Range header1286 *1287 * @param array $data Data1288 * @param array $headers Headers1289 *1290 * @return void1291 */...

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1$var = new Variable();2$var->isNotFalse();3$var = new Variable();4$var->isNotFalse();5$var = new Variable();6$var->isNotFalse();7$var = new Variable();8$var->isNotFalse();9$var = new Variable();10$var->isNotFalse();11$var = new Variable();12$var->isNotFalse();13$var = new Variable();14$var->isNotFalse();15$var = new Variable();16$var->isNotFalse();17$var = new Variable();18$var->isNotFalse();19$var = new Variable();20$var->isNotFalse();21$var = new Variable();22$var->isNotFalse();23$var = new Variable();24$var->isNotFalse();25$var = new Variable();26$var->isNotFalse();27$var = new Variable();28$var->isNotFalse();29$var = new Variable();30$var->isNotFalse();31$var = new Variable();32$var->isNotFalse();

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1$var = new Variable();2$var->setValue(1);3$var->isNotFalse();4$var = new Variable();5$var->setValue(0);6$var->isNotFalse();7$var = new Variable();8$var->setValue(false);9$var->isNotFalse();

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1$var = new Variable();2$var = new Variable();3$var = new Variable();4$var = new Variable();5$var = new Variable();6$var = new Variable();

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1$var = Variable::create('var');2$var->isNotFalse();3echo $var->get();4$var = Variable::create('var');5$var->isNotFalse();6echo $var->get();7$var = Variable::create('var');8$var->isNotFalse();9echo $var->get();10$var = Variable::create('var');11$var->isNotFalse();12echo $var->get();13$var = Variable::create('var');14$var->isNotFalse();15echo $var->get();16$var = Variable::create('var');17$var->isNotFalse();18echo $var->get();19$var = Variable::create('var');20$var->isNotFalse();21echo $var->get();22$var = Variable::create('var');23$var->isNotFalse();24echo $var->get();25$var = Variable::create('var');26$var->isNotFalse();27echo $var->get();28$var = Variable::create('var');29$var->isNotFalse();30echo $var->get();31$var = Variable::create('var');32$var->isNotFalse();33echo $var->get();34$var = Variable::create('var');35$var->isNotFalse();36echo $var->get();

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1require_once("variable.php");2$var = new variable();3$var->set_value("Hello");4$var->isNotFalse();5require_once("variable.php");6$var = new variable();7$var->set_value("0");8$var->isNotFalse();9require_once("variable.php");10$var = new variable();11$var->set_value("");12$var->isNotFalse();13require_once("variable.php");14$var = new variable();15$var->set_value(false);16$var->isNotFalse();17require_once("variable.php");18$var = new variable();19$var->set_value(null);20$var->isNotFalse();21require_once("variable.php");22$var = new variable();23$var->set_value(0);24$var->isNotFalse();25require_once("variable.php");26$var = new variable();27$var->set_value("0");28$var->isNotFalse();29require_once("variable.php");30$var = new variable();31$var->set_value("false");32$var->isNotFalse();33require_once("variable.php");34$var = new variable();35$var->set_value("false");

Full Screen

Full Screen

isNotFalse

Using AI Code Generation

copy

Full Screen

1include('variable.php');2$var = new Variable();3$var->isNotFalse(false);4$var->isNotFalse(true);5include('variable.php');6$var = new Variable();7$var->isNotTrue(false);8$var->isNotTrue(true);9include('variable.php');10$var = new Variable();11$var->isNotArray(false);12$var->isNotArray(true);13$var->isNotArray(1);14$var->isNotArray(0);15$var->isNotArray(1.1);16$var->isNotArray(0.0);17$var->isNotArray("string");18$var->isNotArray(array());19$var->isNotArray(array(1,2,3));20include('variable.php');21$var = new Variable();22$var->isNotString(false);23$var->isNotString(true);24$var->isNotString(1);25$var->isNotString(0);26$var->isNotString(1.1);27$var->isNotString(0.0);28$var->isNotString("string");29$var->isNotString(array());30$var->isNotString(array(1,2,3));

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful