Commit 1338a21b authored by Alexandre Delaunay's avatar Alexandre Delaunay Committed by Johan Cwiklinski

rewrite isInfocomOption, follows #3898

parent d92c1f85
......@@ -5859,14 +5859,16 @@ class Search {
* @return boolean
**/
static function isInfocomOption($itemtype, $searchID) {
global $CFG_GLPI;
if (!InfoCom::canApplyOn($itemtype)) {
return false;
}
$infocom_options = Infocom::rawSearchOptionsToAdd($itemtype);
$found_infocoms = array_filter($infocom_options, function($option) use ($searchID) {
return isset($option['id']) && $searchID == $option['id'];
});
return (((($searchID >= 25) && ($searchID <= 28))
|| (($searchID >= 37) && ($searchID <= 38))
|| (($searchID >= 50) && ($searchID <= 59))
|| (($searchID >= 120) && ($searchID <= 125))
|| ($searchID == 142))
&& InfoCom::canApplyOn($itemtype));
return (count($found_infocoms) > 0);
}
......
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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.
*
* GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
namespace tests\units;
/* Test for inc/search.class.php */
class Search extends \GLPITestCase {
public function dataInfocomOptions() {
return [
[1, false],
[2, false],
[4, false],
[40, false],
[31, false],
[80, false],
[25, true],
[26, true],
[27, true],
[28, true],
[37, true],
[38, true],
[50, true],
[51, true],
[52, true],
[53, true],
[54, true],
[55, true],
[56, true],
[57, true],
[58, true],
[59, true],
[120, true],
[122, true],
[123, true],
[124, true],
[125, true],
[142, true],
[159, true],
[173, true],
];
}
/**
* @dataProvider dataInfocomOptions
*/
public function testIsInfocomOption($index, $expected) {
$this->boolean(\Search::isInfocomOption('Computer', $index))->isIdenticalTo($expected);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment