2013-11-14 13:43:38 +01:00
|
|
|
<?php
|
2016-09-09 09:00:05 +02:00
|
|
|
|
2017-09-01 03:33:54 +02:00
|
|
|
namespace Symbiote\GridFieldExtensions\Tests;
|
|
|
|
|
2016-09-09 09:00:05 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
2016-12-19 05:11:56 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
2017-06-16 06:07:09 +02:00
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
|
2017-09-01 03:33:54 +02:00
|
|
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubA;
|
|
|
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubB;
|
|
|
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubC;
|
2016-09-09 09:00:05 +02:00
|
|
|
|
2013-11-14 13:43:38 +01:00
|
|
|
/**
|
|
|
|
* Tests for {@link GridFieldAddNewMultiClass}.
|
|
|
|
*/
|
2016-12-21 03:34:58 +01:00
|
|
|
class GridFieldAddNewMultiClassTest extends SapphireTest
|
|
|
|
{
|
2013-11-14 13:43:38 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
public function testGetClasses()
|
|
|
|
{
|
|
|
|
$grid = new GridField('TestGridField');
|
2017-09-01 03:33:54 +02:00
|
|
|
$grid->setModelClass(StubA::class);
|
2013-11-14 13:43:38 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
$component = new GridFieldAddNewMultiClass();
|
2013-11-14 13:43:38 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2017-09-01 03:33:54 +02:00
|
|
|
'Symbiote-GridFieldExtensions-Tests-Stub-StubA' => 'A',
|
|
|
|
'Symbiote-GridFieldExtensions-Tests-Stub-StubB' => 'B',
|
|
|
|
'Symbiote-GridFieldExtensions-Tests-Stub-StubC' => 'C'
|
2016-12-21 03:34:58 +01:00
|
|
|
),
|
|
|
|
$component->getClasses($grid),
|
|
|
|
'Subclasses are populated by default and sorted'
|
|
|
|
);
|
2013-11-14 13:43:38 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
$component->setClasses(array(
|
2017-09-01 03:33:54 +02:00
|
|
|
StubB::class => 'Custom Title',
|
|
|
|
StubA::class
|
2016-12-21 03:34:58 +01:00
|
|
|
));
|
2013-11-14 13:43:38 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2017-09-01 03:33:54 +02:00
|
|
|
'Symbiote-GridFieldExtensions-Tests-Stub-StubB' => 'Custom Title',
|
|
|
|
'Symbiote-GridFieldExtensions-Tests-Stub-StubA' => 'A'
|
2016-12-21 03:34:58 +01:00
|
|
|
),
|
|
|
|
$component->getClasses($grid),
|
|
|
|
'Sorting and custom titles can be specified'
|
|
|
|
);
|
|
|
|
}
|
2013-11-14 13:43:38 +01:00
|
|
|
}
|