Skip to content

Commit

Permalink
TEST Cover base table last edited update
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Sep 25, 2017
1 parent fbc7278 commit 23c0a58
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
52 changes: 52 additions & 0 deletions tests/GridFieldOrderableRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GridFieldOrderableRowsTest extends SapphireTest {
'GridFieldOrderableRowsTest_Parent',
'GridFieldOrderableRowsTest_Ordered',
'GridFieldOrderableRowsTest_Subclass',
'GridFieldOrderableRowsTest_Unorderable',
'GridFieldOrderableRowsTest_OrderableChild',
);

public function testReorderItems() {
Expand Down Expand Up @@ -49,6 +51,35 @@ public function testReorderItems() {

}

public function testSortableChildClass() {
$orderable = new GridFieldOrderableRows('Sort');
$reflection = new ReflectionMethod($orderable, 'executeReorder');
$reflection->setAccessible(true);

$parent = $this->objFromFixture('GridFieldOrderableRowsTest_Ordered', 'nestedtest');

$config = new GridFieldConfig_RelationEditor();
$config->addComponent($orderable);

$grid = new GridField(
'Children',
'Children',
$parent->Children(),
$config
);

$originalOrder = $parent->Children()->column('ID');
$desiredOrder = array_reverse($originalOrder);

$this->assertNotEquals($originalOrder, $desiredOrder);

$reflection->invoke($orderable, $grid, $desiredOrder);

$newOrder = $parent->Children()->column('ID');

$this->assertEquals($desiredOrder, $newOrder);
}

/**
* @covers GridFieldOrderableRows::getSortTable
*/
Expand Down Expand Up @@ -112,6 +143,10 @@ class GridFieldOrderableRowsTest_Ordered extends DataObject implements TestOnly
'Parent' => 'GridFieldOrderableRowsTest_Parent'
);

private static $has_many = array(
'Children' => 'GridFieldOrderableRowsTest_OrderableChild',
);

private static $belongs_many_many =array(
'MyManyMany' => 'GridFieldOrderableRowsTest_Parent',
);
Expand All @@ -121,4 +156,21 @@ class GridFieldOrderableRowsTest_Ordered extends DataObject implements TestOnly
class GridFieldOrderableRowsTest_Subclass extends GridFieldOrderableRowsTest_Ordered implements TestOnly {
}

class GridFieldOrderableRowsTest_Unorderable extends DataObject implements TestOnly {
}

class GridFieldOrderableRowsTest_OrderableChild extends GridFieldOrderableRowsTest_Unorderable implements TestOnly {

private static $db = array(
'Sort' => 'Int',
);

private static $has_one = array(
'Parent' => 'GridFieldOrderableRowsTest_Ordered',
);

private static $default_sort = '"Sort" ASC';

}

/**#@-*/
31 changes: 24 additions & 7 deletions tests/GridFieldOrderableRowsTest.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
GridFieldOrderableRowsTest_Ordered:
item1:
item2:
item3:
item4:
item5:
item6:
GridFieldOrderableRowsTest_Parent:
parent:
MyManyMany:
Expand All @@ -20,3 +13,27 @@ GridFieldOrderableRowsTest_Parent:
ManyManySort: 108
- 5: =>GridFieldOrderableRowsTest_Ordered.item6
ManyManySort: 108
GridFieldOrderableRowsTest_OrderableChild:
item1:
Sort: 1
item2:
Sort: 2
item3:
Sort: 3
item4:
Sort: 4
GridFieldOrderableRowsTest_Ordered:
item1:
Sort: 1
item2:
Sort: 2
item3:
Sort: 3
item4:
Sort: 4
item5:
Sort: 5
item6:
Sort: 6
nestedtest:
Children: =>GridFieldOrderableRowsTest_OrderableChild.item1,=>GridFieldOrderableRowsTest_OrderableChild.item2,=>GridFieldOrderableRowsTest_OrderableChild.item3,=>GridFieldOrderableRowsTest_OrderableChild.item4

0 comments on commit 23c0a58

Please sign in to comment.