Update to Drupal 8.0.3. For more information, see https://www.drupal.org/drupal-8.0.3-release-notes

This commit is contained in:
Pantheon Automation 2016-02-03 14:56:31 -08:00 committed by Greg Anderson
parent 10f9f7fbde
commit 9db4fae9a7
202 changed files with 3806 additions and 760 deletions

View file

@ -29,7 +29,6 @@ use Drupal\Core\Session\UserSession;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Zend\Diactoros\Uri;
@ -42,7 +41,16 @@ use Zend\Diactoros\Uri;
abstract class WebTestBase extends TestBase {
use AssertContentTrait;
use BlockCreationTrait {
placeBlock as drupalPlaceBlock;
}
use ContentTypeCreationTrait {
createContentType as drupalCreateContentType;
}
use NodeCreationTrait {
getNodeByTitle as drupalGetNodeByTitle;
createNode as drupalCreateNode;
}
use UserCreationTrait {
createUser as drupalCreateUser;
createRole as drupalCreateRole;
@ -230,108 +238,6 @@ abstract class WebTestBase extends TestBase {
$this->classLoader = require DRUPAL_ROOT . '/autoload.php';
}
/**
* Get a node from the database based on its title.
*
* @param string|\Drupal\Component\Render\MarkupInterface $title
* A node title, usually generated by $this->randomMachineName().
* @param $reset
* (optional) Whether to reset the entity cache.
*
* @return \Drupal\node\NodeInterface
* A node entity matching $title.
*/
function drupalGetNodeByTitle($title, $reset = FALSE) {
if ($reset) {
\Drupal::entityManager()->getStorage('node')->resetCache();
}
// Cast MarkupInterface objects to string.
$title = (string) $title;
$nodes = entity_load_multiple_by_properties('node', array('title' => $title));
// Load the first node returned from the database.
$returned_node = reset($nodes);
return $returned_node;
}
/**
* Creates a node based on default settings.
*
* @param array $settings
* (optional) An associative array of settings for the node, as used in
* entity_create(). Override the defaults by specifying the key and value
* in the array, for example:
* @code
* $this->drupalCreateNode(array(
* 'title' => t('Hello, world!'),
* 'type' => 'article',
* ));
* @endcode
* The following defaults are provided:
* - body: Random string using the default filter format:
* @code
* $settings['body'][0] = array(
* 'value' => $this->randomMachineName(32),
* 'format' => filter_default_format(),
* );
* @endcode
* - title: Random string.
* - type: 'page'.
* - uid: The currently logged in user, or anonymous.
*
* @return \Drupal\node\NodeInterface
* The created node entity.
*/
protected function drupalCreateNode(array $settings = array()) {
// Populate defaults array.
$settings += array(
'body' => array(array(
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
)),
'title' => $this->randomMachineName(8),
'type' => 'page',
'uid' => \Drupal::currentUser()->id(),
);
$node = entity_create('node', $settings);
$node->save();
return $node;
}
/**
* Creates a custom content type based on default settings.
*
* @param array $values
* An array of settings to change from the defaults.
* Example: 'type' => 'foo'.
*
* @return \Drupal\node\Entity\NodeType
* Created content type.
*/
protected function drupalCreateContentType(array $values = array()) {
// Find a non-existent random type name.
if (!isset($values['type'])) {
do {
$id = strtolower($this->randomMachineName(8));
} while (NodeType::load($id));
}
else {
$id = $values['type'];
}
$values += array(
'type' => $id,
'name' => $id,
);
$type = entity_create('node_type', $values);
$status = $type->save();
node_add_body_field($type);
\Drupal::service('router.builder')->rebuild();
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created content type %type.', array('%type' => $type->id())));
return $type;
}
/**
* Builds the renderable view of an entity.
*
@ -390,58 +296,6 @@ abstract class WebTestBase extends TestBase {
return $build;
}
/**
* Creates a block instance based on default settings.
*
* @param string $plugin_id
* The plugin ID of the block type for this block instance.
* @param array $settings
* (optional) An associative array of settings for the block entity.
* Override the defaults by specifying the key and value in the array, for
* example:
* @code
* $this->drupalPlaceBlock('system_powered_by_block', array(
* 'label' => t('Hello, world!'),
* ));
* @endcode
* The following defaults are provided:
* - label: Random string.
* - ID: Random string.
* - region: 'sidebar_first'.
* - theme: The default theme.
* - visibility: Empty array.
*
* @return \Drupal\block\Entity\Block
* The block entity.
*
* @todo
* Add support for creating custom block instances.
*/
protected function drupalPlaceBlock($plugin_id, array $settings = array()) {
$settings += array(
'plugin' => $plugin_id,
'region' => 'sidebar_first',
'id' => strtolower($this->randomMachineName(8)),
'theme' => $this->config('system.theme')->get('default'),
'label' => $this->randomMachineName(8),
'visibility' => array(),
'weight' => 0,
);
$values = [];
foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) {
$values[$key] = $settings[$key];
// Remove extra values that do not belong in the settings array.
unset($settings[$key]);
}
foreach ($values['visibility'] as $id => $visibility) {
$values['visibility'][$id]['id'] = $id;
}
$values['settings'] = $settings;
$block = entity_create('block', $values);
$block->save();
return $block;
}
/**
* Checks to see whether a block appears on the page.
*
@ -674,6 +528,14 @@ abstract class WebTestBase extends TestBase {
* being executed.
*/
protected function setUp() {
// Set an explicit time zone to not rely on the system one, which may vary
// from setup to setup. The Australia/Sydney time zone is chosen so all
// tests are run using an edge case scenario (UTC+10 and DST). This choice
// is made to prevent time zone related regressions and reduce the
// fragility of the testing system in general. This is also set in config in
// \Drupal\simpletest\WebTestBase::initConfig().
date_default_timezone_set('Australia/Sydney');
// Preserve original batch for later restoration.
$this->setBatch();
@ -983,6 +845,7 @@ abstract class WebTestBase extends TestBase {
'name' => 'admin',
'mail' => 'admin@example.com',
'pass_raw' => $this->randomMachineName(),
'timezone' => date_default_timezone_get(),
));
// The child site derives its session name from the database prefix when
@ -2005,8 +1868,7 @@ abstract class WebTestBase extends TestBase {
}
// @todo Ajax commands can target any jQuery selector, but these are
// hard to fully emulate with XPath. For now, just handle 'head'
// and 'body', since these are used by
// \Drupal\Core\Ajax\AjaxResponse::ajaxRender().
// and 'body', since these are used by the Ajax renderer.
elseif (in_array($command['selector'], array('head', 'body'))) {
$wrapperNode = $xpath->query('//' . $command['selector'])->item(0);
}