public function testAssetsManager() { $assets = new Phalcon\Assets\Manager(); $assets->addCss('/css/style1.css'); $assets->addCss('/css/style2.css'); $collection = $assets->get('css'); $number = 0; foreach ($collection as $resource) { $this->assertEquals($resource->getType(), 'css'); $number++; } $this->assertEquals($number, 2); $assets->addJs('/js/scripts1.js'); $assets->addJs('/js/scripts2.js'); $collection = $assets->get('js'); $number = 0; foreach ($collection as $resource) { $this->assertEquals($resource->getType(), 'js'); $number++; } $this->assertEquals($number, 2); $assets->addResource(new Phalcon\Assets\Resource\Css('/css/style.css', false)); $this->assertEquals(count($assets->get('css')), 3); Phalcon\DI::reset(); //Create a default DI $di = new Phalcon\DI(); $di->set('url', function () { $url = new Phalcon\Mvc\Url(); $url->setBaseUri('/'); return $url; }); $di->set('escaper', function () { return new \Phalcon\Escaper(); }); //With implicit output ob_start(); $assets->outputCss(); $html = ob_get_clean(); $this->assertEquals($html, '<link rel="stylesheet" href="//css/style1.css" type="text/css" /> <link rel="stylesheet" href="//css/style2.css" type="text/css" /> <link rel="stylesheet" href="/css/style.css" type="text/css" />' . PHP_EOL); ob_start(); $assets->outputJs(); $html = ob_get_clean(); $this->assertEquals($html, '<script src="//js/scripts1.js" type="text/javascript"></script> <script src="//js/scripts2.js" type="text/javascript"></script>' . PHP_EOL); //Without implicit output $assets->useImplicitOutput(false); $html = $assets->outputCss(); $this->assertEquals($html, '<link rel="stylesheet" href="//css/style1.css" type="text/css" /> <link rel="stylesheet" href="//css/style2.css" type="text/css" /> <link rel="stylesheet" href="/css/style.css" type="text/css" />' . PHP_EOL); $html = $assets->outputJs(); $this->assertEquals($html, '<script src="//js/scripts1.js" type="text/javascript"></script> <script src="//js/scripts2.js" type="text/javascript"></script>' . PHP_EOL); //Test collections $assets->collection('footer')->addCss('css/style-1.css'); $footer = $assets->collection('footer'); $footer->addCss('css/style-2.css'); $html = $assets->outputCss('footer'); $this->assertEquals($html, '<link rel="stylesheet" href="/css/style-1.css" type="text/css" /> <link rel="stylesheet" href="/css/style-2.css" type="text/css" />' . PHP_EOL); $scripts = $assets->collection('header')->setPrefix('http:://cdn.example.com/')->setLocal(false)->addJs('js/jquery.js')->addJs('js/bootstrap.min.js'); $html = $assets->outputJs('header'); $this->assertEquals($html, '<script src="http:://cdn.example.com/js/jquery.js" type="text/javascript"></script> <script src="http:://cdn.example.com/js/bootstrap.min.js" type="text/javascript"></script>' . PHP_EOL); }
public function testIssue1198() { @unlink(__DIR__ . '/assets/production/1198.css'); $di = new \Phalcon\DI\FactoryDefault(); $assets = new \Phalcon\Assets\Manager(); $assets->useImplicitOutput(false); $css = $assets->collection('css'); $css->setTargetPath(__DIR__ . '/assets/production/1198.css'); $css->addCss(__DIR__ . '/assets/1198.css'); $css->addFilter(new UppercaseFilter()); $css->addFilter(new TrimFilter()); $css->join(true); $assets->outputCss('css'); $this->assertEquals(file_get_contents(__DIR__ . '/assets/production/1198.css'), 'A{TEXT-DECORATION:NONE;}B{FONT-WEIGHT:BOLD;}'); @unlink(__DIR__ . '/assets/production/1198.css'); }