Proof of reorder bug

This commit is contained in:
Daniel Hensby 2016-07-21 15:04:37 +01:00
parent 423a0d006e
commit 66c09cd60d
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 54 additions and 0 deletions

View File

@ -6,12 +6,44 @@ class GridFieldOrderableRowsTest extends SapphireTest {
protected $usesDatabase = true;
protected static $fixture_file = 'GridFieldOrderableRowsTest.yml';
protected $extraDataObjects = array(
'GridFieldOrderableRowsTest_Parent',
'GridFieldOrderableRowsTest_Ordered',
'GridFieldOrderableRowsTest_Subclass',
);
public function testReorderItems() {
$orderable = new GridFieldOrderableRows('ManyManySort');
$reflection = new ReflectionMethod($orderable, 'executeReorder');
$reflection->setAccessible(true);
$parent = $this->objFromFixture('GridFieldOrderableRowsTest_Parent', 'parent');
$config = new GridFieldConfig_RelationEditor();
$config->addComponent($orderable);
$grid = new GridField(
'MyManyMany',
'My Many Many',
$parent->MyManyMany()->sort('ManyManySort'),
$config
);
$originalOrder = $parent->MyManyMany()->sort('ManyManySort')->column('ID');
$desiredOrder = array_reverse($originalOrder);
$this->assertNotEquals($originalOrder, $desiredOrder);
$reflection->invoke($orderable, $grid, $desiredOrder);
$newOrder = $parent->MyManyMany()->sort('ManyManySort')->column('ID');
$this->assertEquals($desiredOrder, $newOrder);
}
/**
* @covers GridFieldOrderableRows::getSortTable
*/

View File

@ -0,0 +1,22 @@
GridFieldOrderableRowsTest_Ordered:
item1:
item2:
item3:
item4:
item5:
item6:
GridFieldOrderableRowsTest_Parent:
parent:
MyManyMany:
- 0: =>GridFieldOrderableRowsTest_Ordered.item1
ManyManySort: 1
- 1: =>GridFieldOrderableRowsTest_Ordered.item2
ManyManySort: 1
- 2: =>GridFieldOrderableRowsTest_Ordered.item3
ManyManySort: 2
- 3: =>GridFieldOrderableRowsTest_Ordered.item4
ManyManySort: 2
- 4: =>GridFieldOrderableRowsTest_Ordered.item5
ManyManySort: 108
- 5: =>GridFieldOrderableRowsTest_Ordered.item6
ManyManySort: 108