Fix files using CrLf, convert them to Lf to have the whole repo using Lf

Warn your git config (core.autocrlf = input or true)
This commit is contained in:
Pierre Goiffon
2018-09-04 17:38:22 +02:00
parent cad18bee73
commit 40a4e6d7b0
378 changed files with 152833 additions and 152833 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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)));
}
}
}

View File

@@ -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'));
}
}

View File

@@ -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

View File

@@ -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';
}
}

View File

@@ -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());
}
}