Backup of db before drupal security update
[yaffs-website] / web / core / modules / contact / tests / src / Functional / Views / ContactFieldsTest.php
1 <?php
2
3 namespace Drupal\Tests\contact\Functional\Views;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\contact\Entity\ContactForm;
9
10 /**
11  * Tests which checks that no fieldapi fields are added on contact.
12  *
13  * @group contact
14  */
15 class ContactFieldsTest extends ViewTestBase {
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = ['field', 'text', 'contact'];
23
24   /**
25    * Contains the field storage definition for contact used for this test.
26    *
27    * @var \Drupal\field\Entity\FieldStorageConfig
28    */
29   protected $fieldStorage;
30
31   protected function setUp($import_test_views = TRUE) {
32     parent::setUp($import_test_views);
33
34     $this->fieldStorage = FieldStorageConfig::create([
35       'field_name' => strtolower($this->randomMachineName()),
36       'entity_type' => 'contact_message',
37       'type' => 'text'
38     ]);
39     $this->fieldStorage->save();
40
41     ContactForm::create([
42       'id' => 'contact_message',
43       'label' => 'Test contact form',
44     ])->save();
45
46     FieldConfig::create([
47       'field_storage' => $this->fieldStorage,
48       'bundle' => 'contact_message',
49     ])->save();
50
51     $this->container->get('views.views_data')->clear();
52   }
53
54   /**
55    * Tests the views data generation.
56    */
57   public function testViewsData() {
58     // Test that the field is not exposed to views, since contact_message
59     // entities have no storage.
60     $table_name = 'contact_message__' . $this->fieldStorage->getName();
61     $data = $this->container->get('views.views_data')->get($table_name);
62     $this->assertFalse($data, 'The field is not exposed to Views.');
63   }
64
65 }