class CodeFilterTest in Code Filter 8
Tests code filter functions.
@group CodeFilter
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\codefilter\Tests\CodeFilterTest
Expanded class hierarchy of CodeFilterTest
File
- src/
Tests/ CodeFilterTest.php, line 13
Namespace
Drupal\codefilter\TestsView source
class CodeFilterTest extends UnitTestCase {
/**
* Test info.
*/
public static function getInfo() {
return [
'name' => 'Codefilter module text filters',
'description' => 'Tests raw filtering functions.',
];
}
/**
* Test codefilter_process_php().
*
* @dataProvider providerCodefilterProcessPHP
*/
public function testCodefilterProcessPHP($input, $expected) {
$result = CodeFilter::processPHP($input);
$this
->assertEquals($expected, $result);
}
/**
* Test codefilter_process_code().
*
* @dataProvider providerCodefilterProcessCode
*/
public function testCodefilterProcessCode($input, $expected) {
$result = CodeFilter::processCode($input);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testCodefilterProcessPHP().
*/
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>',
],
];
}
/**
* Data provider for testCodefilterProcessPHP().
*/
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>',
],
];
}
/**
* Provides a string with php code.
*
* @return string
* The php code as a string.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CodeFilterTest:: |
public static | function | Test info. | |
CodeFilterTest:: |
public static | function | Provides a string with php code. | |
CodeFilterTest:: |
public static | function | Data provider for testCodefilterProcessPHP(). | |
CodeFilterTest:: |
public static | function | Data provider for testCodefilterProcessPHP(). | |
CodeFilterTest:: |
public | function | Test codefilter_process_code(). | |
CodeFilterTest:: |
public | function | Test codefilter_process_php(). | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |