Skip to content
Snippets Groups Projects
Commit da33c720 authored by Conrad Lara's avatar Conrad Lara
Browse files

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
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment