Update to Drupal 8.1.8. For more information, see https://www.drupal.org/project/drupal/releases/8.1.8
This commit is contained in:
parent
e9f047ccf8
commit
f9f23cdf38
312 changed files with 6751 additions and 1546 deletions
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\KernelTests\Core\Database;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Tests that the prefix info for a database schema is correct.
|
||||
*
|
||||
* @group Database
|
||||
*/
|
||||
class PrefixInfoTest extends DatabaseTestBase {
|
||||
|
||||
/**
|
||||
* Tests that DatabaseSchema::getPrefixInfo() returns the right database.
|
||||
*
|
||||
* We are testing if the return array of the method
|
||||
* \Drupal\Core\Database\Driver\mysql\Schema::getPrefixInfo(). This return
|
||||
* array is a keyed array with info about amongst other things the database.
|
||||
* The other two by Drupal core supported databases do not have this variable
|
||||
* set in the return array.
|
||||
*/
|
||||
function testGetPrefixInfo() {
|
||||
$connection_info = Database::getConnectionInfo('default');
|
||||
if ($connection_info['default']['driver'] == 'mysql') {
|
||||
// Copy the default connection info to the 'extra' key.
|
||||
Database::addConnectionInfo('extra', 'default', $connection_info['default']);
|
||||
|
||||
$db1_connection = Database::getConnection('default', 'default');
|
||||
$db1_schema = $db1_connection->schema();
|
||||
$db2_connection = Database::getConnection('default', 'extra');
|
||||
|
||||
// Get the prefix info for the first databse.
|
||||
$method = new \ReflectionMethod($db1_schema, 'getPrefixInfo');
|
||||
$method->setAccessible(TRUE);
|
||||
$db1_info = $method->invoke($db1_schema);
|
||||
|
||||
// We change the database after opening the connection, so as to prevent
|
||||
// connecting to a non-existent database.
|
||||
$reflection = new \ReflectionObject($db2_connection);
|
||||
$property = $reflection->getProperty('connectionOptions');
|
||||
$property->setAccessible(TRUE);
|
||||
$connection_info['default']['database'] = 'foobar';
|
||||
$property->setValue($db2_connection, $connection_info['default']);
|
||||
|
||||
// For testing purposes, we also change the database info.
|
||||
$reflection_class = new \ReflectionClass('Drupal\Core\Database\Database');
|
||||
$property = $reflection_class->getProperty('databaseInfo');
|
||||
$property->setAccessible(TRUE);
|
||||
$info = $property->getValue();
|
||||
$info['extra']['default']['database'] = 'foobar';
|
||||
$property->setValue(NULL, $info);
|
||||
|
||||
$extra_info = Database::getConnectionInfo('extra');
|
||||
$this->assertSame($extra_info['default']['database'], 'foobar');
|
||||
$db2_schema = $db2_connection->schema();
|
||||
$db2_info = $method->invoke($db2_schema);
|
||||
|
||||
$this->assertNotSame($db2_info['database'], $db1_info['database'], 'Each target connection has a different database.');
|
||||
$this->assertSame($db2_info['database'], 'foobar', 'The new profile has a different database.');
|
||||
|
||||
Database::removeConnection('extra');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -154,6 +154,20 @@ class SelectComplexTest extends DatabaseTestBase {
|
|||
$this->assertEqual($query_result, 2, 'Returned the correct number of rows.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the range property of a select clause can be undone.
|
||||
*/
|
||||
function testRangeUndo() {
|
||||
$query = db_select('test');
|
||||
$name_field = $query->addField('test', 'name');
|
||||
$age_field = $query->addField('test', 'age', 'age');
|
||||
$query->range(0, 2);
|
||||
$query->range(NULL, NULL);
|
||||
$query_result = $query->countQuery()->execute()->fetchField();
|
||||
|
||||
$this->assertEqual($query_result, 4, 'Returned the correct number of rows.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests distinct queries.
|
||||
*/
|
||||
|
|
|
@ -322,6 +322,64 @@ class SelectTest extends DatabaseTestBase {
|
|||
$this->assertEqual(count($names), $count, "The count query's result matched the number of rows in the UNION query.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can UNION multiple Select queries together and set the ORDER.
|
||||
*/
|
||||
function testUnionOrder() {
|
||||
// This gives George and Ringo.
|
||||
$query_1 = db_select('test', 't')
|
||||
->fields('t', array('name'))
|
||||
->condition('age', array(27, 28), 'IN');
|
||||
|
||||
// This gives Paul.
|
||||
$query_2 = db_select('test', 't')
|
||||
->fields('t', array('name'))
|
||||
->condition('age', 26);
|
||||
|
||||
$query_1->union($query_2);
|
||||
$query_1->orderBy('name', 'DESC');
|
||||
|
||||
$names = $query_1->execute()->fetchCol();
|
||||
|
||||
// Ensure we get all 3 records.
|
||||
$this->assertEqual(count($names), 3, 'UNION returned rows from both queries.');
|
||||
|
||||
// Ensure that the names are in the correct reverse alphabetical order,
|
||||
// regardless of which query they came from.
|
||||
$this->assertEqual($names[0], 'Ringo', 'First query returned correct name.');
|
||||
$this->assertEqual($names[1], 'Paul', 'Second query returned correct name.');
|
||||
$this->assertEqual($names[2], 'George', 'Third query returned correct name.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can UNION multiple Select queries together with and a LIMIT.
|
||||
*/
|
||||
function testUnionOrderLimit() {
|
||||
// This gives George and Ringo.
|
||||
$query_1 = db_select('test', 't')
|
||||
->fields('t', array('name'))
|
||||
->condition('age', array(27, 28), 'IN');
|
||||
|
||||
// This gives Paul.
|
||||
$query_2 = db_select('test', 't')
|
||||
->fields('t', array('name'))
|
||||
->condition('age', 26);
|
||||
|
||||
$query_1->union($query_2);
|
||||
$query_1->orderBy('name', 'DESC');
|
||||
$query_1->range(0, 2);
|
||||
|
||||
$names = $query_1->execute()->fetchCol();
|
||||
|
||||
// Ensure we get all only 2 of the 3 records.
|
||||
$this->assertEqual(count($names), 2, 'UNION with a limit returned rows from both queries.');
|
||||
|
||||
// Ensure that the names are in the correct reverse alphabetical order,
|
||||
// regardless of which query they came from.
|
||||
$this->assertEqual($names[0], 'Ringo', 'First query returned correct name.');
|
||||
$this->assertEqual($names[1], 'Paul', 'Second query returned correct name.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that random ordering of queries works.
|
||||
*
|
||||
|
|
|
@ -62,4 +62,31 @@ class ContentEntityCloneTest extends EntityKernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the flag for enforcing a new entity is not shared.
|
||||
*/
|
||||
public function testEnforceIsNewOnClonedEntityTranslation() {
|
||||
// Create a test entity.
|
||||
$entity = EntityTestMul::create([
|
||||
'name' => $this->randomString(),
|
||||
'language' => 'en',
|
||||
]);
|
||||
$entity->save();
|
||||
$entity_translation = $entity->addTranslation('de');
|
||||
$entity->save();
|
||||
|
||||
// The entity is not new anymore.
|
||||
$this->assertFalse($entity_translation->isNew());
|
||||
|
||||
// The clone should not be new as well.
|
||||
$clone = clone $entity_translation;
|
||||
$this->assertFalse($clone->isNew());
|
||||
|
||||
// After enforcing the clone to be new only it should be flagged as new,
|
||||
// but the original entity should not be flagged as new.
|
||||
$clone->enforceIsNew();
|
||||
$this->assertTrue($clone->isNew());
|
||||
$this->assertFalse($entity_translation->isNew());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -174,4 +174,37 @@ class ContentEntityNonRevisionableFieldTest extends EntityKernelTestBase {
|
|||
$this->assertEquals($expected_non_rev_field_revision_ids, $non_rev_field_revision_ids, 'Revision ids found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multi column non revisionable base field for revisionable entity.
|
||||
*/
|
||||
public function testMultiColumnNonRevisionableBaseField() {
|
||||
\Drupal::state()->set('entity_test.multi_column', TRUE);
|
||||
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
|
||||
// Refresh the storage.
|
||||
$this->mulRev = $this->entityManager->getStorage('entity_test_mulrev');
|
||||
$user1 = $this->createUser();
|
||||
|
||||
// Create a test entity.
|
||||
$entity = EntityTestMulRev::create([
|
||||
'name' => $this->randomString(),
|
||||
'user_id' => $user1->id(),
|
||||
'language' => 'en',
|
||||
'non_rev_field' => 'Huron',
|
||||
'description' => [
|
||||
'shape' => 'shape',
|
||||
'color' => 'color',
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
$entity = $this->mulRev->loadUnchanged($entity->id());
|
||||
$expected = [
|
||||
[
|
||||
'shape' => 'shape',
|
||||
'color' => 'color',
|
||||
],
|
||||
];
|
||||
$this->assertEquals('Huron', $entity->get('non_rev_field')->value, 'Huron found on entity 1');
|
||||
$this->assertEquals($expected, $entity->description->getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -87,4 +87,49 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase {
|
|||
$this->assertFalse($entity->hasTranslation('de'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the translation values when saving a forward revision.
|
||||
*/
|
||||
public function testTranslationValuesWhenSavingForwardRevisions() {
|
||||
$user = $this->createUser();
|
||||
$storage = $this->entityManager->getStorage('entity_test_mulrev');
|
||||
|
||||
// Create a test entity and a translation for it.
|
||||
$entity = EntityTestMulRev::create([
|
||||
'name' => 'default revision - en',
|
||||
'user_id' => $user->id(),
|
||||
'language' => 'en',
|
||||
]);
|
||||
$entity->addTranslation('de', ['name' => 'default revision - de']);
|
||||
$entity->save();
|
||||
|
||||
// Create a forward revision for the entity and change a field value for
|
||||
// both languages.
|
||||
$forward_revision = $this->reloadEntity($entity);
|
||||
|
||||
$forward_revision->setNewRevision();
|
||||
$forward_revision->isDefaultRevision(FALSE);
|
||||
|
||||
$forward_revision->name = 'forward revision - en';
|
||||
$forward_revision->save();
|
||||
|
||||
$forward_revision_translation = $forward_revision->getTranslation('de');
|
||||
$forward_revision_translation->name = 'forward revision - de';
|
||||
$forward_revision_translation->save();
|
||||
|
||||
$forward_revision_id = $forward_revision->getRevisionId();
|
||||
$forward_revision = $storage->loadRevision($forward_revision_id);
|
||||
|
||||
// Change the value of the field in the default language, save the forward
|
||||
// revision and check that the value of the field in the second language is
|
||||
// also taken from the forward revision, *not* from the default revision.
|
||||
$forward_revision->name = 'updated forward revision - en';
|
||||
$forward_revision->save();
|
||||
|
||||
$forward_revision = $storage->loadRevision($forward_revision_id);
|
||||
|
||||
$this->assertEquals($forward_revision->name->value, 'updated forward revision - en');
|
||||
$this->assertEquals($forward_revision->getTranslation('de')->name->value, 'forward revision - de');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -165,6 +165,7 @@ class EntityViewBuilderTest extends EntityKernelTestBase {
|
|||
$this->assertTrue(isset($build['#cache']) && array_keys($build['#cache']) == ['tags', 'contexts', 'max-age'], 'A view mode with render cache disabled has the correct output (only cache tags, contexts and max-age).');
|
||||
|
||||
// Test that an entity type can opt out of render caching completely.
|
||||
$this->installEntitySchema('entity_test_label');
|
||||
$entity_test_no_cache = $this->createTestEntity('entity_test_label');
|
||||
$entity_test_no_cache->save();
|
||||
$build = $this->container->get('entity.manager')->getViewBuilder('entity_test_label')->view($entity_test_no_cache, 'full');
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\KernelTests\Core\Entity;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Test view/render hooks for entities.
|
||||
*
|
||||
* @todo Add tests for the following hooks. https://www.drupal.org/node/2755353
|
||||
* hook_entity_view_display_alter()
|
||||
* hook_entity_prepare_view()
|
||||
* hook_ENTITY_TYPE_view()
|
||||
* hook_entity_view()
|
||||
* hook_ENTITY_TYPE_view_alter()
|
||||
* hook_entity_view_alter()
|
||||
*
|
||||
* @group Entity
|
||||
*/
|
||||
class EntityViewHookTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* Test hook_entity_display_build_alter().
|
||||
*/
|
||||
public function testHookEntityDisplayBuildAlter() {
|
||||
entity_test_create_bundle('display_build_alter_bundle');
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = $this->container->get('renderer');
|
||||
|
||||
$entity_ids = [];
|
||||
// Create some entities to test.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$entity = EntityTest::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'type' => 'display_build_alter_bundle',
|
||||
]);
|
||||
$entity->save();
|
||||
$entity_ids[] = $entity->id();
|
||||
}
|
||||
|
||||
/** @var \Drupal\entity_test\EntityTestViewBuilder $view_builder */
|
||||
$view_builder = $this->container->get('entity_type.manager')->getViewBuilder('entity_test');
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
|
||||
$storage->resetCache();
|
||||
$entities = $storage->loadMultiple($entity_ids);
|
||||
|
||||
$build = $view_builder->viewMultiple($entities);
|
||||
|
||||
$output = $renderer->renderRoot($build);
|
||||
$this->setRawContent($output->__toString());
|
||||
// Confirm that the content added in
|
||||
// entity_test_entity_display_build_alter() appears multiple times, not
|
||||
// just for the final entity.
|
||||
foreach ($entity_ids as $id) {
|
||||
$this->assertText('Content added in hook_entity_display_build_alter for entity id ' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -274,6 +274,7 @@ class FieldSqlStorageTest extends EntityKernelTestBase {
|
|||
function testLongNames() {
|
||||
// Use one of the longest entity_type names in core.
|
||||
$entity_type = $bundle = 'entity_test_label_callback';
|
||||
$this->installEntitySchema('entity_test_label_callback');
|
||||
$storage = $this->container->get('entity.manager')->getStorage($entity_type);
|
||||
|
||||
// Create two fields and generate random values.
|
||||
|
|
Reference in a new issue