/** * @covers SilverStripe\Forms\GridField\GridField::getCastedValue */ public function testGetCastedValueObject() { $obj = new GridField('testfield', 'testfield'); $value = $obj->getCastedValue('This is a sentance. This ia another.', 'Date'); $this->assertEquals(null, $value); }
/** * Casts a field to a string which is safe to insert into HTML * * @param GridField $gridField * @param string $fieldName * @param string $value * @return string */ protected function castValue($gridField, $fieldName, $value) { // If a fieldCasting is specified, we assume the result is safe if (array_key_exists($fieldName, $this->fieldCasting)) { $value = $gridField->getCastedValue($value, $this->fieldCasting[$fieldName]); } else { if (is_object($value)) { // If the value is an object, we do one of two things if (method_exists($value, 'Nice')) { // If it has a "Nice" method, call that & make sure the result is safe $value = Convert::raw2xml($value->Nice()); } else { // Otherwise call forTemplate - the result of this should already be safe $value = $value->forTemplate(); } } else { // Otherwise, just treat as a text string & make sure the result is safe $value = Convert::raw2xml($value); } } return $value; }