Core and composer updates

This commit is contained in:
Rob Davies 2017-07-03 16:47:07 +01:00
parent a82634bb98
commit 62cac30480
1118 changed files with 21770 additions and 6306 deletions

View file

@ -15,6 +15,7 @@ use Drupal\Core\Utility\Error;
use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\Tests\SessionTestTrait;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
/**
* Base class for Drupal tests.
@ -27,6 +28,7 @@ abstract class TestBase {
use SessionTestTrait;
use RandomGeneratorTrait;
use AssertHelperTrait;
use GeneratePermutationsTrait;
// For backwards compatibility switch the visbility of the methods to public.
use ConfigTestTrait {
configImporter as public;
@ -1343,55 +1345,6 @@ abstract class TestBase {
new Settings($settings);
}
/**
* Converts a list of possible parameters into a stack of permutations.
*
* Takes a list of parameters containing possible values, and converts all of
* them into a list of items containing every possible permutation.
*
* Example:
* @code
* $parameters = array(
* 'one' => array(0, 1),
* 'two' => array(2, 3),
* );
* $permutations = TestBase::generatePermutations($parameters);
* // Result:
* $permutations == array(
* array('one' => 0, 'two' => 2),
* array('one' => 1, 'two' => 2),
* array('one' => 0, 'two' => 3),
* array('one' => 1, 'two' => 3),
* )
* @endcode
*
* @param $parameters
* An associative array of parameters, keyed by parameter name, and whose
* values are arrays of parameter values.
*
* @return
* A list of permutations, which is an array of arrays. Each inner array
* contains the full list of parameters that have been passed, but with a
* single value only.
*/
public static function generatePermutations($parameters) {
$all_permutations = [[]];
foreach ($parameters as $parameter => $values) {
$new_permutations = [];
// Iterate over all values of the parameter.
foreach ($values as $value) {
// Iterate over all existing permutations.
foreach ($all_permutations as $permutation) {
// Add the new parameter value to existing permutations.
$new_permutations[] = $permutation + [$parameter => $value];
}
}
// Replace the old permutations with the new permutations.
$all_permutations = $new_permutations;
}
return $all_permutations;
}
/**
* Ensures test files are deletable within file_unmanaged_delete_recursive().
*

View file

@ -9,16 +9,15 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Core\Test\FunctionalTestSetupTrait;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\Tests\EntityViewTrait;
use Drupal\Tests\Traits\Core\CronRunTrait;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\XdebugRequestTrait;
@ -59,6 +58,9 @@ abstract class WebTestBase extends TestBase {
}
use XdebugRequestTrait;
use EntityViewTrait {
buildEntityView as drupalBuildEntityView;
}
/**
* The profile to install as a basis for testing.
@ -209,64 +211,6 @@ abstract class WebTestBase extends TestBase {
$this->classLoader = require DRUPAL_ROOT . '/autoload.php';
}
/**
* Builds the renderable view of an entity.
*
* Entities postpone the composition of their renderable arrays to #pre_render
* functions in order to maximize cache efficacy. This means that the full
* renderable array for an entity is constructed in drupal_render(). Some
* tests require the complete renderable array for an entity outside of the
* drupal_render process in order to verify the presence of specific values.
* This method isolates the steps in the render process that produce an
* entity's renderable array.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to prepare a renderable array for.
* @param string $view_mode
* (optional) The view mode that should be used to build the entity.
* @param null $langcode
* (optional) For which language the entity should be prepared, defaults to
* the current content language.
* @param bool $reset
* (optional) Whether to clear the cache for this entity.
* @return array
*
* @see drupal_render()
*/
protected function drupalBuildEntityView(EntityInterface $entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE) {
$ensure_fully_built = function(&$elements) use (&$ensure_fully_built) {
// If the default values for this element have not been loaded yet, populate
// them.
if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) {
$elements += \Drupal::service('element_info')->getInfo($elements['#type']);
}
// Make any final changes to the element before it is rendered. This means
// that the $element or the children can be altered or corrected before the
// element is rendered into the final text.
if (isset($elements['#pre_render'])) {
foreach ($elements['#pre_render'] as $callable) {
$elements = call_user_func($callable, $elements);
}
}
// And recurse.
$children = Element::children($elements, TRUE);
foreach ($children as $key) {
$ensure_fully_built($elements[$key]);
}
};
$render_controller = $this->container->get('entity.manager')->getViewBuilder($entity->getEntityTypeId());
if ($reset) {
$render_controller->resetCache([$entity->id()]);
}
$build = $render_controller->view($entity, $view_mode, $langcode);
$ensure_fully_built($build);
return $build;
}
/**
* Checks to see whether a block appears on the page.
*