2011-09-27 23:25:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2011-09-30 00:59:44 +02:00
|
|
|
* This is a Unittest class for GridFieldTest
|
2011-09-27 23:25:24 +02:00
|
|
|
*
|
|
|
|
*/
|
2011-09-30 00:59:44 +02:00
|
|
|
class GridFieldTest extends SapphireTest {
|
2011-09-27 23:25:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-09-30 00:59:44 +02:00
|
|
|
static $fixture_file = 'sapphire/tests/forms/GridFieldTest.yml';
|
2011-09-27 23:25:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $extraDataObjects = array(
|
2011-09-30 00:59:44 +02:00
|
|
|
'GridFieldTest_Person',
|
2011-09-27 23:25:24 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
public function testGetInstance() {
|
2011-09-30 00:59:44 +02:00
|
|
|
$this->assertTrue(new GridField('Testgrid') instanceof FormField, 'GridField should be a FormField');
|
2011-09-27 23:25:24 +02:00
|
|
|
}
|
2011-09-29 01:16:15 +02:00
|
|
|
|
2011-09-27 23:25:24 +02:00
|
|
|
public function testSetDataSource() {
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
2011-09-27 23:25:24 +02:00
|
|
|
$source = new ArrayList();
|
2011-10-27 05:11:26 +02:00
|
|
|
$grid->setList($source);
|
|
|
|
$this->assertEquals($source, $grid->getList());
|
2011-09-27 23:25:24 +02:00
|
|
|
}
|
2011-09-29 01:16:15 +02:00
|
|
|
|
|
|
|
function testSetEmptyDataPresenter() {
|
|
|
|
$this->setExpectedException('Exception');
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
|
|
|
$grid->setPresenter('');
|
2011-09-27 23:25:24 +02:00
|
|
|
}
|
2011-09-29 01:16:15 +02:00
|
|
|
|
|
|
|
function testSetNonExistingDataPresenter() {
|
|
|
|
$this->setExpectedException('Exception');
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
|
|
|
$grid->setPresenter('ifThisClassExistsIWouldBeSurprised');
|
2011-09-27 23:25:24 +02:00
|
|
|
}
|
2011-09-29 01:16:15 +02:00
|
|
|
|
|
|
|
function testSetDataPresenterWithDataObject() {
|
|
|
|
$this->setExpectedException('Exception');
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
|
|
|
$grid->setPresenter('DataObject');
|
2011-09-29 01:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSetDataPresenter() {
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
|
|
|
$grid->setPresenter('GridFieldPresenter');
|
2011-09-29 01:16:15 +02:00
|
|
|
}
|
|
|
|
|
2011-09-29 02:47:56 +02:00
|
|
|
function testSetDataclass() {
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
2011-09-29 02:47:56 +02:00
|
|
|
$grid->setModelClass('SiteTree');
|
|
|
|
$this->assertEquals('SiteTree', $grid->getModelClass());
|
2011-09-29 01:16:15 +02:00
|
|
|
}
|
|
|
|
|
2011-09-29 02:47:56 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function testFieldHolderWithoutDataSource() {
|
|
|
|
$this->setExpectedException('Exception');
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
2011-09-29 02:47:56 +02:00
|
|
|
$this->assertNotNull($grid->FieldHolder());
|
2011-09-29 01:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-30 00:59:44 +02:00
|
|
|
* This is better tested in the GridFieldFunctionalTest
|
2011-09-29 01:16:15 +02:00
|
|
|
*
|
2011-09-30 00:59:44 +02:00
|
|
|
* @see GridFieldFunctionalTest
|
2011-09-29 01:16:15 +02:00
|
|
|
*/
|
|
|
|
function testFieldHolder() {
|
2011-09-30 00:59:44 +02:00
|
|
|
$grid = new GridField('Testgrid');
|
2011-10-27 05:11:26 +02:00
|
|
|
$grid->setList(new DataList('GridFieldTest_Person'));
|
2011-09-29 01:16:15 +02:00
|
|
|
$this->assertNotNull($grid->FieldHolder());
|
2011-09-27 23:25:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:59:44 +02:00
|
|
|
class GridFieldTest_Person extends Dataobject implements TestOnly {
|
2011-09-27 23:25:24 +02:00
|
|
|
|
|
|
|
public static $db = array(
|
|
|
|
'Name' => 'Varchar'
|
|
|
|
);
|
|
|
|
|
|
|
|
public static $summary_fields = array(
|
|
|
|
'Name',
|
|
|
|
'ID'
|
|
|
|
);
|
|
|
|
}
|