mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Added one more unit test for GridFieldNestedForm
This commit is contained in:
parent
f8c777dcc5
commit
4fc20fb771
@ -11,6 +11,8 @@ use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
|||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldNestedForm;
|
use Symbiote\GridFieldExtensions\GridFieldNestedForm;
|
||||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubHierarchy;
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubHierarchy;
|
||||||
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubOrdered;
|
||||||
|
use Symbiote\GridFieldExtensions\Tests\Stub\StubParent;
|
||||||
use Symbiote\GridFieldExtensions\Tests\Stub\TestController;
|
use Symbiote\GridFieldExtensions\Tests\Stub\TestController;
|
||||||
|
|
||||||
class GridFieldNestedFormTest extends SapphireTest
|
class GridFieldNestedFormTest extends SapphireTest
|
||||||
@ -18,7 +20,9 @@ class GridFieldNestedFormTest extends SapphireTest
|
|||||||
protected static $fixture_file = 'GridFieldNestedFormTest.yml';
|
protected static $fixture_file = 'GridFieldNestedFormTest.yml';
|
||||||
|
|
||||||
protected static $extra_dataobjects = [
|
protected static $extra_dataobjects = [
|
||||||
StubHierarchy::class
|
StubHierarchy::class,
|
||||||
|
StubParent::class,
|
||||||
|
StubOrdered::class
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testHierarchy()
|
public function testHierarchy()
|
||||||
@ -55,4 +59,30 @@ class GridFieldNestedFormTest extends SapphireTest
|
|||||||
$child2 = $this->objFromFixture(StubHierarchy::class, 'item1_1_1');
|
$child2 = $this->objFromFixture(StubHierarchy::class, 'item1_1_1');
|
||||||
$this->assertEquals($child2->ID, $list->first()->ID);
|
$this->assertEquals($child2->ID, $list->first()->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHasManyRelation()
|
||||||
|
{
|
||||||
|
// test that GridFieldNestedForm works with HasMany relations
|
||||||
|
$parent = $this->objFromFixture(StubParent::class, 'parent1');
|
||||||
|
$list = new ArrayList([$parent]);
|
||||||
|
$config = new GridFieldConfig_RecordEditor();
|
||||||
|
$config->addComponent($nestedForm = new GridFieldNestedForm());
|
||||||
|
$nestedForm->setRelationName('MyHasMany');
|
||||||
|
|
||||||
|
$controller = new TestController('Test');
|
||||||
|
$form = new Form($controller, 'TestForm', new FieldList(
|
||||||
|
$gridField = new GridField(__FUNCTION__, 'test', $list, $config)
|
||||||
|
), new FieldList());
|
||||||
|
|
||||||
|
$request = new HTTPRequest('GET', '/');
|
||||||
|
$itemEditForm = $nestedForm->handleNestedItem($gridField, $request, $parent);
|
||||||
|
$this->assertNotNull($itemEditForm);
|
||||||
|
$nestedGridField = $itemEditForm->Fields()->first();
|
||||||
|
$this->assertNotNull($nestedGridField);
|
||||||
|
$list = $nestedGridField->getList();
|
||||||
|
$this->assertEquals(2, $list->count());
|
||||||
|
|
||||||
|
$child1 = $this->objFromFixture(StubOrdered::class, 'child1');
|
||||||
|
$this->assertEquals($child1->ID, $list->first()->ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,3 +7,13 @@ Symbiote\GridFieldExtensions\Tests\Stub\StubHierarchy:
|
|||||||
item1_1_1:
|
item1_1_1:
|
||||||
Title: 'Item 1.1.1'
|
Title: 'Item 1.1.1'
|
||||||
ParentID: =>Symbiote\GridFieldExtensions\Tests\Stub\StubHierarchy.item1_1
|
ParentID: =>Symbiote\GridFieldExtensions\Tests\Stub\StubHierarchy.item1_1
|
||||||
|
Symbiote\GridFieldExtensions\Tests\Stub\StubParent:
|
||||||
|
parent1:
|
||||||
|
Title: 'Parent 1'
|
||||||
|
Symbiote\GridFieldExtensions\Tests\Stub\StubOrdered:
|
||||||
|
child1:
|
||||||
|
Title: 'Child 1'
|
||||||
|
ParentID: =>Symbiote\GridFieldExtensions\Tests\Stub\StubParent.parent1
|
||||||
|
child2:
|
||||||
|
Title: 'Child 2'
|
||||||
|
ParentID: =>Symbiote\GridFieldExtensions\Tests\Stub\StubParent.parent1
|
||||||
|
Loading…
Reference in New Issue
Block a user