silverstripe-framework/tests/forms/GridFieldTest.php
Stig Lindqvist 83e90aaafe ENHANCEMENT Release of DataGridPagination
This class extends the DataGridPresenter with the behaviour and looks of a paginated Datagrid.
2011-10-28 17:34:15 +13:00

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