Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -7,6 +7,7 @@
namespace Drupal\simpletest;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Random;
use Drupal\Component\Utility\SafeMarkup;
@ -29,6 +30,7 @@ abstract class TestBase {
use SessionTestTrait;
use RandomGeneratorTrait;
use AssertHelperTrait;
/**
* The test run ID.
@ -359,7 +361,7 @@ abstract class TestBase {
* @param $status
* Can be 'pass', 'fail', 'exception', 'debug'.
* TRUE is a synonym for 'pass', FALSE for 'fail'.
* @param $message
* @param string|\Drupal\Component\Render\MarkupInterface $message
* (optional) A message to display with the assertion. Do not translate
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
* variables in the message text, not t(). If left blank, a default message
@ -377,6 +379,9 @@ abstract class TestBase {
* is the caller function itself.
*/
protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) {
if ($message instanceof MarkupInterface) {
$message = (string) $message;
}
// Convert boolean status to string status.
if (is_bool($status)) {
$status = $status ? 'pass' : 'fail';
@ -654,7 +659,17 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertEqual($first, $second, $message = '', $group = 'Other') {
return $this->assert($first == $second, $message ? $message : SafeMarkup::format('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
// Cast objects implementing MarkupInterface to string instead of
// relying on PHP casting them to string depending on what they are being
// comparing with.
$first = $this->castSafeStrings($first);
$second = $this->castSafeStrings($second);
$is_equal = $first == $second;
if (!$is_equal || !$message) {
$default_message = SafeMarkup::format('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($is_equal, $message, $group);
}
/**
@ -679,7 +694,17 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotEqual($first, $second, $message = '', $group = 'Other') {
return $this->assert($first != $second, $message ? $message : SafeMarkup::format('Value @first is not equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
// Cast objects implementing MarkupInterface to string instead of
// relying on PHP casting them to string depending on what they are being
// comparing with.
$first = $this->castSafeStrings($first);
$second = $this->castSafeStrings($second);
$not_equal = $first != $second;
if (!$not_equal || !$message) {
$default_message = SafeMarkup::format('Value @first is not equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($not_equal, $message, $group);
}
/**
@ -704,7 +729,12 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
return $this->assert($first === $second, $message ? $message : SafeMarkup::format('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
$is_identical = $first === $second;
if (!$is_identical || !$message) {
$default_message = SafeMarkup::format('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($is_identical, $message, $group);
}
/**
@ -729,7 +759,12 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
return $this->assert($first !== $second, $message ? $message : SafeMarkup::format('Value @first is not identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
$not_identical = $first !== $second;
if (!$not_identical || !$message) {
$default_message = SafeMarkup::format('Value @first is not identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($not_identical, $message, $group);
}
/**
@ -754,9 +789,9 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') {
$message = $message ?: SafeMarkup::format('!object1 is identical to !object2', array(
'!object1' => var_export($object1, TRUE),
'!object2' => var_export($object2, TRUE),
$message = $message ?: SafeMarkup::format('@object1 is identical to @object2', array(
'@object1' => var_export($object1, TRUE),
'@object2' => var_export($object2, TRUE),
));
$identical = TRUE;
foreach ($object1 as $key => $value) {
@ -872,7 +907,8 @@ abstract class TestBase {
$verbose_filename = $this->verboseClassName . '-' . $this->verboseId . '-' . $this->testId . '.html';
if (file_put_contents($this->verboseDirectory . '/' . $verbose_filename, $message)) {
$url = $this->verboseDirectoryUrl . '/' . $verbose_filename;
// Not using _l() to avoid invoking the theme system, so that unit tests
// Not using \Drupal\Core\Utility\LinkGeneratorInterface::generate()
// to avoid invoking the theme system, so that unit tests
// can use verbose() as well.
$url = '<a href="' . $url . '" target="_blank">Verbose message</a>';
$this->error($url, 'User notice');
@ -933,6 +969,10 @@ abstract class TestBase {
$this->httpAuthCredentials = $username . ':' . $password;
}
// Force assertion failures to be thrown as AssertionError for PHP 5 & 7
// compatibility.
\Drupal\Component\Assertion\Handle::register();
set_error_handler(array($this, 'errorHandler'));
// Iterate through all the methods in this class, unless a specific list of
// methods to run was passed.
@ -1478,7 +1518,7 @@ abstract class TestBase {
if (!$this->configImporter) {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.staging'),
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
);