updated core to 8.6.3

This commit is contained in:
2018-11-21 12:49:46 +01:00
parent 8ca34853a3
commit c92c348eee
521 changed files with 12199 additions and 4578 deletions
@@ -0,0 +1,103 @@
<?php
namespace Drupal\KernelTests\Core\Ajax;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Performs tests on AJAX framework commands.
*
* @group Ajax
*/
class CommandsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'node', 'ajax_test', 'ajax_forms_test'];
/**
* Regression test: Settings command exists regardless of JS aggregation.
*/
public function testAttachedSettings() {
$assert = function ($message) {
$response = new AjaxResponse();
$response->setAttachments([
'library' => ['core/drupalSettings'],
'drupalSettings' => ['foo' => 'bar'],
]);
$ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
$subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
$event = new FilterResponseEvent(
\Drupal::service('http_kernel'),
new Request(),
HttpKernelInterface::MASTER_REQUEST,
$response
);
$subscriber->onResponse($event);
$expected = [
'command' => 'settings',
];
$this->assertCommand($response->getCommands(), $expected, $message);
};
$config = $this->config('system.performance');
$config->set('js.preprocess', FALSE)->save();
$assert('Settings command exists when JS aggregation is disabled.');
$config->set('js.preprocess', TRUE)->save();
$assert('Settings command exists when JS aggregation is enabled.');
}
/**
* Asserts the array of Ajax commands contains the searched command.
*
* An AjaxResponse object stores an array of Ajax commands. This array
* sometimes includes commands automatically provided by the framework in
* addition to commands returned by a particular controller. During testing,
* we're usually interested that a particular command is present, and don't
* care whether other commands precede or follow the one we're interested in.
* Additionally, the command we're interested in may include additional data
* that we're not interested in. Therefore, this function simply asserts that
* one of the commands in $haystack contains all of the keys and values in
* $needle. Furthermore, if $needle contains a 'settings' key with an array
* value, we simply assert that all keys and values within that array are
* present in the command we're checking, and do not consider it a failure if
* the actual command contains additional settings that aren't part of
* $needle.
*
* @param $haystack
* An array of rendered Ajax commands returned by the server.
* @param $needle
* Array of info we're expecting in one of those commands.
* @param $message
* An assertion message.
*/
protected function assertCommand($haystack, $needle, $message) {
$found = FALSE;
foreach ($haystack as $command) {
// If the command has additional settings that we're not testing for, do
// not consider that a failure.
if (isset($command['settings']) && is_array($command['settings']) && isset($needle['settings']) && is_array($needle['settings'])) {
$command['settings'] = array_intersect_key($command['settings'], $needle['settings']);
}
// If the command has additional data that we're not testing for, do not
// consider that a failure. Also, == instead of ===, because we don't
// require the key/value pairs to be in any particular order
// (http://php.net/manual/language.operators.array.php).
if (array_intersect_key($command, $needle) == $needle) {
$found = TRUE;
break;
}
}
$this->assertTrue($found, $message);
}
}
@@ -12,62 +12,42 @@ use Drupal\KernelTests\KernelTestBase;
* @group Common
*/
class SizeTest extends KernelTestBase {
protected $exactTestCases;
protected $roundedTestCases;
protected function setUp() {
parent::setUp();
$kb = Bytes::KILOBYTE;
$this->exactTestCases = [
'1 byte' => 1,
'1 KB' => $kb,
'1 MB' => $kb * $kb,
'1 GB' => $kb * $kb * $kb,
'1 TB' => $kb * $kb * $kb * $kb,
'1 PB' => $kb * $kb * $kb * $kb * $kb,
'1 EB' => $kb * $kb * $kb * $kb * $kb * $kb,
'1 ZB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb,
'1 YB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb * $kb,
];
$this->roundedTestCases = [
'2 bytes' => 2,
// Rounded to 1 MB (not 1000 or 1024 kilobyte!).
'1 MB' => ($kb * $kb) - 1,
// Megabytes.
round(3623651 / ($this->exactTestCases['1 MB']), 2) . ' MB' => 3623651,
// Petabytes.
round(67234178751368124 / ($this->exactTestCases['1 PB']), 2) . ' PB' => 67234178751368124,
// Yottabytes.
round(235346823821125814962843827 / ($this->exactTestCases['1 YB']), 2) . ' YB' => 235346823821125814962843827,
];
}
/**
* Checks that format_size() returns the expected string.
*
* @dataProvider providerTestCommonFormatSize
*/
public function testCommonFormatSize() {
foreach ([$this->exactTestCases, $this->roundedTestCases] as $test_cases) {
foreach ($test_cases as $expected => $input) {
$this->assertEqual(
($result = format_size($input, NULL)),
$expected,
$expected . ' == ' . $result . ' (' . $input . ' bytes)'
);
}
}
public function testCommonFormatSize($expected, $input) {
$size = format_size($input, NULL);
$this->assertEquals($expected, $size);
}
/**
* Cross-tests Bytes::toInt() and format_size().
* Provides a list of byte size to test.
*/
public function testCommonParseSizeFormatSize() {
foreach ($this->exactTestCases as $size) {
$this->assertEqual(
$size,
($parsed_size = Bytes::toInt($string = format_size($size, NULL))),
$size . ' == ' . $parsed_size . ' (' . $string . ')'
);
}
public function providerTestCommonFormatSize() {
$kb = Bytes::KILOBYTE;
return [
['1 byte', 1],
['2 bytes', 2],
['1 KB', $kb],
['1 MB', pow($kb, 2)],
['1 GB', pow($kb, 3)],
['1 TB', pow($kb, 4)],
['1 PB', pow($kb, 5)],
['1 EB', pow($kb, 6)],
['1 ZB', pow($kb, 7)],
['1 YB', pow($kb, 8)],
// Rounded to 1 MB - not 1000 or 1024 kilobyte
['1 MB', ($kb * $kb) - 1],
// Decimal Megabytes
['3.46 MB', 3623651],
// Decimal Petabytes
['59.72 PB', 67234178751368124],
// Decimal Yottabytes
['194.67 YB', 235346823821125814962843827],
];
}
}
@@ -623,7 +623,7 @@ class ConfigImporterTest extends KernelTestBase {
}
}
// Make a config entity have mulitple unmet dependencies.
// Make a config entity have multiple unmet dependencies.
$config_entity_data = $sync->read('config_test.dynamic.dotted.default');
$config_entity_data['dependencies'] = ['module' => ['unknown', 'dblog']];
$sync->write('config_test.dynamic.dotted.module', $config_entity_data);
@@ -848,7 +848,7 @@ class ConfigImporterTest extends KernelTestBase {
}
/**
* Helper meothd to test custom config installer steps.
* Helper method to test custom config installer steps.
*
* @param array $context
* Batch context.
@@ -151,6 +151,11 @@ abstract class ConfigStorageTestBase extends KernelTestBase {
// Listing on a non-existing storage bin returns an empty array.
$result = $this->invalidStorage->listAll();
$this->assertIdentical($result, []);
// Getting all collections on a non-existing storage bin return an empty
// array.
$this->assertSame([], $this->invalidStorage->getAllCollectionNames());
// Writing to a non-existing storage bin creates the bin.
$this->invalidStorage->write($name, ['foo' => 'bar']);
$result = $this->invalidStorage->read($name);
@@ -30,7 +30,7 @@ class PrefixInfoTest extends DatabaseTestBase {
$db1_schema = $db1_connection->schema();
$db2_connection = Database::getConnection('default', 'extra');
// Get the prefix info for the first databse.
// Get the prefix info for the first database.
$method = new \ReflectionMethod($db1_schema, 'getPrefixInfo');
$method->setAccessible(TRUE);
$db1_info = $method->invoke($db1_schema);
@@ -22,6 +22,10 @@ class SelectCloneTest extends DatabaseTestBase {
$query->condition('id', $subquery, 'IN');
$clone = clone $query;
// Cloned query should have a different unique identifier.
$this->assertNotEquals($query->uniqueIdentifier(), $clone->uniqueIdentifier());
// Cloned query should not be altered by the following modification
// happening on original query.
$subquery->condition('age', 25, '>');
@@ -34,4 +38,31 @@ class SelectCloneTest extends DatabaseTestBase {
$this->assertEqual(2, $query_result, 'The query returns the expected number of rows');
}
/**
* Tests that nested SELECT queries are cloned properly.
*/
public function testNestedQueryCloning() {
$sub_query = $this->connection->select('test', 't');
$sub_query->addField('t', 'id', 'id');
$sub_query->condition('age', 28, '<');
$query = $this->connection->select($sub_query, 't');
$clone = clone $query;
// Cloned query should have a different unique identifier.
$this->assertNotEquals($query->uniqueIdentifier(), $clone->uniqueIdentifier());
// Cloned query should not be altered by the following modification
// happening on original query.
$sub_query->condition('age', 25, '>');
$clone_result = $clone->countQuery()->execute()->fetchField();
$query_result = $query->countQuery()->execute()->fetchField();
// Make sure the cloned query has not been modified.
$this->assertEquals(3, $clone_result, 'The cloned query returns the expected number of rows');
$this->assertEquals(2, $query_result, 'The query returns the expected number of rows');
}
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\KernelTests\Core\Entity;
/**
* @coversDefaultClass \Drupal\Core\Entity\EntityBundleListener
*
* @group Entity
*/
class EntityBundleListenerTest extends EntityKernelTestBase {
/**
* @covers ::onBundleCreate
*
* Note: Installing the entity_schema_test module will mask the bug this test
* was written to cover, as the field map cache is cleared manually by
* \Drupal\Core\Field\FieldDefinitionListener::onFieldDefinitionCreate().
*/
public function testOnBundleCreate() {
$field_map = $this->container->get('entity_field.manager')->getFieldMap();
$expected = [
'entity_test' => 'entity_test',
];
$this->assertEquals($expected, $field_map['entity_test']['id']['bundles']);
entity_test_create_bundle('custom');
$field_map = $this->container->get('entity_field.manager')->getFieldMap();
$expected = [
'entity_test' => 'entity_test',
'custom' => 'custom',
];
$this->assertSame($expected, $field_map['entity_test']['id']['bundles']);
}
}
@@ -57,7 +57,7 @@ class EntityDecoupledTranslationRevisionsTest extends EntityKernelTestBase {
protected $previousRevisionId = [];
/**
* The previous unstranslatable field value.
* The previous untranslatable field value.
*
* @var string[]
*/
@@ -4,9 +4,9 @@ namespace Drupal\KernelTests\Core\Entity;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Tests the Entity Query relationship API.
@@ -6,10 +6,10 @@ use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -630,7 +630,7 @@ class EntityQueryTest extends EntityKernelTestBase {
->condition("$figures.%delta", 1)
->sort('id')
->execute();
// Entity needs to have atleast two figures.
// Entity needs to have at least two figures.
$this->assertResult(3, 7, 11, 15);
// Numeric delta on single value base field should return results only if
@@ -7,9 +7,9 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
@@ -3,11 +3,13 @@
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Tests adding a custom bundle field.
* Tests the default entity storage schema handler.
*
* @group system
* @group Entity
*/
class EntitySchemaTest extends EntityKernelTestBase {
@@ -109,6 +111,178 @@ class EntitySchemaTest extends EntityKernelTestBase {
$this->assertTrue($schema_handler->tableExists($dedicated_tables[0]), new FormattableMarkup('Field schema correct for the @table table.', ['@table' => $table]));
}
/**
* Tests deleting and creating a field that is part of a primary key.
*
* @param string $entity_type_id
* The ID of the entity type whose schema is being tested.
* @param string $field_name
* The name of the field that is being re-installed.
*
* @dataProvider providerTestPrimaryKeyUpdate
*/
public function testPrimaryKeyUpdate($entity_type_id, $field_name) {
// EntityKernelTestBase::setUp() already installs the schema for the
// 'entity_test' entity type.
if ($entity_type_id !== 'entity_test') {
$this->installEntitySchema($entity_type_id);
}
/* @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager */
$update_manager = $this->container->get('entity.definition_update_manager');
$entity_type = $update_manager->getEntityType($entity_type_id);
/* @see \Drupal\Core\Entity\ContentEntityBase::baseFieldDefinitions() */
switch ($field_name) {
case 'id':
$field = BaseFieldDefinition::create('integer')
->setLabel('ID')
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
break;
case 'revision_id':
$field = BaseFieldDefinition::create('integer')
->setLabel('Revision ID')
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
break;
case 'langcode':
$field = BaseFieldDefinition::create('language')
->setLabel('Language');
if ($entity_type->isRevisionable()) {
$field->setRevisionable(TRUE);
}
if ($entity_type->isTranslatable()) {
$field->setTranslatable(TRUE);
}
break;
}
$field
->setName($field_name)
->setTargetEntityTypeId($entity_type_id)
->setProvider($entity_type->getProvider());
// Build up a map of expected primary keys depending on the entity type
// configuration.
$id_key = $entity_type->getKey('id');
$revision_key = $entity_type->getKey('revision');
$langcode_key = $entity_type->getKey('langcode');
$expected = [];
$expected[$entity_type->getBaseTable()] = [$id_key];
if ($entity_type->isRevisionable()) {
$expected[$entity_type->getRevisionTable()] = [$revision_key];
}
if ($entity_type->isTranslatable()) {
$expected[$entity_type->getDataTable()] = [$id_key, $langcode_key];
}
if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
$expected[$entity_type->getRevisionDataTable()] = [$revision_key, $langcode_key];
}
// First, test explicitly deleting and re-installing a field. Make sure that
// all primary keys are there to start with.
$this->assertSame($expected, $this->findPrimaryKeys($entity_type));
// Then uninstall the field and make sure all primary keys that the field
// was part of have been updated. Since this is not a valid state of the
// entity type (for example a revisionable entity type without a revision ID
// field or a translatable entity type without a language code field) the
// actual primary keys at this point are irrelevant.
$update_manager->uninstallFieldStorageDefinition($field);
$this->assertNotEquals($expected, $this->findPrimaryKeys($entity_type));
// Finally, reinstall the field and make sure the primary keys have been
// recreated.
$update_manager->installFieldStorageDefinition($field->getName(), $entity_type_id, $field->getProvider(), $field);
$this->assertSame($expected, $this->findPrimaryKeys($entity_type));
// Now test updating a field without data. This will end up deleting
// and re-creating the field, similar to the code above.
$update_manager->updateFieldStorageDefinition($field);
$this->assertSame($expected, $this->findPrimaryKeys($entity_type));
// Now test updating a field with data.
/* @var \Drupal\Core\Entity\FieldableEntityStorageInterface $storage */
$storage = $this->entityManager->getStorage($entity_type_id);
// The schema of ID fields is incorrectly recreated as 'int' instead of
// 'serial', so we manually have to specify an ID.
// @todo Remove this in https://www.drupal.org/project/drupal/issues/2928906
$storage->create(['id' => 1, 'revision_id' => 1])->save();
$this->assertTrue($storage->countFieldData($field, TRUE));
$update_manager->updateFieldStorageDefinition($field);
$this->assertSame($expected, $this->findPrimaryKeys($entity_type));
$this->assertTrue($storage->countFieldData($field, TRUE));
}
/**
* Finds the primary keys for a given entity type.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type whose primary keys are being fetched.
*
* @return array[]
* An array where the keys are the table names of the entity type's tables
* and the values are a list of the respective primary keys.
*/
protected function findPrimaryKeys(EntityTypeInterface $entity_type) {
$base_table = $entity_type->getBaseTable();
$revision_table = $entity_type->getRevisionTable();
$data_table = $entity_type->getDataTable();
$revision_data_table = $entity_type->getRevisionDataTable();
$schema = $this->database->schema();
$find_primary_key_columns = new \ReflectionMethod(get_class($schema), 'findPrimaryKeyColumns');
$find_primary_key_columns->setAccessible(TRUE);
// Build up a map of primary keys depending on the entity type
// configuration. If the field that is being removed is part of a table's
// primary key, we skip the assertion for that table as this represents an
// intermediate and invalid state of the entity schema.
$primary_keys[$base_table] = $find_primary_key_columns->invoke($schema, $base_table);
if ($entity_type->isRevisionable()) {
$primary_keys[$revision_table] = $find_primary_key_columns->invoke($schema, $revision_table);
}
if ($entity_type->isTranslatable()) {
$primary_keys[$data_table] = $find_primary_key_columns->invoke($schema, $data_table);
}
if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
$primary_keys[$revision_data_table] = $find_primary_key_columns->invoke($schema, $revision_data_table);
}
return $primary_keys;
}
/**
* Provides test cases for EntitySchemaTest::testPrimaryKeyUpdate()
*
* @return array
* An array of test cases consisting of an entity type ID and a field name.
*/
public function providerTestPrimaryKeyUpdate() {
// Build up test cases for all possible entity type configurations.
// For each entity type we test reinstalling each field that is part of
// any table's primary key.
$tests = [];
$tests['entity_test:id'] = ['entity_test', 'id'];
$tests['entity_test_rev:id'] = ['entity_test_rev', 'id'];
$tests['entity_test_rev:revision_id'] = ['entity_test_rev', 'revision_id'];
$tests['entity_test_mul:id'] = ['entity_test_mul', 'id'];
$tests['entity_test_mul:langcode'] = ['entity_test_mul', 'langcode'];
$tests['entity_test_mulrev:id'] = ['entity_test_mulrev', 'id'];
$tests['entity_test_mulrev:revision_id'] = ['entity_test_mulrev', 'revision_id'];
$tests['entity_test_mulrev:langcode'] = ['entity_test_mulrev', 'langcode'];
return $tests;
}
/**
* {@inheritdoc}
*/
@@ -4,8 +4,8 @@ namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
@@ -154,12 +154,12 @@ class RevisionableContentEntityBaseTest extends EntityKernelTestBase {
}
/**
* Asserts the ammount of items on entity related tables.
* Asserts the amount of items on entity related tables.
*
* @param int $count
* The number of items expected to be in revisions related tables.
* @param \Drupal\Core\Entity\EntityTypeInterface $definition
* The definition and metada of the entity being tested.
* The definition and metadata of the entity being tested.
*/
protected function assertItemsTableCount($count, EntityTypeInterface $definition) {
$this->assertEqual(1, db_query('SELECT COUNT(*) FROM {' . $definition->getBaseTable() . '}')->fetchField());
@@ -6,9 +6,9 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
@@ -201,7 +201,7 @@ class ValidReferenceConstraintValidatorTest extends EntityKernelTestBase {
$violations = $referencing_entity->field_test->validate();
$this->assertCount(0, $violations);
// Remove one of the referencable bundles and check that a pre-existing node
// Remove one of the referenceable bundles and check that a pre-existing node
// of that bundle can not be referenced anymore.
$field = FieldConfig::loadByName('entity_test', 'entity_test', 'field_test');
$field->setSetting('handler_settings', ['target_bundles' => ['article']]);
@@ -53,7 +53,7 @@ class MimeTypeTest extends FileTestBase {
$this->assertIdentical($output, $expected, format_string('Mimetype (using default mappings) for %input is %output (expected: %expected).', ['%input' => $input, '%output' => $output, '%expected' => $expected]));
}
// Now test the extension gusser by passing in a custom mapping.
// Now test the extension guesser by passing in a custom mapping.
$mapping = [
'mimetypes' => [
0 => 'application/java-archive',
@@ -8,7 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests form validation mesages are displayed in the same order as the fields.
* Tests form validation messages are displayed in the same order as the fields.
*
* @group Form
*/
@@ -0,0 +1,50 @@
<?php
namespace Drupal\KernelTests\Core\Menu;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the local action manager.
*
* @coversDefaultClass \Drupal\Core\Menu\LocalActionManager
* @group Menu
*/
class LocalActionManagerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_test', 'user', 'system'];
/**
* Tests the cacheability of local actions.
*/
public function testCacheability() {
/** @var \Drupal\Core\Menu\LocalActionManager $local_action_manager */
$local_action_manager = \Drupal::service('plugin.manager.menu.local_action');
$build = [
'#cache' => [
'key' => 'foo',
],
$local_action_manager->getActionsForRoute('menu_test.local_action7'),
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$renderer->renderRoot($build);
$this->assertContains('menu_local_action7', $build[0]['menu_test.local_action7']['#cache']['tags']);
$this->assertContains('url.query_args:menu_local_action7', $build[0]['menu_test.local_action7']['#cache']['contexts']);
$this->assertContains('menu_local_action8', $build[0]['menu_test.local_action8']['#cache']['tags']);
$this->assertContains('url.query_args:menu_local_action8', $build[0]['menu_test.local_action8']['#cache']['contexts']);
$this->assertContains('menu_local_action7', $build['#cache']['tags']);
$this->assertContains('url.query_args:menu_local_action7', $build['#cache']['contexts']);
$this->assertContains('menu_local_action8', $build['#cache']['tags']);
$this->assertContains('url.query_args:menu_local_action8', $build['#cache']['contexts']);
}
}
@@ -241,7 +241,7 @@ class AliasTest extends PathUnitTestBase {
// Lookup admin path in whitelist. It will query the DB and figure out
// that it indeed has an alias, and add it to the internal whitelist and
// flag it to be peristed to cache.
// flag it to be persisted to cache.
$this->assertTrue($whitelist->get('admin'));
// Destruct the whitelist so it persists its cache.
@@ -0,0 +1,63 @@
<?php
namespace Drupal\KernelTests\Core\Plugin;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests that contexts work properly with the typed data manager.
*
* @coversDefaultClass \Drupal\Core\Plugin\Context\Context
* @group Context
*/
class ContextTypedDataTest extends KernelTestBase {
/**
* Tests that contexts can be serialized.
*/
public function testSerialize() {
$definition = new ContextDefinition('any');
$data_definition = DataDefinition::create('string');
$typed_data = new StringData($data_definition);
$typed_data->setValue('example string');
$context = new Context($definition, $typed_data);
// getContextValue() will cause the context to reference the typed data
// manager service.
$value = $context->getContextValue();
$context = serialize($context);
$context = unserialize($context);
$this->assertSame($value, $context->getContextValue());
}
/**
* Tests that getting a context value does not throw fatal errors.
*
* This test ensures that the typed data manager is set correctly on the
* Context class.
*
* @covers ::getContextValue
*/
public function testGetContextValue() {
$data_definition = DataDefinition::create('string');
$typed_data = new StringData($data_definition);
$typed_data->setValue('example string');
// Prepare a container that holds the typed data manager mock.
$typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
$typed_data_manager->getCanonicalRepresentation($typed_data)->will(function ($arguments) {
return $arguments[0]->getValue();
});
$this->container->set('typed_data_manager', $typed_data_manager->reveal());
$definition = new ContextDefinition('any');
$context = new Context($definition, $typed_data);
$value = $context->getContextValue();
$this->assertSame($value, $typed_data->getValue());
}
}
@@ -2,9 +2,7 @@
namespace Drupal\KernelTests\Core\Routing;
use Drupal\Core\Cache\MemoryBackend;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Lock\NullLockBackend;
use Drupal\Core\State\State;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Routing\Route;
@@ -38,7 +36,7 @@ class MatcherDumperTest extends KernelTestBase {
parent::setUp();
$this->fixtures = new RoutingFixtures();
$this->state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$this->state = new State(new KeyValueMemoryFactory());
}
/**
@@ -12,7 +12,6 @@ use Drupal\Core\Cache\MemoryBackend;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Lock\NullLockBackend;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Routing\MatcherDumper;
use Drupal\Core\Routing\RouteProvider;
@@ -84,7 +83,7 @@ class RouteProviderTest extends KernelTestBase {
protected function setUp() {
parent::setUp();
$this->fixtures = new RoutingFixtures();
$this->state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$this->state = new State(new KeyValueMemoryFactory());
$this->currentPath = new CurrentPathStack(new RequestStack());
$this->cache = new MemoryBackend();
$this->pathProcessor = \Drupal::service('path_processor_manager');
@@ -97,7 +96,7 @@ class RouteProviderTest extends KernelTestBase {
public function register(ContainerBuilder $container) {
parent::register($container);
// Readd the incoming path alias for these tests.
// Read the incoming path alias for these tests.
if ($container->hasDefinition('path_processor_alias')) {
$definition = $container->getDefinition('path_processor_alias');
$definition->addTag('path_processor_inbound');
@@ -19,6 +19,13 @@ class AnonymousPrivateTempStoreTest extends KernelTestBase {
*/
public static $modules = ['system'];
/**
* The private temp store.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
protected $tempStore;
/**
* {@inheritdoc}
*/
@@ -29,30 +36,35 @@ class AnonymousPrivateTempStoreTest extends KernelTestBase {
// full Drupal environment.
$this->installSchema('system', ['key_value_expire']);
$session = $this->container->get('session');
$request = Request::create('/');
$request->setSession($session);
$stack = $this->container->get('request_stack');
$stack->pop();
$stack->push($request);
$this->tempStore = $this->container->get('tempstore.private')->get('anonymous_private_temp_store');
}
/**
* Tests anonymous can get without a previous set.
*/
public function testAnonymousCanUsePrivateTempStoreGet() {
$actual = $this->tempStore->get('foo');
$this->assertNull($actual);
}
/**
* Tests anonymous can use the PrivateTempStore.
*/
public function testAnonymousCanUsePrivateTempStore() {
$temp_store = $this->container->get('tempstore.private')->get('anonymous_private_temp_store');
$temp_store->set('foo', 'bar');
$metadata1 = $temp_store->getMetadata('foo');
public function testAnonymousCanUsePrivateTempStoreSet() {
$this->tempStore->set('foo', 'bar');
$metadata1 = $this->tempStore->getMetadata('foo');
$this->assertEquals('bar', $temp_store->get('foo'));
$this->assertEquals('bar', $this->tempStore->get('foo'));
$this->assertNotEmpty($metadata1->owner);
$temp_store->set('foo', 'bar2');
$metadata2 = $temp_store->getMetadata('foo');
$this->assertEquals('bar2', $temp_store->get('foo'));
$this->tempStore->set('foo', 'bar2');
$metadata2 = $this->tempStore->getMetadata('foo');
$this->assertEquals('bar2', $this->tempStore->get('foo'));
$this->assertNotEmpty($metadata2->owner);
$this->assertEquals($metadata2->owner, $metadata1->owner);
}