| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Thunder\Shortcode\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Thunder\Shortcode\EventHandler\FilterRawEventHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Thunder\Shortcode\Events; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Thunder\Shortcode\HandlerContainer\HandlerContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Thunder\Shortcode\Parser\RegexParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Thunder\Shortcode\Shortcode\Shortcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Thunder\Shortcode\Shortcode\ShortcodeInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Thunder\Shortcode\ShortcodeFacade; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Thunder\Shortcode\Syntax\CommonSyntax; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author Tomasz Kowalczyk <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | final class FacadeTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     public function testFacade() | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $handlers = new HandlerContainer(); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $handlers | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |             ->add('name', function (ShortcodeInterface $s) { return $s->getName(); }) | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |             ->addAlias('n', 'name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $facade = ShortcodeFacade::create($handlers, new CommonSyntax()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $facade->addHandler('content', function (ShortcodeInterface $s) { return $s->getContent(); }); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $facade->addHandlerAlias('c', 'content'); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $facade->setParser(new RegexParser()); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertSame('n', $facade->process('[n]')); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $this->assertSame('c', $facade->process('[c]c[/c]')); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         $shortcodes = $facade->parse('[b]'); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->assertInstanceOf('Thunder\\Shortcode\\Shortcode\\ParsedShortcodeInterface', $shortcodes[0]); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function testFacadeEvents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $facade = new ShortcodeFacade(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $facade->addHandler('n', function (ShortcodeInterface $s) { return $s->getName(); }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $facade->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(array('raw'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertSame('[raw] [n] [/raw]', $facade->process('[raw] [n] [/raw]')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function testSerialization() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $facade = new ShortcodeFacade(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $s = new Shortcode('c', array(), null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertSame('[c /]', $facade->serializeToText($s)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertSame('c', $facade->unserializeFromText('[c]')->getName()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->assertSame('[c /]', $facade->serialize($s, 'text')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertSame('c', $facade->unserialize('[c]', 'text')->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $json = '{"name":"c","parameters":[],"content":null,"bbCode":null}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertSame($json, $facade->serializeToJson($s)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertSame('c', $facade->unserializeFromJson($json)->getName()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->assertSame($json, $facade->serialize($s, 'json')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertSame('c', $facade->unserialize($json, 'json')->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $yaml = <<<EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | name: c | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | parameters: {  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | content: null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | bbCode: null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | EOF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertSame($yaml, $facade->serialize($s, 'yaml')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->assertSame('c', $facade->unserialize($yaml, 'yaml')->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $xml = <<<EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | <?xml version="1.0" encoding="UTF-8"?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | <shortcode name="c"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |   <bbCode/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |   <parameters/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |   <content/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | </shortcode> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | EOF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->assertSame($xml, $facade->serialize($s, 'xml')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertSame('c', $facade->unserialize($xml, 'xml')->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     public function testInvalidSerializationFormatException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->setExpectedException('InvalidArgumentException'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $facade = new ShortcodeFacade(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $facade->serialize(new Shortcode('name', array(), null), 'invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     public function testInvalidUnserializationFormatException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->setExpectedException('InvalidArgumentException'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $facade = new ShortcodeFacade(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $facade->unserialize('[c]', 'invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  | 
            
                        
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.