function WorkspaceIntegrationTest::assertWorkspaceStatus

Same name and namespace in other branches
  1. 9 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::assertWorkspaceStatus()
  2. 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::assertWorkspaceStatus()
  3. 10 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.

1 call to WorkspaceIntegrationTest::assertWorkspaceStatus()
WorkspaceIntegrationTest::testWorkspaces in core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php
Tests various scenarios for creating and publishing content in workspaces.

File

core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php, line 841

Class

WorkspaceIntegrationTest
Tests a complete publishing scenario across different workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

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']]);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.