-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRoleAssignmentCreateDataValidationTest.php
More file actions
140 lines (127 loc) · 4.81 KB
/
RoleAssignmentCreateDataValidationTest.php
File metadata and controls
140 lines (127 loc) · 4.81 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Tests\AdminUi\Form\Data\Role;
use Ibexa\AdminUi\Form\Data\Role\RoleAssignmentCreateData;
use Ibexa\AdminUi\Form\Type\Content\LocationType;
use Ibexa\AdminUi\Form\Type\Role\RoleAssignmentCreateType;
use Ibexa\AdminUi\Form\Type\Section\SectionChoiceType;
use Ibexa\AdminUi\Form\Type\User\UserCollectionType;
use Ibexa\AdminUi\Form\Type\User\UserGroupCollectionType;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\SectionService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\Section;
use Ibexa\Tests\AdminUi\Form\Data\AbstractFormDataValidationTestCase;
use Ibexa\Tests\AdminUi\Form\Data\FormErrorDataTestWrapper;
use Symfony\Component\Form\FormInterface;
/**
* @covers \Ibexa\AdminUi\Form\Data\Role\RoleAssignmentCreateData
* @covers \Ibexa\AdminUi\Form\Type\Role\RoleAssignmentCreateType
*/
final class RoleAssignmentCreateDataValidationTest extends AbstractFormDataValidationTestCase
{
public static function getDataForTestFormSubmitValidation(): iterable
{
yield 'Empty data' => [
[],
[
new FormErrorDataTestWrapper('validator.assign_users_or_groups', [], 'data'),
new FormErrorDataTestWrapper(
'This value should not be null.',
['{{ value }}' => 'null'],
'data.limitationType'
),
],
];
yield 'Unsupported limitation type' => [
[
'users' => '14,10',
'limitation_type' => 'foo',
],
[
new FormErrorDataTestWrapper(
'The selected choice is invalid.',
['{{ value }}' => 'foo'],
'children[limitation_type]'
),
],
];
yield 'Sections not defined' => [
[
'users' => '13',
'limitation_type' => RoleAssignmentCreateData::LIMITATION_TYPE_SECTION,
],
[
new FormErrorDataTestWrapper(
'validator.define_subtree_or_section_limitation',
['{{ value }}' => 'array'],
'data.sections'
),
],
];
yield 'Subtree Location not defined' => [
[
'users' => '14,10',
'limitation_type' => RoleAssignmentCreateData::LIMITATION_TYPE_LOCATION,
],
[
new FormErrorDataTestWrapper(
'validator.define_subtree_or_section_limitation',
['{{ value }}' => 'array'],
'data.locations'
),
],
];
yield 'valid data - sections' => [
[
'users' => '10',
'limitation_type' => RoleAssignmentCreateData::LIMITATION_TYPE_SECTION,
'sections' => ['1'],
],
[],
];
yield 'valid data - locations' => [
[
'users' => '10',
'limitation_type' => RoleAssignmentCreateData::LIMITATION_TYPE_LOCATION,
'locations' => '1,2',
],
[],
];
}
/**
* @return array<string, \Symfony\Component\Form\FormTypeInterface<mixed>>
*/
protected function getTypes(): array
{
$sectionServiceMock = $this->createMock(SectionService::class);
$sectionServiceMock->method('loadSections')->willReturn(
[
new Section(['id' => 1, 'identifier' => 'standard', 'name' => 'Standard']),
]
);
$locationServiceMock = $this->createMock(LocationService::class);
$locationServiceMock->method('loadLocation')->willReturn($this->createMock(Location::class));
return [
UserGroupCollectionType::class => new UserGroupCollectionType($this->createMock(UserService::class)),
UserCollectionType::class => new UserCollectionType($this->createMock(UserService::class)),
SectionChoiceType::class => new SectionChoiceType($sectionServiceMock),
LocationType::class => new LocationType($locationServiceMock),
];
}
/**
* @return \Symfony\Component\Form\FormInterface<\Ibexa\AdminUi\Form\Data\Role\RoleAssignmentCreateData>
*/
protected function getForm(): FormInterface
{
return $this->factory->create(
RoleAssignmentCreateType::class,
new RoleAssignmentCreateData()
);
}
}