mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Merge branch 'develop' into feature/b931
# Conflicts: # application/applicationextension.inc.php # core/attributedef.class.inc.php # core/cmdbchangeop.class.inc.php # core/cmdbobject.class.inc.php # core/dbobjectsearch.class.php # core/oql/expression.class.inc.php # core/oql/oql-lexer.plex # core/oql/oql-parser.y # core/oql/oqlquery.class.inc.php # css/light-grey.scss # datamodels/2.x/itop-full-itil/datamodel.itop-full-itil.xml # datamodels/2.x/itop-portal/datamodel.itop-portal.xml # datamodels/2.x/itop-tickets/en.dict.itop-tickets.php # dictionaries/en.dictionary.itop.core.php # dictionaries/fr.dictionary.itop.core.php # setup/xmldataloader.class.inc.php # test/ItopDataTestCase.php
This commit is contained in:
@@ -1,343 +1,343 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
require_once ('../approot.inc.php');
|
||||
require_once(APPROOT.'application/application.inc.php');
|
||||
require_once(APPROOT.'application/itopwebpage.class.inc.php');
|
||||
require_once(APPROOT.'application/startup.inc.php');
|
||||
require_once(APPROOT.'application/loginwebpage.class.inc.php');
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Main program
|
||||
//
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed
|
||||
|
||||
|
||||
$sSubmit = utils::ReadParam('submit', '', false, 'raw_data');
|
||||
if ($sSubmit != 'Reset')
|
||||
{
|
||||
$sOQL = utils::ReadParam('OQL_Request', '', false, 'raw_data');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sOQL = '';
|
||||
}
|
||||
$bError = false;
|
||||
$oP = new iTopWebPage('Database inconsistencies');
|
||||
$oP->set_base(utils::GetAbsoluteUrlAppRoot().'test/');
|
||||
$oP->set_title('Grouping with functions');
|
||||
$oP->add('<div style="padding: 15px;"><h2>Grouping with functions</h2>');
|
||||
$oP->add('<div style="padding: 15px; background: #ddd;">');
|
||||
try
|
||||
{
|
||||
if (!empty($sOQL))
|
||||
{
|
||||
// Getting class attributes
|
||||
$oSearch = DBSearch::FromOQL($sOQL);
|
||||
$aSearches = $oSearch->GetSearches();
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
$sClass = $aSearches[0]->GetClassAlias();
|
||||
$sRealClass = $aSearches[0]->GetClass();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sClass = $oSearch->GetClassAlias();
|
||||
$sRealClass = $oSearch->GetClass();
|
||||
}
|
||||
|
||||
$sGroupBy1 = utils::ReadParam('groupby_1', '');
|
||||
$sGroupBy2 = utils::ReadParam('groupby_2', '');
|
||||
$sOrderBy1 = utils::ReadParam('orderby_1', '');
|
||||
$sOrderBy2 = utils::ReadParam('orderby_2', '');
|
||||
|
||||
$sAttributesOptions1 = '';
|
||||
$sAttributesOptions2 = '';
|
||||
$sAttributesOptions3 = '';
|
||||
$sAttributesOptions4 = '';
|
||||
|
||||
foreach(array('_itop_sum_', '_itop_avg_', '_itop_min_', '_itop_max_', '_itop_count_', 'group1', 'group2') as $sAttCode)
|
||||
{
|
||||
$sAttributesOptions3 .= '<option value="'.$sAttCode.'" '.($sOrderBy1 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
$sAttributesOptions4 .= '<option value="'.$sAttCode.'" '.($sOrderBy2 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
}
|
||||
|
||||
foreach(MetaModel::ListAttributeDefs($sRealClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
foreach($aSearches as $oSubQuery)
|
||||
{
|
||||
$sSubClass = $oSubQuery->GetClass();
|
||||
if (!MetaModel::IsValidAttCode($sSubClass, $sAttCode))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sAttributesOptions1 .= '<option value="'.$sAttCode.'" '.($sGroupBy1 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
$sAttributesOptions2 .= '<option value="'.$sAttCode.'" '.($sGroupBy2 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
}
|
||||
|
||||
$iLimit = intval(utils::ReadParam('top', '0'));
|
||||
|
||||
$sInvOrder1 = utils::ReadParam('desc1', '');
|
||||
$sCheck1 = ($sInvOrder1 == 'on' ? 'checked' : '');
|
||||
|
||||
$sInvOrder2 = utils::ReadParam('desc2', '');
|
||||
$sCheck2 = ($sInvOrder2 == 'on' ? 'checked' : '');
|
||||
|
||||
$sFuncField = utils::ReadParam('funcfield', '');
|
||||
|
||||
$sFuncFieldOption = '';
|
||||
foreach(MetaModel::ListAttributeDefs($sRealClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
foreach($aSearches as $oSubQuery)
|
||||
{
|
||||
$sSubClass = $oSubQuery->GetClass();
|
||||
if (!MetaModel::IsValidAttCode($sSubClass, $sAttCode))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (get_class($oAttDef))
|
||||
{
|
||||
case 'Integer':
|
||||
case 'AttributeDecimal':
|
||||
case 'AttributeDuration':
|
||||
case 'AttributeSubItem':
|
||||
case 'AttributePercentage':
|
||||
$sFuncFieldOption .= '<option value="'.$sAttCode.'" '.($sFuncField == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$oP->p('<div class="header_message message_error">'.$e->getMessage().'</div>');
|
||||
$bError = true;
|
||||
}
|
||||
$oP->add("<div><form>");
|
||||
$oP->add("<input type=\"submit\" name=\"submit\" value=\"Reset\">\n");
|
||||
$oP->add("</form></div>");
|
||||
|
||||
$oP->add("<form>");
|
||||
|
||||
$oP->add(
|
||||
<<<EOF
|
||||
<div>
|
||||
<label>Search OQL:</label>
|
||||
<div>
|
||||
<textarea id='OQL_Request' name='OQL_Request' cols='60' rows='5'>$sOQL</textarea>
|
||||
</div>
|
||||
</div>
|
||||
EOF
|
||||
);
|
||||
|
||||
if (!empty($sOQL) && !$bError)
|
||||
{
|
||||
$oP->add(
|
||||
<<<EOF
|
||||
<div>
|
||||
<label>Group by:</label>
|
||||
<div>
|
||||
<select id="groupby_1" name="groupby_1">
|
||||
$sAttributesOptions1
|
||||
</select>
|
||||
<select id="groupby_2" name="groupby_2">
|
||||
<option></option>
|
||||
$sAttributesOptions2
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Order by:</label>
|
||||
<div>
|
||||
<select id="orderby_1" name="orderby_1">$sAttributesOptions3</select>
|
||||
<label>Inv order</label><input type="checkbox" name="desc1" $sCheck1/>
|
||||
</div>
|
||||
<div>
|
||||
<select id="orderby_2" name="orderby_2">
|
||||
<option></option>
|
||||
$sAttributesOptions4
|
||||
</select>
|
||||
<label>Inv order</label><input type="checkbox" name="desc2" $sCheck2/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Functions on:</label>
|
||||
<div>
|
||||
<select id="funcfield" name="funcfield">$sFuncFieldOption</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Top:</label>
|
||||
<div><input type="text" id="top" name="top" value="$iLimit"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
$oP->add("<input type=\"submit\" name=\"submit\" value=\"Search\">\n");
|
||||
|
||||
$oP->add("</form>");
|
||||
|
||||
$sSQL = '';
|
||||
|
||||
|
||||
if (empty($sOQL) || empty($sGroupBy1))
|
||||
{
|
||||
$oP->output();
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
$iLimitStart = 0;
|
||||
$aOrderBy = array();
|
||||
if (!empty($sOrderBy1))
|
||||
{
|
||||
$aOrderBy[$sOrderBy1] = ($sInvOrder1 != 'on');
|
||||
}
|
||||
if (!empty($sOrderBy2))
|
||||
{
|
||||
$aOrderBy[$sOrderBy2] = ($sInvOrder2 != 'on');
|
||||
}
|
||||
|
||||
$aGroupBy = array();
|
||||
$oExpr1 = Expression::FromOQL($sClass.'.'.$sGroupBy1);
|
||||
$aGroupBy["group1"] = $oExpr1;
|
||||
|
||||
if (!empty($sGroupBy2))
|
||||
{
|
||||
$oExpr2 = Expression::FromOQL($sClass.'.'.$sGroupBy2);
|
||||
$aGroupBy["group2"] = $oExpr2;
|
||||
}
|
||||
|
||||
$aArgs = array();
|
||||
|
||||
if (empty($sFuncField))
|
||||
{
|
||||
$aFunctions = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$oTimeExpr = Expression::FromOQL($sClass.'.'.$sFuncField);
|
||||
$oSumExpr = new FunctionExpression('SUM', array($oTimeExpr));
|
||||
$oAvgExpr = new FunctionExpression('AVG', array($oTimeExpr));
|
||||
$oMinExpr = new FunctionExpression('MIN', array($oTimeExpr));
|
||||
$oMaxExpr = new FunctionExpression('MAX', array($oTimeExpr));
|
||||
// Alias => Expression
|
||||
$aFunctions = array(
|
||||
'_itop_sum_' => $oSumExpr,
|
||||
'_itop_avg_' => $oAvgExpr,
|
||||
'_itop_min_' => $oMinExpr,
|
||||
'_itop_max_' => $oMaxExpr,
|
||||
);
|
||||
}
|
||||
|
||||
$sSQL = $oSearch->MakeGroupByQuery($aArgs, $aGroupBy, false, $aFunctions, $aOrderBy, $iLimit, $iLimitStart);
|
||||
|
||||
$aRes = CMDBSource::QueryToArray($sSQL);
|
||||
|
||||
// Display results
|
||||
if (!empty($aRes))
|
||||
{
|
||||
$oP->add('<div>');
|
||||
$oP->add('<table class="listResults">');
|
||||
$aLine = $aRes[0];
|
||||
$aCols = array();
|
||||
$oP->add('<tr>');
|
||||
foreach(array_keys($aLine) as $item)
|
||||
{
|
||||
if (!is_numeric($item))
|
||||
{
|
||||
$aCols[] = $item;
|
||||
$oP->add("<th>$item</th>");
|
||||
}
|
||||
}
|
||||
$oP->add('</tr>');
|
||||
|
||||
foreach($aRes as $aLine)
|
||||
{
|
||||
$oP->add('<tr>');
|
||||
foreach($aCols as $sCol)
|
||||
{
|
||||
$oP->add("<td>".$aLine[$sCol]."</td>");
|
||||
}
|
||||
$oP->add('</tr>');
|
||||
}
|
||||
|
||||
$oP->add('</table>');
|
||||
$oP->add('</div>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->add("<p>No Result</p>\n");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$oP->p('<div class="header_message message_error">'.$e->getMessage().'</div>');
|
||||
$bError = true;
|
||||
}
|
||||
|
||||
$oP->add("<div class=\"header_message message_info\">$sSQL</div>\n");
|
||||
|
||||
$oP->output();
|
||||
|
||||
return;
|
||||
|
||||
/*
|
||||
echo "<pre>";
|
||||
$aClassSelection = MetaModel::GetClasses();
|
||||
foreach($aClassSelection as $sClass)
|
||||
{
|
||||
if (!MetaModel::HasTable($sClass))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if (!MetaModel::IsAttributeOrigin($sClass, $sAttCode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (get_class($oAttDef))
|
||||
{
|
||||
case 'Integer':
|
||||
case 'AttributeDecimal':
|
||||
case 'AttributeDuration':
|
||||
case 'AttributeSubItem':
|
||||
case 'AttributePercentage':
|
||||
echo "$sClass:$sAttCode = ".get_class($oAttDef)."\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
require_once ('../approot.inc.php');
|
||||
require_once(APPROOT.'application/application.inc.php');
|
||||
require_once(APPROOT.'application/itopwebpage.class.inc.php');
|
||||
require_once(APPROOT.'application/startup.inc.php');
|
||||
require_once(APPROOT.'application/loginwebpage.class.inc.php');
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Main program
|
||||
//
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed
|
||||
|
||||
|
||||
$sSubmit = utils::ReadParam('submit', '', false, 'raw_data');
|
||||
if ($sSubmit != 'Reset')
|
||||
{
|
||||
$sOQL = utils::ReadParam('OQL_Request', '', false, 'raw_data');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sOQL = '';
|
||||
}
|
||||
$bError = false;
|
||||
$oP = new iTopWebPage('Database inconsistencies');
|
||||
$oP->set_base(utils::GetAbsoluteUrlAppRoot().'test/');
|
||||
$oP->set_title('Grouping with functions');
|
||||
$oP->add('<div style="padding: 15px;"><h2>Grouping with functions</h2>');
|
||||
$oP->add('<div style="padding: 15px; background: #ddd;">');
|
||||
try
|
||||
{
|
||||
if (!empty($sOQL))
|
||||
{
|
||||
// Getting class attributes
|
||||
$oSearch = DBSearch::FromOQL($sOQL);
|
||||
$aSearches = $oSearch->GetSearches();
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
$sClass = $aSearches[0]->GetClassAlias();
|
||||
$sRealClass = $aSearches[0]->GetClass();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sClass = $oSearch->GetClassAlias();
|
||||
$sRealClass = $oSearch->GetClass();
|
||||
}
|
||||
|
||||
$sGroupBy1 = utils::ReadParam('groupby_1', '');
|
||||
$sGroupBy2 = utils::ReadParam('groupby_2', '');
|
||||
$sOrderBy1 = utils::ReadParam('orderby_1', '');
|
||||
$sOrderBy2 = utils::ReadParam('orderby_2', '');
|
||||
|
||||
$sAttributesOptions1 = '';
|
||||
$sAttributesOptions2 = '';
|
||||
$sAttributesOptions3 = '';
|
||||
$sAttributesOptions4 = '';
|
||||
|
||||
foreach(array('_itop_sum_', '_itop_avg_', '_itop_min_', '_itop_max_', '_itop_count_', 'group1', 'group2') as $sAttCode)
|
||||
{
|
||||
$sAttributesOptions3 .= '<option value="'.$sAttCode.'" '.($sOrderBy1 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
$sAttributesOptions4 .= '<option value="'.$sAttCode.'" '.($sOrderBy2 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
}
|
||||
|
||||
foreach(MetaModel::ListAttributeDefs($sRealClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
foreach($aSearches as $oSubQuery)
|
||||
{
|
||||
$sSubClass = $oSubQuery->GetClass();
|
||||
if (!MetaModel::IsValidAttCode($sSubClass, $sAttCode))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sAttributesOptions1 .= '<option value="'.$sAttCode.'" '.($sGroupBy1 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
$sAttributesOptions2 .= '<option value="'.$sAttCode.'" '.($sGroupBy2 == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
}
|
||||
|
||||
$iLimit = intval(utils::ReadParam('top', '0'));
|
||||
|
||||
$sInvOrder1 = utils::ReadParam('desc1', '');
|
||||
$sCheck1 = ($sInvOrder1 == 'on' ? 'checked' : '');
|
||||
|
||||
$sInvOrder2 = utils::ReadParam('desc2', '');
|
||||
$sCheck2 = ($sInvOrder2 == 'on' ? 'checked' : '');
|
||||
|
||||
$sFuncField = utils::ReadParam('funcfield', '');
|
||||
|
||||
$sFuncFieldOption = '';
|
||||
foreach(MetaModel::ListAttributeDefs($sRealClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if ($oSearch instanceof DBUnionSearch)
|
||||
{
|
||||
foreach($aSearches as $oSubQuery)
|
||||
{
|
||||
$sSubClass = $oSubQuery->GetClass();
|
||||
if (!MetaModel::IsValidAttCode($sSubClass, $sAttCode))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (get_class($oAttDef))
|
||||
{
|
||||
case 'Integer':
|
||||
case 'AttributeDecimal':
|
||||
case 'AttributeDuration':
|
||||
case 'AttributeSubItem':
|
||||
case 'AttributePercentage':
|
||||
$sFuncFieldOption .= '<option value="'.$sAttCode.'" '.($sFuncField == $sAttCode ? 'selected' : '').'>'.$sAttCode.'</option>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$oP->p('<div class="header_message message_error">'.$e->getMessage().'</div>');
|
||||
$bError = true;
|
||||
}
|
||||
$oP->add("<div><form>");
|
||||
$oP->add("<input type=\"submit\" name=\"submit\" value=\"Reset\">\n");
|
||||
$oP->add("</form></div>");
|
||||
|
||||
$oP->add("<form>");
|
||||
|
||||
$oP->add(
|
||||
<<<EOF
|
||||
<div>
|
||||
<label>Search OQL:</label>
|
||||
<div>
|
||||
<textarea id='OQL_Request' name='OQL_Request' cols='60' rows='5'>$sOQL</textarea>
|
||||
</div>
|
||||
</div>
|
||||
EOF
|
||||
);
|
||||
|
||||
if (!empty($sOQL) && !$bError)
|
||||
{
|
||||
$oP->add(
|
||||
<<<EOF
|
||||
<div>
|
||||
<label>Group by:</label>
|
||||
<div>
|
||||
<select id="groupby_1" name="groupby_1">
|
||||
$sAttributesOptions1
|
||||
</select>
|
||||
<select id="groupby_2" name="groupby_2">
|
||||
<option></option>
|
||||
$sAttributesOptions2
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Order by:</label>
|
||||
<div>
|
||||
<select id="orderby_1" name="orderby_1">$sAttributesOptions3</select>
|
||||
<label>Inv order</label><input type="checkbox" name="desc1" $sCheck1/>
|
||||
</div>
|
||||
<div>
|
||||
<select id="orderby_2" name="orderby_2">
|
||||
<option></option>
|
||||
$sAttributesOptions4
|
||||
</select>
|
||||
<label>Inv order</label><input type="checkbox" name="desc2" $sCheck2/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Functions on:</label>
|
||||
<div>
|
||||
<select id="funcfield" name="funcfield">$sFuncFieldOption</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Top:</label>
|
||||
<div><input type="text" id="top" name="top" value="$iLimit"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
$oP->add("<input type=\"submit\" name=\"submit\" value=\"Search\">\n");
|
||||
|
||||
$oP->add("</form>");
|
||||
|
||||
$sSQL = '';
|
||||
|
||||
|
||||
if (empty($sOQL) || empty($sGroupBy1))
|
||||
{
|
||||
$oP->output();
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
$iLimitStart = 0;
|
||||
$aOrderBy = array();
|
||||
if (!empty($sOrderBy1))
|
||||
{
|
||||
$aOrderBy[$sOrderBy1] = ($sInvOrder1 != 'on');
|
||||
}
|
||||
if (!empty($sOrderBy2))
|
||||
{
|
||||
$aOrderBy[$sOrderBy2] = ($sInvOrder2 != 'on');
|
||||
}
|
||||
|
||||
$aGroupBy = array();
|
||||
$oExpr1 = Expression::FromOQL($sClass.'.'.$sGroupBy1);
|
||||
$aGroupBy["group1"] = $oExpr1;
|
||||
|
||||
if (!empty($sGroupBy2))
|
||||
{
|
||||
$oExpr2 = Expression::FromOQL($sClass.'.'.$sGroupBy2);
|
||||
$aGroupBy["group2"] = $oExpr2;
|
||||
}
|
||||
|
||||
$aArgs = array();
|
||||
|
||||
if (empty($sFuncField))
|
||||
{
|
||||
$aFunctions = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$oTimeExpr = Expression::FromOQL($sClass.'.'.$sFuncField);
|
||||
$oSumExpr = new FunctionExpression('SUM', array($oTimeExpr));
|
||||
$oAvgExpr = new FunctionExpression('AVG', array($oTimeExpr));
|
||||
$oMinExpr = new FunctionExpression('MIN', array($oTimeExpr));
|
||||
$oMaxExpr = new FunctionExpression('MAX', array($oTimeExpr));
|
||||
// Alias => Expression
|
||||
$aFunctions = array(
|
||||
'_itop_sum_' => $oSumExpr,
|
||||
'_itop_avg_' => $oAvgExpr,
|
||||
'_itop_min_' => $oMinExpr,
|
||||
'_itop_max_' => $oMaxExpr,
|
||||
);
|
||||
}
|
||||
|
||||
$sSQL = $oSearch->MakeGroupByQuery($aArgs, $aGroupBy, false, $aFunctions, $aOrderBy, $iLimit, $iLimitStart);
|
||||
|
||||
$aRes = CMDBSource::QueryToArray($sSQL);
|
||||
|
||||
// Display results
|
||||
if (!empty($aRes))
|
||||
{
|
||||
$oP->add('<div>');
|
||||
$oP->add('<table class="listResults">');
|
||||
$aLine = $aRes[0];
|
||||
$aCols = array();
|
||||
$oP->add('<tr>');
|
||||
foreach(array_keys($aLine) as $item)
|
||||
{
|
||||
if (!is_numeric($item))
|
||||
{
|
||||
$aCols[] = $item;
|
||||
$oP->add("<th>$item</th>");
|
||||
}
|
||||
}
|
||||
$oP->add('</tr>');
|
||||
|
||||
foreach($aRes as $aLine)
|
||||
{
|
||||
$oP->add('<tr>');
|
||||
foreach($aCols as $sCol)
|
||||
{
|
||||
$oP->add("<td>".$aLine[$sCol]."</td>");
|
||||
}
|
||||
$oP->add('</tr>');
|
||||
}
|
||||
|
||||
$oP->add('</table>');
|
||||
$oP->add('</div>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->add("<p>No Result</p>\n");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$oP->p('<div class="header_message message_error">'.$e->getMessage().'</div>');
|
||||
$bError = true;
|
||||
}
|
||||
|
||||
$oP->add("<div class=\"header_message message_info\">$sSQL</div>\n");
|
||||
|
||||
$oP->output();
|
||||
|
||||
return;
|
||||
|
||||
/*
|
||||
echo "<pre>";
|
||||
$aClassSelection = MetaModel::GetClasses();
|
||||
foreach($aClassSelection as $sClass)
|
||||
{
|
||||
if (!MetaModel::HasTable($sClass))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
// Skip this attribute if not defined in this table
|
||||
if (!MetaModel::IsAttributeOrigin($sClass, $sAttCode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (get_class($oAttDef))
|
||||
{
|
||||
case 'Integer':
|
||||
case 'AttributeDecimal':
|
||||
case 'AttributeDuration':
|
||||
case 'AttributeSubItem':
|
||||
case 'AttributePercentage':
|
||||
echo "$sClass:$sAttCode = ".get_class($oAttDef)."\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,59 +1,59 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 20/11/2017
|
||||
* Time: 11:21
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
define('DEBUG_UNIT_TEST', true);
|
||||
|
||||
class ItopTestCase extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
@include_once '../approot.inc.php';
|
||||
@include_once '../../approot.inc.php';
|
||||
@include_once '../../../approot.inc.php';
|
||||
@include_once '../../../../approot.inc.php';
|
||||
|
||||
$this->debug("\n----------\n---------- ".$this->getName()."\n----------\n");
|
||||
|
||||
}
|
||||
|
||||
protected function debug($sMsg)
|
||||
{
|
||||
if (DEBUG_UNIT_TEST)
|
||||
{
|
||||
if (is_string($sMsg))
|
||||
{
|
||||
echo "$sMsg\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r($sMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 20/11/2017
|
||||
* Time: 11:21
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
define('DEBUG_UNIT_TEST', true);
|
||||
|
||||
class ItopTestCase extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
@include_once '../approot.inc.php';
|
||||
@include_once '../../approot.inc.php';
|
||||
@include_once '../../../approot.inc.php';
|
||||
@include_once '../../../../approot.inc.php';
|
||||
|
||||
$this->debug("\n----------\n---------- ".$this->getName()."\n----------\n");
|
||||
|
||||
}
|
||||
|
||||
protected function debug($sMsg)
|
||||
{
|
||||
if (DEBUG_UNIT_TEST)
|
||||
{
|
||||
if (is_string($sMsg))
|
||||
{
|
||||
echo "$sMsg\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print_r($sMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1742
test/benchmark.php
1742
test/benchmark.php
File diff suppressed because it is too large
Load Diff
@@ -1,38 +1,38 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// phpMyORM configuration file
|
||||
//
|
||||
// To be manually edited (or generated by the configuration wizard)
|
||||
//
|
||||
// The file is used in MetaModel::LoadConfig() which does all the necessary initialization job
|
||||
//
|
||||
|
||||
$MySettings = array(
|
||||
'db_host' => 'localhost',
|
||||
'db_user' => 'root',
|
||||
'db_pwd' => '',
|
||||
'db_name' => 'TestFarm',
|
||||
'db_subname' => '', // use it to differentiate two applications instances running on the same DB
|
||||
);
|
||||
|
||||
// Modules: file names should be specified as a absolute paths
|
||||
|
||||
$MyModules = array(
|
||||
'application' => array (
|
||||
// '../core/event.class.inc.php',
|
||||
// '../core/action.class.inc.php',
|
||||
// '../core/trigger.class.inc.php',
|
||||
// to be continued...
|
||||
),
|
||||
'business' => array (
|
||||
'../business/test_farm.class.inc.php',
|
||||
// to be continued...
|
||||
),
|
||||
'addons' => array (
|
||||
//'user rights' => '/addons/userrights/userrightsnull.class.inc.php', // or userrightsmatrix.class.inc.php
|
||||
// other modules to come later
|
||||
)
|
||||
);
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
//
|
||||
// phpMyORM configuration file
|
||||
//
|
||||
// To be manually edited (or generated by the configuration wizard)
|
||||
//
|
||||
// The file is used in MetaModel::LoadConfig() which does all the necessary initialization job
|
||||
//
|
||||
|
||||
$MySettings = array(
|
||||
'db_host' => 'localhost',
|
||||
'db_user' => 'root',
|
||||
'db_pwd' => '',
|
||||
'db_name' => 'TestFarm',
|
||||
'db_subname' => '', // use it to differentiate two applications instances running on the same DB
|
||||
);
|
||||
|
||||
// Modules: file names should be specified as a absolute paths
|
||||
|
||||
$MyModules = array(
|
||||
'application' => array (
|
||||
// '../core/event.class.inc.php',
|
||||
// '../core/action.class.inc.php',
|
||||
// '../core/trigger.class.inc.php',
|
||||
// to be continued...
|
||||
),
|
||||
'business' => array (
|
||||
'../business/test_farm.class.inc.php',
|
||||
// to be continued...
|
||||
),
|
||||
'addons' => array (
|
||||
//'user rights' => '/addons/userrights/userrightsnull.class.inc.php', // or userrightsmatrix.class.inc.php
|
||||
// other modules to come later
|
||||
)
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 02/10/2017
|
||||
* Time: 13:58
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use DBObject;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBObjectTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once(APPROOT.'core/coreexception.class.inc.php');
|
||||
require_once(APPROOT.'core/dbobject.class.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default page name
|
||||
*/
|
||||
public function testGetUIPage()
|
||||
{
|
||||
static::assertEquals('UI.php', DBObject::GetUIPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PKey validation
|
||||
* @dataProvider keyProviderOK
|
||||
* @param $key
|
||||
* @param $res
|
||||
*/
|
||||
public function testIsValidPKeyOK($key, $res)
|
||||
{
|
||||
static::assertEquals(DBObject::IsValidPKey($key), $res);
|
||||
}
|
||||
|
||||
public function keyProviderOK()
|
||||
{
|
||||
return array(
|
||||
array(1, true),
|
||||
array('255', true),
|
||||
array(-24576, true),
|
||||
array(0123, true),
|
||||
array(0xCAFE, true),
|
||||
array(PHP_INT_MIN, true),
|
||||
array(PHP_INT_MAX, true),
|
||||
array('test', false),
|
||||
array('', false),
|
||||
array('a255', false),
|
||||
array('PHP_INT_MIN', false));
|
||||
}
|
||||
|
||||
public function testGetOriginal()
|
||||
{
|
||||
$oObject = $this->CreateUserRequest(190664);
|
||||
|
||||
static::assertNull($oObject->GetOriginal('sla_tto_passed'));
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 02/10/2017
|
||||
* Time: 13:58
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use DBObject;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBObjectTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once(APPROOT.'core/coreexception.class.inc.php');
|
||||
require_once(APPROOT.'core/dbobject.class.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default page name
|
||||
*/
|
||||
public function testGetUIPage()
|
||||
{
|
||||
static::assertEquals('UI.php', DBObject::GetUIPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PKey validation
|
||||
* @dataProvider keyProviderOK
|
||||
* @param $key
|
||||
* @param $res
|
||||
*/
|
||||
public function testIsValidPKeyOK($key, $res)
|
||||
{
|
||||
static::assertEquals(DBObject::IsValidPKey($key), $res);
|
||||
}
|
||||
|
||||
public function keyProviderOK()
|
||||
{
|
||||
return array(
|
||||
array(1, true),
|
||||
array('255', true),
|
||||
array(-24576, true),
|
||||
array(0123, true),
|
||||
array(0xCAFE, true),
|
||||
array(PHP_INT_MIN, true),
|
||||
array(PHP_INT_MAX, true),
|
||||
array('test', false),
|
||||
array('', false),
|
||||
array('a255', false),
|
||||
array('PHP_INT_MIN', false));
|
||||
}
|
||||
|
||||
public function testGetOriginal()
|
||||
{
|
||||
$oObject = $this->CreateUserRequest(190664);
|
||||
|
||||
static::assertNull($oObject->GetOriginal('sla_tto_passed'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,236 +1,236 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 25/01/2018
|
||||
* Time: 11:12
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UserRights;
|
||||
|
||||
class UserRightsTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
public static $aClasses = array(
|
||||
'FunctionalCI' => array('class' => 'FunctionalCI', 'attcode' => 'name'),
|
||||
'URP_UserProfile' => array('class' => 'URP_UserProfile', 'attcode' => 'reason'),
|
||||
'UserLocal' => array('class' => 'UserLocal', 'attcode' => 'login'),
|
||||
'UserRequest' => array('class' => 'UserRequest', 'attcode' => 'title'),
|
||||
'ModuleInstallation' => array('class' => 'ModuleInstallation', 'attcode' => 'name'),
|
||||
);
|
||||
|
||||
|
||||
public function testIsLoggedIn()
|
||||
{
|
||||
$this->assertFalse(UserRights::IsLoggedIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Login validation
|
||||
* @dataProvider LoginProvider
|
||||
* @param $sLogin
|
||||
* @param $bResult
|
||||
*/
|
||||
public function testLogin($sLogin, $bResult)
|
||||
{
|
||||
$_SESSION = array();
|
||||
$this->assertEquals($bResult, UserRights::Login($sLogin));
|
||||
$this->assertEquals($bResult, UserRights::IsLoggedIn());
|
||||
}
|
||||
|
||||
public function LoginProvider()
|
||||
{
|
||||
return array(
|
||||
array('admin', true),
|
||||
array('NotALoginForUnitTests', false),
|
||||
array('', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLogin
|
||||
* @param int $iProfileId initial profile
|
||||
* @return \DBObject
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function AddUser($sLogin, $iProfileId)
|
||||
{
|
||||
$oUser = self::CreateUser('test1', $iProfileId);
|
||||
$oUser->DBUpdate();
|
||||
return $oUser;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed when not logged => always true
|
||||
* @dataProvider ActionAllowedNotLoggedProvider
|
||||
* @param $aClassAction
|
||||
*/
|
||||
public function testIsActionAllowedNotLogged($aClassAction)
|
||||
{
|
||||
$bRes = (UserRights::IsActionAllowed($aClassAction['class'], $aClassAction['action'])) ? true : false;
|
||||
$this->assertEquals(true, $bRes);
|
||||
}
|
||||
|
||||
public function ActionAllowedNotLoggedProvider()
|
||||
{
|
||||
$aClassActions = array();
|
||||
|
||||
foreach(array_keys(self::$aClasses) as $sClass)
|
||||
{
|
||||
for ($i = 1; $i < 8; $i++)
|
||||
{
|
||||
$aClassAction = array('class' => $sClass, 'action' => $i);
|
||||
$aClassActions[] = array($aClassAction);
|
||||
}
|
||||
}
|
||||
return $aClassActions;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed
|
||||
* @dataProvider ActionAllowedProvider
|
||||
* @param $iProfileId
|
||||
* @param $aClassActionResult
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testIsActionAllowed($iProfileId, $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = array();
|
||||
$this->assertTrue(UserRights::Login('test1'));
|
||||
$bRes = (UserRights::IsActionAllowed($aClassActionResult['class'], $aClassActionResult['action'])) ? true : false;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
}
|
||||
|
||||
/*
|
||||
* FunctionalCI => bizmodel searchable
|
||||
* UserRequest => bizmodel searchable requestmgmt
|
||||
* URP_UserProfile => addon/userrights
|
||||
* UserLocal => addon/authentication
|
||||
* ModuleInstallation => core view_in_gui
|
||||
*
|
||||
*/
|
||||
public function ActionAllowedProvider()
|
||||
{
|
||||
return array(
|
||||
/* Administrator (7 = UR_ACTION_CREATE) */
|
||||
'Administrator FunctionalCI write' => array(1 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => true)),
|
||||
'Administrator UserRequest write' => array(1 , array('class' => 'UserRequest', 'action' => 7, 'res' => true)),
|
||||
'Administrator URP_UserProfile write' => array(1 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => true)),
|
||||
'Administrator UserLocal write' => array(1 , array('class' => 'UserLocal', 'action' => 7, 'res' => true)),
|
||||
'Administrator ModuleInstallation write' => array(1 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => true)),
|
||||
|
||||
/* User Portal (7 = UR_ACTION_CREATE) */
|
||||
'User Portal FunctionalCI write' => array(2 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => false)),
|
||||
'User Portal UserRequest write' => array(2 , array('class' => 'UserRequest', 'action' => 7, 'res' => true)),
|
||||
'User Portal URP_UserProfile write' => array(2 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => false)),
|
||||
'User Portal UserLocal write' => array(2 , array('class' => 'UserLocal', 'action' => 7, 'res' => false)),
|
||||
'User Portal ModuleInstallation write' => array(2 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => false)),
|
||||
|
||||
/* Configuration manager (7 = UR_ACTION_CREATE) */
|
||||
'Configuration manager FunctionalCI write' => array(3 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => true)),
|
||||
'Configuration manager UserRequest write' => array(3 , array('class' => 'UserRequest', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager URP_UserProfile write' => array(3 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager UserLocal write' => array(3 , array('class' => 'UserLocal', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation write' => array(3 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => false)),
|
||||
|
||||
/* Administrator (1 = UR_ACTION_READ) */
|
||||
'Administrator FunctionalCI read' => array(1 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'Administrator UserRequest read' => array(1 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'Administrator URP_UserProfile read' => array(1 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => true)),
|
||||
'Administrator UserLocal read' => array(1 , array('class' => 'UserLocal', 'action' => 1, 'res' => true)),
|
||||
'Administrator ModuleInstallation read' => array(1 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
|
||||
/* User Portal (1 = UR_ACTION_READ) */
|
||||
'User Portal FunctionalCI read' => array(2 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'User Portal UserRequest read' => array(2 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'User Portal URP_UserProfile read' => array(2 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => false)),
|
||||
'User Portal UserLocal read' => array(2 , array('class' => 'UserLocal', 'action' => 1, 'res' => false)),
|
||||
'User Portal ModuleInstallation read' => array(2 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
|
||||
/* Configuration manager (1 = UR_ACTION_READ) */
|
||||
'Configuration manager FunctionalCI read' => array(3 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'Configuration manager UserRequest read' => array(3 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'Configuration manager URP_UserProfile read' => array(3 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => false)),
|
||||
'Configuration manager UserLocal read' => array(3 , array('class' => 'UserLocal', 'action' => 1, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation read' =>array(3 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** Test IsActionAllowedOnAttribute
|
||||
* @dataProvider ActionAllowedOnAttributeProvider
|
||||
* @param $iProfileId
|
||||
* @param $aClassActionResult
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testIsActionAllowedOnAttribute($iProfileId, $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = array();
|
||||
$this->assertTrue(UserRights::Login('test1'));
|
||||
$sClass = $aClassActionResult['class'];
|
||||
$bRes = (UserRights::IsActionAllowedOnAttribute($sClass, self::$aClasses[$sClass]['attcode'], $aClassActionResult['action'])) ? true : false;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* FunctionalCI => bizmodel searchable
|
||||
* UserRequest => bizmodel searchable requestmgmt
|
||||
* URP_UserProfile => addon/userrights grant_by_profile
|
||||
* UserLocal => addon/authentication grant_by_profile
|
||||
* ModuleInstallation => core view_in_gui
|
||||
*
|
||||
*/
|
||||
public function ActionAllowedOnAttributeProvider()
|
||||
{
|
||||
$aClassActionResult = array(
|
||||
/* Administrator (2 = UR_ACTION_MODIFY) */
|
||||
'Administrator FunctionalCI' => array(1 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => true)),
|
||||
'Administrator UserRequest' => array(1 , array('class' => 'UserRequest', 'action' => 2, 'res' => true)),
|
||||
'Administrator URP_UserProfile' => array(1 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => true)),
|
||||
'Administrator UserLocal' => array(1 , array('class' => 'UserLocal', 'action' => 2, 'res' => true)),
|
||||
'Administrator ModuleInstallation' => array(1 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
|
||||
/* User Portal (2 = UR_ACTION_MODIFY) */
|
||||
'User Portal FunctionalCI' => array(2 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => false)),
|
||||
'User Portal UserRequest' => array(2 , array('class' => 'UserRequest', 'action' => 2, 'res' => true)),
|
||||
'User Portal URP_UserProfile' => array(2 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => false)),
|
||||
'User Portal UserLocal' => array(2 , array('class' => 'UserLocal', 'action' => 2, 'res' => false)),
|
||||
'User Portal ModuleInstallation' => array(2 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
|
||||
/* Configuration manager (2 = UR_ACTION_MODIFY) */
|
||||
'Configuration manager FunctionalCI' => array(3 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => true)),
|
||||
'Configuration manager UserRequest' => array(3 , array('class' => 'UserRequest', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager URP_UserProfile' => array(3 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager UserLocal' => array(3 , array('class' => 'UserLocal', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation' => array(3 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
);
|
||||
|
||||
return $aClassActionResult;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 25/01/2018
|
||||
* Time: 11:12
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UserRights;
|
||||
|
||||
class UserRightsTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
public static $aClasses = array(
|
||||
'FunctionalCI' => array('class' => 'FunctionalCI', 'attcode' => 'name'),
|
||||
'URP_UserProfile' => array('class' => 'URP_UserProfile', 'attcode' => 'reason'),
|
||||
'UserLocal' => array('class' => 'UserLocal', 'attcode' => 'login'),
|
||||
'UserRequest' => array('class' => 'UserRequest', 'attcode' => 'title'),
|
||||
'ModuleInstallation' => array('class' => 'ModuleInstallation', 'attcode' => 'name'),
|
||||
);
|
||||
|
||||
|
||||
public function testIsLoggedIn()
|
||||
{
|
||||
$this->assertFalse(UserRights::IsLoggedIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Login validation
|
||||
* @dataProvider LoginProvider
|
||||
* @param $sLogin
|
||||
* @param $bResult
|
||||
*/
|
||||
public function testLogin($sLogin, $bResult)
|
||||
{
|
||||
$_SESSION = array();
|
||||
$this->assertEquals($bResult, UserRights::Login($sLogin));
|
||||
$this->assertEquals($bResult, UserRights::IsLoggedIn());
|
||||
}
|
||||
|
||||
public function LoginProvider()
|
||||
{
|
||||
return array(
|
||||
array('admin', true),
|
||||
array('NotALoginForUnitTests', false),
|
||||
array('', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLogin
|
||||
* @param int $iProfileId initial profile
|
||||
* @return \DBObject
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function AddUser($sLogin, $iProfileId)
|
||||
{
|
||||
$oUser = self::CreateUser('test1', $iProfileId);
|
||||
$oUser->DBUpdate();
|
||||
return $oUser;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed when not logged => always true
|
||||
* @dataProvider ActionAllowedNotLoggedProvider
|
||||
* @param $aClassAction
|
||||
*/
|
||||
public function testIsActionAllowedNotLogged($aClassAction)
|
||||
{
|
||||
$bRes = (UserRights::IsActionAllowed($aClassAction['class'], $aClassAction['action'])) ? true : false;
|
||||
$this->assertEquals(true, $bRes);
|
||||
}
|
||||
|
||||
public function ActionAllowedNotLoggedProvider()
|
||||
{
|
||||
$aClassActions = array();
|
||||
|
||||
foreach(array_keys(self::$aClasses) as $sClass)
|
||||
{
|
||||
for ($i = 1; $i < 8; $i++)
|
||||
{
|
||||
$aClassAction = array('class' => $sClass, 'action' => $i);
|
||||
$aClassActions[] = array($aClassAction);
|
||||
}
|
||||
}
|
||||
return $aClassActions;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed
|
||||
* @dataProvider ActionAllowedProvider
|
||||
* @param $iProfileId
|
||||
* @param $aClassActionResult
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testIsActionAllowed($iProfileId, $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = array();
|
||||
$this->assertTrue(UserRights::Login('test1'));
|
||||
$bRes = (UserRights::IsActionAllowed($aClassActionResult['class'], $aClassActionResult['action'])) ? true : false;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
}
|
||||
|
||||
/*
|
||||
* FunctionalCI => bizmodel searchable
|
||||
* UserRequest => bizmodel searchable requestmgmt
|
||||
* URP_UserProfile => addon/userrights
|
||||
* UserLocal => addon/authentication
|
||||
* ModuleInstallation => core view_in_gui
|
||||
*
|
||||
*/
|
||||
public function ActionAllowedProvider()
|
||||
{
|
||||
return array(
|
||||
/* Administrator (7 = UR_ACTION_CREATE) */
|
||||
'Administrator FunctionalCI write' => array(1 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => true)),
|
||||
'Administrator UserRequest write' => array(1 , array('class' => 'UserRequest', 'action' => 7, 'res' => true)),
|
||||
'Administrator URP_UserProfile write' => array(1 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => true)),
|
||||
'Administrator UserLocal write' => array(1 , array('class' => 'UserLocal', 'action' => 7, 'res' => true)),
|
||||
'Administrator ModuleInstallation write' => array(1 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => true)),
|
||||
|
||||
/* User Portal (7 = UR_ACTION_CREATE) */
|
||||
'User Portal FunctionalCI write' => array(2 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => false)),
|
||||
'User Portal UserRequest write' => array(2 , array('class' => 'UserRequest', 'action' => 7, 'res' => true)),
|
||||
'User Portal URP_UserProfile write' => array(2 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => false)),
|
||||
'User Portal UserLocal write' => array(2 , array('class' => 'UserLocal', 'action' => 7, 'res' => false)),
|
||||
'User Portal ModuleInstallation write' => array(2 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => false)),
|
||||
|
||||
/* Configuration manager (7 = UR_ACTION_CREATE) */
|
||||
'Configuration manager FunctionalCI write' => array(3 , array('class' => 'FunctionalCI', 'action' => 7, 'res' => true)),
|
||||
'Configuration manager UserRequest write' => array(3 , array('class' => 'UserRequest', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager URP_UserProfile write' => array(3 , array('class' => 'URP_UserProfile', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager UserLocal write' => array(3 , array('class' => 'UserLocal', 'action' => 7, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation write' => array(3 , array('class' => 'ModuleInstallation', 'action' => 7, 'res' => false)),
|
||||
|
||||
/* Administrator (1 = UR_ACTION_READ) */
|
||||
'Administrator FunctionalCI read' => array(1 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'Administrator UserRequest read' => array(1 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'Administrator URP_UserProfile read' => array(1 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => true)),
|
||||
'Administrator UserLocal read' => array(1 , array('class' => 'UserLocal', 'action' => 1, 'res' => true)),
|
||||
'Administrator ModuleInstallation read' => array(1 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
|
||||
/* User Portal (1 = UR_ACTION_READ) */
|
||||
'User Portal FunctionalCI read' => array(2 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'User Portal UserRequest read' => array(2 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'User Portal URP_UserProfile read' => array(2 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => false)),
|
||||
'User Portal UserLocal read' => array(2 , array('class' => 'UserLocal', 'action' => 1, 'res' => false)),
|
||||
'User Portal ModuleInstallation read' => array(2 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
|
||||
/* Configuration manager (1 = UR_ACTION_READ) */
|
||||
'Configuration manager FunctionalCI read' => array(3 , array('class' => 'FunctionalCI', 'action' => 1, 'res' => true)),
|
||||
'Configuration manager UserRequest read' => array(3 , array('class' => 'UserRequest', 'action' => 1, 'res' => true)),
|
||||
'Configuration manager URP_UserProfile read' => array(3 , array('class' => 'URP_UserProfile', 'action' => 1, 'res' => false)),
|
||||
'Configuration manager UserLocal read' => array(3 , array('class' => 'UserLocal', 'action' => 1, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation read' =>array(3 , array('class' => 'ModuleInstallation', 'action' => 1, 'res' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** Test IsActionAllowedOnAttribute
|
||||
* @dataProvider ActionAllowedOnAttributeProvider
|
||||
* @param $iProfileId
|
||||
* @param $aClassActionResult
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testIsActionAllowedOnAttribute($iProfileId, $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = array();
|
||||
$this->assertTrue(UserRights::Login('test1'));
|
||||
$sClass = $aClassActionResult['class'];
|
||||
$bRes = (UserRights::IsActionAllowedOnAttribute($sClass, self::$aClasses[$sClass]['attcode'], $aClassActionResult['action'])) ? true : false;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* FunctionalCI => bizmodel searchable
|
||||
* UserRequest => bizmodel searchable requestmgmt
|
||||
* URP_UserProfile => addon/userrights grant_by_profile
|
||||
* UserLocal => addon/authentication grant_by_profile
|
||||
* ModuleInstallation => core view_in_gui
|
||||
*
|
||||
*/
|
||||
public function ActionAllowedOnAttributeProvider()
|
||||
{
|
||||
$aClassActionResult = array(
|
||||
/* Administrator (2 = UR_ACTION_MODIFY) */
|
||||
'Administrator FunctionalCI' => array(1 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => true)),
|
||||
'Administrator UserRequest' => array(1 , array('class' => 'UserRequest', 'action' => 2, 'res' => true)),
|
||||
'Administrator URP_UserProfile' => array(1 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => true)),
|
||||
'Administrator UserLocal' => array(1 , array('class' => 'UserLocal', 'action' => 2, 'res' => true)),
|
||||
'Administrator ModuleInstallation' => array(1 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
|
||||
/* User Portal (2 = UR_ACTION_MODIFY) */
|
||||
'User Portal FunctionalCI' => array(2 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => false)),
|
||||
'User Portal UserRequest' => array(2 , array('class' => 'UserRequest', 'action' => 2, 'res' => true)),
|
||||
'User Portal URP_UserProfile' => array(2 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => false)),
|
||||
'User Portal UserLocal' => array(2 , array('class' => 'UserLocal', 'action' => 2, 'res' => false)),
|
||||
'User Portal ModuleInstallation' => array(2 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
|
||||
/* Configuration manager (2 = UR_ACTION_MODIFY) */
|
||||
'Configuration manager FunctionalCI' => array(3 , array('class' => 'FunctionalCI', 'action' => 2, 'res' => true)),
|
||||
'Configuration manager UserRequest' => array(3 , array('class' => 'UserRequest', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager URP_UserProfile' => array(3 , array('class' => 'URP_UserProfile', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager UserLocal' => array(3 , array('class' => 'UserLocal', 'action' => 2, 'res' => false)),
|
||||
'Configuration manager ModuleInstallation' => array(3 , array('class' => 'ModuleInstallation', 'action' => 2, 'res' => true)),
|
||||
);
|
||||
|
||||
return $aClassActionResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 31/10/2017
|
||||
* Time: 14:10
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
define('UNIT_MAX_CACHE_FILES', 10);
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class apcEmulationTest extends ItopTestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once(APPROOT.'core/apc-emulation.php');
|
||||
require_once 'mockApcEmulation.incphp';
|
||||
apc_clear_cache();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
apc_clear_cache();
|
||||
}
|
||||
|
||||
public function testBasic()
|
||||
{
|
||||
$this->assertTrue(apc_store('test-ttl', 'This is a test with TTL', 100));
|
||||
$this->assertTrue(apc_store('test-nottl', 'This is a test without TTL'));
|
||||
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('test-ttl'));
|
||||
$this->assertEquals('This is a test without TTL', apc_fetch('test-nottl'));
|
||||
}
|
||||
|
||||
public function testMultiple()
|
||||
{
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testMultiple'.$i, 'This is a test', 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
}
|
||||
|
||||
public function testNumberOfFilesTTL()
|
||||
{
|
||||
for($i = 0; $i < 2 * UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testNumberOfFilesTTL'.$i, 'This is a test', 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$this->assertFalse(apc_fetch('testNumberOfFilesTTL0'));
|
||||
}
|
||||
|
||||
public function testNumberOfFilesNoTTL()
|
||||
{
|
||||
for($i = 0; $i < 2 * UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testNumberOfFilesNoTTL'.$i, 'This is a test'));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(2 * UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$this->assertTrue(apc_fetch('testNumberOfFilesNoTTL0') !== false);
|
||||
}
|
||||
|
||||
public function testArray()
|
||||
{
|
||||
$aStoredEntries = array();
|
||||
$aFetchedEntries = array();
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$sKey = 'testArray'.$i;
|
||||
$aStoredEntries[$sKey] = 'This is a test ARRAY'.rand();
|
||||
$aFetchedEntries[] = $sKey;
|
||||
}
|
||||
$aResStore = apc_store($aStoredEntries);
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aResStore));
|
||||
foreach($aResStore as $bValue)
|
||||
{
|
||||
$this->assertTrue($bValue);
|
||||
}
|
||||
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$aResFetch = apc_fetch($aFetchedEntries);
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aResFetch));
|
||||
|
||||
foreach($aResFetch as $sKey => $sValue)
|
||||
{
|
||||
$this->assertEquals($aStoredEntries[$sKey], $sValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testSanity()
|
||||
{
|
||||
$this->assertTrue(apc_store('testSanity', null, 100));
|
||||
$this->assertTrue(is_null(apc_fetch('testSanity')));
|
||||
|
||||
$this->assertFalse(apc_store(null, 'testSanity', 100));
|
||||
$this->assertFalse(apc_fetch(null));
|
||||
|
||||
$this->assertTrue(apc_store('testSanity2', null));
|
||||
$this->assertFalse(apc_store(null, 'testSanity2'));
|
||||
$this->assertFalse(apc_store('', 'testSanity2'));
|
||||
|
||||
$this->assertFalse(apc_delete(null));
|
||||
$this->assertFalse(apc_delete(''));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$this->assertTrue(apc_store('test-ttl', 'This is a test with TTL', 100));
|
||||
$this->assertTrue(apc_store('test-nottl', 'This is a test without TTL'));
|
||||
|
||||
$this->assertTrue(apc_delete('test-ttl'));
|
||||
$this->assertFalse(apc_delete('test-ttl'));
|
||||
$this->assertTrue(apc_delete('test-nottl'));
|
||||
|
||||
$this->assertFalse(apc_fetch('test-ttl'));
|
||||
$this->assertFalse(apc_fetch('test-nottl'));
|
||||
}
|
||||
|
||||
public function testReuseSameKey()
|
||||
{
|
||||
// first use of the key
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test with TTL', 100));
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key but no ttl
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test without TTL'));
|
||||
$this->assertEquals('This is a test without TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key with ttl
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test with TTL', 100));
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key with ttl but other content
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test', 100));
|
||||
$this->assertEquals('This is a test', apc_fetch('testReuseSameKey'));
|
||||
// remove entry
|
||||
$this->assertTrue(apc_delete('testReuseSameKey'));
|
||||
// check entry is removed
|
||||
$this->assertFalse(apc_fetch('testReuseSameKey'));
|
||||
}
|
||||
|
||||
public function testHuge()
|
||||
{
|
||||
$ilen = 20000000;
|
||||
$sContent = str_pad(' TEST ', $ilen, "-=", STR_PAD_BOTH);
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testHuge'.$i, $sContent, 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertEquals($ilen, strlen(apc_fetch('testHuge'.$i)));
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 31/10/2017
|
||||
* Time: 14:10
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
define('UNIT_MAX_CACHE_FILES', 10);
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class apcEmulationTest extends ItopTestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once(APPROOT.'core/apc-emulation.php');
|
||||
require_once 'mockApcEmulation.incphp';
|
||||
apc_clear_cache();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
apc_clear_cache();
|
||||
}
|
||||
|
||||
public function testBasic()
|
||||
{
|
||||
$this->assertTrue(apc_store('test-ttl', 'This is a test with TTL', 100));
|
||||
$this->assertTrue(apc_store('test-nottl', 'This is a test without TTL'));
|
||||
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('test-ttl'));
|
||||
$this->assertEquals('This is a test without TTL', apc_fetch('test-nottl'));
|
||||
}
|
||||
|
||||
public function testMultiple()
|
||||
{
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testMultiple'.$i, 'This is a test', 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
}
|
||||
|
||||
public function testNumberOfFilesTTL()
|
||||
{
|
||||
for($i = 0; $i < 2 * UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testNumberOfFilesTTL'.$i, 'This is a test', 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$this->assertFalse(apc_fetch('testNumberOfFilesTTL0'));
|
||||
}
|
||||
|
||||
public function testNumberOfFilesNoTTL()
|
||||
{
|
||||
for($i = 0; $i < 2 * UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testNumberOfFilesNoTTL'.$i, 'This is a test'));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(2 * UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$this->assertTrue(apc_fetch('testNumberOfFilesNoTTL0') !== false);
|
||||
}
|
||||
|
||||
public function testArray()
|
||||
{
|
||||
$aStoredEntries = array();
|
||||
$aFetchedEntries = array();
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$sKey = 'testArray'.$i;
|
||||
$aStoredEntries[$sKey] = 'This is a test ARRAY'.rand();
|
||||
$aFetchedEntries[] = $sKey;
|
||||
}
|
||||
$aResStore = apc_store($aStoredEntries);
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aResStore));
|
||||
foreach($aResStore as $bValue)
|
||||
{
|
||||
$this->assertTrue($bValue);
|
||||
}
|
||||
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
$aResFetch = apc_fetch($aFetchedEntries);
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aResFetch));
|
||||
|
||||
foreach($aResFetch as $sKey => $sValue)
|
||||
{
|
||||
$this->assertEquals($aStoredEntries[$sKey], $sValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testSanity()
|
||||
{
|
||||
$this->assertTrue(apc_store('testSanity', null, 100));
|
||||
$this->assertTrue(is_null(apc_fetch('testSanity')));
|
||||
|
||||
$this->assertFalse(apc_store(null, 'testSanity', 100));
|
||||
$this->assertFalse(apc_fetch(null));
|
||||
|
||||
$this->assertTrue(apc_store('testSanity2', null));
|
||||
$this->assertFalse(apc_store(null, 'testSanity2'));
|
||||
$this->assertFalse(apc_store('', 'testSanity2'));
|
||||
|
||||
$this->assertFalse(apc_delete(null));
|
||||
$this->assertFalse(apc_delete(''));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$this->assertTrue(apc_store('test-ttl', 'This is a test with TTL', 100));
|
||||
$this->assertTrue(apc_store('test-nottl', 'This is a test without TTL'));
|
||||
|
||||
$this->assertTrue(apc_delete('test-ttl'));
|
||||
$this->assertFalse(apc_delete('test-ttl'));
|
||||
$this->assertTrue(apc_delete('test-nottl'));
|
||||
|
||||
$this->assertFalse(apc_fetch('test-ttl'));
|
||||
$this->assertFalse(apc_fetch('test-nottl'));
|
||||
}
|
||||
|
||||
public function testReuseSameKey()
|
||||
{
|
||||
// first use of the key
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test with TTL', 100));
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key but no ttl
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test without TTL'));
|
||||
$this->assertEquals('This is a test without TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key with ttl
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test with TTL', 100));
|
||||
$this->assertEquals('This is a test with TTL', apc_fetch('testReuseSameKey'));
|
||||
// same key with ttl but other content
|
||||
$this->assertTrue(apc_store('testReuseSameKey', 'This is a test', 100));
|
||||
$this->assertEquals('This is a test', apc_fetch('testReuseSameKey'));
|
||||
// remove entry
|
||||
$this->assertTrue(apc_delete('testReuseSameKey'));
|
||||
// check entry is removed
|
||||
$this->assertFalse(apc_fetch('testReuseSameKey'));
|
||||
}
|
||||
|
||||
public function testHuge()
|
||||
{
|
||||
$ilen = 20000000;
|
||||
$sContent = str_pad(' TEST ', $ilen, "-=", STR_PAD_BOTH);
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertTrue(apc_store('testHuge'.$i, $sContent, 100));
|
||||
}
|
||||
$aInfo = apc_cache_info();
|
||||
$this->assertEquals(UNIT_MAX_CACHE_FILES, count($aInfo['cache_list']));
|
||||
|
||||
for($i = 0; $i < UNIT_MAX_CACHE_FILES; $i++)
|
||||
{
|
||||
$this->assertEquals($ilen, strlen(apc_fetch('testHuge'.$i)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +1,58 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 30/10/2017
|
||||
* Time: 13:43
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class dictTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once (APPROOT.'core/coreexception.class.inc.php');
|
||||
require_once (APPROOT.'core/dict.class.inc.php');
|
||||
require_once 'mockDict.incphp';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testType()
|
||||
{
|
||||
$this->assertInternalType('string', Dict::S('Core:AttributeURL'));
|
||||
$this->assertInternalType('string', Dict::Format('Change:AttName_SetTo', '1', '2'));
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 30/10/2017
|
||||
* Time: 13:43
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class dictTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
require_once (APPROOT.'core/coreexception.class.inc.php');
|
||||
require_once (APPROOT.'core/dict.class.inc.php');
|
||||
require_once 'mockDict.incphp';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testType()
|
||||
{
|
||||
$this->assertInternalType('string', Dict::S('Core:AttributeURL'));
|
||||
$this->assertInternalType('string', Dict::Format('Change:AttName_SetTo', '1', '2'));
|
||||
}
|
||||
}
|
||||
@@ -1,52 +1,52 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 03/11/2017
|
||||
* Time: 09:55
|
||||
*/
|
||||
|
||||
// --------------- Mock
|
||||
class utils
|
||||
{
|
||||
public static function GetCachePath()
|
||||
{
|
||||
return APPROOT.'data/cache-unittest/';
|
||||
}
|
||||
}
|
||||
|
||||
class UnitConfig
|
||||
{
|
||||
public function Get($sPropCode)
|
||||
{
|
||||
return UNIT_MAX_CACHE_FILES;
|
||||
}
|
||||
}
|
||||
|
||||
class MetaModel
|
||||
{
|
||||
public static function GetConfig()
|
||||
{
|
||||
return new UnitConfig;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 03/11/2017
|
||||
* Time: 09:55
|
||||
*/
|
||||
|
||||
// --------------- Mock
|
||||
class utils
|
||||
{
|
||||
public static function GetCachePath()
|
||||
{
|
||||
return APPROOT.'data/cache-unittest/';
|
||||
}
|
||||
}
|
||||
|
||||
class UnitConfig
|
||||
{
|
||||
public function Get($sPropCode)
|
||||
{
|
||||
return UNIT_MAX_CACHE_FILES;
|
||||
}
|
||||
}
|
||||
|
||||
class MetaModel
|
||||
{
|
||||
public static function GetConfig()
|
||||
{
|
||||
return new UnitConfig;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------- End Mock
|
||||
@@ -1,26 +1,26 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
class utils
|
||||
{
|
||||
public static function GetCurrentEnvironment()
|
||||
{
|
||||
return 'production';
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
class utils
|
||||
{
|
||||
public static function GetCurrentEnvironment()
|
||||
{
|
||||
return 'production';
|
||||
}
|
||||
}
|
||||
@@ -1,276 +1,276 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 20/12/2017
|
||||
* Time: 11:56
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Exception;
|
||||
use ormLinkSet;
|
||||
|
||||
|
||||
/**
|
||||
* Tests of the ormLinkSet class using N-N links between FunctionalCI and Contact
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormLinkSetTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oOrmLink = new ormLinkSet('UserRequest', 'contacts_list');
|
||||
static::assertNotNull($oOrmLink);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstruct2()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
|
||||
new ormLinkSet('UserRequest', 'ref');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSuccesiveAdds()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
$this->AddContactToCI($this->CreatePerson($i), $oServer);
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(4, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(4, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAddThenRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
$this->RemoveContactFromCI($oPerson, $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemoveThenAdd()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
$this->AddContactToCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAddDuplicate()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->AddContactToCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(6, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testModifyThenRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
for ($i = 3; $i < 6; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
}
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
}
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Eric
|
||||
* Date: 20/12/2017
|
||||
* Time: 11:56
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Exception;
|
||||
use ormLinkSet;
|
||||
|
||||
|
||||
/**
|
||||
* Tests of the ormLinkSet class using N-N links between FunctionalCI and Contact
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormLinkSetTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oOrmLink = new ormLinkSet('UserRequest', 'contacts_list');
|
||||
static::assertNotNull($oOrmLink);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstruct2()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
|
||||
new ormLinkSet('UserRequest', 'ref');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSuccesiveAdds()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
$this->AddContactToCI($this->CreatePerson($i), $oServer);
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(4, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(4, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAddThenRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
$this->RemoveContactFromCI($oPerson, $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(0, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemoveThenAdd()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
$this->AddContactToCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAddDuplicate()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->AddContactToCI($aPersons[$i], $oServer);
|
||||
}
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(6, $oContactsSet->Count());
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testModifyThenRemove()
|
||||
{
|
||||
$oServer = $this->CreateServer(1);
|
||||
$aPersons = array();
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$aPersons[] = $oPerson;
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
|
||||
$oServer->DBUpdate();
|
||||
$this->ReloadObject($oServer);
|
||||
|
||||
for ($i = 3; $i < 6; $i++)
|
||||
{
|
||||
$oPerson = $this->CreatePerson($i);
|
||||
$this->AddContactToCI($oPerson, $oServer);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$this->RemoveContactFromCI($aPersons[$i], $oServer);
|
||||
}
|
||||
|
||||
$oContactsSet = $oServer->Get('contacts_list');
|
||||
static::assertEquals(3, $oContactsSet->Count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Date: 06/10/2017
|
||||
*/
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'application/startup.inc.php');
|
||||
|
||||
|
||||
$sEnvironment = MetaModel::GetEnvironmentId();
|
||||
$aEntries = array();
|
||||
$aCacheUserData = apc_cache_info_compat();
|
||||
if (is_array($aCacheUserData) && isset($aCacheUserData['cache_list']))
|
||||
{
|
||||
$sPrefix = 'itop-'.$sEnvironment.'-query-cache-';
|
||||
|
||||
foreach($aCacheUserData['cache_list'] as $i => $aEntry)
|
||||
{
|
||||
$sEntryKey = array_key_exists('info', $aEntry) ? $aEntry['info'] : $aEntry['key'];
|
||||
if (strpos($sEntryKey, $sPrefix) === 0)
|
||||
{
|
||||
$aEntries[] = $sEntryKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<pre>";
|
||||
|
||||
if (empty($aEntries))
|
||||
{
|
||||
echo "No Data";
|
||||
return;
|
||||
}
|
||||
|
||||
$sKey = $aEntries[0];
|
||||
$result = apc_fetch($sKey);
|
||||
if (!is_object($result))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$oSQLQuery = $result;
|
||||
|
||||
echo "NB Tables before;NB Tables after;";
|
||||
foreach($oSQLQuery->m_aContextData as $sField => $oValue)
|
||||
{
|
||||
echo $sField.';';
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
sort($aEntries);
|
||||
|
||||
foreach($aEntries as $sKey)
|
||||
{
|
||||
$result = apc_fetch($sKey);
|
||||
if (is_object($result))
|
||||
{
|
||||
$oSQLQuery = $result;
|
||||
if (isset($oSQLQuery->m_aContextData))
|
||||
{
|
||||
echo $oSQLQuery->m_iOriginalTableCount.";".$oSQLQuery->CountTables().';';
|
||||
foreach($oSQLQuery->m_aContextData as $oValue)
|
||||
{
|
||||
if (is_array($oValue))
|
||||
{
|
||||
$sVal = json_encode($oValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($oValue))
|
||||
{
|
||||
$sVal = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sVal = $oValue;
|
||||
}
|
||||
}
|
||||
echo $sVal.';';
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "</pre>";
|
||||
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
//
|
||||
|
||||
/**
|
||||
* Date: 06/10/2017
|
||||
*/
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'application/startup.inc.php');
|
||||
|
||||
|
||||
$sEnvironment = MetaModel::GetEnvironmentId();
|
||||
$aEntries = array();
|
||||
$aCacheUserData = apc_cache_info_compat();
|
||||
if (is_array($aCacheUserData) && isset($aCacheUserData['cache_list']))
|
||||
{
|
||||
$sPrefix = 'itop-'.$sEnvironment.'-query-cache-';
|
||||
|
||||
foreach($aCacheUserData['cache_list'] as $i => $aEntry)
|
||||
{
|
||||
$sEntryKey = array_key_exists('info', $aEntry) ? $aEntry['info'] : $aEntry['key'];
|
||||
if (strpos($sEntryKey, $sPrefix) === 0)
|
||||
{
|
||||
$aEntries[] = $sEntryKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<pre>";
|
||||
|
||||
if (empty($aEntries))
|
||||
{
|
||||
echo "No Data";
|
||||
return;
|
||||
}
|
||||
|
||||
$sKey = $aEntries[0];
|
||||
$result = apc_fetch($sKey);
|
||||
if (!is_object($result))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$oSQLQuery = $result;
|
||||
|
||||
echo "NB Tables before;NB Tables after;";
|
||||
foreach($oSQLQuery->m_aContextData as $sField => $oValue)
|
||||
{
|
||||
echo $sField.';';
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
sort($aEntries);
|
||||
|
||||
foreach($aEntries as $sKey)
|
||||
{
|
||||
$result = apc_fetch($sKey);
|
||||
if (is_object($result))
|
||||
{
|
||||
$oSQLQuery = $result;
|
||||
if (isset($oSQLQuery->m_aContextData))
|
||||
{
|
||||
echo $oSQLQuery->m_iOriginalTableCount.";".$oSQLQuery->CountTables().';';
|
||||
foreach($oSQLQuery->m_aContextData as $oValue)
|
||||
{
|
||||
if (is_array($oValue))
|
||||
{
|
||||
$sVal = json_encode($oValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($oValue))
|
||||
{
|
||||
$sVal = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sVal = $oValue;
|
||||
}
|
||||
}
|
||||
echo $sVal.';';
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "</pre>";
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,64 +1,64 @@
|
||||
<!-- Copyright (c) 2010-2017 Combodo SARL -->
|
||||
<!-- -->
|
||||
<!-- This file is part of iTop. -->
|
||||
<!-- -->
|
||||
<!-- iTop is free software; you can redistribute it and/or modify -->
|
||||
<!-- it under the terms of the GNU Affero General Public License as published by -->
|
||||
<!-- the Free Software Foundation, either version 3 of the License, or -->
|
||||
<!-- (at your option) any later version. -->
|
||||
<!-- -->
|
||||
<!-- iTop 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 Affero General Public License for more details. -->
|
||||
<!-- -->
|
||||
<!-- You should have received a copy of the GNU Affero General Public License -->
|
||||
<!-- along with iTop. If not, see <http://www.gnu.org/licenses/> -->
|
||||
<!-- -->
|
||||
|
||||
<phpunit bootstrap="unittestautoload.php"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
cacheTokens="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
forceCoversAnnotation="false"
|
||||
mapTestClassNameToCoveredClassName="false"
|
||||
printerClass="\PHPUnit\TextUI\ResultPrinter"
|
||||
processIsolation="true"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
stopOnRisky="false"
|
||||
timeoutForSmallTests="1"
|
||||
timeoutForMediumTests="10"
|
||||
timeoutForLargeTests="60"
|
||||
verbose="false">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Core">
|
||||
<directory>core</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Tickets">
|
||||
<directory>itop-tickets</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Application">
|
||||
<directory>application</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<!-- Code coverage white list -->
|
||||
<filter>
|
||||
<whitelist>
|
||||
<file>../core/apc-emulation.php</file>
|
||||
<file>../core/ormlinkset.class.inc.php</file>
|
||||
<file>../datamodels/2.x/itop-tickets/main.itop-tickets.php</file>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
</phpunit>
|
||||
<!-- Copyright (c) 2010-2017 Combodo SARL -->
|
||||
<!-- -->
|
||||
<!-- This file is part of iTop. -->
|
||||
<!-- -->
|
||||
<!-- iTop is free software; you can redistribute it and/or modify -->
|
||||
<!-- it under the terms of the GNU Affero General Public License as published by -->
|
||||
<!-- the Free Software Foundation, either version 3 of the License, or -->
|
||||
<!-- (at your option) any later version. -->
|
||||
<!-- -->
|
||||
<!-- iTop 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 Affero General Public License for more details. -->
|
||||
<!-- -->
|
||||
<!-- You should have received a copy of the GNU Affero General Public License -->
|
||||
<!-- along with iTop. If not, see <http://www.gnu.org/licenses/> -->
|
||||
<!-- -->
|
||||
|
||||
<phpunit bootstrap="unittestautoload.php"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
cacheTokens="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
forceCoversAnnotation="false"
|
||||
mapTestClassNameToCoveredClassName="false"
|
||||
printerClass="\PHPUnit\TextUI\ResultPrinter"
|
||||
processIsolation="true"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
stopOnRisky="false"
|
||||
timeoutForSmallTests="1"
|
||||
timeoutForMediumTests="10"
|
||||
timeoutForLargeTests="60"
|
||||
verbose="false">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Core">
|
||||
<directory>core</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Tickets">
|
||||
<directory>itop-tickets</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Application">
|
||||
<directory>application</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<!-- Code coverage white list -->
|
||||
<filter>
|
||||
<whitelist>
|
||||
<file>../core/apc-emulation.php</file>
|
||||
<file>../core/ormlinkset.class.inc.php</file>
|
||||
<file>../datamodels/2.x/itop-tickets/main.itop-tickets.php</file>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
</phpunit>
|
||||
|
||||
338
test/test.php
338
test/test.php
@@ -1,169 +1,169 @@
|
||||
<?php
|
||||
// Copyright (C) 2010-2014 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
/**
|
||||
* Core test page
|
||||
*
|
||||
* @copyright Copyright (C) 2010-2014 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<style>
|
||||
.vardump {
|
||||
font-size:8pt;
|
||||
line-height:100%;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Helpers
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ReadMandatoryParam($sName)
|
||||
{
|
||||
$value = utils::ReadParam($sName, null);
|
||||
if (is_null($value))
|
||||
{
|
||||
echo "<p>Missing mandatory argument <b>$sName</b></p>";
|
||||
exit;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function IsAValidTestClass($sClassName)
|
||||
{
|
||||
// Must be a child of TestHandler
|
||||
//
|
||||
if (!is_subclass_of($sClassName, 'TestHandler')) return false;
|
||||
|
||||
// Must not be abstract
|
||||
//
|
||||
$oReflectionClass = new ReflectionClass($sClassName);
|
||||
if (!$oReflectionClass->isInstantiable()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function GetTestClassLine($sClassName)
|
||||
{
|
||||
$oReflectionClass = new ReflectionClass($sClassName);
|
||||
return $oReflectionClass->getStartLine();
|
||||
}
|
||||
|
||||
function DisplayEvents($aEvents, $sTitle)
|
||||
{
|
||||
echo "<h4>$sTitle</h4>\n";
|
||||
if (count($aEvents) > 0)
|
||||
{
|
||||
echo "<ul>\n";
|
||||
foreach ($aEvents as $sEvent)
|
||||
{
|
||||
echo "<li>$sEvent</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<p>none</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Main
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'/application/utils.inc.php');
|
||||
require_once('./test.class.inc.php');
|
||||
require_once('./testlist.inc.php');
|
||||
|
||||
require_once(APPROOT.'/core/cmdbobject.class.inc.php');
|
||||
|
||||
|
||||
$sTodo = utils::ReadParam("todo", "");
|
||||
if ($sTodo == '')
|
||||
{
|
||||
// Show the list of tests
|
||||
//
|
||||
echo "<h3>Existing tests</h3>\n";
|
||||
echo "<ul>\n";
|
||||
foreach (get_declared_classes() as $sClassName)
|
||||
{
|
||||
if (!IsAValidTestClass($sClassName)) continue;
|
||||
|
||||
$sName = call_user_func(array($sClassName, 'GetName'));
|
||||
$sDescription = call_user_func(array($sClassName, 'GetDescription'));
|
||||
echo "<li><a href=\"?todo=exec&testid=$sClassName\">$sName</a> ($sDescription)</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
}
|
||||
else if ($sTodo == 'exec')
|
||||
{
|
||||
// Execute a test
|
||||
//
|
||||
$sTestClass = ReadMandatoryParam("testid");
|
||||
|
||||
if (!IsAValidTestClass($sTestClass))
|
||||
{
|
||||
echo "<p>Wrong value for testid, expecting a valid class name</p>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$oTest = new $sTestClass();
|
||||
$iStartLine = GetTestClassLine($sTestClass);
|
||||
echo "<h3>Testing: ".$oTest->GetName()."</h3>\n";
|
||||
echo "<h6>testlist.inc.php: $iStartLine</h6>\n";
|
||||
$bRes = $oTest->Execute();
|
||||
}
|
||||
|
||||
/*
|
||||
MyHelpers::var_dump_html($oTest->GetResults());
|
||||
MyHelpers::var_dump_html($oTest->GetWarnings());
|
||||
MyHelpers::var_dump_html($oTest->GetErrors());
|
||||
*/
|
||||
|
||||
if ($bRes)
|
||||
{
|
||||
echo "<p>Success :-)</p>\n";
|
||||
DisplayEvents($oTest->GetResults(), 'Results');
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<p>Failure :-(</p>\n";
|
||||
}
|
||||
DisplayEvents($oTest->GetErrors(), 'Errors');
|
||||
DisplayEvents($oTest->GetWarnings(), 'Warnings');
|
||||
|
||||
// Render the output
|
||||
//
|
||||
echo "<h4>Actual output</h4>\n";
|
||||
echo "<div style=\"border: dashed; background-color:light-grey;\">\n";
|
||||
echo $oTest->GetOutput();
|
||||
echo "</div>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<?php
|
||||
// Copyright (C) 2010-2014 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
/**
|
||||
* Core test page
|
||||
*
|
||||
* @copyright Copyright (C) 2010-2014 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<style>
|
||||
.vardump {
|
||||
font-size:8pt;
|
||||
line-height:100%;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Helpers
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ReadMandatoryParam($sName)
|
||||
{
|
||||
$value = utils::ReadParam($sName, null);
|
||||
if (is_null($value))
|
||||
{
|
||||
echo "<p>Missing mandatory argument <b>$sName</b></p>";
|
||||
exit;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function IsAValidTestClass($sClassName)
|
||||
{
|
||||
// Must be a child of TestHandler
|
||||
//
|
||||
if (!is_subclass_of($sClassName, 'TestHandler')) return false;
|
||||
|
||||
// Must not be abstract
|
||||
//
|
||||
$oReflectionClass = new ReflectionClass($sClassName);
|
||||
if (!$oReflectionClass->isInstantiable()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function GetTestClassLine($sClassName)
|
||||
{
|
||||
$oReflectionClass = new ReflectionClass($sClassName);
|
||||
return $oReflectionClass->getStartLine();
|
||||
}
|
||||
|
||||
function DisplayEvents($aEvents, $sTitle)
|
||||
{
|
||||
echo "<h4>$sTitle</h4>\n";
|
||||
if (count($aEvents) > 0)
|
||||
{
|
||||
echo "<ul>\n";
|
||||
foreach ($aEvents as $sEvent)
|
||||
{
|
||||
echo "<li>$sEvent</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<p>none</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Main
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'/application/utils.inc.php');
|
||||
require_once('./test.class.inc.php');
|
||||
require_once('./testlist.inc.php');
|
||||
|
||||
require_once(APPROOT.'/core/cmdbobject.class.inc.php');
|
||||
|
||||
|
||||
$sTodo = utils::ReadParam("todo", "");
|
||||
if ($sTodo == '')
|
||||
{
|
||||
// Show the list of tests
|
||||
//
|
||||
echo "<h3>Existing tests</h3>\n";
|
||||
echo "<ul>\n";
|
||||
foreach (get_declared_classes() as $sClassName)
|
||||
{
|
||||
if (!IsAValidTestClass($sClassName)) continue;
|
||||
|
||||
$sName = call_user_func(array($sClassName, 'GetName'));
|
||||
$sDescription = call_user_func(array($sClassName, 'GetDescription'));
|
||||
echo "<li><a href=\"?todo=exec&testid=$sClassName\">$sName</a> ($sDescription)</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
}
|
||||
else if ($sTodo == 'exec')
|
||||
{
|
||||
// Execute a test
|
||||
//
|
||||
$sTestClass = ReadMandatoryParam("testid");
|
||||
|
||||
if (!IsAValidTestClass($sTestClass))
|
||||
{
|
||||
echo "<p>Wrong value for testid, expecting a valid class name</p>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$oTest = new $sTestClass();
|
||||
$iStartLine = GetTestClassLine($sTestClass);
|
||||
echo "<h3>Testing: ".$oTest->GetName()."</h3>\n";
|
||||
echo "<h6>testlist.inc.php: $iStartLine</h6>\n";
|
||||
$bRes = $oTest->Execute();
|
||||
}
|
||||
|
||||
/*
|
||||
MyHelpers::var_dump_html($oTest->GetResults());
|
||||
MyHelpers::var_dump_html($oTest->GetWarnings());
|
||||
MyHelpers::var_dump_html($oTest->GetErrors());
|
||||
*/
|
||||
|
||||
if ($bRes)
|
||||
{
|
||||
echo "<p>Success :-)</p>\n";
|
||||
DisplayEvents($oTest->GetResults(), 'Results');
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<p>Failure :-(</p>\n";
|
||||
}
|
||||
DisplayEvents($oTest->GetErrors(), 'Errors');
|
||||
DisplayEvents($oTest->GetWarnings(), 'Warnings');
|
||||
|
||||
// Render the output
|
||||
//
|
||||
echo "<h4>Actual output</h4>\n";
|
||||
echo "<div style=\"border: dashed; background-color:light-grey;\">\n";
|
||||
echo $oTest->GetOutput();
|
||||
echo "</div>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
@include_once('ItopTestCase.php');
|
||||
@include_once('ItopDataTestCase.php');
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
@include_once('ItopTestCase.php');
|
||||
@include_once('ItopDataTestCase.php');
|
||||
|
||||
|
||||
@include_once('./vendor/autoload.php');
|
||||
Reference in New Issue
Block a user