protected function BlockStorageUnitTest::renderTests

Tests the rendering of blocks.

1 call to BlockStorageUnitTest::renderTests()
BlockStorageUnitTest::testBlockCRUD in drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
Tests CRUD operations.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php, line 134
Contains \Drupal\block\Tests\BlockStorageUnitTest.

Class

BlockStorageUnitTest
Tests the storage of blocks.

Namespace

Drupal\block\Tests

Code

protected function renderTests() {

  // Test the rendering of a block.
  $entity = entity_load('block', 'stark.test_block');
  $output = entity_view($entity, 'block');
  $expected = array();
  $expected[] = '<div class="block block-block-test" id="block-test-block">';
  $expected[] = '  ';
  $expected[] = '    ';
  $expected[] = '';
  $expected[] = '  <div class="content">';
  $expected[] = '    ';
  $expected[] = '  </div>';
  $expected[] = '</div>';
  $expected[] = '';
  $expected_output = implode("\n", $expected);
  $this
    ->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.');

  // Reset the HTML IDs so that the next render is not affected.
  drupal_static_reset('drupal_html_id');

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

  // Clean up this entity.
  $entity
    ->delete();
}