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

51 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace Symbiote\GridFieldExtensions\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\GridField\GridField;
2017-06-16 06:07:09 +02:00
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\Tests\Stub\StubA;
use Symbiote\GridFieldExtensions\Tests\Stub\StubB;
use Symbiote\GridFieldExtensions\Tests\Stub\StubC;
/**
* 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(StubA::class);
2016-12-21 03:34:58 +01:00
$component = new GridFieldAddNewMultiClass();
2016-12-21 03:34:58 +01:00
$this->assertEquals(
array(
'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'
);
2016-12-21 03:34:58 +01:00
$component->setClasses(array(
StubB::class => 'Custom Title',
StubA::class
2016-12-21 03:34:58 +01:00
));
2016-12-21 03:34:58 +01:00
$this->assertEquals(
array(
'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'
);
}
}