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

54 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Symbiote\GridFieldExtensions\Tests;
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;
use Symbiote\GridFieldExtensions\Tests\Stub\NamespacedClass;
2017-09-01 03:02:18 +02:00
class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest
{
2017-09-01 03:02:18 +02:00
public function testGetClassesWithNamespaces()
{
$grid = new GridField('TestGridField');
$grid->setModelClass(NamespacedClass::class);
2017-09-01 03:02:18 +02:00
$component = new GridFieldAddNewMultiClass();
2017-09-01 03:02:18 +02:00
$this->assertEquals(
array(
'Symbiote-GridFieldExtensions-Tests-Stub-NamespacedClass' => 'NamespacedClass'
2017-09-01 03:02:18 +02:00
),
$component->getClasses($grid),
'Namespaced classes are sanitised'
);
}
2017-09-01 03:02:18 +02:00
public function testHandleAddWithNamespaces()
{
$grid = new GridField('TestGridField');
$grid->getConfig()->addComponent(new GridFieldDetailForm());
$grid->setModelClass(NamespacedClass::class);
2017-09-01 03:02:18 +02:00
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create()));
2017-09-01 03:02:18 +02:00
$request = new HTTPRequest('POST', 'test');
$request->setRouteParams(array('ClassName' => 'Symbiote-GridFieldExtensions-Tests-Stub-NamespacedClass'));
2017-09-01 03:02:18 +02:00
$component = new GridFieldAddNewMultiClass();
$response = $component->handleAdd($grid, $request);
2017-09-01 03:02:18 +02:00
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
$record->setAccessible(true);
$this->assertInstanceOf(NamespacedClass::class, $record->getValue($response));
2017-09-01 03:02:18 +02:00
}
}