Skip to content

Commit a0f941e

Browse files
committed
adjust tests to specifics of MultiSelect and MultiSelectOption
1 parent 1c3da89 commit a0f941e

File tree

6 files changed

+83
-78
lines changed

6 files changed

+83
-78
lines changed

api/fixtures/contentTypes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ App\Entity\ContentType:
2727
name: 'LAThematicArea'
2828
active: true
2929
entityClass: 'App\Entity\ContentNode\MultiSelect'
30-
jsonConfig: { items: [ 'outdoorTechnique', 'security', 'natureAndEnvironment', 'pioneeringTechnique', 'campsiteAndSurroundings', 'preventionAndIntegration' ] }
30+
jsonConfig: { items: [ 'outdoorTechnique', 'security', 'natureAndEnvironment' ] }

api/tests/Api/ContentNodes/MultiSelect/CreateMultiSelectTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,33 @@ public function setUp(): void {
1717
$this->defaultContentType = static::$fixtures['contentTypeMultiSelect'];
1818
}
1919

20+
public function testCreateMultiSelectCopiesOptionsFromContentType() {
21+
// when
22+
$response = $this->create($this->getExampleWritePayload());
23+
24+
// then
25+
$this->assertResponseStatusCodeSame(201);
26+
$this->assertCount(1, $response->toArray()['_links']['options']);
27+
$this->assertJsonContains([
28+
'_embedded' => [
29+
'options' => [
30+
[
31+
'translateKey' => 'outdoorTechnique',
32+
'checked' => false,
33+
],
34+
[
35+
'translateKey' => 'security',
36+
'checked' => false,
37+
],
38+
[
39+
'translateKey' => 'natureAndEnvironment',
40+
'checked' => false,
41+
],
42+
],
43+
],
44+
]);
45+
}
46+
2047
public function testCreateMultiSelectFromPrototype() {
2148
// given
2249
$prototype = static::$fixtures['multiSelect1'];

api/tests/Api/ContentNodes/MultiSelect/Option/CreateMultiSelectOptionTest.php

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,15 @@
1010
* @internal
1111
*/
1212
class CreateMultiSelectOptionTest extends ECampApiTestCase {
13-
protected MultiSelect $defaultStorybord;
13+
protected MultiSelect $defaultMultiSelect;
1414

1515
public function setUp(): void {
1616
parent::setUp();
1717

1818
$this->endpoint = '/content_node/multi_select_options';
1919
$this->entityClass = MultiSelectOption::class;
2020

21-
$this->defaultStorybord = static::$fixtures['multiSelect1'];
22-
}
23-
24-
public function testCreateCleansHTMLFromText() {
25-
// given
26-
$text = ' testText<script>alert(1)</script>';
27-
28-
// when
29-
$this->create($this->getExampleWritePayload([
30-
'translateKey' => $text,
31-
'checked' => true,
32-
]));
33-
34-
// then
35-
$textSanitized = ' testText';
36-
$this->assertResponseStatusCodeSame(201);
37-
$this->assertJsonContains([
38-
'translateKey' => $textSanitized,
39-
'checked' => true,
40-
]);
21+
$this->defaultMultiSelect = static::$fixtures['multiSelect1'];
4122
}
4223

4324
/**
@@ -60,7 +41,7 @@ public function testCreateIsDeniedForInvitedCollaborator() {
6041
$this->assertResponseStatusCodeSame(400);
6142
$this->assertJsonContains([
6243
'title' => 'An error occurred',
63-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
44+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultMultiSelect).'".',
6445
]);
6546
}
6647

@@ -72,7 +53,7 @@ public function testCreateIsDeniedForInactiveCollaborator() {
7253
$this->assertResponseStatusCodeSame(400);
7354
$this->assertJsonContains([
7455
'title' => 'An error occurred',
75-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
56+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultMultiSelect).'".',
7657
]);
7758
}
7859

@@ -84,7 +65,7 @@ public function testCreateIsDeniedForUnrelatedUser() {
8465
$this->assertResponseStatusCodeSame(400);
8566
$this->assertJsonContains([
8667
'title' => 'An error occurred',
87-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
68+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultMultiSelect).'".',
8869
]);
8970
}
9071

@@ -100,51 +81,40 @@ public function testCreateIsDeniedForGuest() {
10081
]);
10182
}
10283

103-
public function testCreateIsAllowedForMember() {
84+
public function testCreateIsDeniedForMember() {
85+
// when
10486
$this->create(user: static::$fixtures['user2member']);
105-
$this->assertResponseStatusCodeSame(201);
87+
88+
// then
89+
$this->assertResponseStatusCodeSame(403);
90+
$this->assertJsonContains([
91+
'title' => 'An error occurred',
92+
'detail' => 'Access Denied.',
93+
]);
10694
}
10795

108-
public function testCreateIsAllowedForManager() {
96+
public function testCreateIsDeniedForManager() {
10997
// when
11098
$response = $this->create(user: static::$fixtures['user1manager']);
111-
$id = $response->toArray()['id'];
112-
$newMultiSelectOption = $this->getEntityManager()->getRepository($this->entityClass)->find($id);
11399

114100
// then
115-
$this->assertResponseStatusCodeSame(201);
116-
$this->assertJsonContains($this->getExampleReadPayload($newMultiSelectOption), true);
101+
$this->assertResponseStatusCodeSame(403);
102+
$this->assertJsonContains([
103+
'title' => 'An error occurred',
104+
'detail' => 'Access Denied.',
105+
]);
117106
}
118107

119-
/**
120-
* Payload setup.
121-
*/
108+
// Payload setup.
109+
/*
122110
protected function getExampleWritePayload($attributes = [], $except = []) {
123111
return parent::getExampleWritePayload(
124112
array_merge([
125-
'multiSelect' => $this->getIriFor($this->defaultStorybord),
113+
'multiSelect' => $this->getIriFor($this->defaultMultiSelect),
126114
'translateKey' => 'key',
127115
'checked' => true,
128116
], $attributes),
129117
$except
130118
);
131-
}
132-
133-
protected function getExampleReadPayload(MultiSelectOption $self, $attributes = [], $except = []) {
134-
/** @var MultiSelect $multiSelect */
135-
$multiSelect = $this->defaultStorybord;
136-
137-
return [
138-
'translateKey' => 'key',
139-
'checked' => true,
140-
'_links' => [
141-
'self' => [
142-
'href' => $this->getIriFor($self),
143-
],
144-
'multiSelect' => [
145-
'href' => $this->getIriFor($multiSelect),
146-
],
147-
],
148-
];
149-
}
119+
}*/
150120
}

api/tests/Api/ContentNodes/MultiSelect/Option/DeleteMultiSelectOptionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public function testDeleteIsDeniedForGuest() {
5050
$this->assertEntityStillExists();
5151
}
5252

53-
public function testDeleteIsAllowedForMember() {
53+
public function testDeleteIsDeniedForMember() {
5454
$this->delete(user: static::$fixtures['user2member']);
55-
$this->assertResponseStatusCodeSame(204);
56-
$this->assertEntityWasRemoved();
55+
$this->assertResponseStatusCodeSame(403);
56+
$this->assertEntityStillExists();
5757
}
5858

59-
public function testDeleteIsAllowedForManager() {
59+
public function testDeleteIsDeniedForManager() {
6060
$this->delete(user: static::$fixtures['user1manager']);
61-
$this->assertResponseStatusCodeSame(204);
62-
$this->assertEntityWasRemoved();
61+
$this->assertResponseStatusCodeSame(403);
62+
$this->assertEntityStillExists();
6363
}
6464
}

api/tests/Api/ContentNodes/MultiSelect/Option/UpdateMultiSelectOptionTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@ public function setUp(): void {
1515
$this->defaultEntity = static::$fixtures['multiSelectOption1'];
1616
}
1717

18-
public function testPatchCleansHTMLFromText() {
19-
// given
20-
$text = ' testText<script>alert(1)</script>';
21-
18+
public function testPatchCheckedIsAllowed() {
2219
// when
2320
$this->patch($this->defaultEntity, [
24-
'translateKey' => $text,
25-
'checked' => true,
21+
'checked' => false,
2622
]);
2723

2824
// then
29-
$textSanitized = ' testText';
3025
$this->assertResponseStatusCodeSame(200);
3126
$this->assertJsonContains([
32-
'translateKey' => $textSanitized,
33-
'checked' => true,
27+
'checked' => false,
28+
]);
29+
}
30+
31+
public function testPatchTranslateKeyIsDenied() {
32+
// when
33+
$this->patch($this->defaultEntity, [
34+
'translateKey' => 'newTranslateKey',
35+
]);
36+
37+
// then
38+
$this->assertResponseStatusCodeSame(400);
39+
$this->assertJsonContains([
40+
'title' => 'An error occurred',
41+
'detail' => 'Extra attributes are not allowed ("translateKey" is unknown).',
3442
]);
3543
}
3644

37-
public function testPatchMultiSelectNotAllowed() {
45+
public function testPatchMultiSelectIsDenied() {
3846
// when
3947
$this->patch($this->defaultEntity, [
4048
'multiSelect' => $this->getIriFor(static::$fixtures['multiSelect2']),

api/tests/Api/ContentNodes/Storyboard/Section/CreateStoryboardSectionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
* @internal
1111
*/
1212
class CreateStoryboardSectionTest extends ECampApiTestCase {
13-
protected Storyboard $defaultStorybord;
13+
protected Storyboard $defaultStoryboard;
1414

1515
public function setUp(): void {
1616
parent::setUp();
1717

1818
$this->endpoint = '/content_node/storyboard_sections';
1919
$this->entityClass = StoryboardSection::class;
2020

21-
$this->defaultStorybord = static::$fixtures['storyboard1'];
21+
$this->defaultStoryboard = static::$fixtures['storyboard1'];
2222
}
2323

2424
public function testCreateCleansHTMLFromText() {
@@ -62,7 +62,7 @@ public function testCreateIsDeniedForInvitedCollaborator() {
6262
$this->assertResponseStatusCodeSame(400);
6363
$this->assertJsonContains([
6464
'title' => 'An error occurred',
65-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
65+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStoryboard).'".',
6666
]);
6767
}
6868

@@ -74,7 +74,7 @@ public function testCreateIsDeniedForInactiveCollaborator() {
7474
$this->assertResponseStatusCodeSame(400);
7575
$this->assertJsonContains([
7676
'title' => 'An error occurred',
77-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
77+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStoryboard).'".',
7878
]);
7979
}
8080

@@ -86,7 +86,7 @@ public function testCreateIsDeniedForUnrelatedUser() {
8686
$this->assertResponseStatusCodeSame(400);
8787
$this->assertJsonContains([
8888
'title' => 'An error occurred',
89-
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStorybord).'".',
89+
'detail' => 'Item not found for "'.$this->getIriFor($this->defaultStoryboard).'".',
9090
]);
9191
}
9292

@@ -124,7 +124,7 @@ public function testCreateIsAllowedForManager() {
124124
protected function getExampleWritePayload($attributes = [], $except = []) {
125125
return parent::getExampleWritePayload(
126126
array_merge([
127-
'storyboard' => $this->getIriFor($this->defaultStorybord),
127+
'storyboard' => $this->getIriFor($this->defaultStoryboard),
128128
'column1' => 'Column 1',
129129
'column2' => 'Column 2',
130130
'column3' => 'Column 3',
@@ -135,7 +135,7 @@ protected function getExampleWritePayload($attributes = [], $except = []) {
135135

136136
protected function getExampleReadPayload(StoryboardSection $self, $attributes = [], $except = []) {
137137
/** @var Storyboard $storyboard */
138-
$storyboard = $this->defaultStorybord;
138+
$storyboard = $this->defaultStoryboard;
139139

140140
return [
141141
'column1' => 'Column 1',

0 commit comments

Comments
 (0)