|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\Tests\GridField; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\Form; |
|
8
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldGroupDeleteAction; |
|
10
|
|
|
use SilverStripe\Security\Group; |
|
11
|
|
|
use SilverStripe\Security\Member; |
|
12
|
|
|
use SilverStripe\Security\Security; |
|
13
|
|
|
|
|
14
|
|
|
class GridFieldGroupDeleteActionTest extends SapphireTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected static $fixture_file = 'GridFieldGroupDeleteActionTest.yml'; |
|
17
|
|
|
|
|
18
|
|
|
public function testCanUnlink() |
|
19
|
|
|
{ |
|
20
|
|
|
/* @var Group $group*/ |
|
21
|
|
|
$group = $this->objFromFixture(Group::class, 'admingroup'); |
|
22
|
|
|
/* @var Group $othergroup*/ |
|
23
|
|
|
$othergroup = $this->objFromFixture(Group::class, 'otheradmingroup'); |
|
24
|
|
|
|
|
25
|
|
|
/* @var Member $member */ |
|
26
|
|
|
$member = $this->objFromFixture(Member::class, 'admin'); |
|
27
|
|
|
Security::setCurrentUser($member); |
|
28
|
|
|
|
|
29
|
|
|
$gridField = GridField::create('test'); |
|
30
|
|
|
Form::create(null, 'dummy', FieldList::create($gridField), FieldList::create()); |
|
31
|
|
|
|
|
32
|
|
|
$button = new GridFieldGroupDeleteAction($group->ID); |
|
33
|
|
|
$actionGroup = $button->getGroup($gridField, $member, 'dummy'); |
|
34
|
|
|
$column = $button->getColumnContent($gridField, $member, 'dummy'); |
|
35
|
|
|
$this->assertNotNull($actionGroup, 'The unlink action has a menu group if the member has another admin group'); |
|
36
|
|
|
$this->assertNotNull($column, 'The unlink action has a column content if the member has another admin group'); |
|
37
|
|
|
|
|
38
|
|
|
$member->Groups()->remove($othergroup); |
|
39
|
|
|
|
|
40
|
|
|
$actionGroup = $button->getGroup($gridField, $member, 'dummy'); |
|
41
|
|
|
$column = $button->getColumnContent($gridField, $member, 'dummy'); |
|
42
|
|
|
$this->assertNull($actionGroup, 'The unlink action has no menu group if the member has no other admin group'); |
|
43
|
|
|
$this->assertNull($column, 'The unlink action has no column content if the member has no other admin group'); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|