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,8 @@
|
|||
name: 'REST test'
|
||||
type: module
|
||||
description: 'Provides test hooks for REST module.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- rest
|
24
core/modules/rest/tests/modules/rest_test/rest_test.module
Normal file
24
core/modules/rest/tests/modules/rest_test/rest_test.module
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains hook implementations for testing REST module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_rest_type_uri_alter().
|
||||
*/
|
||||
function rest_test_rest_type_uri_alter(&$uri, $context = array()) {
|
||||
if (!empty($context['rest_test'])) {
|
||||
$uri = 'rest_test_type';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rest_relation_uri_alter().
|
||||
*/
|
||||
function rest_test_rest_relation_uri_alter(&$uri, $context = array()) {
|
||||
if (!empty($context['rest_test'])) {
|
||||
$uri = 'rest_test_relation';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: 'REST test views'
|
||||
type: module
|
||||
description: 'Provides default views for views REST tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- rest
|
||||
- views
|
|
@ -0,0 +1,55 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- rest
|
||||
- user
|
||||
id: test_serializer_display_entity
|
||||
label: 'Test serialize display entity rows'
|
||||
module: rest
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: null
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
query:
|
||||
type: views_query
|
||||
exposed_form:
|
||||
type: basic
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_entity
|
||||
sorts:
|
||||
id:
|
||||
id: standard
|
||||
table: entity_test
|
||||
field: id
|
||||
order: DESC
|
||||
plugin_id: date
|
||||
entity_type: entity_test
|
||||
entity_field: id
|
||||
title: 'Test serialize'
|
||||
arguments: { }
|
||||
rest_export_1:
|
||||
display_plugin: rest_export
|
||||
id: rest_export_1
|
||||
display_title: serializer
|
||||
position: null
|
||||
display_options:
|
||||
defaults:
|
||||
access: false
|
||||
path: test/serialize/entity
|
|
@ -0,0 +1,105 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- rest
|
||||
- user
|
||||
id: test_serializer_display_field
|
||||
label: 'Test serializer display field rows'
|
||||
module: rest
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: views_test_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: null
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
query:
|
||||
type: views_query
|
||||
exposed_form:
|
||||
type: basic
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_field
|
||||
fields:
|
||||
name:
|
||||
id: name
|
||||
table: views_test_data
|
||||
field: name
|
||||
label: ''
|
||||
plugin_id: string
|
||||
nothing:
|
||||
id: nothing
|
||||
table: views
|
||||
field: nothing
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Custom text'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: true
|
||||
text: TEST
|
||||
plugin_id: custom
|
||||
created:
|
||||
id: created
|
||||
table: views_test_data
|
||||
field: created
|
||||
plugin_id: date
|
||||
sorts:
|
||||
created:
|
||||
id: created
|
||||
table: views_test_data
|
||||
field: created
|
||||
order: DESC
|
||||
plugin_id: date
|
||||
title: 'Test serialize'
|
||||
arguments: { }
|
||||
rest_export_1:
|
||||
display_plugin: rest_export
|
||||
id: rest_export_1
|
||||
display_title: serializer
|
||||
position: null
|
||||
display_options:
|
||||
defaults:
|
||||
access: false
|
||||
style: false
|
||||
row: false
|
||||
path: test/serialize/field
|
||||
access:
|
||||
type: none
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_field
|
||||
rest_export_2:
|
||||
display_plugin: rest_export
|
||||
id: rest_export_2
|
||||
display_title: 'serialize - access denied'
|
||||
position: null
|
||||
display_options:
|
||||
defaults:
|
||||
access: false
|
||||
style: false
|
||||
row: false
|
||||
path: test/serialize/denied
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'administer views'
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_field
|
|
@ -0,0 +1,131 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.body
|
||||
module:
|
||||
- field
|
||||
- node
|
||||
- rest
|
||||
- rest_test_views
|
||||
- user
|
||||
id: test_serializer_node_display_field
|
||||
label: 'Test serializer display field rows for entity fields'
|
||||
module: rest_test_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: null
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
query:
|
||||
type: views_query
|
||||
exposed_form:
|
||||
type: basic
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_field
|
||||
fields:
|
||||
nid:
|
||||
id: nid
|
||||
table: node
|
||||
field: nid
|
||||
plugin_id: field
|
||||
entity_type: node
|
||||
entity_field: nid
|
||||
body:
|
||||
id: body
|
||||
table: node__body
|
||||
field: body
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Body
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: 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_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: text_default
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
plugin_id: field
|
||||
entity_type: node
|
||||
entity_field: body
|
||||
title: 'Test serialize'
|
||||
arguments: { }
|
||||
rest_export_1:
|
||||
display_plugin: rest_export
|
||||
id: rest_export_1
|
||||
display_title: serializer
|
||||
position: null
|
||||
display_options:
|
||||
defaults:
|
||||
access: false
|
||||
style: false
|
||||
row: false
|
||||
path: test/serialize/node-field
|
||||
access:
|
||||
type: none
|
||||
style:
|
||||
type: serializer
|
||||
row:
|
||||
type: data_field
|
138
core/modules/rest/tests/src/Unit/CollectRoutesTest.php
Normal file
138
core/modules/rest/tests/src/Unit/CollectRoutesTest.php
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\rest\Unit\CollectRoutesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\rest\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\rest\Plugin\views\display\RestExport;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* Tests the REST export view plugin.
|
||||
*
|
||||
* @group rest
|
||||
*/
|
||||
class CollectRoutesTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The REST export instance.
|
||||
*
|
||||
* @var \Drupal\rest\Plugin\views\display\RestExport
|
||||
*/
|
||||
protected $restExport;
|
||||
|
||||
/**
|
||||
* The RouteCollection.
|
||||
*/
|
||||
protected $routes;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->view = $this->getMock('\Drupal\views\Entity\View', array('initHandlers'), array(
|
||||
array('id' => 'test_view'),
|
||||
'view',
|
||||
));
|
||||
|
||||
$view_executable = $this->getMock('\Drupal\views\ViewExecutable', array('initHandlers'), array(), '', FALSE);
|
||||
|
||||
$view_executable->storage = $this->view;
|
||||
$view_executable->argument = array();
|
||||
|
||||
$display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$container->set('plugin.manager.views.display', $display_manager);
|
||||
|
||||
$access_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$container->set('plugin.manager.views.access', $access_manager);
|
||||
|
||||
$route_provider = $this->getMockBuilder('\Drupal\Core\Routing\RouteProviderInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$container->set('router.route_provider', $route_provider);
|
||||
|
||||
$state = $this->getMock('\Drupal\Core\State\StateInterface');
|
||||
$container->set('state', $state);
|
||||
|
||||
$style_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$container->set('plugin.manager.views.style', $style_manager);
|
||||
$container->set('renderer', $this->getMock('Drupal\Core\Render\RendererInterface'));
|
||||
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->restExport = RestExport::create($container, array(), "test_routes", array());
|
||||
$this->restExport->view = $view_executable;
|
||||
|
||||
// Initialize a display.
|
||||
$this->restExport->display = array('id' => 'page_1');
|
||||
|
||||
// Set the style option.
|
||||
$this->restExport->setOption('style', array('type' => 'serializer'));
|
||||
|
||||
$display_manager->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue(array('id' => 'test', 'provider' => 'test')));
|
||||
|
||||
$none = $this->getMockBuilder('\Drupal\views\Plugin\views\access\None')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$access_manager->expects($this->once())
|
||||
->method('createInstance')
|
||||
->will($this->returnValue($none));
|
||||
|
||||
$style_plugin = $this->getMock('\Drupal\rest\Plugin\views\style\Serializer', array('getFormats', 'init'), array(), '', FALSE);
|
||||
|
||||
$style_plugin->expects($this->once())
|
||||
->method('getFormats')
|
||||
->will($this->returnValue(array('json')));
|
||||
|
||||
$style_plugin->expects($this->once())
|
||||
->method('init')
|
||||
->with($view_executable)
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
$style_manager->expects($this->once())
|
||||
->method('createInstance')
|
||||
->will($this->returnValue($style_plugin));
|
||||
|
||||
$this->routes = new RouteCollection();
|
||||
$this->routes->add('test_1', new Route('/test/1'));
|
||||
$this->routes->add('view.test_view.page_1', new Route('/test/2'));
|
||||
|
||||
$this->view->addDisplay('page', NULL, 'page_1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if adding a requirement to a route only modify one route.
|
||||
*/
|
||||
public function testRoutesRequirements() {
|
||||
$this->restExport->collectRoutes($this->routes);
|
||||
|
||||
$requirements_1 = $this->routes->get('test_1')->getRequirements();
|
||||
$requirements_2 = $this->routes->get('view.test_view.page_1')->getRequirements();
|
||||
|
||||
$this->assertEquals(count($requirements_1), 0, 'First route has no requirement.');
|
||||
$this->assertEquals(count($requirements_2), 2, 'Views route with rest export had the format and method requirements added.');
|
||||
}
|
||||
}
|
Reference in a new issue