silverstripe-framework/tests/php/Forms/GridField/GridFieldEditButtonTest.php

76 lines
2.2 KiB
PHP
Raw Normal View History

<?php
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
2016-06-23 01:37:22 +02:00
use SilverStripe\Security\Member;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridField;
2016-06-23 01:37:22 +02:00
class GridFieldEditButtonTest extends SapphireTest {
2015-03-07 13:32:04 +01:00
/** @var ArrayList */
protected $list;
2015-03-07 13:32:04 +01:00
/** @var GridField */
protected $gridField;
2015-03-07 13:32:04 +01:00
/** @var Form */
protected $form;
2015-03-07 13:32:04 +01:00
/** @var string */
protected static $fixture_file = 'GridFieldActionTest.yml';
/** @var array */
protected $extraDataObjects = array('GridFieldAction_Delete_Team', 'GridFieldAction_Edit_Team');
2015-03-07 13:32:04 +01:00
public function setUp() {
parent::setUp();
$this->list = new DataList('GridFieldAction_Edit_Team');
$config = GridFieldConfig::create()->addComponent(new GridFieldEditButton());
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
}
2015-03-07 13:32:04 +01:00
public function testShowEditLinks() {
if(Member::currentUser()) { Member::currentUser()->logOut(); }
2015-03-07 13:32:04 +01:00
$content = new CSSContentParser($this->gridField->FieldHolder());
// Check that there are content
$this->assertEquals(3, count($content->getBySelector('.ss-gridfield-item')));
// Make sure that there are edit links, even though the user doesn't have "edit" permissions
2015-03-07 13:32:04 +01:00
// (they can still view the records)
$this->assertEquals(2, count($content->getBySelector('.edit-link')),
'Edit links should show when not logged in.');
}
2015-03-07 13:32:04 +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 {
private static $db = array(
'Name' => 'Varchar',
'City' => 'Varchar'
);
2015-03-07 13:32:04 +01:00
public function canView($member = null) {
return true;
}
}