SearchTest::testSearchOptions PHP Method

testSearchOptions() public method

This test will add all serachoptions in each itemtype and check if the search give a SQL error
public testSearchOptions ( )
    public function testSearchOptions()
    {
        $displaypref = new DisplayPreference();
        // save table glpi_displaypreferences
        $dp = getAllDatasFromTable($displaypref->getTable());
        foreach ($dp as $line) {
            $displaypref->delete($line, true);
        }
        $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
        /// TODO: review, this can't work.
        foreach (getAllDatasFromTable($displaypref->getTable()) as $line) {
            $displaypref->delete($line, true);
        }
        $this->assertEquals(0, countElementsInTable($displaypref->getTable()));
        foreach ($dp as $input) {
            $displaypref->add($input);
        }
    }