You are here

protected function GeshiFilterTest::assertGeshiFilterHighlighting in GeSHi Filter for syntax highlighting 8

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

Assert function for testing if GeSHi highlighting works.

Parameters

string $body: The body text of the node.

array $check_list: List of items that should be in rendered output (assertRaw). An item is something like array($source_code, $lang, $line_numbering, $linenumbers_start, $inline_mode). If $lang is set, GeSHifilter syntax highlighting is applied to $sourcecode. If $lang is false, $sourcecode is directly looked for.

string $description: Description of the assertion.

bool $invert: If assertNoRaw should be used instead of assertRaw.

12 calls to GeshiFilterTest::assertGeshiFilterHighlighting()
GeshiFilterTest::testBracketsOnlyAngle in tests/src/Functional/GeshiFilterTest.php
Test with brackets only angle.
GeshiFilterTest::testBracketsOnlyDoubleSquare in tests/src/Functional/GeshiFilterTest.php
Test with brackets only double square.
GeshiFilterTest::testBracketsOnlyPhpCodeBlock in tests/src/Functional/GeshiFilterTest.php
Test with brackets only php code block.
GeshiFilterTest::testBracketsOnlySquare in tests/src/Functional/GeshiFilterTest.php
Test with brackets only square.
GeshiFilterTest::testDoNothingMode in tests/src/Functional/GeshiFilterTest.php
Test for do nothing mode.

... See full list

File

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

Class

GeshiFilterTest
Tests for GeshiFilter in node content.

Namespace

Drupal\Tests\geshifilter\Functional

Code

protected function assertGeshiFilterHighlighting($body, array $check_list, $description, $invert = FALSE) {

  // Create a node.
  $node = [
    'title' => 'Test for GeShi Filter',
    'body' => [
      [
        'value' => $body . "\n" . $this
          ->randomMachineName(100),
        'format' => 'geshifilter_text_format',
      ],
    ],
    'type' => 'geshifilter_content_type',
  ];
  $this
    ->drupalCreateNode($node);
  $this
    ->drupalGet('node/' . $this->node);
  $this->node++;

  // $format = entity_load('filter_format', 'geshifilter_text_format');
  // $filter = $format->filters('geshifilter');
  // $format->settings['format'];.
  foreach ($check_list as $fragment) {
    list($source_code, $lang, $line_numbering, $linenumbers_start, $inline_mode) = $fragment;
    if ($lang) {

      // Apply syntax highlighting.
      $source_code = GeshiFilterProcess::geshiProcess($source_code, $lang, $line_numbering, $linenumbers_start, $inline_mode);
    }
    if ($invert) {
      $this
        ->assertNoRaw($source_code, $description);
    }
    else {
      $this
        ->assertRaw($source_code, $description);
    }
  }
}