You are here

public function GeshiFilterTest::setUp 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::setUp()

Code run before each and every test method.

Overrides BrowserTestBase::setUp

File

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

Class

GeshiFilterTest
Tests for GeshiFilter in node content.

Namespace

Drupal\Tests\geshifilter\Functional

Code

public function setUp() {
  parent::setUp();

  // Restore node to default value.
  $this->node = 1;

  // Create object with configuration.
  $this->config = \Drupal::configFactory()
    ->getEditable('geshifilter.settings');

  // And set the path to the geshi library.
  $this->config
    ->set('geshi_dir', '/libraries/geshi');

  // Create a content type, as we will create nodes on test.
  $settings = [
    // Override default type (a random name).
    'type' => 'geshifilter_content_type',
    'name' => 'Geshifilter Content',
  ];
  $this
    ->drupalCreateContentType($settings);

  // Create a filter admin user.
  $permissions = [
    'administer filters',
    'administer nodes',
    'access administration pages',
    'create geshifilter_content_type content',
    'edit any geshifilter_content_type content',
    'administer site configuration',
  ];
  $this->filterAdminUser = $this
    ->drupalCreateUser($permissions);

  // Log in with filter admin user.
  $this
    ->drupalLogin($this->filterAdminUser);

  // Add an text format with only geshi filter.
  $this
    ->createTextFormat('geshifilter_text_format', [
    'filter_geshifilter',
  ]);

  // Set some default GeSHi filter admin settings.
  // Set default highlighting mode to "do nothing".
  $this->config
    ->set('default_highlighting', GeshiFilter::DEFAULT_PLAINTEXT);
  $this->config
    ->set('use_format_specific_options', FALSE);
  $this->config
    ->set('tag_styles', [
    GeshiFilter::BRACKETS_ANGLE => GeshiFilter::BRACKETS_ANGLE,
    GeshiFilter::BRACKETS_SQUARE => GeshiFilter::BRACKETS_SQUARE,
  ]);
  $this->config
    ->set('default_line_numbering', GeshiFilter::LINE_NUMBERS_DEFAULT_NONE);
  $this->config
    ->save();
}