Ejemplo n.º 1
0
 public function testTrigger()
 {
     $event = new \Packaged\Dispatch\DispatchEvent();
     NewDispatcher::clear();
     NewDispatcher::trigger($event);
     $this->assertNull($event->getResult());
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $request->headers->set('HOST', 'packaged.in');
     $request->server->set('REQUEST_URI', '/');
     $dispatcher = new \Packaged\Dispatch\Dispatch(new DummyKernel(), ['source_dir' => 'tests']);
     $dispatcher->handle($request);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_SOURCE);
     $event->setPath('asset');
     \Packaged\Dispatch\Dispatch::trigger($event);
     $expect = '//packaged.in/res/s/dfcbf/asc04e3/76d6c18/test.css';
     $this->assertEquals($expect, $event->getResult());
 }
Ejemplo n.º 2
0
 public function eventProvider()
 {
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $request->headers->set('HOST', 'packaged.in');
     $tests = [];
     $dispatch = $this->getDispatch();
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_SOURCE);
     $event->setPath('asset');
     $expect = '//packaged.in/res/s/dfcbf/asc04e3/76d6c18/test.css';
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch(['run_on' => 'subdomain']);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_SOURCE);
     $event->setPath('asset');
     $expect = '//static.packaged.in/s/dfcbf/asc04e3/76d6c18/test.css';
     $tests[] = [$event, $dispatch, $request, $expect];
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $request->headers->set('HOST', 'www.packaged.in');
     $dispatch = $this->getDispatch(['run_on' => 'subdomain']);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_SOURCE);
     $event->setPath('asset');
     $expect = '//static.packaged.in/s/8cac7/asc04e3/76d6c18/test.css';
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch(['run_on' => 'domain', 'run_match' => 'packagedstatic.com']);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_SOURCE);
     $event->setPath('asset');
     $expect = '//packagedstatic.com/s/8cac7/asc04e3/76d6c18/test.css';
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch();
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('composer.json');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_VENDOR);
     $event->setPath('');
     $event->setLookupParts(['packaged', 'config']);
     $expect = '//www.packaged.in/res/v/packaged/' . 'config/8cac7/b/4568ecc/composer.json';
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch();
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('missing.composer.json');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_VENDOR);
     $event->setPath('');
     $event->setLookupParts(['packaged', 'config']);
     $expect = null;
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch(['aliases' => ['cfger' => 'vendor/packaged/config']]);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('composer.json');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_ALIAS);
     $event->setLookupParts(['cfger']);
     $expect = '//www.packaged.in/res/a/cfger/8cac7/b/4568ecc/composer.json';
     $tests[] = [$event, $dispatch, $request, $expect];
     $dispatch = $this->getDispatch(['assets_dir' => 'tests/asset']);
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename('test.css');
     $event->setMapType(\Packaged\Dispatch\DirectoryMapper::MAP_ASSET);
     $expect = '//www.packaged.in/res/p/8cac7/b/76d6c18/test.css';
     $tests[] = [$event, $dispatch, $request, $expect, 2];
     return $tests;
 }
Ejemplo n.º 3
0
 public function testAccess()
 {
     $event = new \Packaged\Dispatch\DispatchEvent();
     $event->setFilename("filename");
     $this->assertEquals("filename", $event->getFilename());
     $event->setResult("result");
     $this->assertEquals("result", $event->getResult());
     $event->setLookupParts(["lookup"]);
     $this->assertEquals(["lookup"], $event->getLookupParts());
     $event->setMapType("maptype");
     $this->assertEquals("maptype", $event->getMapType());
     $event->setPath("path");
     $this->assertEquals("path", $event->getPath());
 }