Skip to content

Commit

Permalink
Proof of reorder bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Jul 21, 2016
1 parent 423a0d0 commit 66c09cd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/GridFieldOrderableRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/GridFieldOrderableRowsTest.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 66c09cd

Please sign in to comment.