3 namespace Drupal\Tests\options\Kernel\Views;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
10 use Drupal\views\Tests\ViewTestData;
13 * Base class for options views tests.
15 abstract class OptionsTestBase extends ViewsKernelTestBase {
22 public static $modules = ['options', 'options_test_views', 'node', 'user', 'field'];
25 * Stores the nodes used for the different tests.
29 protected $nodes = [];
32 * Stores the field values used for the different tests.
36 protected $fieldValues = [];
39 * The used field names.
43 protected $fieldNames;
45 protected function setUp($import_test_views = TRUE) {
47 $this->mockStandardInstall();
49 ViewTestData::createTestViews(get_class($this), ['options_test_views']);
52 $settings['type'] = 'article';
53 $settings['title'] = $this->randomString();
54 $settings['field_test_list_string'][]['value'] = $this->fieldValues[0];
55 $settings['field_test_list_integer'][]['value'] = 0;
57 $node = Node::create($settings);
60 $this->nodes[] = $node;
61 $node = $node->createDuplicate();
63 $this->nodes[] = $node;
67 * Provides a workaround for the inability to use the standard profile.
69 * @see https://www.drupal.org/node/1708692
71 protected function mockStandardInstall() {
72 $this->installEntitySchema('user');
73 $this->installEntitySchema('node');
78 $this->fieldValues = [
79 $this->randomMachineName(),
80 $this->randomMachineName(),
83 $this->fieldNames = ['field_test_list_string', 'field_test_list_integer'];
85 // Create two field entities.
86 FieldStorageConfig::create([
87 'field_name' => $this->fieldNames[0],
88 'entity_type' => 'node',
89 'type' => 'list_string',
93 $this->fieldValues[0] => $this->fieldValues[0],
94 $this->fieldValues[1] => $this->fieldValues[1],
98 FieldStorageConfig::create([
99 'field_name' => $this->fieldNames[1],
100 'entity_type' => 'node',
101 'type' => 'list_integer',
104 'allowed_values' => [
105 $this->fieldValues[0],
106 $this->fieldValues[1],
110 foreach ($this->fieldNames as $field_name) {
111 FieldConfig::create([
112 'field_name' => $field_name,
113 'entity_type' => 'node',
114 'label' => 'Test options list field',
115 'bundle' => 'article',