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

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2017-07-05 17:15:20 +02:00
namespace Symbiote\Test;
2017-07-05 17:15:20 +02:00
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
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;
class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest {
public function testGetClassesWithNamespaces() {
$grid = new GridField('TestGridField');
2017-07-05 17:15:20 +02:00
$grid->setModelClass('Symbiote\\Test\\NamespacedClass');
$component = new GridFieldAddNewMultiClass();
$this->assertEquals(
array(
2017-07-05 17:15:20 +02:00
'Symbiote-Test-NamespacedClass' => 'NamespacedClass'
),
$component->getClasses($grid),
'Namespaced classes are sanitised'
);
}
public function testHandleAddWithNamespaces() {
$grid = new GridField('TestGridField');
$grid->getConfig()->addComponent(new GridFieldDetailForm());
2017-07-05 17:15:20 +02:00
$grid->setModelClass('Symbiote\\Test\\NamespacedClass');
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create()));
2017-07-05 17:15:20 +02:00
$request = new HTTPRequest('POST', 'test');
$request->setRouteParams(array('ClassName' => 'Symbiote-Test-NamespacedClass'));
$component = new GridFieldAddNewMultiClass();
$response = $component->handleAdd($grid, $request);
2017-07-05 17:15:20 +02:00
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
$record->setAccessible(true);
2017-07-05 17:15:20 +02:00
$this->assertInstanceOf('Symbiote\\Test\\NamespacedClass', $record->getValue($response));
}
}
/**#@+
* @ignore
*/
2017-07-05 17:15:20 +02:00
class NamespacedClass implements TestOnly {
public function i18n_singular_name() {
return 'NamespacedClass';
}
public function canCreate() {
return true;
}
}
/**#@-*/