ContactFieldsTest.php 1.84 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
15
16
17
18
19
20
21
22
23
24
25
26
27
use Drupal\views\Tests\ViewTestBase;

/**
 * Tests which checks that no fieldapi fields are added on contact.
 */
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.
   *
28
   * @var \Drupal\field\Entity\FieldConfig
29
30
31
32
33
34
35
   */
  protected $field;

  public static function getInfo() {
    return array(
      'name' => 'Contact: Field views data',
      'description' => 'Tests which checks that no fieldapi fields are added on contact.',
36
      'group' => 'Views module integration',
37
38
39
40
41
42
    );
  }

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

43
    $this->field = entity_create('field_config', array(
44
45
      'name' => strtolower($this->randomName()),
      'entity_type' => 'contact_message',
46
      'type' => 'text'
47
48
    ));
    $this->field->save();
49

50
51
52
53
54
    entity_create('contact_category', array(
      'id' => 'contact_message',
      'label' => 'Test contact category',
    ))->save();

55
    entity_create('field_instance_config', array(
56
      'field' => $this->field,
57
      'bundle' => 'contact_message',
58
    ))->save();
59
60

    $this->container->get('views.views_data')->clear();
61
62
63
64
65
66
  }

  /**
   * Tests the views data generation.
   */
  public function testViewsData() {
67
68
    // Test that the field is not exposed to views, since contact_message
    // entities have no storage.
69
    $table_name = ContentEntityDatabaseStorage::_fieldTableName($this->field);
70
    $data = $this->container->get('views.views_data')->get($table_name);
71
    $this->assertFalse($data, 'The field is not exposed to Views.');
72
73
74
  }

}