You are here

class CodeFilterTest in Code Filter 8

Tests code filter functions.

@group CodeFilter

Hierarchy

Expanded class hierarchy of CodeFilterTest

File

src/Tests/CodeFilterTest.php, line 13

Namespace

Drupal\codefilter\Tests
View 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">&lt;?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">=&gt; </span><span style="color: #0000BB">$count</span><span style="color: #007700">, </span><span style="color: #DD0000">\'%orphans\' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$orphans</span><span style="color: #007700">, </span><span style="color: #DD0000">\'!link\' </span><span style="color: #007700">=&gt; </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 />&nbsp;* Longer comment is here.<br />&nbsp;**/<br /></span><span style="color: #0000BB">?&gt;</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

Namesort descending Modifiers Type Description Overrides
CodeFilterTest::getInfo public static function Test info.
CodeFilterTest::providerCode public static function Provides a string with php code.
CodeFilterTest::providerCodefilterProcessCode public static function Data provider for testCodefilterProcessPHP().
CodeFilterTest::providerCodefilterProcessPHP public static function Data provider for testCodefilterProcessPHP().
CodeFilterTest::testCodefilterProcessCode public function Test codefilter_process_code().
CodeFilterTest::testCodefilterProcessPHP public function Test codefilter_process_php().
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340