Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
|
@ -0,0 +1,54 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
}
|
125
core/modules/options/src/Tests/Views/OptionsTestBase.php
Normal file
125
core/modules/options/src/Tests/Views/OptionsTestBase.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?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\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Tests\ViewUnitTestBase;
|
||||
|
||||
/**
|
||||
* Base class for options views tests.
|
||||
*/
|
||||
abstract class OptionsTestBase extends ViewUnitTestBase {
|
||||
|
||||
/**
|
||||
* 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['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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
core/modules/options/src/Tests/Views/ViewsDataTest.php
Normal file
66
core/modules/options/src/Tests/Views/ViewsDataTest.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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}
|
||||
*/
|
||||
public 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