2012-01-30 15:47:22 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests\GridField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldConfigTest\MyOtherComponent;
|
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldConfigTest\MyComponent;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
|
|
|
use SilverStripe\Forms\GridField\GridField_URLHandler;
|
|
|
|
|
2012-01-30 15:47:22 +01:00
|
|
|
class GridFieldConfigTest extends SapphireTest {
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetComponents() {
|
2012-01-30 15:47:22 +01:00
|
|
|
$config = GridFieldConfig::create();
|
2016-10-14 03:30:05 +02:00
|
|
|
$this->assertInstanceOf(ArrayList::class, $config->getComponents());
|
|
|
|
$this->assertEquals($config->getComponents()->count(), 0);
|
2012-01-30 15:47:22 +01:00
|
|
|
|
|
|
|
$config
|
2016-10-14 03:30:05 +02:00
|
|
|
->addComponent($c1 = new MyComponent())
|
|
|
|
->addComponent($c2 = new MyOtherComponent())
|
|
|
|
->addComponent($c3 = new MyOtherComponent());
|
2012-01-30 15:47:22 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
new ArrayList(array($c1, $c2, $c3)),
|
2012-01-30 15:47:22 +01:00
|
|
|
$config->getComponents()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetComponentsByType() {
|
2012-01-30 15:47:22 +01:00
|
|
|
$config = GridFieldConfig::create()
|
2016-10-14 03:30:05 +02:00
|
|
|
->addComponent($c1 = new MyComponent())
|
|
|
|
->addComponent($c2 = new MyOtherComponent())
|
|
|
|
->addComponent($c3 = new MyOtherComponent());
|
2012-01-30 15:47:22 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
new ArrayList(array($c1)),
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentsByType(MyComponent::class)
|
2012-01-30 15:47:22 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
new ArrayList(array($c2, $c3)),
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentsByType(MyOtherComponent::class)
|
2012-01-30 15:47:22 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
new ArrayList(array($c1, $c2, $c3)),
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentsByType(GridField_URLHandler::class)
|
2012-01-30 15:47:22 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
new ArrayList(),
|
|
|
|
$config->getComponentsByType('GridFieldConfigTest_UnknownComponent')
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
2012-01-30 15:47:22 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetComponentByType() {
|
2012-01-30 15:47:22 +01:00
|
|
|
$config = GridFieldConfig::create()
|
2016-10-14 03:30:05 +02:00
|
|
|
->addComponent($c1 = new MyComponent())
|
|
|
|
->addComponent($c2 = new MyOtherComponent())
|
|
|
|
->addComponent($c3 = new MyOtherComponent());
|
2012-01-30 15:47:22 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
$c1,
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentByType(MyComponent::class)
|
2012-01-30 15:47:22 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$c2,
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentByType(MyOtherComponent::class)
|
2012-01-30 15:47:22 +01:00
|
|
|
);
|
|
|
|
$this->assertNull(
|
|
|
|
$config->getComponentByType('GridFieldConfigTest_UnknownComponent')
|
|
|
|
);
|
|
|
|
}
|
2012-02-21 22:06:41 +01:00
|
|
|
|
|
|
|
public function testAddComponents() {
|
|
|
|
$config = GridFieldConfig::create()
|
|
|
|
->addComponents(
|
2016-10-14 03:30:05 +02:00
|
|
|
$c1 = new MyComponent(),
|
|
|
|
$c2 = new MyOtherComponent()
|
2012-02-21 22:06:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
$c1,
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentByType(MyComponent::class)
|
2012-02-21 22:06:41 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$c2,
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->getComponentByType(MyOtherComponent::class)
|
2012-02-21 22:06:41 +01:00
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-08 08:00:22 +01:00
|
|
|
public function testRemoveComponents() {
|
|
|
|
$config = GridFieldConfig::create()
|
2016-10-14 03:30:05 +02:00
|
|
|
->addComponent($c1 = new MyComponent())
|
|
|
|
->addComponent($c2 = new MyComponent())
|
|
|
|
->addComponent($c3 = new MyOtherComponent())
|
|
|
|
->addComponent($c4 = new MyOtherComponent());
|
2012-03-08 08:00:22 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
4,
|
2012-03-08 08:00:22 +01:00
|
|
|
$config->getComponents()->count()
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-08 08:00:22 +01:00
|
|
|
$config->removeComponent($c1);
|
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
3,
|
2012-03-08 08:00:22 +01:00
|
|
|
$config->getComponents()->count()
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->removeComponentsByType(MyComponent::class);
|
2012-03-08 08:00:22 +01:00
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
2,
|
2012-03-08 08:00:22 +01:00
|
|
|
$config->getComponents()->count()
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
$config->removeComponentsByType(MyOtherComponent::class);
|
2012-03-08 08:00:22 +01:00
|
|
|
$this->assertEquals(
|
2014-08-15 08:53:05 +02:00
|
|
|
0,
|
2012-03-08 08:00:22 +01:00
|
|
|
$config->getComponents()->count()
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-01-30 15:47:22 +01:00
|
|
|
}
|
|
|
|
|