From 78c63c6725cca07882b720a5c9581da45b04d769 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 28 Sep 2018 17:59:44 +0200 Subject: [PATCH] Add test for getting the correct Sort order from MMTL items, fix incorrect test class name --- tests/GridFieldOrderableRowsTest.php | 34 +++++++++++++++++++++ tests/OrderableRowsThroughVersionedTest.php | 4 +-- tests/Stub/ThroughIntermediary.php | 7 ++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/GridFieldOrderableRowsTest.php b/tests/GridFieldOrderableRowsTest.php index 2ca98a9..dd71b07 100644 --- a/tests/GridFieldOrderableRowsTest.php +++ b/tests/GridFieldOrderableRowsTest.php @@ -88,6 +88,40 @@ class GridFieldOrderableRowsTest extends SapphireTest $this->assertEquals($desiredOrder, $newOrder); } + public function testManyManyThroughListSortOrdersAreUsedForInitialRender() + { + /** @var ThroughDefiner $record */ + $record = $this->objFromFixture(ThroughDefiner::class, 'DefinerOne'); + + $orderable = new GridFieldOrderableRows('Sort'); + $config = new GridFieldConfig_RelationEditor(); + $config->addComponent($orderable); + + $grid = new GridField( + 'Belongings', + 'Testing Many Many', + $record->Belongings()->sort('Sort'), + $config + ); + + // Get the first record, which would be the first one to have column contents generated + /** @var ThroughIntermediary $expected */ + $intermediary = $this->objFromFixture(ThroughIntermediary::class, 'One'); + + $result = $orderable->getColumnContent($grid, $record, 'irrelevant'); + + $this->assertContains( + 'Belongings[GridFieldEditableColumns][' . $record->ID . '][Sort]', + $result, + 'The field name is indexed under the record\'s ID' + ); + $this->assertContains( + 'value="' . $intermediary->Sort . '"', + $result, + 'The value comes from the MMTL intermediary Sort value' + ); + } + public function testSortableChildClass() { $orderable = new GridFieldOrderableRows('Sort'); diff --git a/tests/OrderableRowsThroughVersionedTest.php b/tests/OrderableRowsThroughVersionedTest.php index 694da01..e7e3cb1 100644 --- a/tests/OrderableRowsThroughVersionedTest.php +++ b/tests/OrderableRowsThroughVersionedTest.php @@ -12,7 +12,7 @@ use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediary; use Symbiote\GridFieldExtensions\Tests\Stub\ThroughBelongs; use Symbiote\GridFieldExtensions\GridFieldOrderableRows; -class OrderableRowsThroughTest extends SapphireTest +class OrderableRowsThroughVersionedTest extends SapphireTest { protected static $fixture_file = 'OrderableRowsThroughTest.yml'; @@ -105,7 +105,7 @@ class OrderableRowsThroughTest extends SapphireTest } } $this->assertTrue($differenceFound, 'All records should have changes in draft'); - + // Verify live stage has NOT reordered Versioned::set_stage(Versioned::LIVE); $sameOrder = $parent->$relationName()->sort($sortName)->column('ID'); diff --git a/tests/Stub/ThroughIntermediary.php b/tests/Stub/ThroughIntermediary.php index 12a48e1..9477d61 100644 --- a/tests/Stub/ThroughIntermediary.php +++ b/tests/Stub/ThroughIntermediary.php @@ -2,18 +2,17 @@ namespace Symbiote\GridFieldExtensions\Tests\Stub; -use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\FieldType\DBInt; use SilverStripe\Dev\TestOnly; +use SilverStripe\ORM\DataObject; class ThroughIntermediary extends DataObject implements TestOnly { private static $table_name = 'IntermediaryThrough'; private static $db = [ - 'Sort' => DBInt::class, + 'Sort' => 'Int', ]; - + private static $has_one = [ 'Defining' => ThroughDefiner::class, 'Belonging' => ThroughBelongs::class,