N°931: Integrity controls + unit tests

This commit is contained in:
Eric
2018-09-11 14:10:05 +02:00
parent c706a2d77c
commit 1fc3b3a4ed
7 changed files with 550 additions and 387 deletions

View File

@@ -16,9 +16,12 @@ use TagSetFieldData;
class TagSetFieldDataTest extends ItopDataTestCase
{
// Need commit to create the FULLTEXT INDEX of MySQL
// Need database COMMIT in order to create the FULLTEXT INDEX of MySQL
const USE_TRANSACTION = false;
/**
* @throws \CoreException
*/
public function testGetAllowedValues()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
@@ -41,6 +44,9 @@ class TagSetFieldDataTest extends ItopDataTestCase
static::assertEquals(4, $iCurrCount - $iInitialCount);
}
/**
* @throws \CoreException
*/
public function testDoCheckToWrite()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
@@ -78,7 +84,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
try
{
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag5', 'Fourth');
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'zembrek', 'Fourth');
} catch (\CoreException $e)
{
$this->debug($e->getMessage());
@@ -91,28 +97,38 @@ class TagSetFieldDataTest extends ItopDataTestCase
/**
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \Exception
*/
public function testDoCheckToDelete()
{
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTagData->DBDelete();
// Create a tag
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
//Use it
$oTicket = $this->CreateTicket(1);
$oTicket->Set(TAG_ATTCODE, 'tag1');
$oTicket->DBWrite();
// Try to delete the tag, must complain !
try
{
$oTagData->DBDelete();
}
catch (\CoreException $e)
} catch (\DeleteException $e)
{
static::assertTrue(true);
return;
}
// Should not pass here
static::assertFalse(true);
}
/**
* @throws \CoreException
* @throws \Exception
*/
public function testComputeValues()
{
$sTagClass = \MetaModel::GetTagDataClass(TAG_CLASS, TAG_ATTCODE);
@@ -126,4 +142,59 @@ class TagSetFieldDataTest extends ItopDataTestCase
static::assertEquals(TAG_ATTCODE, $oTagData->Get('tag_attcode'));
}
/**
* Test invalid tag codes
* @dataProvider InvalidTagCodeProvider
*
* @expectedException \CoreException
*
* @param string $sTagCode
*
* @throws \CoreException
*/
public function testInvalidTagCode($sTagCode)
{
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, $sTagCode, 'First');
// Should not pass here
static::assertFalse(true);
}
public function InvalidTagCodeProvider()
{
return array(
'No space' => array('tag1 1'),
'No _' => array('tag_1'),
'No -' => array('tag-1'),
'No %' => array('tag%1'),
'Less than 21 chars' => array('012345678901234567890'),
'At least one char' => array(''),
'No #' => array('#tag'),
'No !' => array('tag!'),
);
}
/**
* Test invalid tag labels
* @expectedException \CoreException
* @throws \CoreException
*/
public function testInvalidTagLabel()
{
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First|Second');
// Should not pass here
static::assertFalse(true);
}
/**
* Test that tag code cannot be modified
* @expectedException \CoreException
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/
public function testUpdateCode()
{
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTagData->Set('tag_code', 'tag2');
$oTagData->DBWrite();
}
}