2016-11-23 06:09:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace SilverStripe\ORM\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\ORM\ValidationResult;
|
|
|
|
|
|
|
|
class ValidationResultTest extends SapphireTest
|
|
|
|
{
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testSerialise()
|
|
|
|
{
|
2016-11-23 06:09:10 +01:00
|
|
|
$result = new ValidationResult();
|
|
|
|
$result->addError("Error", ValidationResult::TYPE_ERROR, null, ValidationResult::CAST_HTML);
|
|
|
|
$result->addMessage("Message", ValidationResult::TYPE_GOOD);
|
|
|
|
$serialised = serialize($result);
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @var ValidationResult $result2
|
|
|
|
*/
|
2022-04-14 03:12:59 +02:00
|
|
|
$result2 = unserialize($serialised ?? '');
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
[
|
2016-11-23 06:09:10 +01:00
|
|
|
[
|
|
|
|
'message' => 'Error',
|
|
|
|
'fieldName' => null,
|
|
|
|
'messageCast' => ValidationResult::CAST_HTML,
|
|
|
|
'messageType' => ValidationResult::TYPE_ERROR,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'message' => 'Message',
|
|
|
|
'fieldName' => null,
|
|
|
|
'messageCast' => ValidationResult::CAST_TEXT,
|
|
|
|
'messageType' => ValidationResult::TYPE_GOOD,
|
|
|
|
]
|
2016-12-16 05:34:21 +01:00
|
|
|
],
|
|
|
|
$result2->getMessages()
|
|
|
|
);
|
2016-11-23 06:09:10 +01:00
|
|
|
$this->assertFalse($result2->isValid());
|
|
|
|
}
|
|
|
|
}
|