silverstripe-gridfieldexten.../tests/GridFieldAddNewMultiClassTest.php

73 lines
1.8 KiB
PHP
Raw Normal View History

<?php
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\GridFieldExtensions\GridFieldAddNewMultiClass;
/**
* Tests for {@link GridFieldAddNewMultiClass}.
*/
2016-12-21 03:34:58 +01:00
class GridFieldAddNewMultiClassTest extends SapphireTest
{
2016-12-21 03:34:58 +01:00
public function testGetClasses()
{
$grid = new GridField('TestGridField');
$grid->setModelClass('GridFieldAddNewMultiClassTest_A');
2016-12-21 03:34:58 +01:00
$component = new GridFieldAddNewMultiClass();
2016-12-21 03:34:58 +01:00
$this->assertEquals(
array(
'GridFieldAddNewMultiClassTest_A' => 'A',
'GridFieldAddNewMultiClassTest_B' => 'B',
'GridFieldAddNewMultiClassTest_C' => 'C'
),
$component->getClasses($grid),
'Subclasses are populated by default and sorted'
);
2016-12-21 03:34:58 +01:00
$component->setClasses(array(
'GridFieldAddNewMultiClassTest_B' => 'Custom Title',
'GridFieldAddNewMultiClassTest_A'
));
2016-12-21 03:34:58 +01:00
$this->assertEquals(
array(
'GridFieldAddNewMultiClassTest_B' => 'Custom Title',
'GridFieldAddNewMultiClassTest_A' => 'A'
),
$component->getClasses($grid),
'Sorting and custom titles can be specified'
);
}
}
/**#@+
* @ignore
*/
2016-12-21 03:34:58 +01:00
class GridFieldAddNewMultiClassTest_A implements TestOnly
{
public function i18n_singular_name()
{
$class = get_class($this);
return substr($class, strpos($class, '_') + 1);
}
2016-12-21 03:34:58 +01:00
public function canCreate()
{
return true;
}
}
2016-12-21 03:34:58 +01:00
class GridFieldAddNewMultiClassTest_B extends GridFieldAddNewMultiClassTest_A implements TestOnly
{
}
class GridFieldAddNewMultiClassTest_C extends GridFieldAddNewMultiClassTest_A implements TestOnly
{
}
/**#@-*/