Example #1
0
 public function testSetters()
 {
     $opts = [];
     $opt = new \Packaged\Config\Provider\ConfigSection('', $opts);
     $dispatcher = new \Packaged\Dispatch\Dispatch(new DummyKernel(), $opt);
     $dispatcher->setBaseDirectory(__DIR__);
     $this->assertEquals(__DIR__, $dispatcher->getBaseDirectory());
     $this->assertSame($dispatcher, $dispatcher->prepare());
     $dispatcher->setFileHashTable(['a' => '1']);
     $dispatcher->addFileHashEntry('b', '2');
     $this->assertEquals('1', $dispatcher->getFileHash('a'));
     $this->assertEquals('2', $dispatcher->getFileHash('b'));
 }
Example #2
0
 public function testGenerateHtmlIncludes()
 {
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $request->headers->set('HOST', 'www.packaged.in');
     $request->server->set('REQUEST_URI', '/');
     $opts = ['assets_dir' => 'asset'];
     $opt = new \Packaged\Config\Provider\ConfigSection('', $opts);
     $dispatcher = new \Packaged\Dispatch\Dispatch(new DummyKernel(), $opt);
     $dispatcher->setBaseDirectory(__DIR__);
     $dispatcher->handle($request);
     $manager = \Packaged\Dispatch\AssetManager::assetType();
     $manager->requireCss('test');
     $manager->requireJs('test', ['delay' => true]);
     $manager->requireJs('tests');
     $manager->requireJs('tests.min');
     $manager->requireJs('testnotfound', ['delay' => true]);
     $this->assertEquals('<link href="//www.packaged.in/res/p/8cac7/b/76d6c18/test.css"' . ' rel="stylesheet" type="text/css">', \Packaged\Dispatch\AssetManager::generateHtmlIncludes('css'));
     $this->assertEquals('<script src="//www.packaged.in/res/p/8cac7/b/e2218e4/test.js"' . ' delay="true"></script>' . '<script src="//www.packaged.in/res/p/8cac7/b/9b0a055/tests.min.js">' . '</script>', \Packaged\Dispatch\AssetManager::generateHtmlIncludes('js'));
     $this->assertEquals('', \Packaged\Dispatch\AssetManager::generateHtmlIncludes('fnt'));
 }
Example #3
0
//Include the composer autoloader
require_once dirname(__DIR__) . '/vendor/autoload.php';
// Set correct enviroment
if (isset($_SERVER['APPLICATION_ID']) && $_SERVER['APPLICATION_ID'] == 'dev~steamranks-com') {
    putenv('CUBEX_ENV=LOCAL');
} else {
    putenv('CUBEX_ENV=PRODUCTION');
}
putenv('CUBEX_ENV=LOCAL');
//Create an instance of cubex, with the web root defined
$app = new \Cubex\Cubex(__DIR__);
$app->boot();
//Create and configure a new dispatcher
$dispatcher = new \Packaged\Dispatch\Dispatch($app, $app->getConfiguration()->getSection('dispatch'));
//Set the correct working directory for dispatcher
$dispatcher->setBaseDirectory(dirname(__DIR__));
//Load in the cache of file hashes to improve performance of dispatched assets
$fileHash = 'conf/dispatch.filehash.ini';
if (file_exists($fileHash)) {
    $hashTable = parse_ini_file($fileHash, false);
    if (!empty($hashTable)) {
        $dispatcher->setFileHashTable($hashTable);
    }
}
//Inject dispatch to handle assets
$app = (new \Stack\Builder())->push([$dispatcher, 'prepare'])->resolve($app);
//Create a request object
$request = \Cubex\Http\Request::createFromGlobals();
//Tell Cubex to handle the request, and do its magic
$response = $app->handle($request);
//Send the generated response to the user
 public function getDispatch(array $options = [])
 {
     $options = array_merge(['source_dir' => 'tests'], $options);
     $kernel = $this->getMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     /**
      * @var $kernel Symfony\Component\HttpKernel\HttpKernelInterface
      */
     $dispatch = new \Packaged\Dispatch\Dispatch($kernel, $options);
     $dispatch->setBaseDirectory(dirname(__DIR__));
     return $dispatch;
 }