ContactFieldsTest.php 1.68 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
 */
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 $field_storage;
33
34
35
36

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

37
    $this->field_storage = entity_create('field_storage_config', array(
38
      'name' => strtolower($this->randomMachineName()),
39
      'entity_type' => 'contact_message',
40
      'type' => 'text'
41
    ));
42
    $this->field_storage->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_storage' => $this->field_storage,
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_storage);
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
  }

}