3 namespace Drupal\field\Tests\Views;
5 @trigger_error(__NAMESPACE__ . '\FieldTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\field\Functional\Views\FieldTestBase. See https://www.drupal.org/node/2971931.', E_USER_DEPRECATED);
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\views\Tests\ViewTestBase;
10 use Drupal\views\Tests\ViewTestData;
11 use Drupal\field\Entity\FieldStorageConfig;
14 * Provides some helper methods for testing fieldapi integration into views.
16 * @todo Test on a generic entity not on a node. What has to be tested:
17 * - Make sure that every wanted field is added to the according entity type.
18 * - Make sure the joins are done correctly.
19 * - Use basic fields and make sure that the full wanted object is built.
20 * - Use relationships between different entity types, for example node and
21 * the node author(user).
23 * @deprecated in Drupal 8.6.0. Will be removed before Drupal 9.0.0. Use
24 * \Drupal\Tests\field\Functional\Views\FieldTestBase instead.
26 * @see https://www.drupal.org/node/2989020
28 abstract class FieldTestBase extends ViewTestBase {
35 public static $modules = ['node', 'field_test_views'];
38 * Stores the field definitions used by the test.
42 public $fieldStorages;
45 * Stores the fields of the field storage. They have the same keys as the
52 protected function setUp($import_test_views = TRUE) {
53 parent::setUp($import_test_views);
55 // Ensure the page node type exists.
61 ViewTestData::createTestViews(get_class($this), ['field_test_views']);
64 public function setUpFieldStorages($amount = 3, $type = 'string') {
65 // Create three fields.
67 for ($i = 0; $i < $amount; $i++) {
68 $field_names[$i] = 'field_name_' . $i;
69 $this->fieldStorages[$i] = FieldStorageConfig::create([
70 'field_name' => $field_names[$i],
71 'entity_type' => 'node',
74 $this->fieldStorages[$i]->save();
79 public function setUpFields($bundle = 'page') {
80 foreach ($this->fieldStorages as $key => $field_storage) {
81 $this->fields[$key] = FieldConfig::create([
82 'field_storage' => $field_storage,
85 $this->fields[$key]->save();