Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -2,10 +2,13 @@
namespace Drupal\rest\Tests;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\node\NodeInterface;
use Drupal\rest\RestResourceConfigInterface;
use Drupal\simpletest\WebTestBase;
use GuzzleHttp\Cookie\FileCookieJar;
use GuzzleHttp\Cookie\SetCookie;
/**
* Test helper class that provides a REST client method to send HTTP requests.
@ -62,18 +65,57 @@ abstract class RESTTestBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('rest', 'entity_test');
public static $modules = ['rest', 'entity_test'];
/**
* The last response.
*
* @var \Psr\Http\Message\ResponseInterface
*/
protected $response;
protected function setUp() {
parent::setUp();
$this->defaultFormat = 'hal_json';
$this->defaultMimeType = 'application/hal+json';
$this->defaultAuth = array('cookie');
$this->defaultAuth = ['cookie'];
$this->resourceConfigStorage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config');
// Create a test content type for node testing.
if (in_array('node', static::$modules)) {
$this->drupalCreateContentType(array('name' => 'resttest', 'type' => 'resttest'));
$this->drupalCreateContentType(['name' => 'resttest', 'type' => 'resttest']);
}
$this->cookieFile = $this->publicFilesDirectory . '/cookie.jar';
}
/**
* Calculates cookies used by guzzle later.
*
* @return \GuzzleHttp\Cookie\CookieJarInterface
* The used CURL options in guzzle.
*/
protected function cookies() {
$cookies = [];
foreach ($this->cookies as $key => $cookie) {
$cookies[$key][] = $cookie['value'];
}
$request = \Drupal::request();
$cookies = NestedArray::mergeDeep($cookies, $this->extractCookiesFromRequest($request));
$cookie_jar = new FileCookieJar($this->cookieFile);
foreach ($cookies as $key => $cookie_values) {
foreach ($cookie_values as $cookie_value) {
// setcookie() sets the value of a cookie to be deleted, when its gonna
// be removed.
if ($cookie_value !== 'deleted') {
$cookie_jar->setCookie(new SetCookie(['Name' => $key, 'Value' => $cookie_value, 'Domain' => $request->getHost()]));
}
}
}
return $cookie_jar;
}
/**
@ -100,118 +142,137 @@ abstract class RESTTestBase extends WebTestBase {
if (!isset($mime_type)) {
$mime_type = $this->defaultMimeType;
}
if (!in_array($method, array('GET', 'HEAD', 'OPTIONS', 'TRACE'))) {
if (!in_array($method, ['GET', 'HEAD', 'OPTIONS', 'TRACE'])) {
// GET the CSRF token first for writing requests.
$requested_token = $this->drupalGet('session/token');
}
$client = \Drupal::httpClient();
$url = $this->buildUrl($url);
$curl_options = array();
$options = [
'http_errors' => FALSE,
'cookies' => $this->cookies(),
'curl' => [
CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'],
],
];
switch ($method) {
case 'GET':
// Set query if there are additional GET parameters.
$curl_options = array(
CURLOPT_HTTPGET => TRUE,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_URL => $url,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type),
);
$options += [
'headers' => [
'Accept' => $mime_type,
],
];
$response = $client->get($url, $options);
break;
case 'HEAD':
$curl_options = array(
CURLOPT_HTTPGET => FALSE,
CURLOPT_CUSTOMREQUEST => 'HEAD',
CURLOPT_URL => $url,
CURLOPT_NOBODY => TRUE,
CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type),
);
$response = $client->head($url, $options);
break;
case 'POST':
$curl_options = array(
CURLOPT_HTTPGET => FALSE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $body,
CURLOPT_URL => $url,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPHEADER => $csrf_token !== FALSE ? array(
'Content-Type: ' . $mime_type,
'X-CSRF-Token: ' . ($csrf_token === NULL ? $requested_token : $csrf_token),
) : array(
'Content-Type: ' . $mime_type,
),
);
$options += [
'headers' => $csrf_token !== FALSE ? [
'Content-Type' => $mime_type,
'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token),
] : [
'Content-Type' => $mime_type,
],
'body' => $body,
];
$response = $client->post($url, $options);
break;
case 'PUT':
$curl_options = array(
CURLOPT_HTTPGET => FALSE,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $body,
CURLOPT_URL => $url,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPHEADER => $csrf_token !== FALSE ? array(
'Content-Type: ' . $mime_type,
'X-CSRF-Token: ' . ($csrf_token === NULL ? $requested_token : $csrf_token),
) : array(
'Content-Type: ' . $mime_type,
),
);
$options += [
'headers' => $csrf_token !== FALSE ? [
'Content-Type' => $mime_type,
'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token),
] : [
'Content-Type' => $mime_type,
],
'body' => $body,
];
$response = $client->put($url, $options);
break;
case 'PATCH':
$curl_options = array(
CURLOPT_HTTPGET => FALSE,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => $body,
CURLOPT_URL => $url,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPHEADER => $csrf_token !== FALSE ? array(
'Content-Type: ' . $mime_type,
'X-CSRF-Token: ' . ($csrf_token === NULL ? $requested_token : $csrf_token),
) : array(
'Content-Type: ' . $mime_type,
),
);
$options += [
'headers' => $csrf_token !== FALSE ? [
'Content-Type' => $mime_type,
'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token),
] : [
'Content-Type' => $mime_type,
],
'body' => $body,
];
$response = $client->patch($url, $options);
break;
case 'DELETE':
$curl_options = array(
CURLOPT_HTTPGET => FALSE,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_URL => $url,
CURLOPT_NOBODY => FALSE,
CURLOPT_HTTPHEADER => $csrf_token !== FALSE ? array(
'X-CSRF-Token: ' . ($csrf_token === NULL ? $requested_token : $csrf_token),
) : array(),
);
$options += [
'headers' => $csrf_token !== FALSE ? [
'Content-Type' => $mime_type,
'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token),
] : [],
];
$response = $client->delete($url, $options);
break;
}
if ($mime_type === 'none') {
unset($curl_options[CURLOPT_HTTPHEADER]['Content-Type']);
}
$this->responseBody = $this->curlExec($curl_options);
$this->response = $response;
$this->responseBody = (string) $response->getBody();
$this->setRawContent($this->responseBody);
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
$headers = $this->drupalGetHeaders();
$this->verbose($method . ' request to: ' . $url .
'<hr />Code: ' . curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE) .
(isset($curl_options[CURLOPT_HTTPHEADER]) ? '<hr />Request headers: ' . nl2br(print_r($curl_options[CURLOPT_HTTPHEADER], TRUE)) : '' ) .
(isset($curl_options[CURLOPT_POSTFIELDS]) ? '<hr />Request body: ' . nl2br(print_r($curl_options[CURLOPT_POSTFIELDS], TRUE)) : '' ) .
'<hr />Response headers: ' . nl2br(print_r($headers, TRUE)) .
'<hr />Code: ' . $this->response->getStatusCode() .
(isset($options['headers']) ? '<hr />Request headers: ' . nl2br(print_r($options['headers'], TRUE)) : '') .
(isset($options['body']) ? '<hr />Request body: ' . nl2br(print_r($options['body'], TRUE)) : '') .
'<hr />Response headers: ' . nl2br(print_r($response->getHeaders(), TRUE)) .
'<hr />Response body: ' . $this->responseBody);
return $this->responseBody;
}
/**
* {@inheritdoc}
*/
protected function assertResponse($code, $message = '', $group = 'Browser') {
if (!isset($this->response)) {
return parent::assertResponse($code, $message, $group);
}
return $this->assertEqual($code, $this->response->getStatusCode(), $message ? $message : "HTTP response expected $code, actual {$this->response->getStatusCode()}", $group);
}
/**
* {@inheritdoc}
*/
protected function drupalGetHeaders($all_requests = FALSE) {
if (!isset($this->response)) {
return parent::drupalGetHeaders($all_requests);
}
$lowercased_keys = array_map('strtolower', array_keys($this->response->getHeaders()));
return array_map(function (array $header) {
return implode(', ', $header);
}, array_combine($lowercased_keys, array_values($this->response->getHeaders())));
}
/**
* {@inheritdoc}
*/
protected function drupalGetHeader($name, $all_requests = FALSE) {
if (!isset($this->response)) {
return parent::drupalGetHeader($name, $all_requests);
}
if ($header = $this->response->getHeader($name)) {
return implode(', ', $header);
}
}
/**
* Creates entity objects based on their types.
*
@ -242,28 +303,28 @@ abstract class RESTTestBase extends WebTestBase {
protected function entityValues($entity_type_id) {
switch ($entity_type_id) {
case 'entity_test':
return array(
return [
'name' => $this->randomMachineName(),
'user_id' => 1,
'field_test_text' => array(0 => array(
'field_test_text' => [0 => [
'value' => $this->randomString(),
'format' => 'plain_text',
)),
);
]],
];
case 'config_test':
return [
'id' => $this->randomMachineName(),
'label' => 'Test label',
];
case 'node':
return array('title' => $this->randomString(), 'type' => 'resttest');
return ['title' => $this->randomString(), 'type' => 'resttest'];
case 'node_type':
return array(
return [
'type' => 'article',
'name' => $this->randomMachineName(),
);
];
case 'user':
return array('name' => $this->randomMachineName());
return ['name' => $this->randomMachineName()];
case 'comment':
return [
@ -279,11 +340,20 @@ abstract class RESTTestBase extends WebTestBase {
'vid' => 'tags',
'name' => $this->randomMachineName(),
];
case 'block':
// Block placements depend on themes, ensure Bartik is installed.
$this->container->get('theme_installer')->install(['bartik']);
return [
'id' => strtolower($this->randomMachineName(8)),
'plugin' => 'system_powered_by_block',
'theme' => 'bartik',
'region' => 'header',
];
default:
if ($this->isConfigEntity($entity_type_id)) {
return $this->configEntityValues($entity_type_id);
}
return array();
return [];
}
}
@ -350,8 +420,7 @@ abstract class RESTTestBase extends WebTestBase {
* Rebuilds routing caches.
*/
protected function rebuildCache() {
// Rebuild routing cache, so that the REST API paths are available.
$this->container->get('router.builder')->rebuild();
$this->container->get('router.builder')->rebuildIfNeeded();
}
/**
@ -362,6 +431,8 @@ abstract class RESTTestBase extends WebTestBase {
* override it every time it is omitted.
*/
protected function curlExec($curl_options, $redirect = FALSE) {
unset($this->response);
if (!isset($curl_options[CURLOPT_CUSTOMREQUEST])) {
if (!empty($curl_options[CURLOPT_HTTPGET])) {
$curl_options[CURLOPT_CUSTOMREQUEST] = 'GET';
@ -389,22 +460,22 @@ abstract class RESTTestBase extends WebTestBase {
case 'entity_test':
switch ($operation) {
case 'view':
return array('view test entity');
return ['view test entity'];
case 'create':
case 'update':
case 'delete':
return array('administer entity_test content');
return ['administer entity_test content'];
}
case 'node':
switch ($operation) {
case 'view':
return array('access content');
return ['access content'];
case 'create':
return array('create resttest content');
return ['create resttest content'];
case 'update':
return array('edit any resttest content');
return ['edit any resttest content'];
case 'delete':
return array('delete any resttest content');
return ['delete any resttest content'];
}
case 'comment':
@ -502,7 +573,7 @@ abstract class RESTTestBase extends WebTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertResponseBody($expected, $message = '', $group = 'REST Response') {
return $this->assertIdentical($expected, $this->responseBody, $message ? $message : strtr('Response body @expected (expected) is equal to @response (actual).', array('@expected' => var_export($expected, TRUE), '@response' => var_export($this->responseBody, TRUE))), $group);
return $this->assertIdentical($expected, $this->responseBody, $message ? $message : strtr('Response body @expected (expected) is equal to @response (actual).', ['@expected' => var_export($expected, TRUE), '@response' => var_export($this->responseBody, TRUE)]), $group);
}
/**

View file

@ -19,7 +19,7 @@ class ResourceTest extends RESTTestBase {
*
* @var array
*/
public static $modules = array('hal', 'rest', 'entity_test', 'rest_test');
public static $modules = ['hal', 'rest', 'entity_test', 'rest_test'];
/**
* The entity.

View file

@ -84,5 +84,4 @@ class ExcludedFieldTokenTest extends ViewTestBase {
$this->assertIdentical($actual_json, json_encode($expected));
}
}

View file

@ -40,14 +40,14 @@ class StyleSerializerTest extends PluginTestBase {
*
* @var array
*/
public static $modules = array('views_ui', 'entity_test', 'hal', 'rest_test_views', 'node', 'text', 'field', 'language', 'basic_auth');
public static $modules = ['views_ui', 'entity_test', 'hal', 'rest_test_views', 'node', 'text', 'field', 'language', 'basic_auth'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_serializer_display_field', 'test_serializer_display_entity', 'test_serializer_display_entity_translated', 'test_serializer_node_display_field', 'test_serializer_node_exposed_filter');
public static $testViews = ['test_serializer_display_field', 'test_serializer_display_entity', 'test_serializer_display_entity_translated', 'test_serializer_node_display_field', 'test_serializer_node_exposed_filter'];
/**
* A user with administrative privileges to look at test entity and configure views.
@ -57,13 +57,13 @@ class StyleSerializerTest extends PluginTestBase {
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('rest_test_views'));
ViewTestData::createTestViews(get_class($this), ['rest_test_views']);
$this->adminUser = $this->drupalCreateUser(array('administer views', 'administer entity_test content', 'access user profiles', 'view test entity'));
$this->adminUser = $this->drupalCreateUser(['administer views', 'administer entity_test content', 'access user profiles', 'view test entity']);
// Save some entity_test entities.
for ($i = 1; $i <= 10; $i++) {
EntityTest::create(array('name' => 'test_' . $i, 'user_id' => $this->adminUser->id()))->save();
EntityTest::create(['name' => 'test_' . $i, 'user_id' => $this->adminUser->id()])->save();
}
$this->enableViewsTestModule();
@ -122,9 +122,9 @@ class StyleSerializerTest extends PluginTestBase {
$headers = $this->drupalGetHeaders();
$this->assertEqual($headers['content-type'], 'application/json', 'The header Content-type is correct.');
$expected = array();
$expected = [];
foreach ($view->result as $row) {
$expected_row = array();
$expected_row = [];
foreach ($view->field as $id => $field) {
$expected_row[$id] = $field->render($row);
}
@ -154,7 +154,7 @@ class StyleSerializerTest extends PluginTestBase {
// Get the serializer service.
$serializer = $this->container->get('serializer');
$entities = array();
$entities = [];
foreach ($view->result as $row) {
$entities[] = $row->_entity;
}
@ -180,15 +180,15 @@ class StyleSerializerTest extends PluginTestBase {
// Change the default format to xml.
$view->setDisplay('rest_export_1');
$view->getDisplay()->setOption('style', array(
$view->getDisplay()->setOption('style', [
'type' => 'serializer',
'options' => array(
'options' => [
'uses_fields' => FALSE,
'formats' => array(
'formats' => [
'xml' => 'xml',
),
),
));
],
],
]);
$view->save();
$expected = $serializer->serialize($entities, 'xml');
$actual_xml = $this->drupalGet('test/serialize/entity');
@ -197,16 +197,16 @@ class StyleSerializerTest extends PluginTestBase {
// Allow multiple formats.
$view->setDisplay('rest_export_1');
$view->getDisplay()->setOption('style', array(
$view->getDisplay()->setOption('style', [
'type' => 'serializer',
'options' => array(
'options' => [
'uses_fields' => FALSE,
'formats' => array(
'formats' => [
'xml' => 'xml',
'json' => 'json',
),
),
));
],
],
]);
$view->save();
$expected = $serializer->serialize($entities, 'json');
$actual_json = $this->drupalGetWithFormat('test/serialize/entity', 'json');
@ -219,7 +219,7 @@ class StyleSerializerTest extends PluginTestBase {
/**
* Verifies site maintenance mode functionality.
*/
protected function testSiteMaintenance() {
public function testSiteMaintenance() {
$view = Views::getView('test_serializer_display_field');
$view->initDisplay();
$this->executeView($view);
@ -346,8 +346,8 @@ class StyleSerializerTest extends PluginTestBase {
$style_options = 'admin/structure/views/nojs/display/test_serializer_display_field/rest_export_1/style_options';
// Select only 'xml' as an accepted format.
$this->drupalPostForm($style_options, array('style_options[formats][xml]' => 'xml'), t('Apply'));
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm($style_options, ['style_options[formats][xml]' => 'xml'], t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
// Should return a 406.
$this->drupalGetWithFormat('test/serialize/field', 'json');
@ -359,8 +359,8 @@ class StyleSerializerTest extends PluginTestBase {
$this->assertResponse(200, 'A 200 response was returned when XML was requested.');
// Add 'json' as an accepted format, so we have multiple.
$this->drupalPostForm($style_options, array('style_options[formats][json]' => 'json'), t('Apply'));
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm($style_options, ['style_options[formats][json]' => 'json'], t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
// Should return a 200.
// @todo This should be fixed when we have better content negotiation.
@ -369,7 +369,7 @@ class StyleSerializerTest extends PluginTestBase {
$this->assertResponse(200, 'A 200 response was returned when any format was requested.');
// Should return a 200. Emulates a sample Firefox header.
$this->drupalGet('test/serialize/field', array(), array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'));
$this->drupalGet('test/serialize/field', [], ['Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8']);
$this->assertHeader('content-type', 'application/json');
$this->assertResponse(200, 'A 200 response was returned when a browser accept header was requested.');
@ -393,7 +393,7 @@ class StyleSerializerTest extends PluginTestBase {
$this->assertResponse(200, 'A 200 response was returned when HTML was requested.');
// Now configure now format, so all of them should be allowed.
$this->drupalPostForm($style_options, array('style_options[formats][json]' => '0', 'style_options[formats][xml]' => '0'), t('Apply'));
$this->drupalPostForm($style_options, ['style_options[formats][json]' => '0', 'style_options[formats][xml]' => '0'], t('Apply'));
// Should return a 200.
$this->drupalGetWithFormat('test/serialize/field', 'json');
@ -424,16 +424,16 @@ class StyleSerializerTest extends PluginTestBase {
// Test an empty string for an alias, this should not be used. This also
// tests that the form can be submitted with no aliases.
$this->drupalPostForm($row_options, array('row_options[field_options][name][alias]' => ''), t('Apply'));
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm($row_options, ['row_options[field_options][name][alias]' => ''], t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
$view = Views::getView('test_serializer_display_field');
$view->setDisplay('rest_export_1');
$this->executeView($view);
$expected = array();
$expected = [];
foreach ($view->result as $row) {
$expected_row = array();
$expected_row = [];
foreach ($view->field as $id => $field) {
$expected_row[$id] = $field->render($row);
}
@ -443,32 +443,32 @@ class StyleSerializerTest extends PluginTestBase {
$this->assertIdentical($this->drupalGetJSON('test/serialize/field'), $this->castSafeStrings($expected));
// Test a random aliases for fields, they should be replaced.
$alias_map = array(
$alias_map = [
'name' => $this->randomMachineName(),
// Use # to produce an invalid character for the validation.
'nothing' => '#' . $this->randomMachineName(),
'created' => 'created',
);
];
$edit = array('row_options[field_options][name][alias]' => $alias_map['name'], 'row_options[field_options][nothing][alias]' => $alias_map['nothing']);
$edit = ['row_options[field_options][name][alias]' => $alias_map['name'], 'row_options[field_options][nothing][alias]' => $alias_map['nothing']];
$this->drupalPostForm($row_options, $edit, t('Apply'));
$this->assertText(t('The machine-readable name must contain only letters, numbers, dashes and underscores.'));
// Change the map alias value to a valid one.
$alias_map['nothing'] = $this->randomMachineName();
$edit = array('row_options[field_options][name][alias]' => $alias_map['name'], 'row_options[field_options][nothing][alias]' => $alias_map['nothing']);
$edit = ['row_options[field_options][name][alias]' => $alias_map['name'], 'row_options[field_options][nothing][alias]' => $alias_map['nothing']];
$this->drupalPostForm($row_options, $edit, t('Apply'));
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm(NULL, [], t('Save'));
$view = Views::getView('test_serializer_display_field');
$view->setDisplay('rest_export_1');
$this->executeView($view);
$expected = array();
$expected = [];
foreach ($view->result as $row) {
$expected_row = array();
$expected_row = [];
foreach ($view->field as $id => $field) {
$expected_row[$alias_map[$id]] = $field->render($row);
}
@ -491,12 +491,12 @@ class StyleSerializerTest extends PluginTestBase {
// Test an empty string for an alias, this should not be used. This also
// tests that the form can be submitted with no aliases.
$values = array(
$values = [
'row_options[field_options][created][raw_output]' => '1',
'row_options[field_options][name][raw_output]' => '1',
);
];
$this->drupalPostForm($row_options, $values, t('Apply'));
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm(NULL, [], t('Save'));
$view = Views::getView('test_serializer_display_field');
$view->setDisplay('rest_export_1');
@ -562,7 +562,7 @@ class StyleSerializerTest extends PluginTestBase {
// Get the serializer service.
$serializer = $this->container->get('serializer');
$entities = array();
$entities = [];
foreach ($view->result as $row) {
$entities[] = $row->_entity;
}
@ -580,15 +580,15 @@ class StyleSerializerTest extends PluginTestBase {
// Change the request format to xml.
$view->setDisplay('rest_export_1');
$view->getDisplay()->setOption('style', array(
$view->getDisplay()->setOption('style', [
'type' => 'serializer',
'options' => array(
'options' => [
'uses_fields' => FALSE,
'formats' => array(
'formats' => [
'xml' => 'xml',
),
),
));
],
],
]);
$this->executeView($view);
$build = $view->preview();
@ -602,7 +602,7 @@ class StyleSerializerTest extends PluginTestBase {
public function testSerializerViewsUI() {
$this->drupalLogin($this->adminUser);
// Click the "Update preview button".
$this->drupalPostForm('admin/structure/views/view/test_serializer_display_field/edit/rest_export_1', $edit = array(), t('Update preview'));
$this->drupalPostForm('admin/structure/views/view/test_serializer_display_field/edit/rest_export_1', $edit = [], t('Update preview'));
$this->assertResponse(200);
// Check if we receive the expected result.
$result = $this->xpath('//div[@id="views-live-preview"]/pre');
@ -613,7 +613,7 @@ class StyleSerializerTest extends PluginTestBase {
* Tests the field row style using fieldapi fields.
*/
public function testFieldapiField() {
$this->drupalCreateContentType(array('type' => 'page'));
$this->drupalCreateContentType(['type' => 'page']);
$node = $this->drupalCreateNode();
$result = $this->drupalGetJSON('test/serialize/node-field');
@ -749,44 +749,44 @@ class StyleSerializerTest extends PluginTestBase {
* the value provided.
*/
public function testRestViewExposedFilter() {
$this->drupalCreateContentType(array('type' => 'page'));
$node0 = $this->drupalCreateNode(array('title' => 'Node 1'));
$node1 = $this->drupalCreateNode(array('title' => 'Node 11'));
$node2 = $this->drupalCreateNode(array('title' => 'Node 111'));
$this->drupalCreateContentType(['type' => 'page']);
$node0 = $this->drupalCreateNode(['title' => 'Node 1']);
$node1 = $this->drupalCreateNode(['title' => 'Node 11']);
$node2 = $this->drupalCreateNode(['title' => 'Node 111']);
// Test that no filter brings back all three nodes.
$result = $this->drupalGetJSON('test/serialize/node-exposed-filter');
$expected = array(
0 => array(
$expected = [
0 => [
'nid' => $node0->id(),
'body' => $node0->body->processed,
),
1 => array(
],
1 => [
'nid' => $node1->id(),
'body' => $node1->body->processed,
),
2 => array(
],
2 => [
'nid' => $node2->id(),
'body' => $node2->body->processed,
),
);
],
];
$this->assertEqual($result, $expected, 'Querying a view with no exposed filter returns all nodes.');
// Test that title starts with 'Node 11' query finds 2 of the 3 nodes.
$result = $this->drupalGetJSON('test/serialize/node-exposed-filter', ['query' => ['title' => 'Node 11']]);
$expected = array(
0 => array(
$expected = [
0 => [
'nid' => $node1->id(),
'body' => $node1->body->processed,
),
1 => array(
],
1 => [
'nid' => $node2->id(),
'body' => $node2->body->processed,
),
);
],
];
$cache_contexts = [
'languages:language_content',