2012-04-19 01:25:37 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests\GridField;
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
use InvalidArgumentException;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
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;
|
2016-10-14 03:30:05 +02:00
|
|
|
use stdClass;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class GridFieldDataColumnsTest extends SapphireTest
|
|
|
|
{
|
2012-04-19 01:25:37 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldGetDefaultDisplayFields()
|
|
|
|
{
|
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
|
|
|
$expected = Member::singleton()->summaryFields();
|
|
|
|
$columns = $obj->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
2012-04-19 01:25:37 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldCustomDisplayFields()
|
|
|
|
{
|
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
*/
|
2020-04-20 19:58:09 +02:00
|
|
|
$expected = ['Email' => 'Email'];
|
2016-12-16 05:34:21 +01:00
|
|
|
$columns = $obj->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
|
|
|
$columns->setDisplayFields($expected);
|
|
|
|
$this->assertEquals($expected, $columns->getDisplayFields($obj));
|
|
|
|
}
|
2012-04-19 01:25:37 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::setDisplayFields
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::getDisplayFields
|
|
|
|
*/
|
|
|
|
public function testGridFieldDisplayFieldsWithBadArguments()
|
|
|
|
{
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->expectException(InvalidArgumentException::class);
|
2016-12-16 05:34:21 +01:00
|
|
|
$obj = new GridField('testfield', 'testfield', Member::get());
|
|
|
|
$columns = $obj->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
|
|
|
$columns->setDisplayFields(new stdClass());
|
|
|
|
}
|
2012-04-19 01:25:37 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::getFieldCasting
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::setFieldCasting
|
|
|
|
*/
|
|
|
|
public function testFieldCasting()
|
|
|
|
{
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
|
|
|
$columns = $obj->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
2020-04-20 19:58:09 +02:00
|
|
|
$this->assertEquals([], $columns->getFieldCasting());
|
|
|
|
$columns->setFieldCasting(["MyShortText"=>"Text->FirstSentence"]);
|
|
|
|
$this->assertEquals(["MyShortText"=>"Text->FirstSentence"], $columns->getFieldCasting());
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2012-04-19 01:25:37 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::getFieldFormatting
|
|
|
|
* @covers \SilverStripe\Forms\GridField\GridFieldDataColumns::setFieldFormatting
|
|
|
|
*/
|
|
|
|
public function testFieldFormatting()
|
|
|
|
{
|
|
|
|
$obj = new GridField('testfield', 'testfield');
|
|
|
|
$columns = $obj->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
2020-04-20 19:58:09 +02:00
|
|
|
$this->assertEquals([], $columns->getFieldFormatting());
|
|
|
|
$columns->setFieldFormatting(["myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>']);
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2020-04-20 19:58:09 +02:00
|
|
|
["myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'],
|
2016-12-16 05:34:21 +01:00
|
|
|
$columns->getFieldFormatting()
|
|
|
|
);
|
|
|
|
}
|
2012-04-19 01:25:37 +02:00
|
|
|
}
|