mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Dev\TestOnly;
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
use SilverStripe\GridFieldExtensions\GridFieldAddNewMultiClass;
|
|
|
|
/**
|
|
* Tests for {@link GridFieldAddNewMultiClass}.
|
|
*/
|
|
class GridFieldAddNewMultiClassTest extends SapphireTest {
|
|
|
|
public function testGetClasses() {
|
|
$grid = new GridField('TestGridField');
|
|
$grid->setModelClass('GridFieldAddNewMultiClassTest_A');
|
|
|
|
$component = new GridFieldAddNewMultiClass();
|
|
|
|
$this->assertEquals(
|
|
array(
|
|
'GridFieldAddNewMultiClassTest_A' => 'A',
|
|
'GridFieldAddNewMultiClassTest_B' => 'B',
|
|
'GridFieldAddNewMultiClassTest_C' => 'C'
|
|
),
|
|
$component->getClasses($grid),
|
|
'Subclasses are populated by default and sorted'
|
|
);
|
|
|
|
$component->setClasses(array(
|
|
'GridFieldAddNewMultiClassTest_B' => 'Custom Title',
|
|
'GridFieldAddNewMultiClassTest_A'
|
|
));
|
|
|
|
$this->assertEquals(
|
|
array(
|
|
'GridFieldAddNewMultiClassTest_B' => 'Custom Title',
|
|
'GridFieldAddNewMultiClassTest_A' => 'A'
|
|
),
|
|
$component->getClasses($grid),
|
|
'Sorting and custom titles can be specified'
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
/**#@+
|
|
* @ignore
|
|
*/
|
|
|
|
class GridFieldAddNewMultiClassTest_A implements TestOnly {
|
|
public function i18n_singular_name() {
|
|
$class = get_class($this);
|
|
return substr($class, strpos($class, '_') + 1);
|
|
}
|
|
|
|
public function canCreate() {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class GridFieldAddNewMultiClassTest_B extends GridFieldAddNewMultiClassTest_A implements TestOnly {}
|
|
class GridFieldAddNewMultiClassTest_C extends GridFieldAddNewMultiClassTest_A implements TestOnly {}
|
|
|
|
/**#@-*/
|