mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
83e90aaafe
This class extends the DataGridPresenter with the behaviour and looks of a paginated Datagrid.
94 lines
2.1 KiB
PHP
94 lines
2.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This is a Unittest class for GridFieldTest
|
|
*
|
|
*/
|
|
class GridFieldTest extends SapphireTest {
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
static $fixture_file = 'sapphire/tests/forms/GridFieldTest.yml';
|
|
|
|
/**
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $extraDataObjects = array(
|
|
'GridFieldTest_Person',
|
|
);
|
|
|
|
public function testGetInstance() {
|
|
$this->assertTrue(new GridField('Testgrid') instanceof FormField, 'GridField should be a FormField');
|
|
}
|
|
|
|
public function testSetDataSource() {
|
|
$grid = new GridField('Testgrid');
|
|
$source = new ArrayList();
|
|
$grid->setList($source);
|
|
$this->assertEquals($source, $grid->getList());
|
|
}
|
|
|
|
function testSetEmptyDataPresenter() {
|
|
$this->setExpectedException('Exception');
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setPresenter('');
|
|
}
|
|
|
|
function testSetNonExistingDataPresenter() {
|
|
$this->setExpectedException('Exception');
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setPresenter('ifThisClassExistsIWouldBeSurprised');
|
|
}
|
|
|
|
function testSetDataPresenterWithDataObject() {
|
|
$this->setExpectedException('Exception');
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setPresenter('DataObject');
|
|
}
|
|
|
|
function testSetDataPresenter() {
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setPresenter('GridFieldPresenter');
|
|
}
|
|
|
|
function testSetDataclass() {
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setModelClass('SiteTree');
|
|
$this->assertEquals('SiteTree', $grid->getModelClass());
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
function testFieldHolderWithoutDataSource() {
|
|
$this->setExpectedException('Exception');
|
|
$grid = new GridField('Testgrid');
|
|
$this->assertNotNull($grid->FieldHolder());
|
|
}
|
|
|
|
/**
|
|
* This is better tested in the GridFieldFunctionalTest
|
|
*
|
|
* @see GridFieldFunctionalTest
|
|
*/
|
|
function testFieldHolder() {
|
|
$grid = new GridField('Testgrid');
|
|
$grid->setList(new DataList('GridFieldTest_Person'));
|
|
$this->assertNotNull($grid->FieldHolder());
|
|
}
|
|
}
|
|
|
|
class GridFieldTest_Person extends Dataobject implements TestOnly {
|
|
|
|
public static $db = array(
|
|
'Name' => 'Varchar'
|
|
);
|
|
|
|
public static $summary_fields = array(
|
|
'Name',
|
|
'ID'
|
|
);
|
|
} |