function AcquiaLiftsWebTest::testAdminSettingsForm in Acquia Lift Connector 7.3
Tests the configuration form for Acquia Lift.
File
- tests/
acquia_lift.test, line 73 - Tests for Acquia Lift Profiles module.
Class
- AcquiaLiftsWebTest
- Tests Acquia Lift functionality.
Code
function testAdminSettingsForm() {
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('/admin/config/services/acquia_lift');
$submit_confirm_text = t('The configuration settings have been saved.');
$submit_button_text = $this->admin_button_text;
// Confirm expected fields
$fields = array(
'acquia_lift_account_id',
'acquia_lift_site_id',
'acquia_lift_assets_url',
'acquia_lift_decision_api_url',
'acquia_lift_oauth_url',
'acquia_lift_identity_param',
'acquia_lift_identity_type_param',
'acquia_lift_default_identity_type',
'acquia_lift_ignore_path_patterns',
'acquia_lift_bootstrap_mode',
'acquia_lift_content_replacement_mode',
'acquia_lift_content_origin',
'acquia_lift_field_mappings[content_section]',
'acquia_lift_field_mappings[content_keywords]',
'acquia_lift_field_mappings[persona]',
);
for ($i = 1; $i <= 50; $i++) {
$fields[] = 'acquia_lift_udf_mappings[person][person_udf' . $i . ']';
$fields[] = 'acquia_lift_udf_mappings[event][event_udf' . $i . ']';
}
for ($i = 1; $i <= 20; $i++) {
$fields[] = 'acquia_lift_udf_mappings[touch][touch_udf' . $i . ']';
}
foreach ($fields as $fieldname) {
$this
->assertField($fieldname, 'Found field name: ' . $fieldname);
}
// Confirm required fields
$this
->drupalPost(NULL, array(), $submit_button_text);
$this
->assertText(t('Account ID field is required.'), 'Found error for required account id');
$this
->assertText(t('Site ID field is required.'), 'Found error for required site id');
$this
->assertText(t('Assets URL field is required.'), 'Found error for required assets url');
$this
->assertNoText($submit_confirm_text, 'Confirmation text is not shown');
// Update minimum and confirm values set as variables
$edit = array(
'acquia_lift_account_id' => 'MY_ACCOUNT',
'acquia_lift_site_id' => 'MY_SITE',
'acquia_lift_assets_url' => 'example.com/latest',
);
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_account_id'), 'MY_ACCOUNT', 'Account ID was persisted.');
$this
->assertEqual(variable_get('acquia_lift_site_id'), 'MY_SITE', 'Site ID was persisted.');
$this
->assertEqual(variable_get('acquia_lift_assets_url'), 'https://example.com/latest', 'Assets URL was persisted.');
// Test visibility settings
$test_path_patterns = "/testing\n/testing/*";
$this
->assertNotEqual(variable_get('acquia_lift_ignore_path_patterns'), $test_path_patterns, 'Path patterns are in initial state.');
$edit['acquia_lift_ignore_path_patterns'] = $test_path_patterns;
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_ignore_path_patterns'), $test_path_patterns, 'Visibility path patterns were updated.');
// Test bootstrap mode settings
$this
->assertEqual(variable_get('acquia_lift_bootstrap_mode'), 'auto', 'Bootstrap mode initially saved as auto mode.');
$edit['acquia_lift_bootstrap_mode'] = 'manual';
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_bootstrap_mode'), 'manual', 'Bootstrap mode was updated to manual.');
// Test content replacement mode settings
$this
->assertEqual(variable_get('acquia_lift_content_replacement_mode'), 'untrusted', 'Content replacement initially saved in default untrusted mode.');
$edit['acquia_lift_content_replacement_mode'] = 'trusted';
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_content_replacement_mode'), 'trusted', 'Content replacement mode was updated to trusted.');
// Test content origin settings
$this
->assertEqual(variable_get('acquia_lift_content_origin'), '', 'Content origin data is default to empty.');
$edit['acquia_lift_content_origin'] = '08c93130-2e45-45f6-af6d-7c02de8cd90c';
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_content_origin'), '08c93130-2e45-45f6-af6d-7c02de8cd90c', 'Content origin was updated.');
// Only UDF mappings will values should be stored.
$this
->assertTrue(empty(variable_get('acquia_lift_udf_mappings')), 'UDF Mappings are initially empty.');
$edit['acquia_lift_udf_mappings[person][person_udf1]'] = 'taxonomy_context__tags';
$edit['acquia_lift_udf_mappings[event][event_udf3]'] = 'taxonomy_context__tags';
$edit['acquia_lift_udf_mappings[touch][touch_udf2]'] = 'taxonomy_context__tags';
$edit['acquia_lift_udf_mappings[touch][touch_udf10]'] = 'taxonomy_context__tags';
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$expected = array(
'person' => array(
'person_udf1' => 'taxonomy_context__tags',
),
'event' => array(
'event_udf3' => 'taxonomy_context__tags',
),
'touch' => array(
'touch_udf2' => 'taxonomy_context__tags',
'touch_udf10' => 'taxonomy_context__tags',
),
);
$this
->assertEqual(variable_get('acquia_lift_udf_mappings'), $expected, 'Only udfs set to values are saved.');
$edit['acquia_lift_udf_mappings[event][event_udf3]'] = '';
unset($expected['event']);
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_udf_mappings'), $expected, 'Only udfs types with values set are saved.');
// Confirm field mappings only store those with values.
$this
->assertTrue(empty(variable_get('acquia_lift_field_mappings')), 'Field Mappings are initially empty.');
$edit['acquia_lift_field_mappings[content_section]'] = 'taxonomy_context__tags';
$edit['acquia_lift_field_mappings[content_keywords]'] = 'taxonomy_context__tags';
$edit['acquia_lift_field_mappings[persona]'] = 'taxonomy_context__tags';
$expected = array(
'content_section' => 'taxonomy_context__tags',
'content_keywords' => 'taxonomy_context__tags',
'persona' => 'taxonomy_context__tags',
);
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_field_mappings'), $expected, 'All field mappings fields are updateable as expected.');
$edit['acquia_lift_field_mappings[persona]'] = '';
unset($expected['persona']);
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertEqual(variable_get('acquia_lift_field_mappings'), $expected, 'Only field mappings that have values are stored.');
// Confirm account id validation
$invalid = array(
'1myid',
'account-id',
'Accoun#',
);
$valid = array(
'my_account',
'MYID',
);
foreach ($invalid as $test_id) {
$edit['acquia_lift_account_id'] = $test_id;
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertNoText($submit_confirm_text);
$this
->assertText(t('Account ID contains invalid characters'));
}
foreach ($valid as $test_id) {
$edit['acquia_lift_account_id'] = $test_id;
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertNoText(t('Account ID contains invalid characters'));
}
// Confirm url validation
$url_fields = array(
'acquia_lift_assets_url',
'acquia_lift_decision_api_url',
'acquia_lift_oauth_url',
);
$invalid_urls = array(
'test@%',
'2^',
);
$valid_urls = array(
array(
'test' => 'http://www.example.com/',
'result' => 'https://www.example.com',
),
array(
'test' => 'localhost',
'result' => 'https://localhost',
),
array(
'test' => '/myurl',
'result' => 'https://myurl',
),
);
foreach ($url_fields as $test_field) {
foreach ($invalid_urls as $test) {
$edit[$test_field] = $test;
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertNoText($submit_confirm_text);
$this
->assertText(t('is an invalid URL'), $test . ' is an invalid url.');
}
foreach ($valid_urls as $case) {
$expected_variable = $test_field == 'acquia_lift_oauth_url' ? $case['result'] . '/authorize' : $case['result'];
$edit[$test_field] = $case['test'];
$this
->drupalPost(NULL, $edit, $submit_button_text);
$this
->assertText($submit_confirm_text);
$this
->assertNoText(t('is an invalid URL'), $case['test'] . ' is a valid url');
$this
->assertEqual(variable_get($test_field), $expected_variable, $test_field . ' set to ' . $expected_variable);
}
}
}