Add test for getting the correct Sort order from MMTL items, fix incorrect test class name

This commit is contained in:
Robbie Averill 2018-09-28 17:59:44 +02:00
parent b221134ce1
commit 78c63c6725
3 changed files with 39 additions and 6 deletions

View File

@ -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');

View File

@ -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';

View File

@ -2,16 +2,15 @@
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 = [