mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-16 19:58:51 +02:00
N°931: Tag max number and max length per class and field (defined in xml)
This commit is contained in:
@@ -164,7 +164,6 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
||||
'No _' => array('tag_1'),
|
||||
'No -' => array('tag-1'),
|
||||
'No %' => array('tag%1'),
|
||||
'Less than 21 chars' => array('012345678901234567890'),
|
||||
'At least 3 chars' => array(''),
|
||||
'At least 3 chars 1' => array('a'),
|
||||
'At least 3 chars 2' => array('ab'),
|
||||
@@ -197,4 +196,35 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
||||
$oTagData->Set('tag_code', 'tag2');
|
||||
$oTagData->DBWrite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the code length is correctly checked
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function testMaxTagCodeLength()
|
||||
{
|
||||
/** @var \AttributeTagSet $oAttdef */
|
||||
$oAttdef = \MetaModel::GetAttributeDef(TAG_CLASS, TAG_ATTCODE);
|
||||
|
||||
$iMaxLength = $oAttdef->GetTagCodeMaxLength();
|
||||
$sTagCode = str_repeat('a', $iMaxLength);
|
||||
|
||||
// Should work
|
||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, $sTagCode, $sTagCode);
|
||||
|
||||
// Too long
|
||||
$sTagCode = str_repeat('a', $iMaxLength + 1);
|
||||
try
|
||||
{
|
||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, $sTagCode, $sTagCode);
|
||||
} catch (\CoreException $e)
|
||||
{
|
||||
$this->debug('Awaited: '.$e->getMessage());
|
||||
static::assertTrue(true);
|
||||
return;
|
||||
}
|
||||
// Failed
|
||||
static::assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Exception;
|
||||
use ormTagSet;
|
||||
|
||||
define('MAX_TAGS', 12);
|
||||
|
||||
/**
|
||||
* Tests of the ormTagSet class
|
||||
*
|
||||
@@ -57,13 +59,13 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testGetTagDataClass()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
static::assertEquals($oTagSet->GetTagDataClass(), 'TagSetFieldDataFor_Ticket_tagfield');
|
||||
}
|
||||
|
||||
public function testGetValue()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
static::assertEquals($oTagSet->GetValue(), array());
|
||||
|
||||
$oTagSet->AddTag('tag1');
|
||||
@@ -75,7 +77,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testAddTag()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
|
||||
$oTagSet->AddTag('tag1');
|
||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
||||
@@ -90,13 +92,38 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \CoreException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
*/
|
||||
public function testMaxTagLimit()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, 3);
|
||||
|
||||
$oTagSet->SetValue(array('tag1', 'tag2', 'tag3'));
|
||||
|
||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2', 'tag3'));
|
||||
|
||||
try
|
||||
{
|
||||
$oTagSet->SetValue(array('tag1', 'tag2', 'tag3', 'tag4'));
|
||||
}
|
||||
catch (\CoreException $e)
|
||||
{
|
||||
$this->debug('Awaited: '.$e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function testEquals()
|
||||
{
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet1->AddTag('tag1');
|
||||
static::assertTrue($oTagSet1->Equals($oTagSet1));
|
||||
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet2->SetValue(array('tag1'));
|
||||
|
||||
static::assertTrue($oTagSet1->Equals($oTagSet2));
|
||||
@@ -107,7 +134,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testSetValue()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
|
||||
$oTagSet->SetValue(array('tag1'));
|
||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
||||
@@ -119,7 +146,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testRemoveTag()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet->RemoveTag('tag_unknown');
|
||||
static::assertEquals($oTagSet->GetValue(), array());
|
||||
|
||||
@@ -146,10 +173,10 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testGetDelta()
|
||||
{
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet1->SetValue(array('tag1', 'tag2'));
|
||||
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet2->SetValue(array('tag1', 'tag3', 'tag4'));
|
||||
|
||||
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
||||
@@ -160,10 +187,10 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
|
||||
public function testApplyDelta()
|
||||
{
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet1->SetValue(array('tag1', 'tag2'));
|
||||
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet2->SetValue(array('tag1', 'tag3', 'tag4'));
|
||||
|
||||
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
||||
@@ -184,7 +211,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testGetModified($aInitialTags, $aDiffAndExpectedTags)
|
||||
{
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet1->SetValue($aInitialTags);
|
||||
|
||||
foreach($aDiffAndExpectedTags as $aTestItem)
|
||||
@@ -236,7 +263,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testBulkModify($aInitialTags, $aDelta, $aExpectedTags)
|
||||
{
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
$oTagSet1->SetValue($aInitialTags);
|
||||
|
||||
$oTagSet1->ApplyDelta($aDelta);
|
||||
|
||||
Reference in New Issue
Block a user