N°931: Integrity controls

This commit is contained in:
Eric
2018-09-11 12:25:01 +02:00
13 changed files with 2506 additions and 2344 deletions

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (C) 2018 Dennis Lassiter
*
* 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 UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
{
public function setUp()
{
parent::setUp();
require_once(APPROOT . 'application/utils.inc.php');
}
/**
* @dataProvider memoryLimitDataProvider
*/
public function testIsMemoryLimit($expected, $memoryLimit, $requiredMemory)
{
$this->assertSame($expected, utils::IsMemoryLimitOk($memoryLimit, $requiredMemory));
}
/**
* DataProvider for testIsMemoryLimitOk
*
* @return array
*/
public function memoryLimitDataProvider()
{
return [
[true, '-1', 1024],
[true, -1, 1024],
[true, 1024, 1024],
[true, 2048, 1024],
[false, 1024, 2048],
];
}
}

View File

@@ -412,6 +412,11 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key IN 2' => array(
'OQL' => "SELECT Contact WHERE org_id IN ('1', '999999')",
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key empty' => array(
'OQL' => "SELECT Person WHERE location_id = '0'",
'ExpectedOQL' => "SELECT `Person` FROM Person AS `Person` WHERE (`Person`.`location_id` = '0')",
@@ -438,8 +443,8 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'Hierarchical below 2' => array(
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'IP range' => array(

View File

@@ -19,6 +19,28 @@ class TagSetFieldDataTest extends ItopDataTestCase
// Need commit to create the FULLTEXT INDEX of MySQL
const USE_TRANSACTION = false;
public function testGetAllowedValues()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iInitialCount = count($aAllowedValues);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(1, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'Second');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(2, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag3', 'Third');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(3, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'Fourth');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(4, $iCurrCount - $iInitialCount);
}
public function testDoCheckToWrite()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
@@ -67,8 +89,6 @@ class TagSetFieldDataTest extends ItopDataTestCase
}
/**
* @expectedException \CoreException
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/
@@ -76,19 +96,34 @@ class TagSetFieldDataTest extends ItopDataTestCase
{
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTagData->DBDelete();
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTicket = $this->CreateTicket(1);
$oTicket->Set(TAG_ATTCODE, 'tag1');
$oTicket->DBWrite();
$oTagData->DBDelete($oDeletionPlan);
try
{
$oTagData->DBDelete();
}
catch (\CoreException $e)
{
static::assertTrue(true);
return;
}
static::assertFalse(true);
}
public function testComputeValues()
{
$sTagClass = \MetaModel::GetTagDataClass(TAG_CLASS, TAG_ATTCODE);
$oTagData = $this->createObject($sTagClass, array(
'tag_code' => 'tag1',
'tag_label' => 'First',
));
$this->debug("Created {$oTagData->Get('tag_class')}::{$oTagData->Get('tag_attcode')}");
static::assertEquals(TAG_CLASS, $oTagData->Get('tag_class'));
static::assertEquals(TAG_ATTCODE, $oTagData->Get('tag_attcode'));
}
public function testGetAllowedValues()
{
}
}