Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldFormatter\OptionsDefaultFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Field\AllowedTagsXssTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Field\AllowedTagsXssTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldType\ListFloatItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
|
@ -104,7 +99,7 @@ class ListFloatItem extends ListItemBase {
|
|||
// Cast the value to a float first so that .5 and 0.5 are the same value
|
||||
// and then cast to a string so that values like 0.5 can be used as array
|
||||
// keys.
|
||||
// @see http://php.net/manual/en/language.types.array.php
|
||||
// @see http://php.net/manual/language.types.array.php
|
||||
$values[(string) (float) $item['value']] = $item['label'];
|
||||
}
|
||||
return $values;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldType\ListIntegerItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldType\ListItemBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\AllowedTagsXssTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\Field\FieldType\ListStringItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\views\argument\NumberListField.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\views\argument;
|
||||
|
||||
use Drupal\Core\Field\AllowedTagsXssTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\views\argument\StringListField.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\views\argument;
|
||||
|
||||
use Drupal\Core\Field\AllowedTagsXssTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Plugin\views\filter\ListField.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Plugin\views\filter;
|
||||
|
||||
use Drupal\views\FieldAPIHandlerTrait;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsDynamicValuesApiTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsDynamicValuesTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\FieldTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\entity_test\Entity\EntityTestRev;
|
||||
|
||||
/**
|
||||
* Base class for testing allowed values of options fields.
|
||||
|
|
@ -39,7 +37,7 @@ abstract class OptionsDynamicValuesTestBase extends FieldTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$field_name = 'test_options';
|
||||
$this->fieldStorage = entity_create('field_storage_config', [
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test_rev',
|
||||
'type' => 'list_string',
|
||||
|
|
@ -50,7 +48,7 @@ abstract class OptionsDynamicValuesTestBase extends FieldTestBase {
|
|||
]);
|
||||
$this->fieldStorage->save();
|
||||
|
||||
$this->field = entity_create('field_config', [
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test_rev',
|
||||
'bundle' => 'entity_test_rev',
|
||||
|
|
@ -68,7 +66,7 @@ abstract class OptionsDynamicValuesTestBase extends FieldTestBase {
|
|||
'user_id' => mt_rand(1, 10),
|
||||
'name' => $this->randomMachineName(),
|
||||
];
|
||||
$this->entity = entity_create('entity_test_rev', $values);
|
||||
$this->entity = EntityTestRev::create($values);
|
||||
$this->entity->save();
|
||||
$this->test = [
|
||||
'label' => $this->entity->label(),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsDynamicValuesValidationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
|
||||
|
||||
/**
|
||||
* 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 = entity_create('entity_test');
|
||||
$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 = entity_create('entity_test');
|
||||
$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 = entity_create('entity_test');
|
||||
$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 = entity_create('entity_test');
|
||||
$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();
|
||||
entity_create('field_storage_config', $this->fieldStorageDefinition)->save();
|
||||
entity_create('field_config', array(
|
||||
'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 = entity_create('entity_test');
|
||||
$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 = entity_create('entity_test');
|
||||
$entity->{$this->fieldName}->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsFieldUITest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\FieldTestBase;
|
||||
|
||||
|
|
@ -267,16 +263,16 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
*/
|
||||
protected function createOptionsField($type) {
|
||||
// Create a field.
|
||||
entity_create('field_storage_config', array(
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'node',
|
||||
'type' => $type,
|
||||
))->save();
|
||||
entity_create('field_config', array(
|
||||
FieldConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $this->type,
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
entity_get_form_display('node', $this->type, 'default')->setComponent($this->fieldName)->save();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsFieldUnitTestBase.
|
||||
*/
|
||||
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\field\Tests\FieldUnitTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Options module integration tests.
|
||||
*/
|
||||
abstract class OptionsFieldUnitTestBase extends FieldUnitTestBase {
|
||||
|
||||
/**
|
||||
* 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 = entity_create('field_storage_config', $this->fieldStorageDefinition);
|
||||
$this->fieldStorage->save();
|
||||
|
||||
$this->field = entity_create('field_config', array(
|
||||
'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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsFloatFieldImportTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsFormattersTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
/**
|
||||
* 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 = entity_create('entity_test');
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsSelectDynamicValuesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\OptionsWidgetsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\FieldTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the Options widgets.
|
||||
|
|
@ -42,7 +40,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Field storage with cardinality 1.
|
||||
$this->card1 = entity_create('field_storage_config', [
|
||||
$this->card1 = FieldStorageConfig::create([
|
||||
'field_name' => 'card_1',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'list_integer',
|
||||
|
|
@ -62,7 +60,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->card1->save();
|
||||
|
||||
// Field storage with cardinality 2.
|
||||
$this->card2 = entity_create('field_storage_config', [
|
||||
$this->card2 = FieldStorageConfig::create([
|
||||
'field_name' => 'card_2',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'list_integer',
|
||||
|
|
@ -88,7 +86,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
*/
|
||||
function testRadioButtons() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = entity_create('field_config', [
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
'bundle' => 'entity_test',
|
||||
]);
|
||||
|
|
@ -100,7 +98,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = entity_create('entity_test', [
|
||||
$entity = EntityTest::create([
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
]);
|
||||
|
|
@ -145,10 +143,10 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
*/
|
||||
function testCheckBoxes() {
|
||||
// Create an instance of the 'multiple values' field.
|
||||
$field = entity_create('field_config', array(
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card2,
|
||||
'bundle' => 'entity_test',
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card2->getName(), array(
|
||||
|
|
@ -157,7 +155,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = entity_create('entity_test', array(
|
||||
$entity = EntityTest::create(array(
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
|
|
@ -234,11 +232,11 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
*/
|
||||
function testSelectListSingle() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = entity_create('field_config', array(
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
'bundle' => 'entity_test',
|
||||
'required' => TRUE,
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card1->getName(), array(
|
||||
|
|
@ -247,7 +245,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = entity_create('entity_test', array(
|
||||
$entity = EntityTest::create(array(
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
|
|
@ -334,10 +332,10 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
*/
|
||||
function testSelectListMultiple() {
|
||||
// Create an instance of the 'multiple values' field.
|
||||
$field = entity_create('field_config', array(
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card2,
|
||||
'bundle' => 'entity_test',
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card2->getName(), array(
|
||||
|
|
@ -346,7 +344,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = entity_create('entity_test', array(
|
||||
$entity = EntityTest::create(array(
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
|
|
@ -455,7 +453,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
*/
|
||||
function testEmptyValue() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = entity_create('field_config', [
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
'bundle' => 'entity_test',
|
||||
]);
|
||||
|
|
@ -469,7 +467,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = entity_create('entity_test', [
|
||||
$entity = EntityTest::create([
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\Views\OptionsListArgumentTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests\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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\Views\OptionsListFilterTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests\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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\Views\OptionsTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Tests\ViewKernelTestBase;
|
||||
|
||||
/**
|
||||
* Base class for options views tests.
|
||||
*/
|
||||
abstract class OptionsTestBase extends ViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\Views\ViewsDataTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests\Views;
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
parent::setUp();
|
||||
|
||||
$field_name = 'test_options';
|
||||
$this->fieldStorage = entity_create('field_storage_config', [
|
||||
'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 = entity_create('field_config', [
|
||||
'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.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue