summaryrefslogtreecommitdiffstats
path: root/core/modules/contact/src/Tests/Views/ContactFieldsTest.php
blob: 014e9689858321996cbfd92819c0bbfd59039266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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.
 *
 * @group contact
 */
class ContactFieldsTest extends ViewTestBase {

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

  /**
   * Contains the field storage definition for contact used for this test.
   *
   * @var \Drupal\field\Entity\FieldStorageConfig
   */
  protected $fieldStorage;

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

    $this->fieldStorage = entity_create('field_storage_config', array(
      'field_name' => strtolower($this->randomMachineName()),
      'entity_type' => 'contact_message',
      'type' => 'text'
    ));
    $this->fieldStorage->save();

    entity_create('contact_form', array(
      'id' => 'contact_message',
      'label' => 'Test contact form',
    ))->save();

    entity_create('field_config', array(
      'field_storage' => $this->fieldStorage,
      'bundle' => 'contact_message',
    ))->save();

    $this->container->get('views.views_data')->clear();
  }

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

}