You are here

public function ShortcodeTest::testClearShortcode in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ShortcodeTest.php \Drupal\Tests\shortcode\Functional\ShortcodeTest::testClearShortcode()

Tests that the Clear shortcode returns the right content.

File

tests/src/Functional/ShortcodeTest.php, line 82

Class

ShortcodeTest
Tests the Drupal 8 shortcode module functionality.

Namespace

Drupal\Tests\shortcode\Functional

Code

public function testClearShortcode() {
  $sets = [
    [
      'input' => '[clear]<div>Other elements</div>[/clear]',
      'output' => '<div class="clearfix"><div>Other elements</div></div>',
      'message' => 'Clear shortcode output matches.',
    ],
    [
      'input' => '[clear type="s"]<div>Other elements</div>[/clear]',
      'output' => '<span class="clearfix"><div>Other elements</div></span>',
      'message' => 'Clear shortcode with custom type "s" output matches.',
    ],
    [
      'input' => '[clear type="span"]<div>Other elements</div>[/clear]',
      'output' => '<span class="clearfix"><div>Other elements</div></span>',
      'message' => 'Clear shortcode with custom type "span" output matches.',
    ],
    [
      'input' => '[clear type="d"]<div>Other elements</div>[/clear]',
      'output' => '<div class="clearfix"><div>Other elements</div></div>',
      'message' => 'Clear shortcode with custom type "d" output matches.',
    ],
    [
      'input' => '[clear type="d" class="custom-class" id="theLabel" style="background-color: #F00;"]<div>Other elements</div>[/clear]',
      'output' => '<div class="custom-class clearfix" id="theLabel" style="background-color: #F00;"><div>Other elements</div></div>',
      'message' => 'Clear shortcode with custom attributes output matches.',
    ],
  ];
  foreach ($sets as $set) {
    $output = $this->shortcodeService
      ->process($set['input']);
    $this
      ->assertEqual($output, $set['output'], $set['message']);
  }
}