/** * @param $host * @param $locale * * @return \Cubex\Http\Request */ public function createRequest($host, $locale = 'en') { $request = Request::createFromGlobals(); $request->server->set('SERVER_NAME', $host); $request->setLocale($locale); return $request; }
/** * Search for a list of files to process * * @return array */ protected function _processFiles() { if ($this->isCubexAvailable()) { $this->_request = $this->getCubex()->make('request'); } if ($this->_request === null) { $this->_request = Request::createFromGlobals(); } if ($this->_requestReplacements === null) { $this->_requestReplacements = [$this->_request->subDomain(), $this->_request->domain(), $this->_request->tld(), strtolower(substr($this->_request->getLocale(), 0, 2))]; } $files = []; //Search for a full replacement file $replacements = $this->_locateFiles($this->_replaceFiles, null); if ($replacements !== null) { return $replacements; } //Find prepending files $files = array_merge($files, $this->_locateFiles($this->_prependFiles)); //Include the standard file $files = array_merge($files, $this->_locateFiles($this->_standardFiles)); //Find appending files $files = array_merge($files, $this->_locateFiles($this->_appendFiles)); return $files; }
public function testAuthFacade() { $provider = new TestAuthProvider(); $authy = new AuthedUser('brooke', 1); $provider->setRetrieve($authy); $cubex = new Cubex(); $cubex->configure(new TestConfigProvider()); $cubex->processConfiguration($cubex->getConfiguration()); $cubex->instance('request', Request::createFromGlobals()); $cubex->instance('\\Cubex\\Auth\\IAuthProvider', $provider); $sm = new ServiceManager(); $sm->setCubex($cubex); $sm->boot(); Auth::setFacadeApplication($cubex); $username = '******'; $this->assertTrue(Auth::forgottenPassword($username)); $authUser = Auth::login($username, 'password'); $this->assertEquals("brooke", $authUser->getUsername()); $autho = Auth::getAuthedUser(); $this->assertEquals("brooke", $autho->getUsername()); Auth::updateAuthedUser($autho); $this->assertTrue(Auth::isLoggedIn()); $this->assertTrue(Auth::logout()); $this->assertFalse(Auth::isLoggedIn()); }
/** * @param $route * @param $expect * * @dataProvider responseProvider */ public function testResponsesWithNoLayout($route, $expect) { $controller = new TestLayoutController(); $controller->setCubex(new Cubex()); $controller->disableLayout(); $response = $controller->executeRoute(Route::create($route), Request::createFromGlobals(), HttpKernelInterface::MASTER_REQUEST, false); $this->assertEquals($expect, $response->getContent()); }
/** * @requires extension zlib */ public function testResponse() { $request = Request::createFromGlobals(); $config = new TestConfigProvider(); $cubex = new Cubex(__DIR__); $cubex->configure($config); $kernel = $this->getMock('\\Cubex\\Kernel\\CubexKernel'); $kernel->expects($this->any())->method("handle")->will($this->returnValue(new Response("Good Data"))); $kernel->setCubex($cubex); $cubex->instance('\\Cubex\\Kernel\\CubexKernel', $kernel); $cubex->handle($request, Cubex::MASTER_REQUEST, false); }
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 $response->send(); //Shutdown Cubex $app->terminate($request, $response);
/** * @dataProvider offsetPathProvider * * @param $path * @param $expect * @param int $offset * @param int $limit */ public function testOffsetPaths($path, $expect, $offset = 0, $limit = null) { $request = Request::createFromGlobals(); /** * @var \Cubex\Http\Request $request */ $request->server->set('REQUEST_URI', $path); $this->assertEquals($expect, $request->offsetPath($offset, $limit)); }
/** * @param $uri * @param $route * * @dataProvider baseRoutesProvider * * @link https://github.com/cubex/framework/issues/2 */ public function testBaseRoutes($uri, $route) { $request = Request::createFromGlobals(); $request->server->set('REQUEST_URI', $uri); $cubex = new Cubex(); $cubex->prepareCubex(); $cubex->processConfiguration($cubex->getConfiguration()); /** * @var CubexKernel|\PHPUnit_Framework_MockObject_MockObject $kernel */ $kernel = $this->getMock('\\Cubex\\Kernel\\CubexKernel', ['getRoutes', 'resp']); $kernel->expects($this->any())->method("getRoutes")->will($this->returnValue([$route => 'resp'])); $kernel->expects($this->any())->method("resp")->will($this->returnValue("respdata")); $kernel->setCubex($cubex); $resp = $kernel->handle($request, Cubex::MASTER_REQUEST, false); $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $resp); $this->assertEquals("respdata", $resp->getContent()); }
public function testCanProcess() { $kernel = new SubDomainKernelAuthTest(); $result = $kernel->handle(CubexRequest::createFromGlobals(), HttpKernelInterface::MASTER_REQUEST, false); $this->assertContains('Please Login', (string) $result); }