View source
<?php
namespace Drupal\codefilter\Tests;
use Drupal\Tests\UnitTestCase;
use Drupal\codefilter\Plugin\Filter\CodeFilter;
class CodeFilterTest extends UnitTestCase {
public static function getInfo() {
return [
'name' => 'Codefilter module text filters',
'description' => 'Tests raw filtering functions.',
];
}
public function testCodefilterProcessPHP($input, $expected) {
$result = CodeFilter::processPHP($input);
$this
->assertEquals($expected, $result);
}
public function testCodefilterProcessCode($input, $expected) {
$result = CodeFilter::processCode($input);
$this
->assertEquals($expected, $result);
}
public static function providerCodefilterProcessPHP() {
return [
[
self::providerCode(),
'<div class="codeblock"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Comment is here.<br /></span><span style="color: #0000BB">watchdog</span><span style="color: #007700">(</span><span style="color: #DD0000">\'actions\'</span><span style="color: #007700">, </span><span style="color: #DD0000">\'@count orphaned actions (%orphans) exist in the actions table. !link\'</span><span style="color: #007700">, array(</span><span style="color: #DD0000">\'@count\' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$count</span><span style="color: #007700">, </span><span style="color: #DD0000">\'%orphans\' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$orphans</span><span style="color: #007700">, </span><span style="color: #DD0000">\'!link\' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$link</span><span style="color: #007700">), </span><span style="color: #0000BB">WATCHDOG_INFO</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/**<br /> * Longer comment is here.<br /> **/<br /></span><span style="color: #0000BB">?></span></span></code></div>',
],
];
}
public static function providerCodefilterProcessCode() {
return [
[
self::providerCode(),
'<div class="codeblock"><code>// Comment is here.<br />watchdog(\'actions\', \'@count orphaned actions (%orphans) exist in the actions table. !link\', array(\'@count\' => $count, \'%orphans\' => $orphans, \'!link\' => $link), WATCHDOG_INFO);<br />/**<br /> * Longer comment is here.<br /> **/</code></div>',
],
];
}
public static function providerCode() {
return <<<EOF
// Comment is here.
watchdog('actions', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => \$count, '%orphans' => \$orphans, '!link' => \$link), WATCHDOG_INFO);
/**
* Longer comment is here.
**/
EOF;
}
}