You are here

public function GeshiFilterTest::testBracketsOnlyPhpCodeBlock in GeSHi Filter for syntax highlighting 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/GeshiFilterTest.php \Drupal\Tests\geshifilter\Functional\GeshiFilterTest::testBracketsOnlyPhpCodeBlock()

Test with brackets only php code block.

File

tests/src/Functional/GeshiFilterTest.php, line 359

Class

GeshiFilterTest
Tests for GeshiFilter in node content.

Namespace

Drupal\Tests\geshifilter\Functional

Code

public function testBracketsOnlyPhpCodeBlock() {
  $this->config
    ->set('tags', 'code');
  $this->config
    ->set('language.cpp.enabled', TRUE);
  $source_code = "//C++ source code\nfor (int i=0; i<10; ++i) {\n  fun(i);\n  bar.foo(x, y);\n server->start(&pool); \n}";

  // Enable only double square brackets.
  $this->config
    ->set('tag_styles', [
    GeshiFilter::BRACKETS_PHPBLOCK => GeshiFilter::BRACKETS_PHPBLOCK,
  ]);
  $this->config
    ->save();

  // This should be filtered.
  $this
    ->assertGeshiFilterHighlighting('<?php' . $source_code . '?>', [
    [
      $source_code,
      'php',
      0,
      1,
      FALSE,
    ],
  ], t('Checking php code blocks in GeshiFilter::BRACKETS_PHPBLOCK mode'));

  // This should not be filtered.
  $this
    ->assertGeshiFilterHighlighting('<code language="cpp">' . $source_code . '</code>', [
    [
      $source_code,
      NULL,
      0,
      1,
      FALSE,
    ],
  ], t('Checking angle brackets style in GeshiFilter::BRACKETS_PHPBLOCK mode'));
  $this
    ->assertGeshiFilterHighlighting('[code language="cpp"]' . $source_code . '[/code]', [
    [
      $source_code,
      NULL,
      0,
      1,
      FALSE,
    ],
  ], t('Checking [foo] brackets style in GeshiFilter::BRACKETS_PHPBLOCK mode'));
  $this
    ->assertGeshiFilterHighlighting('[[code language="cpp"]]' . $source_code . '[[/code]]', [
    [
      $source_code,
      NULL,
      0,
      1,
      FALSE,
    ],
  ], t('Checking [[foo]] brackets style in GeshiFilter::BRACKETS_PHPBLOCK mode'));
}