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

This commit is contained in:
Pantheon Automation 2016-04-07 11:19:57 -07:00 committed by Greg Anderson
parent 4297c64508
commit b11a755ba8
159 changed files with 2340 additions and 543 deletions

View file

@ -0,0 +1,203 @@
<?php
/**
* @file
* Contains \Drupal\KernelTests\Core\Entity\EntityKernelTestBase.
*/
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
/**
* Defines an abstract test base for entity kernel tests.
*/
abstract class EntityKernelTestBase extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user', 'system', 'field', 'text', 'filter', 'entity_test'];
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* A list of generated identifiers.
*
* @var array
*/
protected $generatedIds = array();
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
protected function setUp() {
parent::setUp();
$this->entityManager = $this->container->get('entity.manager');
$this->state = $this->container->get('state');
$this->installSchema('system', 'sequences');
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
// If the concrete test sub-class installs the Node or Comment modules,
// ensure that the node and comment entity schema are created before the
// field configurations are installed. This is because the entity tables
// need to be created before the body field storage tables. This prevents
// trying to create the body field tables twice.
$class = get_class($this);
while ($class) {
if (property_exists($class, 'modules')) {
// Only check the modules, if the $modules property was not inherited.
$rp = new \ReflectionProperty($class, 'modules');
if ($rp->class == $class) {
foreach (array_intersect(array('node', 'comment'), $class::$modules) as $module) {
$this->installEntitySchema($module);
}
if (in_array('forum', $class::$modules, TRUE)) {
// Forum module is particular about the order that dependencies are
// enabled in. The comment, node and taxonomy config and the
// taxonomy_term schema need to be installed before the forum config
// which in turn needs to be installed before field config.
$this->installConfig(['comment', 'node', 'taxonomy']);
$this->installEntitySchema('taxonomy_term');
$this->installConfig(['forum']);
}
}
}
$class = get_parent_class($class);
}
$this->installConfig(array('field'));
}
/**
* Creates a user.
*
* @param array $values
* (optional) The values used to create the entity.
* @param array $permissions
* (optional) Array of permission names to assign to user.
*
* @return \Drupal\user\Entity\User
* The created user entity.
*/
protected function createUser($values = array(), $permissions = array()) {
if ($permissions) {
// Create a new role and apply permissions to it.
$role = Role::create(array(
'id' => strtolower($this->randomMachineName(8)),
'label' => $this->randomMachineName(8),
));
$role->save();
user_role_grant_permissions($role->id(), $permissions);
$values['roles'][] = $role->id();
}
$account = User::create($values + array(
'name' => $this->randomMachineName(),
'status' => 1,
));
$account->enforceIsNew();
$account->save();
return $account;
}
/**
* Reloads the given entity from the storage and returns it.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be reloaded.
*
* @return \Drupal\Core\Entity\EntityInterface
* The reloaded entity.
*/
protected function reloadEntity(EntityInterface $entity) {
$controller = $this->entityManager->getStorage($entity->getEntityTypeId());
$controller->resetCache(array($entity->id()));
return $controller->load($entity->id());
}
/**
* Returns the entity_test hook invocation info.
*
* @return array
* An associative array of arbitrary hook data keyed by hook name.
*/
protected function getHooksInfo() {
$key = 'entity_test.hooks';
$hooks = $this->state->get($key);
$this->state->set($key, array());
return $hooks;
}
/**
* Installs a module and refreshes services.
*
* @param string $module
* The module to install.
*/
protected function installModule($module) {
$this->enableModules(array($module));
$this->refreshServices();
}
/**
* Uninstalls a module and refreshes services.
*
* @param string $module
* The module to uninstall.
*/
protected function uninstallModule($module) {
$this->disableModules(array($module));
$this->refreshServices();
}
/**
* Refresh services.
*/
protected function refreshServices() {
$this->container = \Drupal::getContainer();
$this->entityManager = $this->container->get('entity.manager');
$this->state = $this->container->get('state');
}
/**
* Generates a random ID avoiding collisions.
*
* @param bool $string
* (optional) Whether the id should have string type. Defaults to FALSE.
*
* @return int|string
* The entity identifier.
*/
protected function generateRandomEntityId($string = FALSE) {
srand(time());
do {
// 0x7FFFFFFF is the maximum allowed value for integers that works for all
// Drupal supported databases and is known to work for other databases
// like SQL Server 2014 and Oracle 10 too.
$id = $string ? $this->randomMachineName() : mt_rand(1, 0x7FFFFFFF);
}
while (isset($this->generatedIds[$id]));
$this->generatedIds[$id] = $id;
return $id;
}
}

View file

@ -0,0 +1,96 @@
<?php
/**
* @file
* Contains \Drupal\KernelTests\Core\Test\AssertMailTraitTest.
*/
namespace Drupal\KernelTests\Core\Test;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests \Drupal\Core\Test\AssertMailTrait works.
*
* @group Test
*
* @coversDefaultClass \Drupal\Core\Test\AssertMailTrait
*/
class AssertMailTraitTest extends KernelTestBase {
use AssertMailTrait;
/**
* Tests that the maintenance theme initializes the theme and its base themes.
*/
public function testAssertMailTrait() {
/* @var \Drupal\Core\Mail\MailManagerInterface $mail_service */
$mail_service = \Drupal::service('plugin.manager.mail');
// Create an email.
$subject = $this->randomString(64);
$body = $this->randomString(128);
$message = [
'id' => 'drupal_mail_test',
'headers' => ['Content-type' => 'text/html'],
'subject' => $subject,
'to' => 'foobar@example.com',
'body' => $body,
];
// Before we send the email, \Drupal\Core\Test\AssertMailTrait::getMails()
// should return an empty array.
$captured_emails = $this->getMails();
$this->assertCount(0, $captured_emails, 'The captured emails queue is empty.');
// Send the email.
$mail_service->getInstance(['module' => 'simpletest', 'key' => 'drupal_mail_test'])->mail($message);
// Ensure that there is one email in the captured emails array.
$captured_emails = $this->getMails();
$this->assertEquals(count($captured_emails), 1, 'One email was captured.');
// Assert that the email was sent by iterating over the message properties
// and ensuring that they are captured intact.
foreach ($message as $field => $value) {
$this->assertMail($field, $value, "The email was sent and the value for property $field is intact.");
}
// Send additional emails so more than one email is captured.
for ($index = 0; $index < 5; $index++) {
$message = [
'id' => 'drupal_mail_test_' . $index,
'headers' => ['Content-type' => 'text/html'],
'subject' => $this->randomString(64),
'to' => $this->randomMachineName(32) . '@example.com',
'body' => $this->randomString(512),
];
$mail_service->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message);
}
// There should now be 6 emails captured.
$captured_emails = $this->getMails();
$this->assertCount(6, $captured_emails, 'All emails were captured.');
// Test different ways of getting filtered emails via
// \Drupal\Core\Test\AssertMailTrait::getMails().
$captured_emails = $this->getMails(['id' => 'drupal_mail_test']);
$this->assertCount(1, $captured_emails, 'Only one email is returned when filtering by id.');
$captured_emails = $this->getMails(['id' => 'drupal_mail_test', 'subject' => $subject]);
$this->assertCount(1, $captured_emails, 'Only one email is returned when filtering by id and subject.');
$captured_emails = $this->getMails([
'id' => 'drupal_mail_test',
'subject' => $subject,
'from' => 'this_was_not_used@example.com',
]);
$this->assertCount(0, $captured_emails, 'No emails are returned when querying with an unused from address.');
// Send the last email again, so we can confirm that
// \Drupal\Core\Test\AssertMailTrait::getMails() filters correctly returns
// all emails with a given property/value.
$mail_service->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message);
$captured_emails = $this->getMails(['id' => 'drupal_mail_test_4']);
$this->assertCount(2, $captured_emails, 'All emails with the same id are returned when filtering by id.');
}
}

View file

@ -370,6 +370,12 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
'class' => '\Drupal\Component\PhpStorage\FileStorage',
];
new Settings($settings);
// Manually configure the test mail collector implementation to prevent
// tests from sending out emails and collect them in state instead.
// While this should be enforced via settings.php prior to installation,
// some tests expect to be able to test mail system implementations.
$GLOBALS['config']['system.mail']['interface']['default'] = 'test_mail_collector';
}
/**
@ -1140,4 +1146,14 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
return [];
}
/**
* {@inheritdoc}
*/
public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) {
$expected = static::castSafeStrings($expected);
$actual = static::castSafeStrings($actual);
parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
}
}

View file

@ -259,4 +259,30 @@ class NestedArrayTest extends UnitTestCase {
$this->assertSame($expected, $actual, 'drupal_array_merge_deep() ignores numeric key order when merging.');
}
/**
* @covers ::filter
* @dataProvider providerTestFilter
*/
public function testFilter($array, $callable, $expected) {
$this->assertEquals($expected, NestedArray::filter($array, $callable));
}
public function providerTestFilter() {
$data = [];
$data['1d-array'] = [
[0, 1, '', TRUE], NULL, [1 => 1, 3 => TRUE]
];
$data['1d-array-callable'] = [
[0, 1, '', TRUE], function ($element) { return $element === ''; }, [2 => '']
];
$data['2d-array'] = [
[[0, 1, '', TRUE], [0, 1, 2, 3]], NULL, [0 => [1 => 1, 3 => TRUE], 1 => [1 => 1, 2 => 2, 3 => 3]],
];
$data['2d-array-callable'] = [
[[0, 1, '', TRUE], [0, 1, 2, 3]], function ($element) { return is_array($element) || $element === 3; }, [0 => [], 1 => [3 => 3]],
];
return $data;
}
}