3 namespace Drupal\field\Tests\Views;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\views\Tests\ViewTestBase;
8 use Drupal\views\Tests\ViewTestData;
9 use Drupal\field\Entity\FieldStorageConfig;
12 * Provides some helper methods for testing fieldapi integration into views.
14 * @todo Test on a generic entity not on a node. What has to be tested:
15 * - Make sure that every wanted field is added to the according entity type.
16 * - Make sure the joins are done correctly.
17 * - Use basic fields and make sure that the full wanted object is built.
18 * - Use relationships between different entity types, for example node and
19 * the node author(user).
21 abstract class FieldTestBase extends ViewTestBase {
28 public static $modules = ['node', 'field_test_views'];
31 * Stores the field definitions used by the test.
35 public $fieldStorages;
38 * Stores the fields of the field storage. They have the same keys as the
45 protected function setUp() {
48 // Ensure the page node type exists.
54 ViewTestData::createTestViews(get_class($this), ['field_test_views']);
57 public function setUpFieldStorages($amount = 3, $type = 'string') {
58 // Create three fields.
60 for ($i = 0; $i < $amount; $i++) {
61 $field_names[$i] = 'field_name_' . $i;
62 $this->fieldStorages[$i] = FieldStorageConfig::create([
63 'field_name' => $field_names[$i],
64 'entity_type' => 'node',
67 $this->fieldStorages[$i]->save();
72 public function setUpFields($bundle = 'page') {
73 foreach ($this->fieldStorages as $key => $field_storage) {
74 $this->fields[$key] = FieldConfig::create([
75 'field_storage' => $field_storage,
78 $this->fields[$key]->save();