silverstripe-framework/tests/php/Model/ModelDataCustomisedTest.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

56 lines
1.5 KiB
PHP

<?php
namespace SilverStripe\Model\Tests;
use SilverStripe\Dev\Constraint\ModelDataContains;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Model\ArrayData;
use SilverStripe\Model\ModelDataCustomised;
/**
* Test for ModelDataCustomised.
*/
class ModelDataCustomisedTest extends SapphireTest
{
public function testNestedModelDataCustomisedAsCustomised()
{
$outerCustomised = ModelDataCustomised::create($this->makeOuterOriginal(), $this->makeInnerModelDataCustomised());
$this->assertThat($outerCustomised, $this->makeTestConstraint());
}
public function testNestedModelDataCustomisedAsOriginal()
{
$outerCustomised = ModelDataCustomised::create($this->makeInnerModelDataCustomised(), $this->makeOuterOriginal());
$this->assertThat($outerCustomised, $this->makeTestConstraint());
}
private function makeTestConstraint()
{
return new ModelDataContains([
'outerOriginal' => 'foobar',
'innerOriginal' => 'hello',
'innerCustomised' => 'world',
]);
}
private function makeOuterOriginal()
{
return ArrayData::create([
'outerOriginal' => 'foobar',
]);
}
private function makeInnerModelDataCustomised()
{
$original = ArrayData::create([
'innerOriginal' => 'hello',
]);
$customised = ArrayData::create([
'innerCustomised' => 'world',
]);
return ModelDataCustomised::create($original, $customised);
}
}