diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index ab03d41..6e33e36 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -117,4 +117,40 @@ function testCommentFormat() { $edit = array('comment_body[und][0][value]' => $this->randomName(8)); $this->drupalPost('node/' . $this->node->nid, $edit, t('Save')); } + + /** + * Tests that comment fields can be managed through the UI. + */ + function testCommentFieldUI() { + // Log in as the administrative user. + $this->drupalLogin($this->admin_user); + + // Create a test node type and a node of that type. + $this->drupalCreateContentType(array('type' => 'test_node_type')); + $node = $this->drupalCreateNode(array('type' => 'test_node_type')); + + // Add a field to the comments for this node type through the UI. + $edit = array( + 'fields[_add_new_field][label]' => t('Test field label'), + 'fields[_add_new_field][field_name]' => 'test_field', + 'fields[_add_new_field][type]' => 'text', + 'fields[_add_new_field][widget_type]' => 'text_textfield', + ); + $this->drupalPost('admin/structure/types/manage/test_node_type/comment/fields', $edit, t('Save')); + + // Confirm that the field is present + $this->drupalGet('comment/reply/' . $node->nid); + $this->assertText(t('Test field label')); + + $this->drupalGet('admin/structure/types/manage/test_node_type/comment/fields'); + + // Delete the field through the UI. + $this->drupalPost('admin/structure/types/manage/test_node_type/comment/fields/field_test_field/delete', array(), t('Delete')); + + // Confirm that the field is no longer present + $this->drupalGet('comment/reply/' . $node->nid); + $this->assertNoText(t('Test field label')); + + } + } diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index ac66c77..b786ca8 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -889,10 +889,18 @@ function field_purge_batch($batch_size) { // field_purge_data() will need the field array. $field = field_info_field_by_id($instance['field_id']); // Retrieve some entities. - $results = $factory->get($entity_type) - ->condition('id:' . $field['id'] . '.deleted', 1) - ->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle) - ->range(0, $batch_size) + $query = $factory->get($entity_type) + ->condition('id:' . $field['id'] . '.deleted', 1); + // Special treatment is required for {taxonomy_term} table as there is no + // vocabulary_machine_name field in the {taxonomy_term} table. + if ($entity_type == 'taxonomy_term') { + $query->condition('vid', taxonomy_vocabulary_machine_name_load($ids->bundle)->vid); + } + else { + $query->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle); + } + + $results = $query->range(0, $batch_size) ->execute(); if ($results) { diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index 17d4bd7..705025e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -353,4 +353,27 @@ function testDuplicateFieldName() { $this->assertText(t('The machine-readable name is already in use. It must be unique.')); $this->assertUrl($url, array(), 'Stayed on the same page.'); } + + /** + * Tests that deletion removes fields and instances as expected for a term. + */ + function testDeleteTaxonomyField() { + // Create a new field. + $bundle_path = 'admin/structure/taxonomy/tags'; + $edit1 = array( + 'fields[_add_new_field][label]' => $this->field_label, + 'fields[_add_new_field][field_name]' => $this->field_name_input, + ); + $this->fieldUIAddNewField($bundle_path, $edit1); + + // Delete the field. + $this->fieldUIDeleteField($bundle_path, $this->field_name, $this->field_label, 'Tags'); + + // Reset the fields info. + field_info_cache_clear(); + // Check that the field instance was deleted. + $this->assertNull(field_info_instance('taxonomy_term', $this->field_name, 'tags'), 'Field instance was deleted.'); + // Check that the field was deleted too. + $this->assertNull(field_info_field($this->field_name), 'Field was deleted.'); + } }