ContactFieldsTest.php 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

/**
 * @file
 * Contains \Drupal\contact\Tests\Views\ContactFieldsTest.
 */

namespace Drupal\contact\Tests\Views;

use Drupal\views\Tests\ViewTestBase;
11
use Drupal\field\Entity\FieldStorageConfig;
12
13
14

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

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

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

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

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

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

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

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

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

}