ContactFieldsTest.php 1.65 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
use Drupal\contact\Entity\ContactForm;
13
14
15

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

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

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

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

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

45
    ContactForm::create([
46
      'id' => 'contact_message',
47
      'label' => 'Test contact form',
48
    ])->save();
49

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

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

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

}