You are here

public function RevisionRelationshipsTest::testBlockContentRevisionRelationship in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php \Drupal\block_content\Tests\Views\RevisionRelationshipsTest::testBlockContentRevisionRelationship()

Create a block_content with revision and rest result count for both views.

File

core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php, line 49
Contains \Drupal\block_content\Tests\Views\RevisionRelationshipsTest.

Class

RevisionRelationshipsTest
Tests the integration of block_content_revision table of block_content module.

Namespace

Drupal\block_content\Tests\Views

Code

public function testBlockContentRevisionRelationship() {
  $block_content = BlockContent::create(array(
    'info' => $this
      ->randomMachineName(),
    'type' => 'basic',
    'langcode' => 'en',
  ));
  $block_content
    ->save();

  // Create revision of the block_content.
  $block_content_revision = clone $block_content;
  $block_content_revision
    ->setNewRevision();
  $block_content_revision
    ->save();
  $column_map = array(
    'revision_id' => 'revision_id',
    'id_1' => 'id_1',
    'block_content_field_data_block_content_field_revision_id' => 'block_content_field_data_block_content_field_revision_id',
  );

  // Here should be two rows.
  $view_id = Views::getView('test_block_content_revision_id');
  $this
    ->executeView($view_id, array(
    $block_content
      ->id(),
  ));
  $resultset_id = array(
    array(
      'revision_id' => '1',
      'id_1' => '1',
      'block_content_field_data_block_content_field_revision_id' => '1',
    ),
    array(
      'revision_id' => '2',
      'id_1' => '1',
      'block_content_field_data_block_content_field_revision_id' => '1',
    ),
  );
  $this
    ->assertIdenticalResultset($view_id, $resultset_id, $column_map);

  // There should be only one row with active revision 2.
  $view_revision_id = Views::getView('test_block_content_revision_revision_id');
  $this
    ->executeView($view_revision_id, array(
    $block_content
      ->id(),
  ));
  $resultset_revision_id = array(
    array(
      'revision_id' => '2',
      'id_1' => '1',
      'block_content_field_data_block_content_field_revision_id' => '1',
    ),
  );
  $this
    ->assertIdenticalResultset($view_revision_id, $resultset_revision_id, $column_map);
}