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:')); }
<?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;
/** * 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; }
/** * 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; }