Core and composer updates
This commit is contained in:
parent
a82634bb98
commit
62cac30480
1118 changed files with 21770 additions and 6306 deletions
|
@ -246,6 +246,20 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
protected $originalShutdownCallbacks = [];
|
||||
|
||||
/**
|
||||
* The number of meta refresh redirects to follow, or NULL if unlimited.
|
||||
*
|
||||
* @var null|int
|
||||
*/
|
||||
protected $maximumMetaRefreshCount = NULL;
|
||||
|
||||
/**
|
||||
* The number of meta refresh redirects followed during ::drupalGet().
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $metaRefreshCount = 0;
|
||||
|
||||
/**
|
||||
* Initializes Mink sessions.
|
||||
*/
|
||||
|
@ -637,6 +651,13 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
|
|||
// Ensure that any changes to variables in the other thread are picked up.
|
||||
$this->refreshVariables();
|
||||
|
||||
// Replace original page output with new output from redirected page(s).
|
||||
if ($new = $this->checkForMetaRefresh()) {
|
||||
$out = $new;
|
||||
// We are finished with all meta refresh redirects, so reset the counter.
|
||||
$this->metaRefreshCount = 0;
|
||||
}
|
||||
|
||||
// Log only for JavascriptTestBase tests because for Goutte we log with
|
||||
// ::getResponseLogHandler.
|
||||
if ($this->htmlOutputEnabled && !($this->getSession()->getDriver() instanceof GoutteDriver)) {
|
||||
|
@ -810,6 +831,12 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
|
|||
// Ensure that any changes to variables in the other thread are picked up.
|
||||
$this->refreshVariables();
|
||||
|
||||
// Check if there are any meta refresh redirects (like Batch API pages).
|
||||
if ($this->checkForMetaRefresh()) {
|
||||
// We are finished with all meta refresh redirects, so reset the counter.
|
||||
$this->metaRefreshCount = 0;
|
||||
}
|
||||
|
||||
// Log only for JavascriptTestBase tests because for Goutte we log with
|
||||
// ::getResponseLogHandler.
|
||||
if ($this->htmlOutputEnabled && !($this->getSession()->getDriver() instanceof GoutteDriver)) {
|
||||
|
@ -1369,4 +1396,26 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
|
|||
return $caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for meta refresh tag and if found call drupalGet() recursively.
|
||||
*
|
||||
* This function looks for the http-equiv attribute to be set to "Refresh" and
|
||||
* is case-sensitive.
|
||||
*
|
||||
* @return string|false
|
||||
* Either the new page content or FALSE.
|
||||
*/
|
||||
protected function checkForMetaRefresh() {
|
||||
$refresh = $this->cssSelect('meta[http-equiv="Refresh"]');
|
||||
if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) {
|
||||
// Parse the content attribute of the meta tag for the format:
|
||||
// "[delay]: URL=[page_to_redirect_to]".
|
||||
if (preg_match('/\d+;\s*URL=(?<url>.*)/i', $refresh[0]->getAttribute('content'), $match)) {
|
||||
$this->metaRefreshCount++;
|
||||
return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url'])));
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,16 @@ class YamlPeclTest extends YamlTestBase {
|
|||
$this->assertEquals($data, YamlPecl::decode(YamlPecl::encode($data)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that php object support is disabled.
|
||||
*/
|
||||
public function testObjectSupportDisabled() {
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
$this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode(YamlPecl::encode([$object])));
|
||||
$this->assertEquals(0, ini_get('yaml.decode_php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests decoding YAML node anchors.
|
||||
*
|
||||
|
|
|
@ -63,4 +63,16 @@ class YamlSymfonyTest extends YamlTestBase {
|
|||
YamlSymfony::decode('foo: [ads');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that php object support is disabled.
|
||||
*
|
||||
* @covers ::encode
|
||||
*/
|
||||
public function testObjectSupportDisabled() {
|
||||
$this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
YamlSymfony::encode([$object]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,6 +76,23 @@ class YamlTest extends UnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that decoding php objects is similar for PECL and Symfony.
|
||||
*
|
||||
* @requires extension yaml
|
||||
*/
|
||||
public function testObjectSupportDisabled() {
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
// In core all Yaml encoding is done via Symfony and it does not support
|
||||
// objects so in order to encode an object we hace to use the PECL
|
||||
// extension.
|
||||
// @see \Drupal\Component\Serialization\Yaml::encode()
|
||||
$yaml = YamlPecl::encode([$object]);
|
||||
$this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode($yaml));
|
||||
$this->assertEquals(['!php/object "O:8:\"stdClass\":1:{s:3:\"foo\";s:3:\"bar\";}"'], YamlSymfony::decode($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider that lists all YAML files in core.
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Component\Render\MarkupTrait;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
|
@ -87,7 +89,12 @@ class HtmlTest extends UnitTestCase {
|
|||
*/
|
||||
public function testHtmlClass() {
|
||||
// Verify Drupal coding standards are enforced.
|
||||
$this->assertSame(Html::getClass('CLASS NAME_[Ü]'), 'class-name--ü', 'Enforce Drupal coding standards.');
|
||||
$this->assertSame('class-name--ü', Html::getClass('CLASS NAME_[Ü]'), 'Enforce Drupal coding standards.');
|
||||
|
||||
// Test Html::getClass() handles Drupal\Component\Render\MarkupInterface
|
||||
// input.
|
||||
$markup = HtmlTestMarkup::create('CLASS_FROM_OBJECT');
|
||||
$this->assertSame('class-from-object', Html::getClass($markup), 'Markup object is converted to CSS class.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,3 +397,11 @@ class HtmlTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks an object's __toString() method as returning markup.
|
||||
*/
|
||||
class HtmlTestMarkup implements MarkupInterface {
|
||||
use MarkupTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class UrlHelperTest extends UnitTestCase {
|
|||
[['a' => ' &#//+%20@۞'], 'a=%20%26%23//%2B%2520%40%DB%9E', 'Value was properly encoded.'],
|
||||
[[' &#//+%20@۞' => 'a'], '%20%26%23%2F%2F%2B%2520%40%DB%9E=a', 'Key was properly encoded.'],
|
||||
[['a' => '1', 'b' => '2', 'c' => '3'], 'a=1&b=2&c=3', 'Multiple values were properly concatenated.'],
|
||||
[['a' => ['b' => '2', 'c' => '3'], 'd' => 'foo'], 'a[b]=2&a[c]=3&d=foo', 'Nested array was properly encoded.'],
|
||||
[['a' => ['b' => '2', 'c' => '3'], 'd' => 'foo'], 'a%5Bb%5D=2&a%5Bc%5D=3&d=foo', 'Nested array was properly encoded.'],
|
||||
[['foo' => NULL], 'foo', 'Simple parameters are properly added.'],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ use Drupal\Core\Ajax\CloseModalDialogCommand;
|
|||
use Drupal\Core\Ajax\SetDialogOptionCommand;
|
||||
use Drupal\Core\Ajax\SetDialogTitleCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Ajax\UpdateBuildIdCommand;
|
||||
|
||||
/**
|
||||
* Test coverage for various classes in the \Drupal\Core\Ajax namespace.
|
||||
|
@ -429,4 +430,20 @@ class AjaxCommandsTest extends UnitTestCase {
|
|||
$this->assertEquals($expected, $command->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Drupal\Core\Ajax\UpdateBuildIdCommand
|
||||
*/
|
||||
public function testUpdateBuildIdCommand() {
|
||||
$old = 'ThisStringisOld';
|
||||
$new = 'ThisStringIsNew';
|
||||
$command = new UpdateBuildIdCommand($old, $new);
|
||||
$expected = [
|
||||
'command' => 'update_build_id',
|
||||
'old' => $old,
|
||||
'new' => $new,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $command->render());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
34
web/core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php
Normal file
34
web/core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Test;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @group Test
|
||||
* @group legacy
|
||||
*
|
||||
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
|
||||
*/
|
||||
class KernelTestBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Drupal\KernelTests\KernelTestBase::isTestInIsolation() is deprecated in Drupal 8.4.x, for removal before the Drupal 9.0.0 release. KernelTestBase tests are always run in isolated processes.
|
||||
*
|
||||
* @covers ::isTestInIsolation
|
||||
*/
|
||||
public function testDeprecatedIsTestInIsolation() {
|
||||
$kernel_test = $this->getMockBuilder(KernelTestBase::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$is_isolated = new \ReflectionMethod($kernel_test, 'isTestInIsolation');
|
||||
$is_isolated->setAccessible(TRUE);
|
||||
|
||||
// Assert that the return value is a bool, because this unit test might or
|
||||
// might not be running in process isolation.
|
||||
$this->assertInternalType('bool', $is_isolated->invoke($kernel_test));
|
||||
}
|
||||
|
||||
}
|
|
@ -736,6 +736,7 @@ class UrlTest extends UnitTestCase {
|
|||
['/?page=1000'],
|
||||
['?page=1000'],
|
||||
['?breed=bengal&page=1000'],
|
||||
['?referrer=https://kittenfacts'],
|
||||
// Paths with various token formats but no leading slash.
|
||||
['/[duckies]'],
|
||||
['/%bunnies'],
|
||||
|
|
71
web/core/tests/Drupal/Tests/EntityViewTrait.php
Normal file
71
web/core/tests/Drupal/Tests/EntityViewTrait.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Provides helper methods to deal with building entity views in tests.
|
||||
*/
|
||||
trait EntityViewTrait {
|
||||
|
||||
/**
|
||||
* 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 buildEntityView(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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Traits\Core;
|
||||
|
||||
/**
|
||||
* Adds ability to convert a list of parameters into a stack of permutations.
|
||||
*/
|
||||
trait GeneratePermutationsTrait {
|
||||
|
||||
/**
|
||||
* 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 = [
|
||||
* 'one' => [0, 1],
|
||||
* 'two' => [2, 3],
|
||||
* ];
|
||||
* $permutations = $this->generatePermutations($parameters);
|
||||
* // Result:
|
||||
* $permutations == [
|
||||
* ['one' => 0, 'two' => 2],
|
||||
* ['one' => 1, 'two' => 2],
|
||||
* ['one' => 0, 'two' => 3],
|
||||
* ['one' => 1, 'two' => 3],
|
||||
* ]
|
||||
* @endcode
|
||||
*
|
||||
* @param array $parameters
|
||||
* An associative array of parameters, keyed by parameter name, and whose
|
||||
* values are arrays of parameter values.
|
||||
*
|
||||
* @return array[]
|
||||
* 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(array $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;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue