function ContactFieldsTest::testViewsData

Same name and namespace in other branches
  1. 9 core/modules/contact/tests/src/Kernel/Views/ContactFieldsTest.php \Drupal\Tests\contact\Kernel\Views\ContactFieldsTest::testViewsData()
  2. 8.9.x core/modules/contact/tests/src/Kernel/Views/ContactFieldsTest.php \Drupal\Tests\contact\Kernel\Views\ContactFieldsTest::testViewsData()
  3. 10 core/modules/contact/tests/src/Kernel/Views/ContactFieldsTest.php \Drupal\Tests\contact\Kernel\Views\ContactFieldsTest::testViewsData()

Tests the views data generation.

File

core/modules/contact/tests/src/Kernel/Views/ContactFieldsTest.php, line 34

Class

ContactFieldsTest
Tests that no storage is created for the contact_message entity.

Namespace

Drupal\Tests\contact\Kernel\Views

Code

public function testViewsData() : void {
    $this->installConfig([
        'contact',
    ]);
    FieldStorageConfig::create([
        'type' => 'text',
        'entity_type' => 'contact_message',
        'field_name' => $field_name = $this->randomMachineName(),
    ])
        ->save();
    ContactForm::create([
        'id' => 'contact_message',
        'label' => 'Test contact form',
    ])->save();
    FieldConfig::create([
        'entity_type' => 'contact_message',
        'bundle' => 'contact_message',
        'field_name' => $field_name,
    ])->save();
    // Test that the field is not exposed to views, since contact_message
    // entities have no storage.
    $table_name = 'contact_message__' . $field_name;
    $data = $this->container
        ->get('views.views_data')
        ->get($table_name);
    $this->assertEmpty($data);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.