2012-04-19 01:25:37 +02:00
|
|
|
<?php
|
|
|
|
class GridFieldDataColumnsTest extends SapphireTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldGetDefaultDisplayFields() {
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2012-04-20 01:38:06 +02:00
|
|
|
$expected = singleton('Member')->summaryFields();
|
2012-04-19 01:25:37 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldCustomDisplayFields() {
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2012-04-19 01:25:37 +02:00
|
|
|
$expected = array('Email' => 'Email');
|
|
|
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$columns->setDisplayFields($expected);
|
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldDisplayFieldsWithBadArguments() {
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2012-04-19 01:25:37 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$columns->setDisplayFields(new stdClass());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers GridFieldDataColumns::getFieldCasting
|
|
|
|
* @covers GridFieldDataColumns::setFieldCasting
|
|
|
|
*/
|
|
|
|
public function testFieldCasting() {
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
|
|
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$this->assertEquals(array(), $columns->getFieldCasting());
|
|
|
|
$columns->setFieldCasting(array("MyShortText"=>"Text->FirstSentence"));
|
|
|
|
$this->assertEquals(array("MyShortText"=>"Text->FirstSentence"), $columns->getFieldCasting());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers GridFieldDataColumns::getFieldFormatting
|
|
|
|
* @covers GridFieldDataColumns::setFieldFormatting
|
|
|
|
*/
|
|
|
|
public function testFieldFormatting() {
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
|
|
|
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$this->assertEquals(array(), $columns->getFieldFormatting());
|
|
|
|
$columns->setFieldFormatting(array("myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(array("myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'),
|
|
|
|
$columns->getFieldFormatting());
|
2012-04-19 01:25:37 +02:00
|
|
|
}
|
|
|
|
}
|