From 761eec773646f3ec0f62bec2827b806d77520a4c Mon Sep 17 00:00:00 2001 From: CheeseSucker Date: Wed, 19 Jun 2013 00:47:47 +0200 Subject: [PATCH] Unit test for bugfix in ViewableData::obj(). --- tests/view/ViewableDataTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/view/ViewableDataTest.php b/tests/view/ViewableDataTest.php index a90c165fe..8de0d715d 100644 --- a/tests/view/ViewableDataTest.php +++ b/tests/view/ViewableDataTest.php @@ -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"; + } +} + /**#@-*/