Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vault-3435322
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
vault-3435322
Commits
da33c720
Commit
da33c720
authored
1 year ago
by
Conrad Lara
Browse files
Options
Downloads
Patches
Plain Diff
Tests: do not expect ajax response to always be in same order/position.
parent
76f6f463
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/src/Kernel/VaultConfigFormKernelTest.php
+35
-4
35 additions, 4 deletions
tests/src/Kernel/VaultConfigFormKernelTest.php
with
35 additions
and
4 deletions
tests/src/Kernel/VaultConfigFormKernelTest.php
+
35
−
4
View file @
da33c720
...
...
@@ -109,10 +109,14 @@ class VaultConfigFormKernelTest extends KernelTestBase {
$this
->
assertIsString
(
$response
->
getContent
());
$data
=
json_decode
(
$response
->
getContent
(),
TRUE
);
$this
->
assertIsArray
(
$data
,
'Response data decoded'
);
$this
->
assertStringContainsString
(
'name="plugin_auth_settings[test_auth_plugin_field]"'
,
$data
[
4
][
'data'
]);
$ajax_data
=
$this
->
getAjaxResponseByCommand
(
$data
,
'insert'
);
$this
->
assertNotEmpty
(
$ajax_data
);
$this
->
assertStringContainsString
(
'name="plugin_auth_settings[test_auth_plugin_field]"'
,
$ajax_data
[
'data'
]);
// Test the lease plugin forms.
$settings
[
'form_build_id'
]
=
$data
[
3
][
'new'
];
$ajax_data
=
$this
->
getAjaxResponseByCommand
(
$data
,
'update_build_id'
);
$this
->
assertNotEmpty
(
$ajax_data
);
$settings
[
'form_build_id'
]
=
$ajax_data
[
'new'
];
$settings
[
'plugin_lease_storage'
]
=
"cileaseform"
;
$settings
[
'_triggering_element_name'
]
=
"plugin_lease_storage"
;
...
...
@@ -122,10 +126,14 @@ class VaultConfigFormKernelTest extends KernelTestBase {
$this
->
assertIsString
(
$response
->
getContent
());
$data
=
json_decode
(
$response
->
getContent
(),
TRUE
);
$this
->
assertIsArray
(
$data
,
'Response data decoded'
);
$this
->
assertStringContainsString
(
'name="lease_storage_plugin_config[test_lease_plugin_field]"'
,
$data
[
4
][
'data'
]);
$ajax_data
=
$this
->
getAjaxResponseByCommand
(
$data
,
'insert'
);
$this
->
assertNotEmpty
(
$ajax_data
);
$this
->
assertStringContainsString
(
'name="lease_storage_plugin_config[test_lease_plugin_field]"'
,
$ajax_data
[
'data'
]);
// Test submit form.
$settings
[
'form_build_id'
]
=
$data
[
3
][
'new'
];
$ajax_data
=
$this
->
getAjaxResponseByCommand
(
$data
,
'update_build_id'
);
$this
->
assertNotEmpty
(
$ajax_data
);
$settings
[
'form_build_id'
]
=
$ajax_data
[
'new'
];
$settings
[
'form_op'
]
=
'Save configuration'
;
unset
(
$settings
[
'_drupal_ajax'
]);
unset
(
$settings
[
'_triggering_element_name'
]);
...
...
@@ -171,4 +179,27 @@ class VaultConfigFormKernelTest extends KernelTestBase {
return
$dom
->
getAttribute
(
'value'
);
}
/**
* Get the data from a specific ajax response command.
*
* @param array $ajax_response
* An array of ajax response commands.
* @param string $command
* The command to return data for.
*
* @return array|null
* The response data, or null.
*/
protected
function
getAjaxResponseByCommand
(
array
$ajax_response
,
string
$command
):
?array
{
foreach
(
$ajax_response
as
$data
)
{
if
(
!
is_array
(
$data
))
{
continue
;
}
if
(
!
empty
(
$data
[
'command'
]
&&
$data
[
'command'
]
==
$command
))
{
return
$data
;
}
}
return
NULL
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment