| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Evheniy\MaterializeBundle\Tests\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Assetic\Extension\Twig\AsseticExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Assetic\Factory\AssetFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Evheniy\MaterializeBundle\Twig\MaterializeExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Evheniy\MaterializeBundle\DependencyInjection\MaterializeExtension as MaterializeExtensionDI; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Class DefaultControllerTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @package Evheniy\MaterializeBundle\Tests\Controller | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | class DefaultControllerTest extends \PHPUnit_Framework_TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     protected function getTwig(array $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $twig = new \Twig_Environment( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             new \Twig_Loader_Array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 array('MaterializeBundle:Materialize:js.html.twig' => file_get_contents(dirname(__FILE__) . '/../../Resources/views/Materialize/js.html.twig')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $container = new ContainerBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $extension = new MaterializeExtensionDI(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $extension->load($data, $container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $twig ->addExtension(new AsseticExtension(new AssetFactory(dirname(__FILE__) . '/'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $twig ->addExtension(new MaterializeExtension($container)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         return $twig; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function testWithCdn() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $html = $this->getTwig(array(array('local_cdn' => 'cdn.site.com')))->render('MaterializeBundle:Materialize:js.html.twig'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->assertRegExp('/href\=\"\/\/cdn\.site\.comcss\/materialize.min.css\"/', $html); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertRegExp('/src\=\"\/\/cdn\.site\.comjs\/materialize.min.js\"/', $html); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function testWithOutCdn() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $html = $this->getTwig(array(array()))->render('MaterializeBundle:Materialize:js.html.twig'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertRegExp('/href\=\"css\/materialize.min.css\"/', $html); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->assertRegExp('/src\=\"js\/materialize.min.js\"/', $html); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 55 |  |  | } |