2012-03-05 23:19:46 +01:00
|
|
|
<?php
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldToolbarHeaderTest extends SapphireTest {
|
2012-03-05 23:19:46 +01:00
|
|
|
|
2012-03-09 04:47:35 +01:00
|
|
|
static $fixture_file = 'GridFieldToolbarHeaderTest.yml';
|
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
2012-03-09 04:55:20 +01:00
|
|
|
'GridFieldToolbarHeaderTest_Company',
|
2012-03-09 04:47:35 +01:00
|
|
|
);
|
2012-03-05 23:19:46 +01:00
|
|
|
|
|
|
|
public function testGridTitleAddNewEnabled() {
|
2012-03-08 01:58:53 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2012-03-05 23:19:46 +01:00
|
|
|
//construct a fake form field to render out the grid field within it
|
|
|
|
$config = new GridFieldConfig();
|
2012-03-09 00:54:02 +01:00
|
|
|
$config->addComponent($titleField = new GridFieldToolbarHeader());
|
2012-03-05 23:19:46 +01:00
|
|
|
$actions = new FieldList();
|
2012-03-09 04:55:20 +01:00
|
|
|
$grid = new GridField('TestField', 'Test Field', new DataList('GridFieldToolbarHeaderTest_Company'),$config);
|
2012-03-05 23:19:46 +01:00
|
|
|
$fields = new FieldList($rootTab = new TabSet("Root",$tabMain = new Tab('Main',$grid)));
|
|
|
|
$form = new Form(Controller::curr(), "TestForm", $fields, $actions);
|
|
|
|
|
|
|
|
$titleField->setNewEnabled(true);
|
|
|
|
$html = $form->forTemplate();
|
|
|
|
$this->assertContains('data-icon="add"', $html,"HTML contains the 'add new' button");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGridTitleAddNewDisabled() {
|
2012-03-08 01:58:53 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2012-03-05 23:19:46 +01:00
|
|
|
//construct a fake form field to render out the grid field within it
|
|
|
|
$config = new GridFieldConfig();
|
2012-03-09 00:54:02 +01:00
|
|
|
$config->addComponent($titleField = new GridFieldToolbarHeader());
|
2012-03-05 23:19:46 +01:00
|
|
|
$actions = new FieldList();
|
2012-03-09 04:55:20 +01:00
|
|
|
$grid = new GridField('TestField', 'Test Field', new DataList('GridFieldToolbarHeaderTest_Company'),$config);
|
2012-03-05 23:19:46 +01:00
|
|
|
$fields = new FieldList($rootTab = new TabSet("Root",$tabMain = new Tab('Main',$grid)));
|
|
|
|
$form = new Form(Controller::curr(), "TestForm", $fields, $actions);
|
|
|
|
|
|
|
|
$titleField->setNewEnabled(false);
|
|
|
|
$html = $form->forTemplate();
|
|
|
|
$this->assertNotContains('data-icon="add"', $html,"HTML does not contain the 'add new' button");
|
|
|
|
}
|
2012-03-08 01:58:53 +01:00
|
|
|
|
|
|
|
public function testGridTitleAddNewWithoutPermission() {
|
|
|
|
if(Member::currentUser()) { Member::currentUser()->logOut(); }
|
|
|
|
$config = new GridFieldConfig();
|
2012-03-09 00:54:02 +01:00
|
|
|
$config->addComponent($titleField = new GridFieldToolbarHeader());
|
2012-03-09 04:55:20 +01:00
|
|
|
$grid = new GridField('TestField', 'Test Field', new DataList('GridFieldToolbarHeaderTest_Company'),$config);
|
2012-03-08 01:58:53 +01:00
|
|
|
$fields = new FieldList(new TabSet("Root",$tabMain = new Tab('Main',$grid)));
|
|
|
|
$form = new Form(Controller::curr(), "TestForm", $fields, new FieldList());
|
|
|
|
|
|
|
|
$html = $form->forTemplate();
|
|
|
|
$this->assertNotContains('data-icon="add"', $html, "HTML should not contain the 'add new' button");
|
|
|
|
}
|
2012-03-09 04:47:35 +01:00
|
|
|
}
|
2012-03-09 04:55:20 +01:00
|
|
|
class GridFieldToolbarHeaderTest_Company extends DataObject implements TestOnly {
|
2012-03-09 04:47:35 +01:00
|
|
|
|
|
|
|
public static $db = array(
|
|
|
|
'Name' => 'Varchar(100)'
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|