Skip to content

Commit

Permalink
Add test for getting the correct Sort order from MMTL items, fix inco…
Browse files Browse the repository at this point in the history
…rrect test class name
  • Loading branch information
robbieaverill committed Sep 28, 2018
1 parent b221134 commit 78c63c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
34 changes: 34 additions & 0 deletions tests/GridFieldOrderableRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,40 @@ public function testReorderItems($fixtureID, $relationName, $sortName)
$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');
Expand Down
4 changes: 2 additions & 2 deletions tests/OrderableRowsThroughVersionedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughBelongs;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

class OrderableRowsThroughTest extends SapphireTest
class OrderableRowsThroughVersionedTest extends SapphireTest
{
protected static $fixture_file = 'OrderableRowsThroughTest.yml';

Expand Down Expand Up @@ -105,7 +105,7 @@ public function testReorderingSavesAndPublishes()
}
}
$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');
Expand Down
7 changes: 3 additions & 4 deletions tests/Stub/ThroughIntermediary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 78c63c6

Please sign in to comment.