Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\field\Tests\Views;
|
Chris@0
|
4
|
Chris@17
|
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);
|
Chris@17
|
6
|
Chris@0
|
7 use Drupal\field\Entity\FieldConfig;
|
Chris@0
|
8 use Drupal\node\Entity\NodeType;
|
Chris@0
|
9 use Drupal\views\Tests\ViewTestBase;
|
Chris@0
|
10 use Drupal\views\Tests\ViewTestData;
|
Chris@0
|
11 use Drupal\field\Entity\FieldStorageConfig;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Provides some helper methods for testing fieldapi integration into views.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @todo Test on a generic entity not on a node. What has to be tested:
|
Chris@0
|
17 * - Make sure that every wanted field is added to the according entity type.
|
Chris@0
|
18 * - Make sure the joins are done correctly.
|
Chris@0
|
19 * - Use basic fields and make sure that the full wanted object is built.
|
Chris@0
|
20 * - Use relationships between different entity types, for example node and
|
Chris@0
|
21 * the node author(user).
|
Chris@17
|
22 *
|
Chris@17
|
23 * @deprecated in Drupal 8.6.0. Will be removed before Drupal 9.0.0. Use
|
Chris@17
|
24 * \Drupal\Tests\field\Functional\Views\FieldTestBase instead.
|
Chris@17
|
25 *
|
Chris@17
|
26 * @see https://www.drupal.org/node/2989020
|
Chris@0
|
27 */
|
Chris@0
|
28 abstract class FieldTestBase extends ViewTestBase {
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * Modules to enable.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @var array
|
Chris@0
|
34 */
|
Chris@0
|
35 public static $modules = ['node', 'field_test_views'];
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Stores the field definitions used by the test.
|
Chris@0
|
39 *
|
Chris@0
|
40 * @var array
|
Chris@0
|
41 */
|
Chris@0
|
42 public $fieldStorages;
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * Stores the fields of the field storage. They have the same keys as the
|
Chris@0
|
46 * field storages.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @var array
|
Chris@0
|
49 */
|
Chris@0
|
50 public $fields;
|
Chris@0
|
51
|
Chris@14
|
52 protected function setUp($import_test_views = TRUE) {
|
Chris@14
|
53 parent::setUp($import_test_views);
|
Chris@0
|
54
|
Chris@0
|
55 // Ensure the page node type exists.
|
Chris@0
|
56 NodeType::create([
|
Chris@0
|
57 'type' => 'page',
|
Chris@0
|
58 'name' => 'page',
|
Chris@0
|
59 ])->save();
|
Chris@0
|
60
|
Chris@0
|
61 ViewTestData::createTestViews(get_class($this), ['field_test_views']);
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 public function setUpFieldStorages($amount = 3, $type = 'string') {
|
Chris@0
|
65 // Create three fields.
|
Chris@0
|
66 $field_names = [];
|
Chris@0
|
67 for ($i = 0; $i < $amount; $i++) {
|
Chris@0
|
68 $field_names[$i] = 'field_name_' . $i;
|
Chris@0
|
69 $this->fieldStorages[$i] = FieldStorageConfig::create([
|
Chris@0
|
70 'field_name' => $field_names[$i],
|
Chris@0
|
71 'entity_type' => 'node',
|
Chris@0
|
72 'type' => $type,
|
Chris@0
|
73 ]);
|
Chris@0
|
74 $this->fieldStorages[$i]->save();
|
Chris@0
|
75 }
|
Chris@0
|
76 return $field_names;
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 public function setUpFields($bundle = 'page') {
|
Chris@0
|
80 foreach ($this->fieldStorages as $key => $field_storage) {
|
Chris@0
|
81 $this->fields[$key] = FieldConfig::create([
|
Chris@0
|
82 'field_storage' => $field_storage,
|
Chris@0
|
83 'bundle' => $bundle,
|
Chris@0
|
84 ]);
|
Chris@0
|
85 $this->fields[$key]->save();
|
Chris@0
|
86 }
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 }
|