View source
<?php
namespace Drupal\Tests\dynamic_entity_reference\Functional\Update;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\entity_test\Entity\EntityTestStringId;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class DerRevUpdateTest extends UpdatePathTestBase {
protected $installProfile = 'testing';
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../fixtures/update/der_rev_dump.php.gz',
];
}
public function testUpdate8201() {
$connection = \Drupal::database();
$this
->runUpdates();
$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());
$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());
$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());
$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());
$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());
$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());
$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());
$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());
$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();
$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());
$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());
$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());
$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());
$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());
$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());
$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());
$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());
}
}