updated core
This commit is contained in:
@@ -49,7 +49,6 @@ class GetFilenameTest extends KernelTestBase {
|
||||
// a fixed location and naming.
|
||||
$this->assertIdentical(drupal_get_filename('profile', 'testing'), 'core/profiles/testing/testing.info.yml');
|
||||
|
||||
|
||||
// Generate a non-existing module name.
|
||||
$non_existing_module = uniqid("", TRUE);
|
||||
|
||||
|
||||
@@ -235,9 +235,9 @@ class ConfigDependencyTest extends EntityKernelTestBase {
|
||||
// Ensure that alphabetical order has no influence on dependency fixing and
|
||||
// removal.
|
||||
return [
|
||||
[['a', 'b', 'c', 'd']],
|
||||
[['d', 'c', 'b', 'a']],
|
||||
[['c', 'd', 'a', 'b']],
|
||||
[['a', 'b', 'c', 'd', 'e']],
|
||||
[['e', 'd', 'c', 'b', 'a']],
|
||||
[['e', 'c', 'd', 'a', 'b']],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -316,6 +316,25 @@ class ConfigDependencyTest extends EntityKernelTestBase {
|
||||
);
|
||||
$entity_4->save();
|
||||
|
||||
// Entity 5 will be fixed because it is dependent on entity 3, which is
|
||||
// unchanged, and entity 1 which will be fixed because
|
||||
// \Drupal\config_test\Entity::onDependencyRemoval() will remove the
|
||||
// dependency.
|
||||
$entity_5 = $storage->create(
|
||||
[
|
||||
'id' => 'entity_' . $entity_id_suffixes[4],
|
||||
'dependencies' => [
|
||||
'enforced' => [
|
||||
'config' => [
|
||||
$entity_1->getConfigDependencyName(),
|
||||
$entity_3->getConfigDependencyName(),
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$entity_5->save();
|
||||
|
||||
// Set a more complicated test where dependencies will be fixed.
|
||||
\Drupal::state()->set('config_test.fix_dependencies', [$entity_1->getConfigDependencyName()]);
|
||||
\Drupal::state()->set('config_test.on_dependency_removal_called', []);
|
||||
@@ -323,14 +342,22 @@ class ConfigDependencyTest extends EntityKernelTestBase {
|
||||
// Do a dry run using
|
||||
// \Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval().
|
||||
$config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('module', ['node']);
|
||||
|
||||
// Assert that \Drupal\config_test\Entity\ConfigTest::onDependencyRemoval()
|
||||
// is called as expected and with the correct dependencies.
|
||||
$called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
|
||||
$this->assertArrayNotHasKey($entity_3->id(), $called, 'ConfigEntityInterface::onDependencyRemoval() is not called for entity 3.');
|
||||
$this->assertSame([$entity_1->id(), $entity_4->id(), $entity_2->id(), $entity_5->id()], array_keys($called), 'The most dependent entites have ConfigEntityInterface::onDependencyRemoval() called first.');
|
||||
$this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_1->id()]);
|
||||
$this->assertSame(['config' => [$entity_1->getConfigDependencyName()], 'content' => [], 'module' => [], 'theme' => []], $called[$entity_2->id()]);
|
||||
$this->assertSame(['config' => [$entity_1->getConfigDependencyName()], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_4->id()]);
|
||||
$this->assertSame(['config' => [$entity_1->getConfigDependencyName()], 'content' => [], 'module' => [], 'theme' => []], $called[$entity_5->id()]);
|
||||
|
||||
$this->assertEqual($entity_1->uuid(), $config_entities['delete'][1]->uuid(), 'Entity 1 will be deleted.');
|
||||
$this->assertEqual($entity_2->uuid(), reset($config_entities['update'])->uuid(), 'Entity 2 will be updated.');
|
||||
$this->assertEqual($entity_2->uuid(), $config_entities['update'][0]->uuid(), 'Entity 2 will be updated.');
|
||||
$this->assertEqual($entity_3->uuid(), reset($config_entities['unchanged'])->uuid(), 'Entity 3 is not changed.');
|
||||
$this->assertEqual($entity_4->uuid(), $config_entities['delete'][0]->uuid(), 'Entity 4 will be deleted.');
|
||||
|
||||
$called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
|
||||
$this->assertFalse(in_array($entity_3->id(), $called), 'ConfigEntityInterface::onDependencyRemoval() is not called for entity 3.');
|
||||
$this->assertSame([$entity_1->id(), $entity_4->id(), $entity_2->id()], $called, 'The most dependent entites have ConfigEntityInterface::onDependencyRemoval() called first.');
|
||||
$this->assertEqual($entity_5->uuid(), $config_entities['update'][1]->uuid(), 'Entity 5 is updated.');
|
||||
|
||||
// Perform a module rebuild so we can know where the node module is located
|
||||
// and uninstall it.
|
||||
@@ -443,8 +470,11 @@ class ConfigDependencyTest extends EntityKernelTestBase {
|
||||
$this->assertSame($expected, $config_entity_ids);
|
||||
|
||||
$called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
|
||||
$this->assertFalse(in_array($entity_3->id(), $called), 'ConfigEntityInterface::onDependencyRemoval() is not called for entity 3.');
|
||||
$this->assertSame([$entity_1->id(), $entity_4->id(), $entity_2->id()], $called, 'The most dependent entities have ConfigEntityInterface::onDependencyRemoval() called first.');
|
||||
$this->assertArrayNotHasKey($entity_3->id(), $called, 'ConfigEntityInterface::onDependencyRemoval() is not called for entity 3.');
|
||||
$this->assertSame([$entity_1->id(), $entity_4->id(), $entity_2->id()], array_keys($called), 'The most dependent entities have ConfigEntityInterface::onDependencyRemoval() called first.');
|
||||
$this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_1->id()]);
|
||||
$this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_2->id()]);
|
||||
$this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []], $called[$entity_4->id()]);
|
||||
|
||||
// Perform a module rebuild so we can know where the node module is located
|
||||
// and uninstall it.
|
||||
|
||||
@@ -75,7 +75,7 @@ class ConfigDiffTest extends KernelTestBase {
|
||||
|
||||
// Test diffing a renamed config entity.
|
||||
$test_entity_id = $this->randomMachineName();
|
||||
$test_entity = entity_create('config_test', [
|
||||
$test_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
|
||||
'id' => $test_entity_id,
|
||||
'label' => $this->randomMachineName(),
|
||||
]);
|
||||
|
||||
@@ -24,7 +24,7 @@ class ConfigEntityNormalizeTest extends KernelTestBase {
|
||||
}
|
||||
|
||||
public function testNormalize() {
|
||||
$config_entity = entity_create('config_test', ['id' => 'system', 'label' => 'foobar', 'weight' => 1]);
|
||||
$config_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create(['id' => 'system', 'label' => 'foobar', 'weight' => 1]);
|
||||
$config_entity->save();
|
||||
|
||||
// Modify stored config entity, this is comparable with a schema change.
|
||||
|
||||
@@ -22,7 +22,7 @@ class ConfigEntityStatusTest extends KernelTestBase {
|
||||
* Tests the enabling/disabling of entities.
|
||||
*/
|
||||
public function testCRUD() {
|
||||
$entity = entity_create('config_test', [
|
||||
$entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
|
||||
'id' => strtolower($this->randomMachineName()),
|
||||
]);
|
||||
$this->assertTrue($entity->status(), 'Default status is enabled.');
|
||||
|
||||
@@ -67,7 +67,7 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
|
||||
public function testRenameValidation() {
|
||||
// Create a test entity.
|
||||
$test_entity_id = $this->randomMachineName();
|
||||
$test_entity = entity_create('config_test', [
|
||||
$test_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
|
||||
'id' => $test_entity_id,
|
||||
'label' => $this->randomMachineName(),
|
||||
]);
|
||||
|
||||
@@ -692,7 +692,7 @@ class ConfigImporterTest extends KernelTestBase {
|
||||
// does not use an install profile. This situation should be impossible
|
||||
// to get in but site's can removed the install profile setting from
|
||||
// settings.php so the test is valid.
|
||||
$this->assertEqual(['Cannot change the install profile from <em class="placeholder">this_will_not_work</em> to <em class="placeholder"></em> once Drupal is installed.'], $error_log);
|
||||
$this->assertEqual(['Cannot change the install profile from <em class="placeholder"></em> to <em class="placeholder">this_will_not_work</em> once Drupal is installed.'], $error_log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,6 @@ class ConfigSchemaTest extends KernelTestBase {
|
||||
$expected['mapping']['upscale']['label'] = 'Upscale';
|
||||
$expected['type'] = 'image.effect.image_scale';
|
||||
|
||||
|
||||
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for image.effect.image_scale');
|
||||
|
||||
// Most complex case, get metadata for actual configuration element.
|
||||
|
||||
@@ -467,7 +467,6 @@ class SelectTest extends DatabaseTestBase {
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$database = $this->container->get('database');
|
||||
foreach ($test_groups as $test_group) {
|
||||
$query = $database->select('test', 't');
|
||||
|
||||
@@ -626,7 +626,8 @@ class ConfigEntityQueryTest extends KernelTestBase {
|
||||
$key_value = $this->container->get('keyvalue')->get(QueryFactory::CONFIG_LOOKUP_PREFIX . 'config_test');
|
||||
|
||||
$test_entities = [];
|
||||
$entity = entity_create('config_test', [
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('config_test');
|
||||
$entity = $storage->create([
|
||||
'label' => $this->randomMachineName(),
|
||||
'id' => '1',
|
||||
'style' => 'test',
|
||||
@@ -635,11 +636,10 @@ class ConfigEntityQueryTest extends KernelTestBase {
|
||||
$entity->enforceIsNew();
|
||||
$entity->save();
|
||||
|
||||
|
||||
$expected[] = $entity->getConfigDependencyName();
|
||||
$this->assertEqual($expected, $key_value->get('style:test'));
|
||||
|
||||
$entity = entity_create('config_test', [
|
||||
$entity = $storage->create([
|
||||
'label' => $this->randomMachineName(),
|
||||
'id' => '2',
|
||||
'style' => 'test',
|
||||
@@ -650,7 +650,7 @@ class ConfigEntityQueryTest extends KernelTestBase {
|
||||
$expected[] = $entity->getConfigDependencyName();
|
||||
$this->assertEqual($expected, $key_value->get('style:test'));
|
||||
|
||||
$entity = entity_create('config_test', [
|
||||
$entity = $storage->create([
|
||||
'label' => $this->randomMachineName(),
|
||||
'id' => '3',
|
||||
'style' => 'blah',
|
||||
|
||||
@@ -131,7 +131,6 @@ class ContentEntityCloneTest extends EntityKernelTestBase {
|
||||
}
|
||||
$this->assertTrue($different_references, 'The entity object and the cloned entity object reference different field item list objects.');
|
||||
|
||||
|
||||
// Reload the entity, initialize one translation, clone it and check that
|
||||
// both entity objects reference different field instances.
|
||||
$entity = $this->reloadEntity($entity);
|
||||
|
||||
@@ -63,7 +63,6 @@ class EntityDisplayFormBaseTest extends KernelTestBase {
|
||||
])
|
||||
->shouldBeCalled();
|
||||
|
||||
|
||||
// An initially visible field, with a submitted region change.
|
||||
$entity->getComponent('field_start_visible_change_region')
|
||||
->willReturn([
|
||||
|
||||
@@ -739,13 +739,135 @@ class EntityFieldTest extends EntityKernelTestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test computed fields.
|
||||
* Tests all the interaction points of a computed field.
|
||||
*/
|
||||
public function testComputedFields() {
|
||||
$this->installEntitySchema('entity_test_computed_field');
|
||||
|
||||
\Drupal::state()->set('entity_test_computed_field_item_list_value', ['foo computed']);
|
||||
|
||||
// Check that the values are not computed unnecessarily during the lifecycle
|
||||
// of an entity when the field is not interacted with directly.
|
||||
\Drupal::state()->set('computed_test_field_execution', 0);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertEquals($entity->computed_string_field->value, 'foo computed');
|
||||
$this->assertSame(0, \Drupal::state()->get('computed_test_field_execution', 0));
|
||||
|
||||
$entity->name->value = $this->randomString();
|
||||
$this->assertSame(0, \Drupal::state()->get('computed_test_field_execution', 0));
|
||||
|
||||
$entity->save();
|
||||
$this->assertSame(0, \Drupal::state()->get('computed_test_field_execution', 0));
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::getValue().
|
||||
\Drupal::state()->set('computed_test_field_execution', 0);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertSame([['value' => 'foo computed']], $entity->computed_string_field->getValue());
|
||||
|
||||
// Check that the values are only computed once.
|
||||
$this->assertSame(1, \Drupal::state()->get('computed_test_field_execution', 0));
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::setValue(). This also
|
||||
// checks that a subsequent getter does not try to re-compute the value.
|
||||
\Drupal::state()->set('computed_test_field_execution', 0);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$entity->computed_string_field->setValue([
|
||||
['value' => 'foo computed 1'],
|
||||
['value' => 'foo computed 2'],
|
||||
]);
|
||||
$this->assertSame([['value' => 'foo computed 1'], ['value' => 'foo computed 2']], $entity->computed_string_field->getValue());
|
||||
|
||||
// Check that the values have not been computed when they were explicitly
|
||||
// set.
|
||||
$this->assertSame(0, \Drupal::state()->get('computed_test_field_execution', 0));
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::getString().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertSame('foo computed', $entity->computed_string_field->getString());
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::get().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertSame('foo computed', $entity->computed_string_field->get(0)->value);
|
||||
$this->assertEmpty($entity->computed_string_field->get(1));
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::set().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$entity->computed_string_field->set(1, 'foo computed 1');
|
||||
$this->assertSame('foo computed', $entity->computed_string_field[0]->value);
|
||||
$this->assertSame('foo computed 1', $entity->computed_string_field[1]->value);
|
||||
$entity->computed_string_field->set(0, 'foo computed 0');
|
||||
$this->assertSame('foo computed 0', $entity->computed_string_field[0]->value);
|
||||
$this->assertSame('foo computed 1', $entity->computed_string_field[1]->value);
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::appendItem().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$entity->computed_string_field->appendItem('foo computed 1');
|
||||
$this->assertSame('foo computed', $entity->computed_string_field[0]->value);
|
||||
$this->assertSame('foo computed 1', $entity->computed_string_field[1]->value);
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::removeItem().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$entity->computed_string_field->removeItem(0);
|
||||
$this->assertTrue($entity->computed_string_field->isEmpty());
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::isEmpty().
|
||||
\Drupal::state()->set('entity_test_computed_field_item_list_value', []);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertTrue($entity->computed_string_field->isEmpty());
|
||||
|
||||
\Drupal::state()->set('entity_test_computed_field_item_list_value', ['foo computed']);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertFalse($entity->computed_string_field->isEmpty());
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::filter().
|
||||
$filter_callback = function ($item) {
|
||||
return !$item->isEmpty();
|
||||
};
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$entity->computed_string_field->filter($filter_callback);
|
||||
$this->assertCount(1, $entity->computed_string_field);
|
||||
|
||||
// Add an empty item to the list and check that it is filtered out.
|
||||
$entity->computed_string_field->appendItem();
|
||||
$entity->computed_string_field->filter($filter_callback);
|
||||
$this->assertCount(1, $entity->computed_string_field);
|
||||
|
||||
// Add a non-empty item to the list and check that it is not filtered out.
|
||||
$entity->computed_string_field->appendItem('foo computed 1');
|
||||
$entity->computed_string_field->filter($filter_callback);
|
||||
$this->assertCount(2, $entity->computed_string_field);
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::offsetExists().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertTrue($entity->computed_string_field->offsetExists(0));
|
||||
$this->assertFalse($entity->computed_string_field->offsetExists(1));
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::getIterator().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
foreach ($entity->computed_string_field as $delta => $item) {
|
||||
$this->assertSame('foo computed', $item->value);
|
||||
}
|
||||
|
||||
// Test \Drupal\Core\TypedData\ComputedItemListTrait::count().
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertCount(1, $entity->computed_string_field);
|
||||
|
||||
// Check that computed items are not auto-created when they have no values.
|
||||
\Drupal::state()->set('entity_test_computed_field_item_list_value', []);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$this->assertCount(0, $entity->computed_string_field);
|
||||
|
||||
// Test \Drupal\Core\Field\FieldItemList::equals() for a computed field.
|
||||
\Drupal::state()->set('entity_test_computed_field_item_list_value', ['foo computed']);
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$computed_item_list1 = $entity->computed_string_field;
|
||||
|
||||
$entity = EntityTestComputedField::create([]);
|
||||
$computed_item_list2 = $entity->computed_string_field;
|
||||
|
||||
$this->assertTrue($computed_item_list1->equals($computed_item_list2));
|
||||
|
||||
$computed_item_list2->value = 'foo computed 2';
|
||||
$this->assertFalse($computed_item_list1->equals($computed_item_list2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -819,7 +819,6 @@ class EntityQueryTest extends EntityKernelTestBase {
|
||||
)->execute();
|
||||
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
|
||||
|
||||
|
||||
// Check the case insensitive field, ENDS_WITH operator.
|
||||
$result = \Drupal::entityQuery('entity_test_mulrev')->condition(
|
||||
'field_ci', $fixtures[1]['lowercase'], 'ENDS_WITH'
|
||||
@@ -842,7 +841,6 @@ class EntityQueryTest extends EntityKernelTestBase {
|
||||
)->execute();
|
||||
$this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
|
||||
|
||||
|
||||
// Check the case insensitive field, CONTAINS operator, use the inner 8
|
||||
// characters of the uppercase and lowercase strings.
|
||||
$result = \Drupal::entityQuery('entity_test_mulrev')->condition(
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\KernelTests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\Validation\Constraint\CompositeConstraintBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the Entity Validation API.
|
||||
@@ -16,7 +17,7 @@ class EntityValidationTest extends EntityKernelTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['filter', 'text'];
|
||||
public static $modules = ['filter', 'text', 'language'];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -39,6 +40,10 @@ class EntityValidationTest extends EntityKernelTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Enable an additional language.
|
||||
ConfigurableLanguage::createFromLangcode('de')
|
||||
->save();
|
||||
|
||||
// Create the test field.
|
||||
module_load_install('entity_test');
|
||||
entity_test_install();
|
||||
@@ -196,8 +201,53 @@ class EntityValidationTest extends EntityKernelTestBase {
|
||||
$this->assertTrue($constraint instanceof CompositeConstraintBase, 'Constraint is composite constraint.');
|
||||
$this->assertEqual('type', $violations[0]->getPropertyPath());
|
||||
|
||||
/** @var CompositeConstraintBase $constraint */
|
||||
/** @var \Drupal\Core\Entity\Plugin\Validation\Constraint\CompositeConstraintBase $constraint */
|
||||
$this->assertEqual($constraint->coversFields(), ['name', 'type'], 'Information about covered fields can be retrieved.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the EntityChangedConstraintValidator with multiple translations.
|
||||
*/
|
||||
public function testEntityChangedConstraintOnConcurrentMultilingualEditing() {
|
||||
$this->installEntitySchema('entity_test_mulrev_changed');
|
||||
$storage = \Drupal::entityTypeManager()
|
||||
->getStorage('entity_test_mulrev_changed');
|
||||
|
||||
// Create a test entity.
|
||||
$entity = $this->createTestEntity('entity_test_mulrev_changed');
|
||||
$entity->save();
|
||||
|
||||
$entity->setChangedTime($entity->getChangedTime() - 1);
|
||||
$violations = $entity->validate();
|
||||
$this->assertEquals(1, $violations->count());
|
||||
$this->assertEqual($violations[0]->getMessage(), 'The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
|
||||
|
||||
$entity = $storage->loadUnchanged($entity->id());
|
||||
$translation = $entity->addTranslation('de');
|
||||
$entity->save();
|
||||
|
||||
// Ensure that the new translation has a newer changed timestamp than the
|
||||
// default translation.
|
||||
$this->assertGreaterThan($entity->getChangedTime(), $translation->getChangedTime());
|
||||
|
||||
// Simulate concurrent form editing by saving the entity with an altered
|
||||
// non-translatable field in order for the changed timestamp to be updated
|
||||
// across all entity translations.
|
||||
$original_entity_time = $entity->getChangedTime();
|
||||
$entity->set('not_translatable', $this->randomString());
|
||||
$entity->save();
|
||||
// Simulate form submission of an uncached form by setting the previous
|
||||
// timestamp of an entity translation on the saved entity object. This
|
||||
// happens in the entity form API where we put the changed timestamp of
|
||||
// the entity in a form hidden value and then set it on the entity which on
|
||||
// form submit is loaded from the storage if the form is not yet cached.
|
||||
$entity->setChangedTime($original_entity_time);
|
||||
// Setting the changed timestamp from the user input on the entity loaded
|
||||
// from the storage is used as a prevention from saving a form built with a
|
||||
// previous version of the entity and thus reverting changes by other users.
|
||||
$violations = $entity->validate();
|
||||
$this->assertEquals(1, $violations->count());
|
||||
$this->assertEqual($violations[0]->getMessage(), 'The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,4 +60,29 @@ class ModuleInstallerTest extends KernelTestBase {
|
||||
$this->assertEquals(1, $modules['module_handler_test_multiple_child'], 'Weight of module_handler_test_multiple_child is set.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cache bins defined by modules are removed when uninstalled.
|
||||
*
|
||||
* @covers ::removeCacheBins
|
||||
*/
|
||||
public function testCacheBinCleanup() {
|
||||
$schema = $this->container->get('database')->schema();
|
||||
$table = 'cache_module_cachebin';
|
||||
|
||||
$module_installer = $this->container->get('module_installer');
|
||||
$module_installer->install(['module_cachebin']);
|
||||
|
||||
// Prime the bin.
|
||||
/** @var \Drupal\Core\Cache\CacheBackendInterface $cache_bin */
|
||||
$cache_bin = $this->container->get('module_cachebin.cache_bin');
|
||||
$cache_bin->set('foo', 'bar');
|
||||
|
||||
// A database backend is used so there is a convenient way check whether the
|
||||
// backend is uninstalled.
|
||||
$this->assertTrue($schema->tableExists($table));
|
||||
|
||||
$module_installer->uninstall(['module_cachebin']);
|
||||
$this->assertFalse($schema->tableExists($table));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class UrlRewritingTest extends FileTestBase {
|
||||
/**
|
||||
* Tests the rewriting of shipped file URLs by hook_file_url_alter().
|
||||
*/
|
||||
public function testShippedFileURL() {
|
||||
public function testShippedFileURL() {
|
||||
// Test generating a URL to a shipped file (i.e. a file that is part of
|
||||
// Drupal core, a module or a theme, for example a JavaScript file).
|
||||
|
||||
|
||||
@@ -214,7 +214,9 @@ class ToolkitGdTest extends KernelTestBase {
|
||||
];
|
||||
|
||||
// Systems using non-bundled GD2 don't have imagerotate. Test if available.
|
||||
if (function_exists('imagerotate')) {
|
||||
// @todo Remove the version check once
|
||||
// https://www.drupal.org/project/drupal/issues/2670966 is resolved.
|
||||
if (function_exists('imagerotate') && (version_compare(phpversion(), '7.0.26') < 0)) {
|
||||
$operations += [
|
||||
'rotate_5' => [
|
||||
'function' => 'rotate',
|
||||
@@ -383,7 +385,7 @@ class ToolkitGdTest extends KernelTestBase {
|
||||
$image = $this->imageFactory->get();
|
||||
$image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00');
|
||||
$file = 'from_null' . image_type_to_extension($type);
|
||||
$file_path = $directory . '/' . $file ;
|
||||
$file_path = $directory . '/' . $file;
|
||||
$this->assertEqual(50, $image->getWidth(), SafeMarkup::format('Image file %file has the correct width.', ['%file' => $file]));
|
||||
$this->assertEqual(20, $image->getHeight(), SafeMarkup::format('Image file %file has the correct height.', ['%file' => $file]));
|
||||
$this->assertEqual(image_type_to_mime_type($type), $image->getMimeType(), SafeMarkup::format('Image file %file has the correct MIME type.', ['%file' => $file]));
|
||||
@@ -463,7 +465,7 @@ class ToolkitGdTest extends KernelTestBase {
|
||||
// Color at top-right pixel should be fully transparent while in memory,
|
||||
// fully opaque after flushing image to file.
|
||||
$file = 'image-test-no-transparent-color-set.gif';
|
||||
$file_path = $directory . '/' . $file ;
|
||||
$file_path = $directory . '/' . $file;
|
||||
// Create image.
|
||||
$image = $this->imageFactory->get();
|
||||
$image->createNew(50, 20, 'gif', NULL);
|
||||
|
||||
@@ -54,7 +54,6 @@ class GarbageCollectionTest extends KernelTestBase {
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
||||
// Perform a new set operation and then trigger garbage collection.
|
||||
$store->setWithExpire('autumn', 'winter', rand(500, 1000000));
|
||||
system_cron();
|
||||
|
||||
@@ -62,9 +62,9 @@ class MenuLinkTreeTest extends KernelTestBase {
|
||||
\Drupal::entityManager()->getStorage('menu')->create(['id' => 'menu1'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu')->create(['id' => 'menu2'])->save();
|
||||
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu2', 'bundle' => 'menu_link_content'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save();
|
||||
\Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu2', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save();
|
||||
|
||||
$output = $this->linkTree->load('menu1', new MenuTreeParameters());
|
||||
$this->assertEqual(count($output), 2);
|
||||
|
||||
@@ -16,7 +16,7 @@ class RenderTest extends KernelTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'common_test'];
|
||||
public static $modules = ['system', 'common_test', 'theme_test'];
|
||||
|
||||
/**
|
||||
* Tests theme preprocess functions being able to attach assets.
|
||||
@@ -43,6 +43,23 @@ class RenderTest extends KernelTestBase {
|
||||
\Drupal::state()->set('theme_preprocess_attached_test', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that render array children are processed correctly.
|
||||
*/
|
||||
public function testRenderChildren() {
|
||||
// Ensure that #prefix and #suffix is only being printed once since that is
|
||||
// the behaviour the caller code expects.
|
||||
$build = [
|
||||
'#type' => 'container',
|
||||
'#theme' => 'theme_test_render_element_children',
|
||||
'#prefix' => 'kangaroo',
|
||||
'#suffix' => 'kitten',
|
||||
];
|
||||
$this->render($build);
|
||||
$this->removeWhiteSpace();
|
||||
$this->assertNoRaw('<div>kangarookitten</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we get an exception when we try to attach an illegal type.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ class MatcherDumperTest extends KernelTestBase {
|
||||
/**
|
||||
* A collection of shared fixture data for tests.
|
||||
*
|
||||
* @var RoutingFixtures
|
||||
* @var \Drupal\Tests\Core\Routing\RoutingFixtures
|
||||
*/
|
||||
protected $fixtures;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class RouteProviderTest extends KernelTestBase {
|
||||
/**
|
||||
* A collection of shared fixture data for tests.
|
||||
*
|
||||
* @var RoutingFixtures
|
||||
* @var \Drupal\Tests\Core\Routing\RoutingFixtures
|
||||
*/
|
||||
protected $fixtures;
|
||||
|
||||
@@ -532,7 +532,6 @@ class RouteProviderTest extends KernelTestBase {
|
||||
|
||||
$request = Request::create($path, 'GET');
|
||||
|
||||
|
||||
$routes = $provider->getRoutesByPattern($path);
|
||||
$this->assertFalse(count($routes), 'No path found with this pattern.');
|
||||
|
||||
|
||||
@@ -164,11 +164,11 @@ class RegistryTest extends KernelTestBase {
|
||||
*/
|
||||
public function testThemeSuggestions() {
|
||||
// Mock the current page as the front page.
|
||||
/** @var PathMatcherInterface $path_matcher */
|
||||
/** @var \Drupal\Core\Path\PathMatcherInterface $path_matcher */
|
||||
$path_matcher = $this->prophesize(PathMatcherInterface::class);
|
||||
$path_matcher->isFrontPage()->willReturn(TRUE);
|
||||
$this->container->set('path.matcher', $path_matcher->reveal());
|
||||
/** @var CurrentPathStack $path_matcher */
|
||||
/** @var \Drupal\Core\Path\CurrentPathStack $path_matcher */
|
||||
$path_current = $this->prophesize(CurrentPathStack::class);
|
||||
$path_current->getPath()->willReturn('/node/1');
|
||||
$this->container->set('path.current', $path_current->reveal());
|
||||
|
||||
@@ -20,6 +20,7 @@ use Drupal\Core\Test\TestDatabase;
|
||||
use Drupal\simpletest\AssertContentTrait;
|
||||
use Drupal\Tests\AssertHelperTrait;
|
||||
use Drupal\Tests\ConfigTestTrait;
|
||||
use Drupal\Tests\PhpunitCompatibilityTrait;
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
use Drupal\Tests\TestRequirementsTrait;
|
||||
use Drupal\simpletest\TestServiceProvider;
|
||||
@@ -76,6 +77,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
|
||||
use RandomGeneratorTrait;
|
||||
use ConfigTestTrait;
|
||||
use TestRequirementsTrait;
|
||||
use PhpunitCompatibilityTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -324,10 +326,10 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
|
||||
private function bootKernel() {
|
||||
$this->setSetting('container_yamls', []);
|
||||
// Allow for test-specific overrides.
|
||||
$settings_services_file = $this->root . '/sites/default' . '/testing.services.yml';
|
||||
$settings_services_file = $this->root . '/sites/default/testing.services.yml';
|
||||
if (file_exists($settings_services_file)) {
|
||||
// Copy the testing-specific service overrides in place.
|
||||
$testing_services_file = $this->root . '/' . $this->siteDirectory . '/services.yml';
|
||||
$testing_services_file = $this->siteDirectory . '/services.yml';
|
||||
copy($settings_services_file, $testing_services_file);
|
||||
$this->setSetting('container_yamls', [$testing_services_file]);
|
||||
}
|
||||
@@ -827,7 +829,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if ($module_handler->moduleExists($module)) {
|
||||
throw new \LogicException("$module module is already enabled.");
|
||||
continue;
|
||||
}
|
||||
$module_handler->addModule($module, $module_list[$module]->getPath());
|
||||
// Maintain the list of enabled modules in configuration.
|
||||
|
||||
Reference in New Issue
Block a user