Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,55 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.options_install_test.body
- node.type.options_install_test
module:
- text
id: node.options_install_test.default
targetEntityType: node
bundle: options_install_test
mode: default
content:
title:
type: string_textfield
weight: -5
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
created:
type: datetime_timestamp
weight: 10
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 16
third_party_settings: { }
body:
type: text_textarea_with_summary
weight: 26
settings:
rows: 9
summary_rows: 3
placeholder: ''
third_party_settings: { }
hidden: { }
third_party_settings: { }

View file

@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.options_install_test.body
- node.type.options_install_test
module:
- text
- user
id: node.options_install_test.default
targetEntityType: node
bundle: options_install_test
mode: default
content:
links:
weight: 100
body:
label: hidden
type: text_default
weight: 101
settings: { }
third_party_settings: { }
hidden:
langcode: true
third_party_settings: { }

View file

@ -0,0 +1,27 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.options_install_test.body
- node.type.options_install_test
module:
- text
- user
id: node.options_install_test.teaser
targetEntityType: node
bundle: options_install_test
mode: teaser
content:
links:
weight: 100
body:
label: hidden
type: text_summary_or_trimmed
weight: 101
settings:
trim_length: 600
third_party_settings: { }
hidden:
langcode: true
third_party_settings: { }

View file

@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.body
- node.type.options_install_test
id: node.options_install_test.body
field_name: body
entity_type: node
bundle: options_install_test
label: Body
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
display_summary: true
third_party_settings: { }
field_type: text_with_summary

View file

@ -0,0 +1,19 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_options_float
- node.type.options_install_test
id: node.options_install_test.field_options_float
field_name: field_options_float
entity_type: node
bundle: options_install_test
label: field_options_float
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
third_party_settings: { }
field_type: list_float

View file

@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
module:
- node
- options
id: node.field_options_float
field_name: field_options_float
entity_type: node
type: list_float
settings:
allowed_values:
-
value: !!float 0
label: Zero
-
value: 0.5
label: 'Point five'
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,11 @@
langcode: en
status: true
dependencies: { }
name: options_install_test
type: options_install_test
description: null
help: null
new_revision: false
preview_mode: 1
display_submitted: true
third_party_settings: { }

View file

@ -0,0 +1,9 @@
name: 'Options config install test'
type: module
description: 'Support module for the Options module tests.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- node
- options

View file

@ -0,0 +1,6 @@
name: 'Options test'
type: module
description: 'Support module for the Options module tests.'
core: 8.x
package: Testing
version: VERSION

View file

@ -0,0 +1,56 @@
<?php
/**
* @file
* Helper module for the List module tests.
*/
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Implements callback_allowed_values_function().
*
* @see options_allowed_values()
*/
function options_test_allowed_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) {
$values = array(
'Group 1' => array(
0 => 'Zero',
),
1 => 'One',
'Group 2' => array(
2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
),
'More <script>dangerous</script> markup' => array(
3 => 'Three',
),
);
return $values;
}
/**
* Implements callback_allowed_values_function().
*
* @todo This function violates the recommendation in options_allowed_values()
* to return a list of all possible values in any context when $items is
* NULL. Since this is not yet used for testing Views integration, that is
* alright for now. Fix this in https://www.drupal.org/node/2012130.
*
* @see options_allowed_values()
*/
function options_test_dynamic_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {
$values = array();
if (isset($entity)) {
$cacheable = FALSE;
$values = array(
$entity->label(),
$entity->url(),
$entity->uuid(),
$entity->bundle(),
);
}
// We need the values of the entity as keys.
return array_combine($values, $values);
}

View file

@ -0,0 +1,9 @@
name: 'Options test views'
type: module
description: 'Provides default views for views options tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- options
- views

View file

@ -0,0 +1,200 @@
langcode: en
status: true
dependencies:
config:
- node.type.article
module:
- node
- user
id: test_options_list_argument_numeric
label: 'test options list argument (numeric)'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: some
options:
items_per_page: 5
offset: 0
style:
type: default
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
plugin_id: field
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: ''
group: 1
plugin_id: boolean
type:
id: type
table: node_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value:
article: article
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: bundle
sorts:
nid:
id: nid
table: nid
field: nid
order: DESC
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
plugin_id: standard
title: 'test options list argument'
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
field_test_list_integer_value:
id: field_test_list_integer_value
table: field_data_field_test_list_integer
field: field_test_list_integer_value
relationship: none
group_type: group
admin_label: ''
default_action: empty
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
items_per_page: 25
count: false
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
human: true
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
plugin_id: number_list_field
display_extenders: { }
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }

View file

@ -0,0 +1,199 @@
langcode: en
status: true
dependencies:
config:
- node.type.article
module:
- node
- user
id: test_options_list_argument_string
label: 'test options list argument (string)'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: some
options:
items_per_page: 5
offset: 0
style:
type: default
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
plugin_id: field
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: ''
group: 1
plugin_id: boolean
type:
id: type
table: node_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value:
article: article
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: bundle
sorts:
nid:
id: nid
table: nid
field: nid
order: DESC
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
plugin_id: standard
title: 'test options list argument'
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
field_test_list_string_value:
id: field_test_list_string_value
table: field_data_field_test_list_string
field: field_test_list_string_value
relationship: none
group_type: group
admin_label: ''
default_action: empty
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
items_per_page: 25
count: false
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
human: true
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
plugin_id: string_list_field
display_extenders: { }
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }

View file

@ -0,0 +1,204 @@
langcode: en
status: true
dependencies:
config:
- node.type.article
module:
- node
- user
id: test_options_list_filter
label: test_options_list_filter
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: some
options:
items_per_page: 5
offset: 0
style:
type: default
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
plugin_id: field
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: ''
group: 1
plugin_id: boolean
field_test_list_string_value:
id: field_test_list_string_value
table: field_data_field_test_list_string
field: field_test_list_string_value
relationship: none
group_type: group
admin_label: ''
operator: or
value:
man: man
woman: woman
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
plugin_id: list_field
type:
id: type
table: node_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value:
article: article
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: bundle
sorts:
nid:
id: nid
table: nid
field: nid
order: DESC
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
plugin_id: standard
title: test_options_list_filter
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }

View file

@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\options\Kernel;
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests for the 'Options' field types.
*
* @group options
*/
class OptionsFieldTest extends OptionsFieldUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('options');
/**
* Test that allowed values can be updated.
*/
function testUpdateAllowedValues() {
// All three options appear.
$entity = EntityTest::create();
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists');
// Use one of the values in an actual entity, and check that this value
// cannot be removed from the list.
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 1;
$entity->save();
$this->fieldStorage->setSetting('allowed_values', [2 => 'Two']);
try {
$this->fieldStorage->save();
$this->fail(t('Cannot update a list field storage to not include keys with existing data.'));
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass(t('Cannot update a list field storage to not include keys with existing data.'));
}
// Empty the value, so that we can actually remove the option.
unset($entity->{$this->fieldName});
$entity->save();
// Removed options do not appear.
$this->fieldStorage->setSetting('allowed_values', [2 => 'Two']);
$this->fieldStorage->save();
$entity = EntityTest::create();
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
$this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist');
// Completely new options appear.
$this->fieldStorage->setSetting('allowed_values', [10 => 'Update', 20 => 'Twenty']);
$this->fieldStorage->save();
// The entity holds an outdated field object with the old allowed values
// setting, so we need to reinitialize the entity object.
$entity = EntityTest::create();
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist');
$this->assertTrue(empty($form[$this->fieldName]['widget'][2]), 'Option 2 does not exist');
$this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][10]), 'Option 10 exists');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][20]), 'Option 20 exists');
// Options are reset when a new field with the same name is created.
$this->fieldStorage->delete();
FieldStorageConfig::create($this->fieldStorageDefinition)->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'required' => TRUE,
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, array(
'type' => 'options_buttons',
))
->save();
$entity = EntityTest::create();
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists');
// Test the generateSampleValue() method.
$entity = EntityTest::create();
$entity->{$this->fieldName}->generateSampleItems();
$this->entityValidateAndSave($entity);
}
}

View file

@ -0,0 +1,81 @@
<?php
namespace Drupal\Tests\options\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Base class for Options module integration tests.
*/
abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('options');
/**
* The field name used in the test.
*
* @var string
*/
protected $fieldName = 'test_options';
/**
* The field storage definition used to created the field storage.
*
* @var array
*/
protected $fieldStorageDefinition;
/**
* The list field storage used in the test.
*
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
/**
* The list field used in the test.
*
* @var \Drupal\field\Entity\FieldConfig
*/
protected $field;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->container->get('router.builder')->rebuild();
$this->fieldStorageDefinition = array(
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'list_integer',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'),
),
);
$this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
]);
$this->field->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, array(
'type' => 'options_buttons',
))
->save();
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\options\Kernel;
use Drupal\entity_test\Entity\EntityTest;
/**
* Tests the Options field type formatters.
*
* @group options
* @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsDefaultFormatter
* @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
*/
class OptionsFormattersTest extends OptionsFieldUnitTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
}
/**
* Tests the formatters.
*/
public function testFormatter() {
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 1;
$items = $entity->get($this->fieldName);
$build = $items->view();
$this->assertEqual($build['#formatter'], 'list_default', 'Ensure to fall back to the default formatter.');
$this->assertEqual($build[0]['#markup'], 'One');
$build = $items->view(array('type' => 'list_key'));
$this->assertEqual($build['#formatter'], 'list_key', 'The chosen formatter is used.');
$this->assertEqual((string) $build[0]['#markup'], 1);
}
}

View file

@ -0,0 +1,92 @@
<?php
namespace Drupal\Tests\options\Kernel\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
/**
* Tests file views data.
*
* @group file
*/
class FileViewsDataTest extends ViewsKernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('file', 'views', 'entity_test', 'user', 'field');
/**
* Tests views data generated for file field relationship.
*
* @see file_field_views_data()
* @see file_field_views_data_views_data_alter()
*/
public function testRelationshipViewsData() {
// Create file field to entity_test.
FieldStorageConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_base_file',
'type' => 'file',
))->save();
FieldConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_base_file',
'bundle' => 'entity_test',
))->save();
// Check the generated views data.
$views_data = Views::viewsData()->get('entity_test__field_base_file');
$relationship = $views_data['field_base_file_target_id']['relationship'];
$this->assertEqual($relationship['id'], 'standard');
$this->assertEqual($relationship['base'], 'file_managed');
$this->assertEqual($relationship['base field'], 'fid');
$this->assertEqual($relationship['entity type'], 'file');
// Check the backwards reference.
$views_data = Views::viewsData()->get('file_managed');
$relationship = $views_data['reverse_field_base_file_entity_test']['relationship'];
$this->assertEqual($relationship['id'], 'entity_reverse');
$this->assertEqual($relationship['base'], 'entity_test');
$this->assertEqual($relationship['base field'], 'id');
$this->assertEqual($relationship['field table'], 'entity_test__field_base_file');
$this->assertEqual($relationship['field field'], 'field_base_file_target_id');
$this->assertEqual($relationship['field_name'], 'field_base_file');
$this->assertEqual($relationship['entity_type'], 'entity_test');
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
// Create file field to entity_test_mul.
FieldStorageConfig::create(array(
'entity_type' => 'entity_test_mul',
'field_name' => 'field_data_file',
'type' => 'file',
))->save();
FieldConfig::create(array(
'entity_type' => 'entity_test_mul',
'field_name' => 'field_data_file',
'bundle' => 'entity_test_mul',
))->save();
// Check the generated views data.
$views_data = Views::viewsData()->get('entity_test_mul__field_data_file');
$relationship = $views_data['field_data_file_target_id']['relationship'];
$this->assertEqual($relationship['id'], 'standard');
$this->assertEqual($relationship['base'], 'file_managed');
$this->assertEqual($relationship['base field'], 'fid');
$this->assertEqual($relationship['entity type'], 'file');
// Check the backwards reference.
$views_data = Views::viewsData()->get('file_managed');
$relationship = $views_data['reverse_field_data_file_entity_test_mul']['relationship'];
$this->assertEqual($relationship['id'], 'entity_reverse');
$this->assertEqual($relationship['base'], 'entity_test_mul_property_data');
$this->assertEqual($relationship['base field'], 'id');
$this->assertEqual($relationship['field table'], 'entity_test_mul__field_data_file');
$this->assertEqual($relationship['field field'], 'field_data_file_target_id');
$this->assertEqual($relationship['field_name'], 'field_data_file');
$this->assertEqual($relationship['entity_type'], 'entity_test_mul');
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\Tests\options\Kernel\Views;
use Drupal\views\Views;
/**
* Tests options list argument for views.
*
* @see \Drupal\options\Plugin\views\argument\NumberListField.
* @group views
*/
class OptionsListArgumentTest extends OptionsTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_options_list_argument_numeric', 'test_options_list_argument_string'];
/**
* Tests the options field argument.
*/
public function testViewsTestOptionsListArgument() {
$view = Views::getView('test_options_list_argument_numeric');
$this->executeView($view, [1]);
$resultset = [
['nid' => $this->nodes[0]->nid->value],
['nid' => $this->nodes[1]->nid->value],
];
$column_map = ['nid' => 'nid'];
$this->assertIdenticalResultset($view, $resultset, $column_map);
$view = Views::getView('test_options_list_argument_string');
$this->executeView($view, ['man', 'woman']);
$resultset = [
['nid' => $this->nodes[0]->nid->value],
['nid' => $this->nodes[1]->nid->value],
];
$column_map = ['nid' => 'nid'];
$this->assertIdenticalResultset($view, $resultset, $column_map);
}
}

View file

@ -0,0 +1,38 @@
<?php
namespace Drupal\Tests\options\Kernel\Views;
use Drupal\views\Views;
/**
* Tests options list filter for views.
*
* @see \Drupal\field\Plugin\views\filter\ListField.
* @group views
*/
class OptionsListFilterTest extends OptionsTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_options_list_filter'];
/**
* Tests options list field filter.
*/
public function testViewsTestOptionsListFilter() {
$view = Views::getView('test_options_list_filter');
$this->executeView($view);
$resultset = [
['nid' => $this->nodes[0]->nid->value],
['nid' => $this->nodes[1]->nid->value],
];
$column_map = ['nid' => 'nid'];
$this->assertIdenticalResultset($view, $resultset, $column_map);
}
}

View file

@ -0,0 +1,120 @@
<?php
namespace Drupal\Tests\options\Kernel\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Base class for options views tests.
*/
abstract class OptionsTestBase extends ViewsKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['options', 'options_test_views', 'node', 'user', 'field'];
/**
* Stores the nodes used for the different tests.
*
* @var array
*/
protected $nodes = [];
/**
* Stores the field values used for the different tests.
*
* @var array
*/
protected $fieldValues = [];
/**
* The used field names.
*
* @var string[]
*/
protected $fieldNames;
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$this->mockStandardInstall();
ViewTestData::createTestViews(get_class($this), ['options_test_views']);
$settings = [];
$settings['type'] = 'article';
$settings['title'] = $this->randomString();
$settings['field_test_list_string'][]['value'] = $this->fieldValues[0];
$settings['field_test_list_integer'][]['value'] = 0;
$node = Node::create($settings);
$node->save();
$this->nodes[] = $node;
$node = $node->createDuplicate();
$node->save();
$this->nodes[] = $node;
}
/**
* Provides a workaround for the inability to use the standard profile.
*
* @see https://www.drupal.org/node/1708692
*/
protected function mockStandardInstall() {
$this->installEntitySchema('user');
$this->installEntitySchema('node');
NodeType::create(
['type' => 'article']
)->save();
$this->fieldValues = [
$this->randomMachineName(),
$this->randomMachineName(),
];
$this->fieldNames = ['field_test_list_string', 'field_test_list_integer'];
// Create two field entities.
FieldStorageConfig::create([
'field_name' => $this->fieldNames[0],
'entity_type' => 'node',
'type' => 'list_string',
'cardinality' => 1,
'settings' => [
'allowed_values' => [
$this->fieldValues[0] => $this->fieldValues[0],
$this->fieldValues[1] => $this->fieldValues[1],
],
],
])->save();
FieldStorageConfig::create([
'field_name' => $this->fieldNames[1],
'entity_type' => 'node',
'type' => 'list_integer',
'cardinality' => 1,
'settings' => [
'allowed_values' => [
$this->fieldValues[0],
$this->fieldValues[1],
],
],
])->save();
foreach ($this->fieldNames as $field_name) {
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'label' => 'Test options list field',
'bundle' => 'article',
])->save();
}
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace Drupal\Tests\options\Kernel\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Test to ensure views data is properly created for the Options module.
*
* @group views
*/
class ViewsDataTest extends OptionsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['options', 'options_test', 'entity_test', 'views'];
/**
* The field storage.
*
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface
*/
protected $fieldStorage;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$field_name = 'test_options';
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'list_string',
'cardinality' => 1,
'settings' => [
'allowed_values_function' => 'options_test_dynamic_values_callback',
],
]);
$this->fieldStorage->save();
$this->field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'required' => TRUE,
])->save();
}
/**
* Tests the option module's implementation of hook_field_views_data().
*/
public function testOptionsFieldViewsData() {
$field_data = \Drupal::service('views.views_data')->get('entity_test__test_options');
// Check that the options module has properly overridden default views data.
$test_options_field = $field_data['test_options_value'];
$this->assertEqual($test_options_field['argument']['id'], 'string_list_field', 'Argument handler is properly set for fields with allowed value callbacks.');
$this->assertEqual($test_options_field['filter']['id'], 'list_field', 'Filter handler is properly set for fields with allowed value callbacks.');
}
}