/** * This test will add all serachoptions in each itemtype and check if the * search give a SQL error */ public function testSearchOptions() { $displaypref = new DisplayPreference(); // save table glpi_displaypreferences $dp = getAllDatasFromTable($displaypref->getTable()); $itemtypeslist = $this->getClasses('getSearchOptions'); foreach ($itemtypeslist as $itemtype) { $number = 0; if (!file_exists('front/' . strtolower($itemtype) . '.php') || substr($itemtype, 0, 4) === "Rule" || substr($itemtype, 0, 6) === "Common" || substr($itemtype, 0, 2) === "DB" || $itemtype == 'SlaLevel' || $itemtype == 'Reservation' || $itemtype == 'Event' || $itemtype == 'KnowbaseItem' || $itemtype == 'NetworkPortMigration') { // it's the case where not have search possible in this itemtype continue; } $item = getItemForItemtype($itemtype); foreach ($item->getSearchOptions() as $key => $data) { if (is_int($key)) { $input = array('itemtype' => $itemtype, 'users_id' => 0, 'num' => $key); $displaypref->add($input); $number++; } } $this->assertEquals($number, countElementsInTable($displaypref->getTable(), "`itemtype`='" . $itemtype . "' AND `users_id`=0")); // do a search query $search_params = array('is_deleted' => 0, 'start' => 0, 'criteria' => array(), 'metacriteria' => array()); $data = $this->doSearch($itemtype, $search_params); // check for sql error (data key missing or empty) $this->assertArrayHasKey('data', $data, $data['last_errors']); $this->assertNotCount(0, $data['data'], $data['last_errors']); } // restore displaypreference table foreach (getAllDatasFromTable($displaypref->getTable()) as $line) { $displaypref->delete($line, true); } $this->assertEquals(0, countElementsInTable($displaypref->getTable())); foreach ($dp as $input) { $displaypref->add($input); } }
Html::popHeader(__('Setup'), $_SERVER['PHP_SELF']); Session::haveRightsOr('serach_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL)); $setupdisplay = new DisplayPreference(); if (isset($_POST["activate"])) { $setupdisplay->activatePerso($_POST); } else { if (isset($_POST["disable"])) { if ($_POST['users_id'] == Session::getLoginUserID()) { $setupdisplay->deleteByCriteria(array('users_id' => $_POST['users_id'], 'itemtype' => $_POST['itemtype'])); } } else { if (isset($_POST["add"])) { $setupdisplay->add($_POST); } else { if (isset($_POST["purge"]) || isset($_POST["purge_x"])) { $setupdisplay->delete($_POST, 1); } else { if (isset($_POST["up"]) || isset($_POST["up_x"])) { $setupdisplay->orderItem($_POST, 'up'); } else { if (isset($_POST["down"]) || isset($_POST["down_x"])) { $setupdisplay->orderItem($_POST, 'down'); } } } } } } // Datas may come from GET or POST : use REQUEST if (isset($_REQUEST["itemtype"])) { $setupdisplay->display(array('displaytype' => $_REQUEST['itemtype']));
exit; } else { $itemtype = $_GET["itemtype"]; } if (!isset($_GET["type"])) { exit; } else { $type = $_GET["type"]; } Session::checkSeveralRightsOr(array("search_config_global" => "w", "search_config" => "w")); $setupdisplay = new DisplayPreference(); if (isset($_GET["activate"])) { $setupdisplay->activatePerso($_GET); } else { if (isset($_POST["add"])) { $setupdisplay->add($_REQUEST); } else { if (isset($_GET["delete"]) || isset($_GET["delete_x"])) { $setupdisplay->delete($_GET); } else { if (isset($_GET["up"]) || isset($_GET["up_x"])) { $setupdisplay->orderItem($_GET, 'up'); } else { if (isset($_GET["down"]) || isset($_GET["down_x"])) { $setupdisplay->orderItem($_GET, 'down'); } } } } } header("location: " . GLPI_ROOT . "/plugins/mobile/front/searchconfig.php?type={$type}&itemtype={$itemtype}&rand=" . mt_rand());