Commit 63e448fe authored by catch's avatar catch

Issue #3046377 by naveenvalecha, claudiu.cristea, martin107, catch: Convert...

Issue #3046377 by naveenvalecha, claudiu.cristea, martin107, catch: Convert ContactFieldsTest into a Kernel test
parent 59dd24ad
<?php
namespace Drupal\Tests\contact\Functional\Views;
namespace Drupal\Tests\contact\Kernel\Views;
use Drupal\contact\Entity\ContactForm;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\contact\Entity\ContactForm;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests which checks that no fieldapi fields are added on contact.
* Tests that no storage is created for the contact_message entity.
*
* @group contact
*/
class ContactFieldsTest extends ViewTestBase {
class ContactFieldsTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = ['field', 'text', 'contact'];
protected static $modules = [
'contact',
'field',
'system',
'text',
'user',
'views',
];
/**
* Contains the field storage definition for contact used for this test.
*
* @var \Drupal\field\Entity\FieldStorageConfig
* Tests the views data generation.
*/
protected $fieldStorage;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => strtolower($this->randomMachineName()),
'entity_type' => 'contact_message',
public function testViewsData() {
$this->installConfig(['contact']);
FieldStorageConfig::create([
'type' => 'text',
]);
$this->fieldStorage->save();
'entity_type' => 'contact_message',
'field_name' => $field_name = strtolower($this->randomMachineName()),
])->save();
ContactForm::create([
'id' => 'contact_message',
......@@ -44,22 +43,16 @@ protected function setUp($import_test_views = TRUE) {
])->save();
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'entity_type' => 'contact_message',
'bundle' => 'contact_message',
'field_name' => $field_name,
])->save();
$this->container->get('views.views_data')->clear();
}
/**
* Tests the views data generation.
*/
public function testViewsData() {
// Test that the field is not exposed to views, since contact_message
// entities have no storage.
$table_name = 'contact_message__' . $this->fieldStorage->getName();
$table_name = 'contact_message__' . $field_name;
$data = $this->container->get('views.views_data')->get($table_name);
$this->assertFalse($data, 'The field is not exposed to Views.');
$this->assertFalse($data);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment