You are here

protected function WorkspaceIntegrationTest::assertWorkspaceStatus in Workspace 8.2

Checks entity load, entity queries and views results for a test scenario.

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 tests/src/Kernel/WorkspaceIntegrationTest.php
Tests various scenarios for creating and deploying content in workspaces.

File

tests/src/Kernel/WorkspaceIntegrationTest.php, line 457

Class

WorkspaceIntegrationTest
Tests a complete deployment scenario across different workspaces.

Namespace

Drupal\Tests\workspace\Kernel

Code

protected function assertWorkspaceStatus(array $expected, $entity_type_id) {
  $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']]);
      }
    }
  }
}