public function DerRevUpdateTest::testUpdate8201 in Dynamic Entity Reference 8.2
Test that target_id is converted to string and target_id_int is created.
See also
dynamic_entity_reference_update_8201()
File
- tests/
src/ Functional/ Update/ DerRevUpdateTest.php, line 39
Class
- DerRevUpdateTest
- Tests the revisionable DER fields update path.
Namespace
Drupal\Tests\dynamic_entity_reference\Functional\UpdateCode
public function testUpdate8201() {
$connection = \Drupal::database();
$this
->runUpdates();
// The db dump contain two entity_test_rev entities referencing one
// entity_test_rev entity and one entity_test_mulrev entity.
// Check the basefields value on entity table columns.
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT der__target_id FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
// The db dump contain two entity_test_mulrev entities referencing one
// entity_test_rev entity and one entity_test_mulrev entity.
// Check the basefields value on entity data table columns.
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT der__target_id FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
// Check the basefields value on entity revision table columns.
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
], $connection
->query('SELECT der__target_id FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the basefields value on entity revision data table columns.
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
], $connection
->query('SELECT der__target_id FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
// String id entity can be referenced now.
$referenced_entity = EntityTestStringId::create([
'id' => 'test',
]);
$referenced_entity
->save();
$entity = EntityTestRev::load(3);
$entity->dynamic_references[0] = $entity->der[0] = $referenced_entity;
$entity
->setNewRevision(TRUE);
$entity
->save();
$entity = EntityTestMulRev::load(3);
$entity->dynamic_references[0] = $entity->der[0] = $referenced_entity;
$entity
->setNewRevision(TRUE);
$entity
->save();
// Check the basefields value on entity table columns.
$this
->assertEquals([
NULL,
1,
'test',
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
0,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
1,
'test',
], $connection
->query('SELECT der__target_id FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
0,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_rev} ORDER BY id, revision_id')
->fetchCol());
// The db dump contain two entity_test_mulrev entities referencing one
// entity_test_rev entity and one entity_test_mulrev entity.
// Check the basefields value on entity data table columns.
$this
->assertEquals([
NULL,
1,
'test',
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
0,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
1,
'test',
], $connection
->query('SELECT der__target_id FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
0,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_mulrev_property_data} ORDER BY id, revision_id')
->fetchCol());
// Check the basefields value on entity revision table columns.
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
'test',
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
0,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
'test',
], $connection
->query('SELECT der__target_id FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
0,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_rev_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the basefields value on entity revision data table columns.
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
'test',
], $connection
->query('SELECT dynamic_references__target_id FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
1,
1,
1,
1,
1,
1,
1,
1,
0,
], $connection
->query('SELECT dynamic_references__target_id_int FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
// Check the both columns of the other basefield.
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
'test',
], $connection
->query('SELECT der__target_id FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
$this
->assertEquals([
NULL,
NULL,
NULL,
1,
1,
NULL,
NULL,
1,
1,
0,
], $connection
->query('SELECT der__target_id_int FROM {entity_test_mulrev_property_revision} ORDER BY id, revision_id')
->fetchCol());
}