View source
<?php
namespace Drupal\Tests\geshifilter\Functional;
use Drupal\Tests\BrowserTestBase;
class GeshiFilterCssTest extends BrowserTestBase {
protected $filterAdminUser;
protected $inputFormatIid;
public static $modules = [
'node',
'geshifilter',
'filter',
'file',
];
protected $config;
public function setUp() {
parent::setUp();
$this->config = \Drupal::configFactory()
->getEditable('geshifilter.settings');
$this->config
->set('geshi_dir', '/libraries/geshi');
$settings = [
'type' => 'geshifilter_content_type',
'name' => 'Geshifilter Content',
];
$this
->drupalCreateContentType($settings);
$permissions = [
'administer filters',
'access administration pages',
'administer site configuration',
];
$this->filterAdminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->filterAdminUser);
$this
->createTextFormat('geshifilter_text_format', [
'filter_geshifilter',
]);
}
public function testCss() {
$this
->drupalGet('admin/config/content/formats/geshifilter/generate_css');
$this
->assertRaw('GeSHi Dynamically Generated Stylesheet', 'Test for geshifilter generate css');
}
public function testCssInline() {
$node = [
'title' => 'Test for GeShi Filter',
'body' => [
[
'value' => "dfgdfg <code language=\"php\">echo(\"hi\");</code> dfgdg",
'format' => 'geshifilter_text_format',
],
],
'type' => 'geshifilter_content_type',
];
$form_values = [
'css_mode' => 1,
];
$this
->drupalPostForm('admin/config/content/formats/geshifilter', $form_values, t('Save configuration'));
$this
->drupalCreateNode($node);
$this
->drupalGet('node/1');
$this
->assertRaw('/assets/css/geshifilter.css', 'The CSS file /assets/css/geshifilter.css is present.');
$this
->assertNoRaw('/geshi/geshifilter-languages.css', 'The CSS file /geshi/geshifilter-languages.css is present.');
}
public function testCssExternal() {
$node = [
'title' => 'Test for GeShi Filter',
'body' => [
[
'value' => "dfgdfg <code language=\"php\">echo(\"hi\");</code> dfgdg",
'format' => 'geshifilter_text_format',
],
],
'type' => 'geshifilter_content_type',
];
$form_values = [
'css_mode' => 2,
];
$this
->drupalPostForm('admin/config/content/formats/geshifilter', $form_values, t('Save configuration'));
$this
->drupalCreateNode($node);
$this
->drupalGet('node/1');
$this
->assertRaw('/assets/css/geshifilter.css', 'The CSS file /assets/css/geshifilter.css is present.');
$this
->assertRaw('/geshi/geshifilter-languages.css', 'The CSS file /geshi/geshifilter-languages.css is present.');
}
public function testOnlyCss() {
$node = [
'title' => 'Test for GeShi Filter',
'body' => [
[
'value' => "dfgdfg <code language=\"php\">echo(\"hi\");</code> dfgdg",
'format' => 'geshifilter_text_format',
],
],
'type' => 'geshifilter_content_type',
];
$form_values = [
'css_mode' => 3,
];
$this
->drupalPostForm('admin/config/content/formats/geshifilter', $form_values, t('Save configuration'));
$this
->drupalCreateNode($node);
$this
->drupalGet('node/1');
$this
->assertNoRaw('/assets/css/geshifilter.css', 'The CSS file /assets/css/geshifilter.css is present.');
$this
->assertNoRaw('/geshi/geshifilter-languages.css', 'The CSS file /geshi/geshifilter-languages.css is present.');
}
protected function createTextFormat($format_name, array $filters) {
$edit = [];
$edit['format'] = $format_name;
$edit['name'] = $this
->randomMachineName();
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = 1;
foreach ($filters as $filter) {
$edit['filters[' . $filter . '][status]'] = TRUE;
}
$this
->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
$this
->assertRaw(t('Added text format %format.', [
'%format' => $edit['name'],
]), 'New filter created.');
$this
->drupalGet('admin/config/content/formats');
}
}