public function TestBase::testSave in Workbench Moderation to Content Moderation 8.2
Tests that moderation states are safely saved.
Parameters
array $expectations: (optional) The expectations to assert. See ::createRevisions() for info.
1 call to TestBase::testSave()
- TestBase::testClear in tests/
src/ Kernel/ Migration/ TestBase.php - Tests that moderation states are correctly cleared.
File
- tests/
src/ Kernel/ Migration/ TestBase.php, line 82
Class
- TestBase
- Tests the save-clear-restore migration flow for a single entity type.
Namespace
Drupal\Tests\wbm2cm\Kernel\MigrationCode
public function testSave(array $expectations = NULL) {
$expectations = $expectations ?: $this
->createRevisions();
$entity_type = $this->storage
->getEntityType();
$id_map = $this
->execute($entity_type
->id(), 'save')
->getIdMap();
// Assert that all translations of all revisions were imported.
$reduce = function ($total, array $languages) {
return $total + count($languages);
};
$expected_count = array_reduce($expectations, $reduce, 0);
$this
->assertSame($expected_count, (int) $id_map
->importedCount());
$keys = $entity_type
->getKeys();
foreach ($expectations as $vid => $languages) {
foreach ($languages as $language => $expected_state) {
$lookup = [
$keys['revision'] => $vid,
$keys['langcode'] => $language,
];
$actual_state = $id_map
->lookupDestinationIds($lookup);
$this
->assertEquals($expected_state, $actual_state[0][0]);
}
}
}