2012-04-19 01:25:37 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
|
|
|
use SilverStripe\Security\Member;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
|
|
|
|
|
|
|
2012-04-19 01:25:37 +02:00
|
|
|
class GridFieldDataColumnsTest extends SapphireTest {
|
|
|
|
|
|
|
|
/**
|
2016-09-26 11:54:28 +02:00
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
2012-04-19 01:25:37 +02:00
|
|
|
*/
|
|
|
|
public function testGridFieldGetDefaultDisplayFields() {
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2016-08-19 00:51:35 +02:00
|
|
|
$expected = Member::singleton()->summaryFields();
|
|
|
|
$columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
|
2012-04-19 01:25:37 +02:00
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-26 11:54:28 +02:00
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
2012-04-19 01:25:37 +02:00
|
|
|
*/
|
|
|
|
public function testGridFieldCustomDisplayFields() {
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2016-08-19 00:51:35 +02:00
|
|
|
/** @skipUpgrade */
|
2012-04-19 01:25:37 +02:00
|
|
|
$expected = array('Email' => 'Email');
|
2016-08-19 00:51:35 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
|
2012-04-19 01:25:37 +02:00
|
|
|
$columns->setDisplayFields($expected);
|
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-26 11:54:28 +02:00
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
2012-04-19 01:25:37 +02:00
|
|
|
*/
|
|
|
|
public function testGridFieldDisplayFieldsWithBadArguments() {
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
2012-05-28 11:13:42 +02:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
2016-08-19 00:51:35 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
|
2012-04-19 01:25:37 +02:00
|
|
|
$columns->setDisplayFields(new stdClass());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-26 11:54:28 +02:00
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getFieldCasting
|
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::setFieldCasting
|
2012-04-19 01:25:37 +02:00
|
|
|
*/
|
|
|
|
public function testFieldCasting() {
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
2016-08-19 00:51:35 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
|
2012-04-19 01:25:37 +02:00
|
|
|
$this->assertEquals(array(), $columns->getFieldCasting());
|
|
|
|
$columns->setFieldCasting(array("MyShortText"=>"Text->FirstSentence"));
|
|
|
|
$this->assertEquals(array("MyShortText"=>"Text->FirstSentence"), $columns->getFieldCasting());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-26 11:54:28 +02:00
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getFieldFormatting
|
|
|
|
* @covers SilverStripe\Forms\GridField\GridFieldDataColumns::setFieldFormatting
|
2012-04-19 01:25:37 +02:00
|
|
|
*/
|
|
|
|
public function testFieldFormatting() {
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
2016-08-19 00:51:35 +02:00
|
|
|
$columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
|
2012-04-19 01:25:37 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|