public function assertHintsContain($str)
 {
     $config = $this->configurator->asConfig();
     ConfigHelper::filterVariants($config, 'JS');
     $xsl = $this->configurator->rendering->engine->getXSL($this->configurator->rendering);
     $generator = new HintGenerator();
     $generator->setConfig($config);
     $generator->setPlugins($this->configurator->plugins);
     $generator->setXSL($xsl);
     $this->assertContains($str, $generator->getHints());
 }
 /**
  * @testdox asConfig() returns a list of [attrName, Regexp instance, map] arrays
  */
 public function testGetConfig()
 {
     $collection = new AttributePreprocessorCollection();
     $collection->add('x', '#(?<x1>x1)#');
     $collection->add('x', '#(?<x2>x2)#');
     $collection->add('y', '#(?<y1>y1)#');
     $collection->add('y', '#(?<y2>y2)#');
     $config = $collection->asConfig();
     ConfigHelper::filterVariants($config);
     $this->assertSame([['x', '#(?<x1>x1)#', ['', 'x1']], ['x', '#(?<x2>x2)#', ['', 'x2']], ['y', '#(?<y1>y1)#', ['', 'y1']], ['y', '#(?<y2>y2)#', ['', 'y2']]], $config);
 }
Example #3
0
 public function getParser(array $config = \null)
 {
     $this->configOptimizer->reset();
     $rendererGenerator = new XSLT();
     $this->xsl = $rendererGenerator->getXSL($this->configurator->rendering);
     $this->config = isset($config) ? $config : $this->configurator->asConfig();
     ConfigHelper::filterVariants($this->config, 'JS');
     $this->config = $this->callbackGenerator->replaceCallbacks($this->config);
     $src = $this->getHints() . $this->injectConfig($this->getSource());
     $src .= $this->getExports();
     $src = $this->getMinifier()->get($src);
     $src = '(function(){' . $src . '})()';
     return $src;
 }
 /**
  * @testdox Filters work
  * @dataProvider getData
  */
 public function testFilters($filter, $original, $expected, $logs = [], $setup = null)
 {
     $this->configurator->tags->add('FOO')->attributes->add('foo')->filterChain->append($filter);
     if (isset($setup)) {
         $setup($this->configurator);
     }
     $config = $this->configurator->asConfig();
     ConfigHelper::filterVariants($config);
     $logger = new Logger();
     $parser = new ReflectionClass('s9e\\TextFormatter\\Parser');
     $method = $parser->getMethod('executeFilter');
     $method->setAccessible(true);
     $actual = $method->invoke(null, $config['tags']['FOO']['attributes']['foo']['filterChain'][0], ['attrName' => 'foo', 'attrValue' => $original, 'logger' => $logger, 'registeredVars' => $config['registeredVars']]);
     $this->assertSame($expected, $actual);
     if ($logs instanceof Closure) {
         $logs = $logs();
     }
     $this->assertSame($logs, $logger->get(), "Logs don't match");
 }
 /**
  * @testdox Words using the default replacement do not appear in the replacements
  */
 public function testAsConfigDefaultReplacement()
 {
     $plugin = $this->configurator->plugins->load('Censor', ['defaultReplacement' => '**']);
     $plugin->add('apple', '**');
     $plugin->add('cherry', 'banana');
     $config = $plugin->asConfig();
     ConfigHelper::filterVariants($config);
     $this->assertSame([['/^cherry$/Diu', 'banana']], $config['replacements']);
 }
Example #6
0
 /**
  * Return an instance of s9e\TextFormatter\Plugins\Censor\Helper
  *
  * @return Helper
  */
 public function getHelper()
 {
     $config = $this->asConfig();
     if (isset($config)) {
         ConfigHelper::filterVariants($config);
     } else {
         // Use a dummy config with a regexp that doesn't match anything
         $config = ['attrName' => $this->attrName, 'regexp' => '/(?!)/', 'tagName' => $this->tagName];
     }
     return new Helper($config);
 }
 /**
  * @testdox asConfig() preserves aliased attributes' keys in a JS variant
  */
 public function testAsConfigAliasAttribute()
 {
     $plugin = $this->configurator->plugins->load('HTMLElements');
     $plugin->aliasAttribute('A', 'HREF', 'URL');
     $pluginConfig = $plugin->asConfig();
     ConfigHelper::filterVariants($pluginConfig, 'JS');
     $this->assertEquals(new Dictionary(['a' => new Dictionary(['href' => 'url'])]), $pluginConfig['aliases']);
 }
Example #8
0
 public function getHelper()
 {
     $config = $this->asConfig();
     if (isset($config)) {
         ConfigHelper::filterVariants($config);
     } else {
         $config = array('attrName' => $this->attrName, 'regexp' => '/(?!)/', 'tagName' => $this->tagName);
     }
     return new Helper($config);
 }
 /**
  * @testdox executeAttributePreprocessors() returns TRUE even if no source attribute was present
  */
 public function testExecuteAttributePreprocessorsReturnsTrue()
 {
     $tagConfig = new TagConfig();
     $tagConfig->attributePreprocessors->add('foo', '/^(?<bar>[a-z])(?<baz>[a-z])$/i');
     $tagConfig = $tagConfig->asConfig();
     ConfigHelper::filterVariants($tagConfig);
     $tag = new Tag(Tag::SELF_CLOSING_TAG, 'X', 0, 0);
     $this->assertTrue(Parser::executeAttributePreprocessors($tag, $tagConfig));
 }
Example #10
0
 public function getParser()
 {
     $config = $this->asConfig();
     ConfigHelper::filterVariants($config);
     return new Parser($config);
 }
 /**
  * @testdox asConfig() returns predefinedAttributes in a Dictionary
  */
 public function testAsConfigPreservesPredefinedAttributeNames()
 {
     $plugin = $this->configurator->plugins->load('BBCodes');
     $plugin->add('FOO')->predefinedAttributes['k'] = 'v';
     $config = $plugin->asConfig();
     ConfigHelper::filterVariants($config, 'JS');
     $this->assertInstanceOf('s9e\\TextFormatter\\Configurator\\JavaScript\\Dictionary', $config['bbcodes']['FOO']['predefinedAttributes']);
     $this->assertArrayHasKey('k', $config['bbcodes']['FOO']['predefinedAttributes']);
 }
Example #12
0
 /**
  * Get a JavaScript parser
  *
  * @param  array  $config Config array returned by the configurator
  * @return string         JavaScript parser
  */
 public function getParser(array $config = null)
 {
     $this->configOptimizer->reset();
     // Get the stylesheet used for rendering
     $this->xsl = (new XSLT())->getXSL($this->configurator->rendering);
     // Prepare the parser's config
     $this->config = isset($config) ? $config : $this->configurator->asConfig();
     ConfigHelper::filterVariants($this->config, 'JS');
     $this->config = $this->callbackGenerator->replaceCallbacks($this->config);
     // Get the parser's source and inject its config
     $src = $this->getHints() . $this->injectConfig($this->getSource());
     // Export the public API
     $src .= $this->getExports();
     // Minify the source
     $src = $this->getMinifier()->get($src);
     // Wrap the source in a function to protect the global scope
     $src = '(function(){' . $src . '})()';
     return $src;
 }
 /**
  * @testdox The regexp has the Unicode modifier if notBefore contains a Unicode property
  */
 public function testNotBeforeUnicode()
 {
     $plugin = $this->configurator->plugins->load('Emoticons');
     $plugin->add('x', 'x');
     $plugin->notBefore = '\\pL';
     $config = $plugin->asConfig();
     ConfigHelper::filterVariants($config);
     $this->assertSame('/x(?!\\pL)/Su', $config['regexp']);
 }
Example #14
0
 /**
  * @testdox asConfig() uses target names as keys for closeParent
  */
 public function testAsConfigFlipsCloseParent()
 {
     $ruleset = new Ruleset();
     $ruleset->closeParent('X');
     $ruleset->closeParent('Y');
     $config = $ruleset->asConfig();
     ConfigHelper::filterVariants($config);
     $this->assertArrayHasKey('closeParent', $config);
     $this->assertArrayHasKey('X', $config['closeParent']);
     $this->assertArrayHasKey('Y', $config['closeParent']);
 }
 /**
  * @testdox asConfig() returns the regexps in a "generics" array where each element is in the form [<tagName>,<regexp>,<passthrough index>,<map>]
  */
 public function testAsConfig()
 {
     $plugin = $this->configurator->plugins->load('Preg');
     $plugin->replace('/(?<foo>[0-9]+)/', '');
     $plugin->replace('/(?<bar>[a-z]+)/', '');
     $config = $plugin->asConfig();
     ConfigHelper::filterVariants($config);
     $this->assertEquals(['generics' => [['PREG_C53BB427', '/(?<foo>[0-9]+)/', 0, ['', 'foo']], ['PREG_DCEA6E9C', '/(?<bar>[a-z]+)/', 0, ['', 'bar']]]], $config);
 }
Example #16
0
 /**
  * Return an instance of Parser based on the current config
  *
  * @return \s9e\TextFormatter\Parser
  */
 public function getParser()
 {
     // Generate the config array
     $config = $this->asConfig();
     // Remove variants
     ConfigHelper::filterVariants($config);
     return new Parser($config);
 }