silverstripe-gridfieldexten.../tests/GridFieldAddNewMultiClassWithNamespacesTest.php

49 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2018-02-21 10:49:04 +01:00
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler;
use Symbiote\GridFieldExtensions\Tests\Stub\NamespacedClass;
class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest {
public function testGetClassesWithNamespaces() {
$grid = new GridField('TestGridField');
2018-02-21 10:49:04 +01:00
$grid->setModelClass(NamespacedClass::class);
$component = new GridFieldAddNewMultiClass();
$this->assertEquals(
array(
2018-02-21 10:49:04 +01:00
'Symbiote-GridFieldExtensions-Tests-Stub-NamespacedClass' => 'NamespacedClass'
),
$component->getClasses($grid),
'Namespaced classes are sanitised'
);
}
public function testHandleAddWithNamespaces() {
$grid = new GridField('TestGridField');
$grid->getConfig()->addComponent(new GridFieldDetailForm());
2018-02-21 10:49:04 +01:00
$grid->setModelClass(NamespacedClass::class);
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create()));
2018-02-21 10:49:04 +01:00
$request = new HTTPRequest('POST', 'test');
$request->setRouteParams(array('ClassName' => 'Symbiote-GridFieldExtensions-Tests-Stub-NamespacedClass'));
$component = new GridFieldAddNewMultiClass();
$response = $component->handleAdd($grid, $request);
2018-02-21 10:49:04 +01:00
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
$record->setAccessible(true);
2018-02-21 10:49:04 +01:00
$this->assertInstanceOf(NamespacedClass::class, $record->getValue($response));
}
}