Commit c9e1f935 authored by alexpott's avatar alexpott

Issue #2394417 by hussainweb, tibbsa, sivaji@knackforge.com: Clean-up field_ui...

Issue #2394417 by hussainweb, tibbsa, sivaji@knackforge.com: Clean-up field_ui module test members - ensure property definition and use of camelCase naming convention
parent 353a1609
......@@ -17,6 +17,11 @@
*/
class EntityDisplayTest extends KernelTestBase {
/**
* Modules to install.
*
* @var string[]
*/
public static $modules = array('field_ui', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system', 'entity_reference');
protected function setUp() {
......
......@@ -17,6 +17,11 @@
*/
class EntityFormDisplayTest extends KernelTestBase {
/**
* Modules to install.
*
* @var string[]
*/
public static $modules = array('field_ui', 'field', 'entity_test', 'field_test', 'user', 'text', 'entity_reference');
protected function setUp() {
......
......@@ -17,7 +17,9 @@
class FieldUIRouteTest extends WebTestBase {
/**
* Modules to enable.
* Modules to install.
*
* @var string[]
*/
public static $modules = array('entity_test', 'field_ui');
......
......@@ -22,7 +22,7 @@ class ManageDisplayTest extends WebTestBase {
use FieldUiTestTrait;
/**
* Modules to enable.
* Modules to install.
*
* @var array
*/
......
......@@ -24,12 +24,40 @@ class ManageFieldsTest extends WebTestBase {
use FieldUiTestTrait;
/**
* Modules to enable.
* Modules to install.
*
* @var array
*/
public static $modules = array('node', 'field_ui', 'field_test', 'taxonomy', 'image', 'block');
/**
* A custom content type created for testing.
*
* @var \Drupal\node\Entity\NodeType
*/
protected $contentType;
/**
* The label for a random field to be created for testing.
*
* @var string
*/
protected $fieldLabel;
/**
* The input name of a random field to be created for testing.
*
* @var string
*/
protected $fieldNameInput;
/**
* The name of a random field to be created for testing.
*
* @var string
*/
protected $fieldName;
/**
* {@inheritdoc}
*/
......@@ -44,12 +72,12 @@ protected function setUp() {
// Create content type, with underscores.
$type_name = strtolower($this->randomMachineName(8)) . '_test';
$type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
$this->type = $type->id();
$this->contentType = $type->id();
// Create random field name.
$this->field_label = $this->randomMachineName(8);
$this->field_name_input = strtolower($this->randomMachineName(8));
$this->field_name = 'field_'. $this->field_name_input;
$this->fieldLabel = $this->randomMachineName(8);
$this->fieldNameInput = strtolower($this->randomMachineName(8));
$this->fieldName = 'field_'. $this->fieldNameInput;
// Create Basic page and Article node types.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
......@@ -105,7 +133,7 @@ function testCRUDFields() {
* (optional) The name of a content type.
*/
function manageFieldsPage($type = '') {
$type = empty($type) ? $this->type : $type;
$type = empty($type) ? $this->contentType : $type;
$this->drupalGet('admin/structure/types/manage/' . $type . '/fields');
// Check all table columns.
$table_headers = array(
......@@ -138,16 +166,16 @@ function manageFieldsPage($type = '') {
*/
function createField() {
// Create a test field.
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $this->field_name_input, $this->field_label);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
}
/**
* Tests editing an existing field.
*/
function updateField() {
$field_id = 'node.' . $this->type . '.' . $this->field_name;
$field_id = 'node.' . $this->contentType . '.' . $this->fieldName;
// Go to the field edit page.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/' . $field_id . '/storage');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id . '/storage');
// Populate the field settings with new settings.
$string = 'updated dummy test string';
......@@ -157,7 +185,7 @@ function updateField() {
$this->drupalPostForm(NULL, $edit, t('Save field settings'));
// Go to the field edit page.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/' . $field_id);
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id);
$edit = array(
'field[settings][test_field_setting]' => $string,
);
......@@ -165,10 +193,10 @@ function updateField() {
$this->drupalPostForm(NULL, $edit, t('Save settings'));
// Assert the field settings are correct.
$this->assertFieldSettings($this->type, $this->field_name, $string);
$this->assertFieldSettings($this->contentType, $this->fieldName, $string);
// Assert redirection back to the "manage fields" page.
$this->assertUrl('admin/structure/types/manage/' . $this->type . '/fields');
$this->assertUrl('admin/structure/types/manage/' . $this->contentType . '/fields');
}
/**
......@@ -183,10 +211,10 @@ function addExistingField() {
// do not show up in the "Re-use existing field" list.
$this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value="comment"]'), 'The list of options respects entity type restrictions.');
// Validate the FALSE assertion above by also testing a valid one.
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $this->field_name)), 'The list of options shows a valid option.');
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $this->fieldName)), 'The list of options shows a valid option.');
// Add a new field based on an existing field.
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->field_name, $this->field_label . '_2');
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName, $this->fieldLabel . '_2');
}
/**
......@@ -240,8 +268,8 @@ function cardinalitySettings() {
*/
protected function deleteField() {
// Delete the field.
$field_id = 'node.' . $this->type . '.' . $this->field_name;
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/' . $field_id);
$field_id = 'node.' . $this->contentType . '.' . $this->fieldName;
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id);
$this->drupalPostForm(NULL, array(), t('Delete field'));
$this->assertResponse(200);
}
......@@ -250,20 +278,20 @@ protected function deleteField() {
* Tests that persistent field storage appears in the field UI.
*/
protected function addPersistentFieldStorage() {
$field_storage = FieldStorageConfig::loadByName('node', $this->field_name);
$field_storage = FieldStorageConfig::loadByName('node', $this->fieldName);
// Persist the field storage even if there are no fields.
$field_storage->set('persist_with_no_fields', TRUE)->save();
// Delete all instances of the field.
foreach ($field_storage->getBundles() as $node_type) {
// Delete all the body field instances.
$this->drupalPostForm('admin/structure/types/manage/' . $node_type . '/fields/node.' . $node_type . '.' . $this->field_name, array(), t('Delete field'));
$this->drupalPostForm('admin/structure/types/manage/' . $node_type . '/fields/node.' . $node_type . '.' . $this->fieldName, array(), t('Delete field'));
$this->drupalPostForm(NULL, array(), t('Delete'));
}
// Check "Re-use existing field" appears.
$this->drupalGet('admin/structure/types/manage/page/fields/add-field');
$this->assertRaw(t('Re-use an existing field'), '"Re-use existing field" was found.');
// Add a new field for the orphaned storage.
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->field_name);
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName);
}
/**
......@@ -305,13 +333,13 @@ function testFieldPrefix() {
'label' => $field_exceed_max_length_label,
'field_name' => $field_exceed_max_length_input,
);
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/fields/add-field', $edit, t('Save and continue'));
$this->drupalPostForm('admin/structure/types/manage/' . $this->contentType . '/fields/add-field', $edit, t('Save and continue'));
$this->assertText('Machine-readable name cannot be longer than 22 characters but is currently 23 characters long.');
// Create a valid field.
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $this->field_name_input, $this->field_label);
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $field_prefix . $this->field_name_input);
$this->assertText(format_string('@label settings for @type', array('@label' => $this->field_label, '@type' => $this->type)));
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_prefix . $this->fieldNameInput);
$this->assertText(format_string('@label settings for @type', array('@label' => $this->fieldLabel, '@type' => $this->contentType)));
}
/**
......@@ -328,15 +356,15 @@ function testDefaultValue() {
$field = entity_create('field_config', array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $this->type,
'bundle' => $this->contentType,
));
$field->save();
entity_get_form_display('node', $this->type, 'default')
entity_get_form_display('node', $this->contentType, 'default')
->setComponent($field_name)
->save();
$admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/' . $field->id();
$admin_path = 'admin/structure/types/manage/' . $this->contentType . '/fields/' . $field->id();
$element_id = "edit-default-value-input-$field_name-0-value";
$element_name = "default_value_input[{$field_name}][0][value]";
$this->drupalGet($admin_path);
......@@ -351,7 +379,7 @@ function testDefaultValue() {
$edit = array($element_name => '1');
$this->drupalPostForm($admin_path, $edit, t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->type, $field_name);
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
$this->assertEqual($field->default_value, array(array('value' => 1)), 'The default value was correctly saved.');
// Check that the default value shows up in the form
......@@ -362,7 +390,7 @@ function testDefaultValue() {
$edit = array($element_name => '');
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->type, $field_name);
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
$this->assertEqual($field->default_value, NULL, 'The default value was correctly saved.');
// Check that the default value can be empty when the field is marked as
......@@ -380,7 +408,7 @@ function testDefaultValue() {
$this->drupalGet($admin_path);
$this->drupalPostForm(NULL, array(), t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->type, $field_name);
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
$this->assertEqual($field->default_value, NULL, 'The default value was correctly saved.');
// Check that the default widget is used when the field is hidden.
......@@ -395,8 +423,8 @@ function testDefaultValue() {
*/
function testDeleteField() {
// Create a new field.
$bundle_path1 = 'admin/structure/types/manage/' . $this->type;
$this->fieldUIAddNewField($bundle_path1, $this->field_name_input, $this->field_label);
$bundle_path1 = 'admin/structure/types/manage/' . $this->contentType;
$this->fieldUIAddNewField($bundle_path1, $this->fieldNameInput, $this->fieldLabel);
// Create an additional node type.
$type_name2 = strtolower($this->randomMachineName(8)) . '_test';
......@@ -405,23 +433,23 @@ function testDeleteField() {
// Add a field to the second node type.
$bundle_path2 = 'admin/structure/types/manage/' . $type_name2;
$this->fieldUIAddExistingField($bundle_path2, $this->field_name, $this->field_label);
$this->fieldUIAddExistingField($bundle_path2, $this->fieldName, $this->fieldLabel);
// Delete the first field.
$this->fieldUIDeleteField($bundle_path1, "node.$this->type.$this->field_name", $this->field_label, $this->type);
$this->fieldUIDeleteField($bundle_path1, "node.$this->contentType.$this->fieldName", $this->fieldLabel, $this->contentType);
// Check that the field was deleted.
$this->assertNull(FieldConfig::loadByName('node', $this->type, $this->field_name), 'Field was deleted.');
$this->assertNull(FieldConfig::loadByName('node', $this->contentType, $this->fieldName), 'Field was deleted.');
// Check that the field storage was not deleted
$this->assertNotNull(FieldStorageConfig::loadByName('node', $this->field_name), 'Field storage was not deleted.');
$this->assertNotNull(FieldStorageConfig::loadByName('node', $this->fieldName), 'Field storage was not deleted.');
// Delete the second field.
$this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$this->field_name", $this->field_label, $type_name2);
$this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$this->fieldName", $this->fieldLabel, $type_name2);
// Check that the field was deleted.
$this->assertNull(FieldConfig::loadByName('node', $type_name2, $this->field_name), 'Field was deleted.');
$this->assertNull(FieldConfig::loadByName('node', $type_name2, $this->fieldName), 'Field was deleted.');
// Check that the field storage was deleted too.
$this->assertNull(FieldStorageConfig::loadByName('node', $this->field_name), 'Field storage was deleted.');
$this->assertNull(FieldStorageConfig::loadByName('node', $this->fieldName), 'Field storage was deleted.');
}
/**
......@@ -439,13 +467,13 @@ function testDisallowedFieldNames() {
// Try with an entity key.
$edit['field_name'] = 'title';
$bundle_path = 'admin/structure/types/manage/' . $this->type;
$bundle_path = 'admin/structure/types/manage/' . $this->contentType;
$this->drupalPostForm("$bundle_path/fields/add-field", $edit, t('Save and continue'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
// Try with a base field.
$edit['field_name'] = 'sticky';
$bundle_path = 'admin/structure/types/manage/' . $this->type;
$bundle_path = 'admin/structure/types/manage/' . $this->contentType;
$this->drupalPostForm("$bundle_path/fields/add-field", $edit, t('Save and continue'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
}
......@@ -467,23 +495,23 @@ function testLockedField() {
$field_storage->save();
entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => $this->type,
'bundle' => $this->contentType,
))->save();
entity_get_form_display('node', $this->type, 'default')
entity_get_form_display('node', $this->contentType, 'default')
->setComponent($field_name, array(
'type' => 'test_field_widget',
))
->save();
// Check that the links for edit and delete are not present.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
$locked = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
$this->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');
$edit_link = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
$this->assertFalse(in_array('edit', $edit_link), 'Edit option for locked field is not present the UI');
$delete_link = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
$this->assertFalse(in_array('delete', $delete_link), 'Delete option for locked field is not present the UI');
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $field_name . '/delete');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
$this->assertResponse(403);
}
......@@ -492,7 +520,7 @@ function testLockedField() {
*/
function testHiddenFields() {
// Check that the field type is not available in the 'add new field' row.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/add-field');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/add-field');
$this->assertFalse($this->xpath('//select[@id="edit-new-storage-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property.");
$this->assertTrue($this->xpath('//select[@id="edit-new-storage-type"]//option[@value="shape"]'), "The 'add new field' select shows a valid option.");
......@@ -505,19 +533,19 @@ function testHiddenFields() {
))->save();
$field = array(
'field_name' => $field_name,
'bundle' => $this->type,
'bundle' => $this->contentType,
'entity_type' => 'node',
'label' => t('Hidden field'),
);
entity_create('field_config', $field)->save();
entity_get_form_display('node', $this->type, 'default')
entity_get_form_display('node', $this->contentType, 'default')
->setComponent($field_name)
->save();
$this->assertTrue(FieldConfig::load('node.' . $this->type . '.' . $field_name), format_string('A field of the field storage %field was created programmatically.', array('%field' => $field_name)));
$this->assertTrue(FieldConfig::load('node.' . $this->contentType . '.' . $field_name), format_string('A field of the field storage %field was created programmatically.', array('%field' => $field_name)));
// Check that the newly added field appears on the 'Manage Fields'
// screen.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields');
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
$this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="hidden-test-field"]//td[1]', $field['label'], 'Field was created and appears in the overview page.');
// Check that the field does not appear in the 're-use existing field' row
......@@ -547,7 +575,7 @@ function testRenameBundle() {
$options = array(
'type' => $type2,
);
$this->drupalPostForm('admin/structure/types/manage/' . $this->type, $options, t('Save content type'));
$this->drupalPostForm('admin/structure/types/manage/' . $this->contentType, $options, t('Save content type'));
$this->manageFieldsPage($type2);
}
......@@ -562,7 +590,7 @@ function testDuplicateFieldName() {
'label' => $this->randomMachineName(),
'new_storage_type' => 'taxonomy_term_reference',
);
$url = 'admin/structure/types/manage/' . $this->type . '/fields/add-field';
$url = 'admin/structure/types/manage/' . $this->contentType . '/fields/add-field';
$this->drupalPostForm($url, $edit, t('Save and continue'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
......@@ -576,15 +604,15 @@ function testDeleteTaxonomyField() {
// Create a new field.
$bundle_path = 'admin/structure/taxonomy/manage/tags/overview';
$this->fieldUIAddNewField($bundle_path, $this->field_name_input, $this->field_label);
$this->fieldUIAddNewField($bundle_path, $this->fieldNameInput, $this->fieldLabel);
// Delete the field.
$this->fieldUIDeleteField($bundle_path, "taxonomy_term.tags.$this->field_name", $this->field_label, 'Tags');
$this->fieldUIDeleteField($bundle_path, "taxonomy_term.tags.$this->fieldName", $this->fieldLabel, 'Tags');
// Check that the field was deleted.
$this->assertNull(FieldConfig::loadByName('taxonomy_term', 'tags', $this->field_name), 'Field was deleted.');
$this->assertNull(FieldConfig::loadByName('taxonomy_term', 'tags', $this->fieldName), 'Field was deleted.');
// Check that the field storage was deleted too.
$this->assertNull(FieldStorageConfig::loadByName('taxonomy_term', $this->field_name), 'Field storage was deleted.');
$this->assertNull(FieldStorageConfig::loadByName('taxonomy_term', $this->fieldName), 'Field storage was deleted.');
}
/**
......@@ -632,7 +660,7 @@ function testHelpDescriptions() {
*/
function fieldListAdminPage() {
$this->drupalGet('admin/reports/fields');
$this->assertText($this->field_name, 'Field name is displayed in field list.');
$this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->type . '/fields'), 'Link to content type using field is displayed in field list.');
$this->assertText($this->fieldName, 'Field name is displayed in field list.');
$this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->contentType . '/fields'), 'Link to content type using field is displayed in field list.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment