You are here

public function BlockViewBuilderTest::testBasicRendering in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block/src/Tests/BlockViewBuilderTest.php \Drupal\block\Tests\BlockViewBuilderTest::testBasicRendering()

Tests the rendering of blocks.

File

core/modules/block/src/Tests/BlockViewBuilderTest.php, line 79
Contains \Drupal\block\Tests\BlockViewBuilderTest.

Class

BlockViewBuilderTest
Tests the block view builder.

Namespace

Drupal\block\Tests

Code

public function testBasicRendering() {
  \Drupal::state()
    ->set('block_test.content', '');
  $entity = $this->controller
    ->create(array(
    'id' => 'test_block1',
    'theme' => 'stark',
    'plugin' => 'test_html',
  ));
  $entity
    ->save();

  // Test the rendering of a block.
  $entity = Block::load('test_block1');
  $output = entity_view($entity, 'block');
  $expected = array();
  $expected[] = '<div id="block-test-block1">';
  $expected[] = '  ';
  $expected[] = '    ';
  $expected[] = '      ';
  $expected[] = '  </div>';
  $expected[] = '';
  $expected_output = implode("\n", $expected);
  $this
    ->assertEqual($this->renderer
    ->renderRoot($output), $expected_output);

  // Reset the HTML IDs so that the next render is not affected.
  Html::resetSeenIds();

  // Test the rendering of a block with a given title.
  $entity = $this->controller
    ->create(array(
    'id' => 'test_block2',
    'theme' => 'stark',
    'plugin' => 'test_html',
    'settings' => array(
      'label' => 'Powered by Bananas',
    ),
  ));
  $entity
    ->save();
  $output = entity_view($entity, 'block');
  $expected = array();
  $expected[] = '<div id="block-test-block2">';
  $expected[] = '  ';
  $expected[] = '      <h2>Powered by Bananas</h2>';
  $expected[] = '    ';
  $expected[] = '      ';
  $expected[] = '  </div>';
  $expected[] = '';
  $expected_output = implode("\n", $expected);
  $this
    ->assertEqual($this->renderer
    ->renderRoot($output), $expected_output);
}