You are here

public function ShortcodeTest::testButtonShortcode in Shortcode 2.0.x

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

Tests that the Button shortcode returns the right content.

File

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

Class

ShortcodeTest
Tests the Drupal 8 shortcode module functionality.

Namespace

Drupal\Tests\shortcode\Functional

Code

public function testButtonShortcode() {
  $sets = [
    [
      'input' => '[button]Label[/button]',
      'output' => '<a href="' . $this->siteUrl . '" class="button" title="Label"><span>Label</span></a>',
      'message' => 'Button shortcode output matches.',
    ],
    [
      'input' => '[button path="<front>" class="custom-class"]Label[/button]',
      'output' => '<a href="' . $this->siteUrl . '" class="custom-class button" title="Label"><span>Label</span></a>',
      'message' => 'Button shortcode with custom class output matches.',
    ],
    [
      'input' => '[button path="http://www.google.com" class="custom-class" title="Title" id="theLabel" style="border-radius:5px;"]Label[/button]',
      'output' => '<a href="http://www.google.com" class="custom-class button" id="theLabel" style="border-radius:5px;" title="Title"><span>Label</span></a>',
      'message' => 'Button shortcode with custom attributes and absolute output matches.',
    ],
  ];
  foreach ($sets as $set) {
    $output = $this->shortcodeService
      ->process($set['input']);
    $this
      ->assertEqual($output, $set['output'], $set['message']);
  }
}