ContactFieldsTest.php 1.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?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.
14
15
 *
 * @group contact
16
17
18
19
20
21
22
23
24
25
26
 */
class ContactFieldsTest extends ViewTestBase {

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

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

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

36
    $this->fieldStorage = entity_create('field_storage_config', array(
37
      'field_name' => strtolower($this->randomMachineName()),
38
      'entity_type' => 'contact_message',
39
      'type' => 'text'
40
    ));
41
    $this->fieldStorage->save();
42

43
    entity_create('contact_form', array(
44
      'id' => 'contact_message',
45
      'label' => 'Test contact form',
46
47
    ))->save();

48
    entity_create('field_config', array(
49
      'field_storage' => $this->fieldStorage,
50
      'bundle' => 'contact_message',
51
    ))->save();
52
53

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

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

}