Ejemplo n.º 1
0
 public function testJavaScript()
 {
     $groups = new ResourceGroups();
     $groups->addGroup('foo');
     $groups->addGroup('bar');
     $res = new JavaScriptResourceManager($groups, function (JavaScriptResource $res) {
         $combine = new JavaScriptCombineFiles();
         $combine->setInputDir(__DIR__)->setOutputDir(__DIR__ . '/tmp/cache')->setOutputBaseUrl('/tmp/cache')->setOutputForceRefresh(true)->setOutputLifeTime(0)->setOutputStrategy('manual')->setCacheDb(CombineFilesCacheDB::openFile(__DIR__ . '/tmp/cache/js.db'));
         $url = new UrlManager();
         $res->setCombineObject($combine);
         $res->setUrlManager($url);
     });
     $this->assertSame($groups, $res->getGroups());
     $res->add(new JavaScriptResource('foo_and_bar', array('/tmp/js/foo.js', '/tmp/js/bar.js'), array('combine' => true)), 'foo');
     $res->add(new JavaScriptResource('bar_and_foo', array('/tmp/js/bar.js', '/tmp/js/foo.js'), array('combine' => true)), 'bar');
     $this->assertTrue(file_exists(__DIR__ . '/tmp/cache/js.db'));
     foreach ($res->resources() as $js) {
         foreach ($js->getUrl() as $url) {
             $this->assertTrue(file_exists(__DIR__ . $url));
         }
     }
     $this->assertNotEmpty($res->render('json'));
     $this->assertNotEmpty($res->render('html'));
 }