You are here

public function BlockContentTypeTemplatesTest::testBlockContentView in Acquia Content Hub 8

Checks the acquia-contenthub block templates functionality.

Overrides BlockContentTypeTest::testBlockContentView

File

tests/src/Functional/BlockContentTypeTemplatesTest.php, line 27

Class

BlockContentTypeTemplatesTest
Create a block and test block markup by attempting to view the altered block.

Namespace

Drupal\Tests\acquia_contenthub\Functional

Code

public function testBlockContentView() {
  \Drupal::service('theme_handler')
    ->install([
    'test_basetheme',
    'ch_test_subtheme',
    'ch_test_subtheme_advanced',
  ]);

  // Make ch_test_subtheme theme default.
  $this
    ->config('system.theme')
    ->set('default', 'ch_test_subtheme')
    ->save();
  $this
    ->assertEqual($this
    ->config('system.theme')
    ->get('default'), 'ch_test_subtheme');
  $this
    ->drupalLogin($this->adminUser);
  $block = $this
    ->createBlockContent();
  $block
    ->set('body', 'block_body_value');
  $block
    ->save();

  // Attempt to view the block.
  $this
    ->drupalGet('acquia-contenthub/display/block_content/' . $block
    ->id() . '/default');
  $this
    ->removeWhiteSpace();
  $expected = '</head><body><div><p>block_body_value</p></div><div data-content-barrier-exclude="true"></div></body></html>';
  $this
    ->assertRaw($expected, 'The block.html.twig and the block--block-content.html.twig are not used.');
  $this
    ->assertOffCanvasWrapperRemoved();

  // Make ch_test_subtheme_advanced theme default.
  $this
    ->config('system.theme')
    ->set('default', 'ch_test_subtheme_advanced')
    ->save();
  $this
    ->assertEqual($this
    ->config('system.theme')
    ->get('default'), 'ch_test_subtheme_advanced');
  $this
    ->drupalGet('acquia-contenthub/display/block_content/' . $block
    ->id() . '/default');
  $this
    ->removeWhiteSpace();
  $expected = '</head><body><div>block--block-content--acquia-contenthub.html.twig<h2>' . $block
    ->label() . '</h2><div><p>block_body_value</p></div></div><div data-content-barrier-exclude="true"></div></body></html>';
  $this
    ->assertRaw($expected, 'The block--block-content--acquia-contenthub.html.twig is used.');
  $this
    ->assertOffCanvasWrapperRemoved();
}