diff --git a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..71700305fcef1de0610b9dcde07786fa803b43fd --- /dev/null +++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php @@ -0,0 +1,74 @@ +<?php + +/** + * @file + * Contains \Drupal\contact\Tests\Views\ContactFieldsTest. + */ + +namespace Drupal\contact\Tests\Views; + +use Drupal\views\Tests\ViewTestBase; + +/** + * Tests which checks that no fieldapi fields are added on contact. + */ +class ContactFieldsTest extends ViewTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('field', 'text', 'contact'); + + /** + * Contains the field definition array attached to contact used for this test. + * + * @var array + */ + protected $field; + + public static function getInfo() { + return array( + 'name' => 'Contact: Field views data', + 'description' => 'Tests which checks that no fieldapi fields are added on contact.', + 'group' => 'Views Modules', + ); + } + + protected function setUp() { + parent::setUp(); + + $field = array( + 'field_name' => strtolower($this->randomName()), + 'type' => 'text' + ); + + $this->field = field_create_field($field); + + $instance = array( + 'field_name' => $field['field_name'], + 'entity_type' => 'contact_message', + 'bundle' => 'contact_message', + ); + field_create_instance($instance); + } + + /** + * Tests the views data generation. + */ + public function testViewsData() { + $field_name = $this->field['field_name']; + $table_name = _field_sql_storage_tablename($this->field); + $data = drupal_container()->get('views.views_data')->get($table_name); + + // Test that the expected data array is returned. + $expected = array('', '_value', '_format'); + $this->assertEqual(count($data), count($expected), 'The expected amount of array keys were found.'); + foreach ($expected as $suffix) { + $this->assertTrue(isset($data[$field_name . $suffix])); + } + $this->assertTrue(empty($data['table']['join']), 'The field is not joined to the non existent contact message base table.'); + } + +} diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index de2234972c396e543f2a9ddd72667ce83600de2b..2c5d5db0b735e5d171dac797062be271a312a400 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -127,6 +127,9 @@ function field_views_field_default_views_data($field) { $group_name = $groups[$entity]; } + if (!isset($entity_info['base_table'])) { + continue; + } $entity_tables[$entity_info['base_table']] = $entity; $current_tables[$entity] = $entity_info['base_table']; if (isset($entity_info['revision_table'])) { @@ -201,6 +204,9 @@ function field_views_field_default_views_data($field) { $aliases = array(); $also_known = array(); foreach ($all_labels as $entity_name => $labels) { + if (!isset($current_tables[$entity_name])) { + continue; + } foreach ($labels as $label_name => $true) { if ($type == FIELD_LOAD_CURRENT) { if ($group_name != $groups[$entity_name] || $label != $label_name) {