mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-27 14:14:11 +01:00
# Conflicts: # tests/manual-visual-tests/Backoffice/RenderAllUiBlocks.php # tests/php-unit-tests/ItopDataTestCase.php # tests/php-unit-tests/ItopTestCase.php # tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.KO.wrong_php # tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.OK.php # tests/php-unit-tests/integration-tests/iTopModulesPhpVersionChecklistTest.php # tests/php-unit-tests/integration-tests/iTopXmlVersionChecklistTest.php # tests/php-unit-tests/phpunit.xml.dist # tests/php-unit-tests/unitary-tests/application/SCSSCompilationTest.php # tests/php-unit-tests/unitary-tests/application/Session/SessionTest.php # tests/php-unit-tests/unitary-tests/application/ThemeHandlerTest.php # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/DO_NOT_CHANGE.css-variables.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/DO_NOT_CHANGE.light-grey.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/README.md # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/_included_file3.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/cross_reference1.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/cross_reference2.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/feature1/_feature1.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/included_file1.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/included_scss/included_file2.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/included_scss/included_file4.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/multi_imports.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/shortcut.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/shortcut2.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/simple_import.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/simple_import2.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/typography.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/css/ui-lightness/DO_NOT_CHANGE.jqueryui.scss # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_1c94c4_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_222222_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_E87C1E_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_F26522_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_ffd27a_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/css/ui-lightness/images/ui-icons_ffffff_256x240.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/ac-background.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/actions_right.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/bg.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/breadcrumb-separator.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/calendar.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/delete.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/desc.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/error.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/eye-closed-555.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/eye-closed-fff.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/eye-open-555.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/eye-open-fff.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/full-screen.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/green-header.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/green-square.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/indicator.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/info-mini.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/minus.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/ok.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/orange-header.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/plus.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/red-header.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/truncated.png # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-collapsable-last.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-collapsable.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-expandable-last.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-expandable.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-item-last.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/testimages/images/tv-item.gif # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main_imagemodified.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main_importmodified.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main_stylesheet.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main_testcompilethemes.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/main_varchanged.css # tests/php-unit-tests/unitary-tests/application/theme-handler/expected/themes/basque-red/theme-parameters.json # tests/php-unit-tests/unitary-tests/application/theme-handler/getimages/expected-getimages.json # tests/php-unit-tests/unitary-tests/application/theme-handler/getimages/test-getimages.scss # tests/php-unit-tests/unitary-tests/core/ActionEmailTest.php # tests/php-unit-tests/unitary-tests/core/AttributeDefTest.inc.php # tests/php-unit-tests/unitary-tests/core/AttributeURLDefaultPattern.php # tests/php-unit-tests/unitary-tests/core/AttributeURLTest.php # tests/php-unit-tests/unitary-tests/core/BulkChangeTest.inc.php # tests/php-unit-tests/unitary-tests/core/CSVParserTest.php # tests/php-unit-tests/unitary-tests/core/DBObjectTest.php # tests/php-unit-tests/unitary-tests/core/DBSearchAddConditionPointingTo.php # tests/php-unit-tests/unitary-tests/core/ExpressionEvaluateTest.php # tests/php-unit-tests/unitary-tests/core/GetSelectFilterTest.php # tests/php-unit-tests/unitary-tests/core/InlineImageTest.php # tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest.php # tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest/Exceptions.php # tests/php-unit-tests/unitary-tests/core/Log/LogAPITest.php # tests/php-unit-tests/unitary-tests/core/Log/LogFileNameBuilderTest.php # tests/php-unit-tests/unitary-tests/core/LogAPITest.php # tests/php-unit-tests/unitary-tests/core/LogFileNameBuilderTest.php # tests/php-unit-tests/unitary-tests/core/MetaModelTest.php # tests/php-unit-tests/unitary-tests/core/OQLTest.php # tests/php-unit-tests/unitary-tests/core/UniquenessConstraintTest.php # tests/php-unit-tests/unitary-tests/core/XMLDataLoaderTest.php # tests/php-unit-tests/unitary-tests/core/dictApcuTest.php # tests/php-unit-tests/unitary-tests/core/dictTest.php # tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php # tests/php-unit-tests/unitary-tests/core/ormPasswordTest.php # tests/php-unit-tests/unitary-tests/core/ormStyleTest.php # tests/php-unit-tests/unitary-tests/setup/MFCompilerTest.php # tests/php-unit-tests/unitary-tests/setup/SubMFCompiler.php # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/1.7_to_1.6.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/1.7_to_1.6.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.6_to_1.7_2.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.6_to_1.7_2.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_1.6.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_1.6.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_1.6_2.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_1.6_2.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_3.0.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/1.7_to_3.0.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/3.0_to_1.7.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/3.0_to_1.7.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/Bug_4569.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/Convert-samples/Bug_4569.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_deleted.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_deleted.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_not-in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_deleted_to_not-in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_deleted.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_deleted.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_not-in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_in-definition_to_not-in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_deleted.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_deleted.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_not-in-definition.expected.xml # tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/MoveNode-samples/from_not-in-definition_to_not-in-definition.input.xml # tests/php-unit-tests/unitary-tests/setup/ressources/datamodels/datamodel-branding.xml # tests/php-unit-tests/unitary-tests/sources/application/Helper/WebResourcesHelperTest.php # tests/php-unit-tests/unitary-tests/sources/application/status/StatusIncTest.php # tests/php-unit-tests/unitary-tests/sources/application/status/status.php # tests/php-unit-tests/unitary-tests/synchro/DataSynchroTest.php
288 lines
8.3 KiB
PHP
288 lines
8.3 KiB
PHP
<?php
|
|
// Copyright (c) 2010-2021 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;
|
|
use MetaModel;
|
|
|
|
|
|
/**
|
|
* @group specificOrgInSampleData
|
|
*
|
|
* @runTestsInSeparateProcesses
|
|
* @preserveGlobalState disabled
|
|
* @backupGlobals disabled
|
|
*/
|
|
class DBObjectTest extends ItopDataTestCase
|
|
{
|
|
const CREATE_TEST_ORG = true;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->RequireOnceItopFile('core/dbobject.class.php');
|
|
}
|
|
|
|
/**
|
|
* Test default page name
|
|
* @covers DBObject::GetUIPage
|
|
*/
|
|
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));
|
|
}
|
|
|
|
/**
|
|
* @group itopRequestMgmt
|
|
* @covers DBObject::GetOriginal
|
|
*/
|
|
public function testGetOriginal()
|
|
{
|
|
$oObject = $this->CreateUserRequest(190664);
|
|
|
|
static::assertNull($oObject->GetOriginal('sla_tto_passed'));
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public function testListPreviousValuesForUpdatedAttributes()
|
|
{
|
|
$oOrg = $this->CreateOrganization('testListPreviousValuesForUpdatedAttributes');
|
|
|
|
$this->assertCount(0, $oOrg->ListChanges());
|
|
$oOrg->Set('code', strtoupper('testListPreviousValuesForUpdatedAttributes'));
|
|
$this->assertCount(1, $oOrg->ListChanges());
|
|
$oOrg->DBUpdate();
|
|
$this->assertCount(0, $oOrg->ListChanges());
|
|
$this->assertCount(1, $oOrg->ListPreviousValuesForUpdatedAttributes());
|
|
|
|
$oOrg->DBUpdate();
|
|
|
|
$this->assertCount(0, $oOrg->ListChanges());
|
|
$this->assertCount(1, $oOrg->ListPreviousValuesForUpdatedAttributes());
|
|
|
|
$oOrg->DBDelete();
|
|
|
|
$oOrg = MetaModel::NewObject('Organization');
|
|
$oOrg->Set('name', 'testListPreviousValuesForUpdatedAttributes');
|
|
$oOrg->DBInsert();
|
|
$oOrg->Set('code', strtoupper('testListPreviousValuesForUpdatedAttributes'));
|
|
$oOrg->DBUpdate();
|
|
$oOrg->DBUpdate();
|
|
$this->markTestIncomplete('This test has not been implemented yet. wait for N°4967 fix');
|
|
$this->debug("ERROR: N°4967 - 'Previous Values For Updated Attributes' not updated if DBUpdate is called without modifying the object");
|
|
//$this->assertCount(0, $oOrg->ListPreviousValuesForUpdatedAttributes());
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::NewObject
|
|
* @covers DBObject::Get
|
|
* @covers DBObject::Set
|
|
*/
|
|
public function testAttributeRefresh_FriendlyName()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
|
|
|
static::assertEquals('John Foo', $oObject->Get('friendlyname'));
|
|
$oObject->Set('name', 'Who');
|
|
static::assertEquals('John Who', $oObject->Get('friendlyname'));
|
|
}
|
|
|
|
/**
|
|
* @covers MetaModel::GetObject
|
|
* @covers DBObject::Get
|
|
* @covers DBObject::Set
|
|
*/
|
|
public function testAttributeRefresh_FriendlyNameFromDB()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Gary', 'first_name' => 'Romain', 'org_id' => 3, 'location_id' => 2));
|
|
$oObject->DBInsert();
|
|
$iObjKey = $oObject->GetKey();
|
|
|
|
$oObject = \MetaModel::GetObject('Person', $iObjKey);
|
|
|
|
static::assertEquals('Romain Gary', $oObject->Get('friendlyname'));
|
|
$oObject->Set('name', 'Duris');
|
|
static::assertEquals('Romain Duris', $oObject->Get('friendlyname'));
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::NewObject
|
|
* @covers DBObject::Get
|
|
*/
|
|
public function testPartialAttributeEvaluation()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'org_id' => 3, 'location_id' => 2));
|
|
|
|
static::assertEquals('', $oObject->Get('friendlyname'));
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::NewObject
|
|
* @covers DBObject::Get
|
|
*/
|
|
public function testEmptyAttributeEvaluation()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('org_id' => 3, 'location_id' => 2));
|
|
|
|
static::assertEquals('', $oObject->Get('friendlyname'));
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::Get
|
|
* @covers DBObject::Set
|
|
*/
|
|
public function testFriendlyNameLnk()
|
|
{
|
|
$oUserProfile = new \URP_UserProfile();
|
|
$oUserProfile->Set('profileid', 2);
|
|
|
|
static::assertEquals('', $oUserProfile->Get('friendlyname'));
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::NewObject
|
|
* @covers DBObject::Get
|
|
* @covers DBObject::Set
|
|
*/
|
|
public function testAttributeRefresh_ObsolescenceFlag()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
|
|
|
static::assertEquals(false, (bool)$oObject->Get('obsolescence_flag'));
|
|
$oObject->Set('status', 'inactive');
|
|
static::assertEquals(true, (bool)$oObject->Get('obsolescence_flag'));
|
|
}
|
|
|
|
/**
|
|
* @covers DBObject::NewObject
|
|
* @covers DBObject::Get
|
|
* @covers DBObject::Set
|
|
*/
|
|
public function testAttributeRefresh_ExternalKeysAndFields()
|
|
{
|
|
static::assertDBQueryCount(0, function() use (&$oObject){
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
|
});
|
|
static::assertDBQueryCount(2, function() use (&$oObject){
|
|
static::assertEquals('Demo', $oObject->Get('org_id_friendlyname'));
|
|
static::assertEquals('Grenoble', $oObject->Get('location_id_friendlyname'));
|
|
});
|
|
|
|
// External key given as an id
|
|
static::assertDBQueryCount(1, function() use (&$oObject){
|
|
$oObject->Set('org_id', 2);
|
|
static::assertEquals('IT Department', $oObject->Get('org_id_friendlyname'));
|
|
});
|
|
|
|
// External key given as an object
|
|
static::assertDBQueryCount(1, function() use (&$oBordeaux){
|
|
$oBordeaux = \MetaModel::GetObject('Location', 1);
|
|
});
|
|
|
|
static::assertDBQueryCount(0, function() use (&$oBordeaux, &$oObject){
|
|
$oObject->Set('location_id', $oBordeaux);
|
|
static::assertEquals('IT Department', $oObject->Get('org_id_friendlyname'));
|
|
static::assertEquals('IT Department', $oObject->Get('org_name'));
|
|
static::assertEquals('Bordeaux', $oObject->Get('location_id_friendlyname'));
|
|
});
|
|
}
|
|
|
|
public function testSetExtKeyUnsetDependentAttribute()
|
|
{
|
|
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
|
$oOrg = \MetaModel::GetObject('Organization', 2);
|
|
$oObject->Set('org_id', $oOrg);
|
|
|
|
// though it's a dependent field, it keeps its value (not OQL based nor External field)
|
|
static::assertEquals(2, $oObject->Get('location_id'));
|
|
|
|
// Dependent external field is updated because the Set('org_id') is done with an object
|
|
static::assertDBQueryCount(0, function() use (&$oObject){
|
|
static::assertNotEmpty($oObject->Get('org_name'));
|
|
});
|
|
|
|
// Dependent external field is reset and reloaded from DB
|
|
$oObject->Set('org_id', 3);
|
|
static::assertDBQueryCount(1, function() use (&$oObject){
|
|
static::assertNotEmpty($oObject->Get('org_name'));
|
|
}); }
|
|
|
|
/**
|
|
* @group Integration
|
|
*/
|
|
public function testModelExpressions()
|
|
{
|
|
foreach (\MetaModel::GetClasses() as $sClass)
|
|
{
|
|
if (\MetaModel::IsAbstract($sClass)) continue;
|
|
|
|
$oObject = \MetaModel::NewObject($sClass);
|
|
foreach (\MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
|
|
{
|
|
if ($oAttDef->IsBasedOnOQLExpression())
|
|
{
|
|
$this->debug("$sClass::$sAttCode");
|
|
static::assertDBQueryCount(0, function() use (&$oObject, &$oAttDef){
|
|
$oObject->EvaluateExpression($oAttDef->GetOQLExpression());
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|