ContactFieldsTest.php 1.6 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\contact\Tests\Views;

5
use Drupal\field\Entity\FieldConfig;
6
use Drupal\views\Tests\ViewTestBase;
7
use Drupal\field\Entity\FieldStorageConfig;
8
use Drupal\contact\Entity\ContactForm;
9 10 11

/**
 * Tests which checks that no fieldapi fields are added on contact.
12 13
 *
 * @group contact
14 15 16 17 18 19 20 21 22 23 24
 */
class ContactFieldsTest extends ViewTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('field', 'text', 'contact');

  /**
25
   * Contains the field storage definition for contact used for this test.
26
   *
27
   * @var \Drupal\field\Entity\FieldStorageConfig
28
   */
29
  protected $fieldStorage;
30 31 32 33

  protected function setUp() {
    parent::setUp();

34
    $this->fieldStorage = FieldStorageConfig::create(array(
35
      'field_name' => strtolower($this->randomMachineName()),
36
      'entity_type' => 'contact_message',
37
      'type' => 'text'
38
    ));
39
    $this->fieldStorage->save();
40

41
    ContactForm::create([
42
      'id' => 'contact_message',
43
      'label' => 'Test contact form',
44
    ])->save();
45

46
    FieldConfig::create([
47
      'field_storage' => $this->fieldStorage,
48
      'bundle' => 'contact_message',
49
    ])->save();
50 51

    $this->container->get('views.views_data')->clear();
52 53 54 55 56 57
  }

  /**
   * Tests the views data generation.
   */
  public function testViewsData() {
58 59
    // Test that the field is not exposed to views, since contact_message
    // entities have no storage.
60
    $table_name = 'contact_message__' . $this->fieldStorage->getName();
61
    $data = $this->container->get('views.views_data')->get($table_name);
62
    $this->assertFalse($data, 'The field is not exposed to Views.');
63 64 65
  }

}