/** * 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 testFromModGeoIp() { $cubex = $this->newCubexInstace(); $request = new Request(); $server = ['REMOTE_ADDR' => '123.123.123.123', 'GEOIP_ADDR' => '123.123.123.123', 'GEOIP_COUNTRY_CODE' => 'US', 'GEOIP_CITY' => 'Mountain View', 'GEOIP_REGION_NAME' => 'CA']; $request->initialize([], [], [], [], [], $server); $cubex->instance('request', $request); $visitor = new Visitor($request, $cubex); $this->assertEquals('US', $visitor->getCountry()); $this->assertEquals('Mountain View', $visitor->getCity()); $this->assertEquals('CA', $visitor->getRegion()); }
/** * @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; }
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()); }
public function testResult() { $kernel = new MockEndpointKernel(); $kernel->setCubex($this->getCubex()); $result = $kernel->handle(Request::create('/result', 'GET', [])); $this->assertContains('json', $result->headers->get('content-type')); $this->assertEquals('{"status":{"code":200,"message":""},' . '"type":"\\CubexTest\\Cubex\\Kernel\\MockEndpointResult"' . ',"result":{"name":"Test"}}', stripcslashes($result->getContent())); }
/** * @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()); }
public function __construct(Request $request, Cubex $cubex) { $this->setCubex($cubex); $this->_request = $request; $this->_ip = $this->_request->getClientIp(); try { $this->_config = $cubex->getConfiguration()->getSection('http_visitor'); } catch (\Exception $e) { $this->_config = new ConfigSection('http_visitor', []); } $this->configure($this->_config); if (System::isAppEngine($request->server->get('SERVER_SOFTWARE'))) { $this->_fromAppEngine(); } else { if ($request->server->get('GEOIP_ADDR', null) !== null) { $this->_fromModGeoIP(); } } }
/** * @param $remoteAddr * @param $country * @param $city * @param $region * @param null $config * * @dataProvider visitorProvider */ public function testVisitor($remoteAddr, $country, $city, $region, $config = null) { if (!file_exists($this->_geoipdb)) { $this->markTestSkipped("GeoIP Database Not Downloaded"); return; } $cubex = $this->newCubexInstace(); $request = new Request(); $server = ['REMOTE_ADDR' => $remoteAddr]; $request->initialize([], [], [], [], [], $server); $cubex->instance('request', $request); if ($config === null) { $config = new ConfigSection('http_visitor', ['database' => $this->_geoipdb]); } $config->addItem('database', $config->getItem('database', $this->_geoipdb)); $cubex->getConfiguration()->addSection($config); $visitor = new MaxmindVisitor(); $visitor->configure($config); $visitor->setClientIp($remoteAddr); $this->assertEquals($country, $visitor->getCountry()); $this->assertEquals($city, $visitor->getCity()); $this->assertEquals($region, $visitor->getRegion()); }
/** * @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);
/** * Retrieve a response from the project * * @param $uri * @param string $method * @param array $parameters * * @return TestResponse * @throws \Exception */ public function getResponse($uri, $method = 'GET', $parameters = []) { $request = Request::create($uri, $method, $parameters); $this->setLastResponse(new TestResponse($this->getCubex()->handle($request))); return $this->getLastResponse(); }
public function _getCookieDomain(Request $request = null) { if ($request === null) { return $this->getCubex()->getConfiguration()->getItem('auth', 'cookie_domain'); } return $request->urlSprintf($this->getCubex()->getConfiguration()->getItem('auth', 'cookie_domain_format', "%d.%t")); }
public function testXForwardedFor() { //http://en.wikipedia.org/wiki/X-Forwarded-For#Format $request = new Request(); //8.8.8.8 = client IP //4.4.4.4 = proxy1 $server = ['HTTP_X_FORWARDED_FOR' => '8.8.8.8, 4.4.4.4', 'REMOTE_ADDR' => '8.8.4.4']; $request->initialize([], [], [], [], [], $server); $request->setTrustedProxies(['8.8.4.4']); $this->assertEquals('8.8.8.8', $request->getClientIp()); }
/** * @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); }