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

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

namespace Drupal\contact\Tests\Views;

10
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
11
12
13
14
use Drupal\views\Tests\ViewTestBase;

/**
 * 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
28
29
 */
class ContactFieldsTest extends ViewTestBase {

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

  /**
   * Contains the field definition array attached to contact used for this test.
   *
30
   * @var \Drupal\field\Entity\FieldConfig
31
32
33
34
35
36
   */
  protected $field;

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

37
    $this->field = entity_create('field_config', array(
38
39
      'name' => strtolower($this->randomName()),
      'entity_type' => 'contact_message',
40
      'type' => 'text'
41
42
    ));
    $this->field->save();
43

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

49
    entity_create('field_instance_config', array(
50
      'field' => $this->field,
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 = ContentEntityDatabaseStorage::_fieldTableName($this->field);
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
  }

}