protected function WorkspaceIntegrationTest::assertWorkspaceStatus in Drupal 10
Same name and namespace in other branches
- 8 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::assertWorkspaceStatus()
- 9 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::assertWorkspaceStatus()
Checks entity load, entity queries and views results for a test scenario.
@internal
Parameters
array $expected: An array of expected values, as defined in ::testWorkspaces().
string $entity_type_id: The ID of the entity type that is being tested.
File
- core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceIntegrationTest.php, line 766
Class
- WorkspaceIntegrationTest
- Tests a complete publishing scenario across different workspaces.
Namespace
Drupal\Tests\workspaces\KernelCode
protected function assertWorkspaceStatus(array $expected, string $entity_type_id) : void {
$expected = $this
->flattenExpectedValues($expected, $entity_type_id);
$entity_keys = $this->entityTypeManager
->getDefinition($entity_type_id)
->getKeys();
foreach ($expected as $workspace_id => $expected_values) {
$this
->switchToWorkspace($workspace_id);
// Check that default revisions are swapped with the workspace revision.
$this
->assertEntityLoad($expected_values, $entity_type_id);
// Check that non-default revisions are not changed.
$this
->assertEntityRevisionLoad($expected_values, $entity_type_id);
// Check that entity queries return the correct results.
$this
->assertEntityQuery($expected_values, $entity_type_id);
// Check that the 'Frontpage' view only shows published content that is
// also considered as the default revision in the given workspace.
$expected_frontpage = array_filter($expected_values, function ($expected_value) {
return $expected_value['status'] === TRUE && $expected_value['default_revision'] === TRUE;
});
// The 'Frontpage' view will output nodes in reverse creation order.
usort($expected_frontpage, function ($a, $b) {
return $b['nid'] - $a['nid'];
});
$view = Views::getView('frontpage');
$view
->execute();
$this
->assertIdenticalResultset($view, $expected_frontpage, [
'nid' => 'nid',
]);
$rendered_view = $view
->render('page_1');
$output = \Drupal::service('renderer')
->renderRoot($rendered_view);
$this
->setRawContent($output);
foreach ($expected_values as $expected_entity_values) {
if ($expected_entity_values[$entity_keys['published']] === TRUE && $expected_entity_values['default_revision'] === TRUE) {
$this
->assertRaw($expected_entity_values[$entity_keys['label']]);
}
elseif ($workspace_id != 'stage' && $expected_entity_values[$entity_keys['id']] != 4) {
$this
->assertNoRaw($expected_entity_values[$entity_keys['label']]);
}
}
// Add a filter on a field that is stored in a dedicated table in order to
// test field joins with extra conditions (e.g. 'deleted' and 'langcode').
$view
->destroy();
$view
->setDisplay('page_1');
$filters = $view->displayHandlers
->get('page_1')
->getOption('filters');
$view->displayHandlers
->get('page_1')
->overrideOption('filters', $filters + [
'body_value' => [
'id' => 'body_value',
'table' => 'node__body',
'field' => 'body_value',
'operator' => 'not empty',
'plugin_id' => 'string',
],
]);
$view
->execute();
$this
->assertIdenticalResultset($view, $expected_frontpage, [
'nid' => 'nid',
]);
}
}