-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathActionFactoryTest.php
More file actions
92 lines (72 loc) · 3.88 KB
/
ActionFactoryTest.php
File metadata and controls
92 lines (72 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Unit\Factory;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Factory\ActionFactory;
use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\ButtonVariant;
use PHPUnit\Framework\TestCase;
class ActionFactoryTest extends TestCase
{
public function testAutomaticOrdering(): void
{
$actions = Actions::new();
// add actions in a mixed order
$actions->add('index', Action::new('action_warning')->linkToCrudAction('index')->asWarningAction());
$actions->add('index', Action::new('action_primary')->linkToCrudAction('index')->asPrimaryAction());
$actions->add('index', Action::new('action_danger_text')->linkToCrudAction('index')->asDangerAction()->asTextLink());
$actions->add('index', Action::new('action_success')->linkToCrudAction('index')->asSuccessAction());
$actions->add('index', Action::new('action_info')->linkToCrudAction('index')->asInfoAction());
$actions->add('index', Action::new('action_text')->linkToCrudAction('index')->asTextLink());
$actions->add('index', Action::new('action_danger')->linkToCrudAction('index')->asDangerAction());
$actions->add('index', Action::new('action_default')->linkToCrudAction('index'));
$dto = $actions->getAsDto('index');
$allActions = $dto->getActions()->all();
$actionNames = array_keys($allActions);
$expectedOrderBeforeSorting = [
'action_warning',
'action_primary',
'action_danger_text',
'action_success',
'action_info',
'action_text',
'action_danger',
'action_default',
];
// since automatic ordering is enabled by default, this should be the order before ActionFactory processes them
$this->assertSame($expectedOrderBeforeSorting, $actionNames);
}
public function testInfoVariantSurvivesConfigObjectRoundTrip(): void
{
$action = Action::new('info_action')->linkToCrudAction('index')->asInfoAction();
$roundTripped = $action->getAsDto()->getAsConfigObject();
$this->assertSame(ButtonVariant::Info, $roundTripped->getAsDto()->getVariant());
}
public function testDisableAutomaticOrdering(): void
{
$actions = Actions::new();
// add actions in a mixed order
$actions->add('index', Action::new('action_warning')->linkToCrudAction('index')->asWarningAction());
$actions->add('index', Action::new('action_primary')->linkToCrudAction('index')->asPrimaryAction());
$actions->add('index', Action::new('action_danger_text')->linkToCrudAction('index')->asDangerAction()->asTextLink());
$actions->add('index', Action::new('action_success')->linkToCrudAction('index')->asSuccessAction());
$actions->disableAutomaticOrdering();
$dto = $actions->getAsDto('index');
$this->assertFalse($dto->getUseAutomaticOrdering());
}
public function testReorderDisablesAutomaticOrdering(): void
{
$actions = Actions::new();
$actions->add('index', Action::new('action_1')->linkToCrudAction('index'));
$actions->add('index', Action::new('action_2')->linkToCrudAction('index'));
$actions->add('index', Action::new('action_3')->linkToCrudAction('index'));
// use reorder which should automatically disable automatic ordering
$actions->reorder('index', ['action_3', 'action_1', 'action_2']);
$dto = $actions->getAsDto('index');
$this->assertFalse($dto->getUseAutomaticOrdering());
// verify the custom order is preserved
$allActions = $dto->getActions()->all();
$actionNames = array_keys($allActions);
$expectedOrder = ['action_3', 'action_1', 'action_2'];
$this->assertSame($expectedOrder, $actionNames);
}
}