2012-03-08 01:58:53 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldEditButtonTest extends SapphireTest {
|
2012-03-08 01:58:53 +01:00
|
|
|
|
|
|
|
/** @var ArrayList */
|
|
|
|
protected $list;
|
|
|
|
|
|
|
|
/** @var GridField */
|
|
|
|
protected $gridField;
|
|
|
|
|
|
|
|
/** @var Form */
|
|
|
|
protected $form;
|
|
|
|
|
|
|
|
/** @var string */
|
2012-03-24 04:38:57 +01:00
|
|
|
public static $fixture_file = 'GridFieldActionTest.yml';
|
2012-03-08 01:58:53 +01:00
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
protected $extraDataObjects = array('GridFieldAction_Delete_Team', 'GridFieldAction_Edit_Team');
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->list = new DataList('GridFieldAction_Edit_Team');
|
2012-03-09 00:54:02 +01:00
|
|
|
$config = GridFieldConfig::create()->addComponent(new GridFieldEditButton());
|
2012-03-08 01:58:53 +01:00
|
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
|
|
|
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
|
|
|
}
|
|
|
|
|
2012-12-17 00:47:23 +01:00
|
|
|
public function testShowEditLinks() {
|
2012-03-08 01:58:53 +01:00
|
|
|
if(Member::currentUser()) { Member::currentUser()->logOut(); }
|
|
|
|
|
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder());
|
|
|
|
// Check that there are content
|
|
|
|
$this->assertEquals(3, count($content->getBySelector('.ss-gridfield-item')));
|
2012-12-17 00:47:23 +01:00
|
|
|
// Make sure that there are edit links, even though the user doesn't have "edit" permissions
|
|
|
|
// (he can still view the records)
|
|
|
|
$this->assertEquals(2, count($content->getBySelector('.edit-link')),
|
|
|
|
'Edit links should show when not logged in.');
|
2012-03-08 01:58:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testShowEditLinksWithAdminPermission() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder());
|
|
|
|
$editLinks = $content->getBySelector('.edit-link');
|
|
|
|
$this->assertEquals(2, count($editLinks), 'Edit links should show when logged in.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GridFieldAction_Edit_Team extends DataObject implements TestOnly {
|
|
|
|
static $db = array(
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'City' => 'Varchar'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function canView($member = null) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|