|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\Tests\GridField; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
|
6
|
|
|
use SilverStripe\Dev\CSSContentParser; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\Forms\FieldList; |
|
9
|
|
|
use SilverStripe\Forms\Form; |
|
10
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
11
|
|
|
use SilverStripe\Forms\GridField\GridField_ActionMenu; |
|
12
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig; |
|
13
|
|
|
use SilverStripe\Forms\GridField\GridFieldEditButton; |
|
14
|
|
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
|
15
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader; |
|
16
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions; |
|
17
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player; |
|
18
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team; |
|
19
|
|
|
use SilverStripe\ORM\ArrayList; |
|
20
|
|
|
use SilverStripe\ORM\DataList; |
|
21
|
|
|
use SilverStripe\Security\Member; |
|
22
|
|
|
use SilverStripe\Security\Security; |
|
23
|
|
|
|
|
24
|
|
|
class GridFieldActionMenuTest extends SapphireTest |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ArrayList |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $list; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var GridField |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $gridField; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Form |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $form; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected static $fixture_file = 'GridFieldActionTest.yml'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected static $extra_dataobjects = array( |
|
51
|
|
|
Team::class, |
|
52
|
|
|
Cheerleader::class, |
|
53
|
|
|
Player::class, |
|
54
|
|
|
Permissions::class, |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
protected function setUp() |
|
58
|
|
|
{ |
|
59
|
|
|
parent::setUp(); |
|
60
|
|
|
$this->list = new DataList(Team::class); |
|
|
|
|
|
|
61
|
|
|
$config = GridFieldConfig::create() |
|
62
|
|
|
->addComponent(new GridFieldEditButton()) |
|
63
|
|
|
->addComponent(new GridFieldDeleteAction()) |
|
64
|
|
|
->addComponent(new GridField_ActionMenu()); |
|
65
|
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config); |
|
66
|
|
|
$this->form = new Form(null, 'mockform', new FieldList(array($this->gridField)), new FieldList()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testShowActionMenu() |
|
70
|
|
|
{ |
|
71
|
|
|
if (Security::getCurrentUser()) { |
|
72
|
|
|
Security::setCurrentUser(null); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder()); |
|
76
|
|
|
// Check that there are content |
|
77
|
|
|
$this->assertEquals(4, count($content->getBySelector('.ss-gridfield-item'))); |
|
78
|
|
|
// Make sure that there are edit links, even though the user doesn't have "edit" permissions |
|
79
|
|
|
// (they can still view the records) |
|
80
|
|
|
$this->assertEquals( |
|
81
|
|
|
3, |
|
82
|
|
|
count($content->getBySelector('.gridfield-actionmenu__container')), |
|
83
|
|
|
'Edit links should show when not logged in.' |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testShowEditLinksWithAdminPermission() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->logInWithPermission('ADMIN'); |
|
90
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder()); |
|
91
|
|
|
$editLinks = $content->getBySelector('.gridfield-actionmenu__container'); |
|
92
|
|
|
$this->assertEquals(3, count($editLinks), 'Edit links should show when logged in.'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..