silverstripe-framework/tests/php/Core/Validation/ValidationResultTest.php
Guy Sartorelli e2e32317d6
API Move various classes to more appropriate namespaces (#11370)
Also rename ViewableData to ModelData ahead of the template layer
lift-and-shift
2024-09-23 14:31:50 +12:00

42 lines
1.2 KiB
PHP

<?php
namespace SilverStripe\Core\Tests\Validation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Core\Validation\ValidationResult;
class ValidationResultTest extends SapphireTest
{
public function testSerialise()
{
$result = new ValidationResult();
$result->addError("Error", ValidationResult::TYPE_ERROR, null, ValidationResult::CAST_HTML);
$result->addMessage("Message", ValidationResult::TYPE_GOOD);
$serialised = serialize($result);
/**
* @var ValidationResult $result2
*/
$result2 = unserialize($serialised ?? '');
$this->assertEquals(
[
[
'message' => 'Error',
'fieldName' => null,
'messageCast' => ValidationResult::CAST_HTML,
'messageType' => ValidationResult::TYPE_ERROR,
],
[
'message' => 'Message',
'fieldName' => null,
'messageCast' => ValidationResult::CAST_TEXT,
'messageType' => ValidationResult::TYPE_GOOD,
]
],
$result2->getMessages()
);
$this->assertFalse($result2->isValid());
}
}