mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
385e9e105c
* WIP GridField action menu work, the gist of the idea is using a new gridfield component * Add delete action to actions menu * Actions are added automatically to action menu (allows for extension) * Add test and minor changes * Add docs and minor changes * Refactor ActionMenuItem into distinct types, general ActionMenu cleanup * Add icons and fix title * Pass columnName, so it can be used by components * Update test to open and find action menu buttons * Add section in changelog upgrade section for GridField_ActionMenu
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Forms\Tests\GridField;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
use SilverStripe\Dev\CSSContentParser;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\Form;
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
use SilverStripe\Forms\GridField\GridField_ActionMenu;
|
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
|
use SilverStripe\Forms\GridField\GridFieldEditButton;
|
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader;
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions;
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
|
use SilverStripe\ORM\ArrayList;
|
|
use SilverStripe\ORM\DataList;
|
|
use SilverStripe\Security\Member;
|
|
use SilverStripe\Security\Security;
|
|
|
|
class GridFieldActionMenuTest extends SapphireTest
|
|
{
|
|
|
|
/**
|
|
* @var ArrayList
|
|
*/
|
|
protected $list;
|
|
|
|
/**
|
|
* @var GridField
|
|
*/
|
|
protected $gridField;
|
|
|
|
/**
|
|
* @var Form
|
|
*/
|
|
protected $form;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected static $fixture_file = 'GridFieldActionTest.yml';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected static $extra_dataobjects = array(
|
|
Team::class,
|
|
Cheerleader::class,
|
|
Player::class,
|
|
Permissions::class,
|
|
);
|
|
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
$this->list = new DataList(Team::class);
|
|
$config = GridFieldConfig::create()
|
|
->addComponent(new GridFieldEditButton())
|
|
->addComponent(new GridFieldDeleteAction())
|
|
->addComponent(new GridField_ActionMenu());
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
|
$this->form = new Form(null, 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
|
}
|
|
|
|
public function testShowActionMenu()
|
|
{
|
|
if (Security::getCurrentUser()) {
|
|
Security::setCurrentUser(null);
|
|
}
|
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder());
|
|
// Check that there are content
|
|
$this->assertEquals(4, count($content->getBySelector('.ss-gridfield-item')));
|
|
// Make sure that there are edit links, even though the user doesn't have "edit" permissions
|
|
// (they can still view the records)
|
|
$this->assertEquals(
|
|
3,
|
|
count($content->getBySelector('.gridfield-actionmenu__container')),
|
|
'Edit links should show when not logged in.'
|
|
);
|
|
}
|
|
|
|
public function testShowEditLinksWithAdminPermission()
|
|
{
|
|
$this->logInWithPermission('ADMIN');
|
|
$content = new CSSContentParser($this->gridField->FieldHolder());
|
|
$editLinks = $content->getBySelector('.gridfield-actionmenu__container');
|
|
$this->assertEquals(3, count($editLinks), 'Edit links should show when logged in.');
|
|
}
|
|
}
|