コード例 #1
0
ファイル: ConformanceTest.php プロジェクト: vanilla/nbbc
 /**
  * Run a given test array.
  *
  * @param array $test The test to run.
  */
 protected function performTest($test)
 {
     $testDefaults = ['newline_ignore' => false, 'detect_urls' => false, 'urltarget' => false, 'urlforcetarget' => false, 'plainmode' => false, 'tag_marker' => '', 'skip' => false];
     $test = array_replace($testDefaults, $test);
     if ($test['skip']) {
         $this->markTestSkipped('Skipped test: ' . $test['descr']);
         return;
     }
     $bbcode = new BBCode();
     $bbcode->addRule('wstest', ['mode' => BBCode::BBCODE_MODE_ENHANCED, 'allow' => ['_default' => '/^[a-zA-Z0-9._ -]+$/'], 'template' => '<span style="wstest:{$_default}">{$_content}</span>', 'class' => 'inline', 'allow_in' => ['listitem', 'block', 'columns', 'inline', 'link']]);
     $bbcode->setLocalImgDir(__DIR__ . '/../smileys');
     $bbcode->setLocalImgURL('smileys');
     $bbcode->setTagMarker('[');
     $bbcode->setAllowAmpersand(false);
     $bbcode->setIgnoreNewlines((bool) $test['newline_ignore']);
     $bbcode->setDetectURLs((bool) $test['detect_urls']);
     $bbcode->setURLTargetable($test['urltarget'] == true);
     $bbcode->setURLTarget($test['urlforcetarget']);
     $bbcode->setPlainMode($test['plainmode']);
     if ($test['tag_marker'] === '<') {
         $bbcode->setTagMarker('<');
         $bbcode->setAllowAmpersand(true);
     } elseif (!empty($test['tag_marker'])) {
         $bbcode->setTagMarker($test['tag_marker']);
     }
     $result = $bbcode->parse($test['bbcode']);
     if (!empty($test['regex'])) {
         $this->assertRegExp($test['regex'], $result, $test['descr']);
     } else {
         $this->assertSame($test['html'], $result, $test['descr']);
     }
 }