commit 773c1fd1b78b348b25f9b9ab13c36eeb77f555c3 Author: Lee Rowlands Date: Thu Nov 1 21:51:50 2012 +1000 Fixed last failing tests diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 55701d1..583822b 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -24,14 +24,8 @@ function comment_uninstall() { return TRUE; } }); - foreach ($comment_fields as $entity_type => $bundles) { - foreach ($bundles as $bundle => $fields) { - foreach ($fields as $field_name => $field) { - $instance = field_info_instance($entity_type, $field_name, $bundle); - field_attach_delete_bundle('comment', $field_name); - field_delete_instance($instance); - } - } + foreach ($comment_fields as $field_name => $field) { + field_attach_delete_bundle('comment', $field_name); } } @@ -42,20 +36,20 @@ function comment_uninstall() { function comment_enable() { $comment_fields = comment_get_comment_fields(); $entity_info = entity_get_info(); - foreach ($comment_fields as $entity_type => $bundles) { - foreach ($bundles as $bundle => $fields) { - foreach ($fields as $field_name => $field) { + foreach ($comment_fields as $field_name => $info) { + foreach ($info['bundles'] as $entity_type => $bundles) { + foreach ($bundles as $bundle) { $entity_detail = $entity_info[$entity_type]; - if (!empty($entity_detail['base table']) && - !empty($entity_detail['entity keys']['id'])) { - $table = $entity_detail['base table']; + if (!empty($entity_detail['base_table']) && + !empty($entity_detail['entity_keys']['id'])) { + $table = $entity_detail['base_table']; $schema = drupal_get_schema($table); // Insert records into the comment_entity_statistics for entities that // are missing. $query = db_select($table, 'e'); // Filter by bundle. - $query->condition($entity_detail['entity keys']['bundle'], $bundle); - $query->leftJoin('comment_entity_statistics', 'ces', 'ces.entity_id = e.' . $entity_detail['entity keys']['id'] . ' AND ces.entity_type = ' . $entity_type); + $query->condition($entity_detail['entity_keys']['bundle'], $bundle); + $query->leftJoin('comment_entity_statistics', 'ces', 'ces.entity_id = e.' . $entity_detail['entity_keys']['id'] . " AND ces.entity_type = '$entity_type'"); if (!empty($schema[$table]['fields']['created'])) { $query->addField('e', 'created', 'last_comment_timestamp'); } @@ -70,9 +64,9 @@ function comment_enable() { // No uid field for this entity type, default to anonymous. $query->addExpression(0, 'last_comment_uid'); } - $query->addField('e', $entity_detail['entity keys']['id'], 'entity_id'); - $query->addExpression($entity_type, 'entity_type'); - $query->addExpression($field_name, 'field_name'); + $query->addField('e', $entity_detail['entity_keys']['id'], 'entity_id'); + $query->addExpression("'$entity_type'", 'entity_type'); + $query->addExpression("'$field_name'", 'field_name'); $query->addExpression('0', 'comment_count'); $query->addExpression('NULL', 'last_comment_name'); $query->isNull('ces.comment_count'); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 338e1d0..5f7d0cd 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -476,8 +476,6 @@ function comment_count_unpublished() { * @param string $field_name * Name of the comment field attached to the entity type and bundle. * - * @todo make this trigger when the comment field is created, rather than the - * node type. */ function _comment_body_field_create($entity_type, $bundle, $field_name) { // Create the field if needed. @@ -2079,11 +2077,8 @@ function comment_add_default_comment_field($entity_type, $bundle, $field_name = if (!field_info_field($field_name)) { // Add a default comment field for existing node comments. $field = array( - 'cardinality' => '1', 'field_name' => $field_name, - 'module' => 'comment', 'settings' => array(), - 'translatable' => '0', 'type' => 'comment', ); // Create the field. @@ -2150,12 +2145,30 @@ function comment_add_default_comment_field($entity_type, $bundle, $field_name = } /** - * Implements hook_field_insert(). + * Implements hook_field_create_instance(). */ function comment_field_create_instance($instance) { $field = field_info_field($instance['field_name']); if ($field['type'] == 'comment') { _comment_body_field_create($instance['entity_type'], $instance['bundle'], $instance['field_name']); cache()->delete('comment_entity_info'); + if (module_exists('views')) { + // Refresh views data. + views_fetch_data('comment', TRUE); + } + } +} + +/** + * Implements hook_field_delete_instance(). + */ +function comment_field_delete_instance($instance) { + $field = field_info_field($instance['field_name']); + if ($field['type'] == 'comment') { + cache()->delete('comment_entity_info'); + if (module_exists('views')) { + // Refresh views data. + views_fetch_data('comment'); + } } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index a6e9768..67c661b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -19,7 +19,7 @@ * * @var array */ - public static $modules = array('file', 'file_module_test'); + public static $modules = array('file', 'file_module_test', 'field_test'); protected $profile = 'standard'; diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 052cc9a..dc6faab 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -18,19 +18,17 @@ function forum_install() { variable_set('node_options_forum', array('status')); // Make sure the comment module is loaded. drupal_load('module', 'comment'); - // Add the comment field. - field_info_cache_clear(); - comment_add_default_comment_field('node', 'forum', 'comment_node_forum', COMMENT_ENTITY_OPEN); } /** * Implements hook_enable(). */ function forum_enable() { - // If we enable forum at the same time as taxonomy we need to call + // If we enable forum/comment at the same time as taxonomy we need to call // field_associate_fields() as otherwise the field won't be enabled until // hook modules_enabled is called which takes place after hook_enable events. field_associate_fields('taxonomy'); + field_associate_fields('comment'); // Create the forum vocabulary if it does not exist. // @todo Change Forum module so forum.settings can contain the vocabulary's @@ -113,6 +111,8 @@ function forum_enable() { node_types_rebuild(); $types = node_type_get_types(); node_add_body_field($types['forum']); + // Add the comment field. + comment_add_default_comment_field('node', 'forum', 'comment_node_forum', COMMENT_ENTITY_OPEN); } /** @@ -129,6 +129,7 @@ function forum_uninstall() { // Delete comment field, load comment in case it has been disabled. drupal_load('module', 'comment'); // Remove the forum comment field. + field_associate_fields('comment'); field_delete_field('comment_node_forum'); // Purge field data now to allow taxonomy and comment modules to be @@ -136,7 +137,7 @@ function forum_uninstall() { // field_purge_batch at least twice as the instances won't be removed until // all data is gone, both cannot be removed in the same call. foreach (array('data', 'instances', 'fields') as $step) { - field_purge_batch(50); + field_purge_batch(10); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 2554b49..cfc542b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -48,15 +48,12 @@ public function testLanguageUpgrade() { // Check that both comments display on the node. $this->drupalGet('node/50'); $node = node_load(50); - debug($node); - debug(field_info_instance('node', 'comment_' . $node->type, $node->type)); $this->assertText('Node title 50', 'Node 50 displayed after update.'); $this->assertText('First test comment', 'Comment 1 displayed after update.'); $this->assertText('Reply to first test comment', 'Comment 2 displayed after update.'); // Directly check the comment language property on the first comment. $comment = db_query('SELECT * FROM {comment} WHERE cid = :cid', array(':cid' => 1))->fetchObject(); - debug($comment); $this->assertTrue($comment->langcode == 'und', 'Comment 1 language code found.'); // Ensure that the language switcher has been correctly upgraded. We need to diff --git a/core/modules/views/lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php b/core/modules/views/lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php index cd798a0..5c98e87 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php +++ b/core/modules/views/lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php @@ -85,6 +85,8 @@ public function setUp() { $comment = entity_create('comment', array()); $comment->uid = 0; $comment->entity_type = 'node'; + // Stagger the comments so the timestamp sorting works. + $comment->created = REQUEST_TIME - $i; $comment->field_name = 'comment'; $comment->entity_id = $this->node->nid; $comment->subject = 'Test comment ' . $i; @@ -107,14 +109,14 @@ public function testBlockDisplay() { $this->executeView($view); $map = array( - 'comment_nid' => 'nid', + 'comment_entity_id' => 'entity_id', 'comment_subject' => 'subject', 'cid' => 'cid', 'comment_changed' => 'changed' ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->entity_id; + $expected_result[$key]['entity_id'] = $comment->entity_id; $expected_result[$key]['subject'] = $comment->subject; $expected_result[$key]['cid'] = $comment->cid; $expected_result[$key]['changed'] = $comment->changed; @@ -138,7 +140,7 @@ public function testPageDisplay() { $this->executeView($view); $map = array( - 'comment_nid' => 'nid', + 'comment_entity_id' => 'entity_id', 'comment_subject' => 'subject', 'comment_changed' => 'changed', 'comment_changed' => 'created', @@ -146,7 +148,7 @@ public function testPageDisplay() { ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->entity_id; + $expected_result[$key]['entity_id'] = $comment->entity_id; $expected_result[$key]['subject'] = $comment->subject; $expected_result[$key]['changed'] = $comment->changed; $expected_result[$key]['created'] = $comment->created; diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php index 549162d..5ee93f2 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php @@ -61,7 +61,6 @@ public function testHandlers() { $view = views_new_view(); $view->base_table = $base_table; - debug('base table ' . $base_table); $view = new ViewExecutable($view); // @todo The groupwise relationship is currently broken. diff --git a/core/modules/views/views.module b/core/modules/views/views.module index f6568a4..5cd0bc3 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -1098,6 +1098,9 @@ function views_hook_info() { $hooks['views_data'] = array( 'group' => 'views', ); + $hooks['views_query_substitutions'] = array( + 'group' => 'views', + ); return $hooks; } commit fd6e44249dd91098dfa9f83a68fb9a055d5c8c65 Author: Daniel Wehner Date: Wed Oct 31 16:30:31 2012 -0700 fix some more tests diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php index 49db5b7..da498db 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php @@ -267,7 +267,7 @@ public function testSetRelationship() { // Setup a broken relationship. $view->addItem('default', 'relationship', $this->randomName(), $this->randomName(), array(), 'broken_relationship'); // Setup a valid relationship. - $view->addItem('default', 'relationship', 'comment', 'entity_id', array('relationship' => 'cid'), 'valid_relationship'); + $view->addItem('default', 'relationship', 'comment', 'node', array('relationship' => 'cid'), 'valid_relationship'); $view->initHandlers(); $field = $view->field['title']; diff --git a/core/modules/views/tests/views_test_config/config/views.view.test_handler_relationships.yml b/core/modules/views/tests/views_test_config/config/views.view.test_handler_relationships.yml index 263b7a4..ab03b57 100644 --- a/core/modules/views/tests/views_test_config/config/views.view.test_handler_relationships.yml +++ b/core/modules/views/tests/views_test_config/config/views.view.test_handler_relationships.yml @@ -12,8 +12,8 @@ display: table: node field: title relationships: - comment_node: - id: comment_node + comment_cid: + id: comment_cid table: node field: comment_cid nid: commit dfa5cc8bd509abc17d848f8e824c969e687aa7b4 Author: Daniel Wehner Date: Wed Oct 31 16:04:37 2012 -0700 Fix the handlers all test diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index bc1641b..a2babe7 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -620,12 +620,16 @@ function comment_views_data_alter(&$data) { 'name field' => 'name', 'id' => 'argument_comment_user_uid', 'no group by' => TRUE, + 'entity_type' => $entity_type, + 'entity_id' => $entity_info['entity_keys']['id'], ), 'filter' => array( 'field' => 'uid', 'name table' => 'users', 'name field' => 'name', 'id' => 'comment_user_uid', + 'entity_type' => $entity_type, + 'entity_id' => $entity_info['entity_keys']['id'], ), ); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/argument/UserUid.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/argument/UserUid.php index eae5822..474a66c 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/argument/UserUid.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/argument/UserUid.php @@ -67,8 +67,11 @@ public function query($group_by = FALSE) { $subselect = db_select('comment', 'c'); $subselect->addField('c', 'cid'); $subselect->condition('c.uid', $this->argument); - $subselect->where("c.entity_id = $this->tableAlias." . $entity_info['entity keys']['id']); - $subselect->condition('c.entity_type', $table_info['table']['entity type']); + + $entity_id = $this->definition['entity_id']; + $entity_type = $this->definition['entity_id']; + $subselect->where("c.entity_id = $this->tableAlias.$entity_id"); + $subselect->condition('c.entity_type', $entity_type); $condition = db_or() ->condition("$this->tableAlias.uid", $this->argument, '=') diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/EntityLink.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/EntityLink.php index c12936a..682d2b8 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/EntityLink.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/EntityLink.php @@ -58,7 +58,9 @@ function pre_render(&$values) { $entity = $row->_entity; $entities[$entity->id()] = $entity; } - $this->build = entity_view_multiple($entities, $this->options['teaser'] ? 'teaser' : 'full'); + if ($entities) { + $this->build = entity_view_multiple($entities, $this->options['teaser'] ? 'teaser' : 'full'); + } } /** diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/UserUid.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/UserUid.php index 32eae9c..a9b788e 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/UserUid.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/UserUid.php @@ -29,7 +29,11 @@ public function query() { $subselect = db_select('comment', 'c'); $subselect->addField('c', 'cid'); $subselect->condition('c.uid', $this->value, $this->operator); - $subselect->where("c.nid = $this->tableAlias.nid"); + + $entity_id = $this->definition['entity_id']; + $entity_type = $this->definition['entity_id']; + $subselect->where("c.entity_id = $this->tableAlias.$entity_id"); + $subselect->condition('c.entity_type', $entity_type); $condition = db_or() ->condition("$this->tableAlias.uid", $this->value, $this->operator)