public function testAddOverriddenSmiley()
 {
     $collection = new EmoticonCollection();
     $emoticon = new Emoticon();
     $emoticon->setSmilies(array(':foo:', ':foofoo:'));
     $emoticon1 = new Emoticon();
     $emoticon1->setSmilies(array(':foo:', ':bar:'));
     $collection->add('foo', $emoticon);
     $collection->add('bar', $emoticon1);
     $this->assertSame(array(':foofoo:', ':foo:', ':bar:'), $collection->getSmilies());
     $this->assertSame($emoticon, $collection->getEmoticonBySmiley(':foofoo:'));
     $this->assertSame($emoticon1, $collection->getEmoticonBySmiley(':foo:'));
     $this->assertSame($emoticon1, $collection->getEmoticonBySmiley(':bar:'));
 }
 public function testGetMatcher()
 {
     $expectEmoticon = new Emoticon();
     $expectEmoticon->setSmiley(':foo:');
     $expectCollection = new EmoticonCollection();
     $expectCollection->add('foo', $expectEmoticon);
     $loader = $this->getMockBuilder('FM\\BbcodeBundle\\Emoticon\\Loader\\FileLoader')->disableOriginalConstructor()->getMockForAbstractClass();
     $loader->expects($this->once())->method('load')->will($this->returnValue($expectCollection));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $result = new EmoticonHook($loader, $container, array('resource' => 'bar'));
     $collection = $result->getEmoticonCollection();
     $matcher = $result->getMatcher();
     $this->assertSame($collection->get('foo'), $expectEmoticon);
     $this->assertContains(':foo:', $matcher->getSmilies());
     $this->assertNotEmpty($matcher->match(':foo:'));
 }
Example #3
0
 /**
  * Gets the EmoticonCollection instance associated with this EmoticonHook.
  *
  * @return EmoticonCollection A EmoticonCollection instance
  */
 public function getEmoticonCollection()
 {
     if (null !== $this->collection) {
         return $this->collection;
     }
     $this->collection = new EmoticonCollection();
     // Convert a default decoda emoticons array to an EmoticonCollection
     $collection = new EmoticonCollection();
     if (!$this->getEmoticons()) {
         if (null === $this->getParser()) {
             $this->setParser(new Decoda());
         }
         $this->startup();
     }
     foreach ($this->getEmoticons() as $name => $smilies) {
         $emoticon = new Emoticon();
         foreach ($smilies as $smiley) {
             $emoticon->setSmiley($smiley);
         }
         $collection->add($name, $emoticon);
     }
     $this->collection->addCollection($collection);
     if (null !== $this->options['resource']) {
         $subCollection = $this->loader->load($this->options['resource'], $this->options['resource_type']);
         $this->collection->addCollection($subCollection);
     }
     $this->resolveParameters($this->collection);
     return $this->collection;
 }
Example #4
0
<?php

use FM\BbcodeBundle\Emoticon\EmoticonCollection;
use FM\BbcodeBundle\Emoticon\Emoticon;
$collection = new EmoticonCollection();
$emoticon = new Emoticon();
$emoticon->addSmilies(array(':foo:'));
$collection->add('foo', $emoticon);
return $collection;
Example #5
0
 /**
  * Parses emoticons.
  *
  * @param EmoticonCollection $collection
  * @param string             $name
  * @param array              $config
  */
 private function parseEmoticon(EmoticonCollection $collection, $name, $config)
 {
     if (!isset($config['smilies']) || !is_array($config['smilies'])) {
         return;
     }
     $emoticon = new Emoticon();
     $emoticon->setSmilies($config['smilies']);
     if (isset($config['url'])) {
         $emoticon->setUrl($config['url']);
     }
     if (isset($config['html'])) {
         $emoticon->setHtml($config['html']);
     }
     if (isset($config['xHtml'])) {
         $emoticon->setXhtml($config['xHtml']);
     }
     $collection->add($name, $emoticon);
 }
Example #6
0
<?php

use Decoda\Decoda;
use Decoda\Hook\EmoticonHook;
use FM\BbcodeBundle\Emoticon\EmoticonCollection;
use FM\BbcodeBundle\Emoticon\Emoticon;
// Convert a default decoda emoticons array to an EmoticonCollection
$collection = new EmoticonCollection();
$decoda = new Decoda();
$hook = new EmoticonHook();
$hook->setParser($decoda);
$hook->startup();
$emoticons = $hook->getEmoticons();
foreach ($emoticons as $name => $smilies) {
    $emoticon = new Emoticon();
    foreach ($smilies as $smiley) {
        $emoticon->setSmiley($smiley);
    }
    $collection->add($name, $emoticon);
}
return $collection;
Example #7
0
 /**
  * Gets the EmoticonCollection instance associated with this EmoticonHook.
  *
  * @return EmoticonCollection A EmoticonCollection instance
  */
 public function getEmoticonCollection()
 {
     if (null !== $this->collection) {
         return $this->collection;
     }
     $this->collection = new EmoticonCollection();
     if (null === $this->_parser) {
         // Gets default decoda emoticons ($this->_emoticons)
         parent::setParser(new Decoda());
     }
     // Convert a default decoda emoticons array to an EmoticonCollection
     $collection = new EmoticonCollection();
     foreach ($this->_emoticons as $name => $smilies) {
         $emoticon = new Emoticon();
         foreach ($smilies as $smiley) {
             $emoticon->setSmiley($smiley);
         }
         $collection->add($name, $emoticon);
     }
     foreach ($this->getParser()->getPaths() as $path) {
         if (!file_exists($path . '/emoticons.json')) {
             continue;
         }
         $collection->addResource(new FileResource($path . '/emoticons.json'));
     }
     $this->collection->addCollection($collection);
     if (null !== $this->options['resource']) {
         $subCollection = $this->loader->load($this->options['resource'], $this->options['resource_type']);
         $this->collection->addCollection($subCollection);
     }
     $this->resolveParameters($this->collection);
     return $this->collection;
 }