mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Unit test for bugfix in ViewableData::obj().
This commit is contained in:
parent
b52087105c
commit
761eec7736
@ -121,6 +121,28 @@ class ViewableDataTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testObjWithCachedStringValueReturnsValidObject() {
|
||||
$obj = new ViewableDataTest_NoCastingInformation();
|
||||
|
||||
// Save a literal string into cache
|
||||
$cache = true;
|
||||
$uncastedData = $obj->obj('noCastingInformation', null, false, $cache);
|
||||
|
||||
// Fetch the cached string as an object
|
||||
$forceReturnedObject = true;
|
||||
$castedData = $obj->obj('noCastingInformation', null, $forceReturnedObject);
|
||||
|
||||
// Uncasted data should always be the nonempty string
|
||||
$this->assertNotEmpty($uncastedData, 'Uncasted data was empty.');
|
||||
$this->assertTrue(is_string($uncastedData), 'Uncasted data should be a string.');
|
||||
|
||||
// Casted data should be the string wrapped in a DBField-object.
|
||||
$this->assertNotEmpty($castedData, 'Casted data was empty.');
|
||||
$this->assertInstanceOf('DBField', $castedData, 'Casted data should be instance of DBField.');
|
||||
|
||||
$this->assertEquals($uncastedData, $castedData->getValue(), 'Casted and uncasted strings are not equal.');
|
||||
}
|
||||
}
|
||||
|
||||
/**#@+
|
||||
@ -212,4 +234,10 @@ class ViewableDataTest_CastingClass extends ViewableData {
|
||||
);
|
||||
}
|
||||
|
||||
class ViewableDataTest_NoCastingInformation extends ViewableData {
|
||||
public function noCastingInformation() {
|
||||
return "No casting information";
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user