public function testBasicSetHttpRequest() { $r = new RwHttpRequest(); $o = new vsc(); $o->setHttpRequest($r); $this->assertSame($r, $o->getHttpRequest()); }
public function testGetCurrentModuleMapWithoutAMap() { $o = new vsc(); try { $o->getCurrentModuleMap(); } catch (\Exception $e) { $this->assertInstanceOf(ExceptionSitemap::class, $e); } }
/** * @param HttpRequestA $oRequest * @return \vsc\domain\models\ModelA * @throws \vsc\presentation\responses\ExceptionResponseError */ public function handleRequest(HttpRequestA $oRequest) { if (!$oRequest->isGet() && !RawHttpRequest::isValid($oRequest)) { $oRequest = new RawHttpRequest(); vsc::getEnv()->setHttpRequest($oRequest); } switch ($oRequest->getHttpMethod()) { case HttpRequestTypes::GET: $oModel = $this->handleGet($oRequest); break; case HttpRequestTypes::HEAD: $oModel = $this->handleHead($oRequest); break; case HttpRequestTypes::POST: $oModel = $this->handlePost($oRequest); break; case HttpRequestTypes::PUT: $oModel = $this->handlePut($oRequest); break; case HttpRequestTypes::DELETE: $oModel = $this->handleDelete($oRequest); break; default: throw new ExceptionResponseError('Method [' . $oRequest->getHttpMethod() . '] is unavailable.', HttpResponseType::METHOD_NOT_ALLOWED); } return $oModel; }
public function testBasicGetResponse() { $o = new ContentTypeController(); $p = new EmptyProcessor(); $r = $o->getResponse(vsc::getEnv()->getHttpRequest(), $p); $this->assertNull($r); }
public function testGetResponseWithCacheableModelThatIsNewer() { $now = new \DateTime('now'); $yesterday = clone $now; $yesterday->sub(new \DateInterval('P1D')); $r = $this->getMockBuilder(RawHttpRequest::class)->disableOriginalConstructor()->getMock(); vsc::getEnv()->setHttpRequest($r); $r->method('getIfModifiedSince')->willReturn($yesterday->format('r')); /** @var ProcessorA $p */ $p = $this->getMockBuilder(ProcessorA::class)->disableOriginalConstructor()->getMock(); $m = $this->getMockBuilder(CacheableModelA::class)->setMethods(['getLastModified'])->disableOriginalConstructor()->getMock(); $m->method('getLastModified')->willReturn($now->format('r')); $v = $this->getMockBuilder(CacheableViewA::class)->setMethods(['getModel', 'getLastModified', 'getMTime', 'display', 'append', 'assign'])->disableOriginalConstructor()->getMock(); $v->expects($this->any())->method('getModel')->willReturn($m); $Controller = new CacheableController_underTest_getResponse(); $Map = new ControllerMap('.', CacheableController_underTest_getResponse::class); $Controller->setView($v); $Controller->setMap($Map); $inTwoWeeks = $now->add(new \DateInterval('P2W')); $response = $Controller->getResponse($r, $p); $expires = new \DateTime($response->getExpires()); $this->assertInstanceOf(HttpResponseA::class, $response); $this->assertEquals($inTwoWeeks->getTimestamp(), $expires->getTimestamp(), '', 2); $this->assertEquals(HttpResponseType::OK, $response->getStatus()); }
/** * @returns HttpRequestA */ public function getRequest() { if (!HttpRequestA::isValid($this->oRequest)) { $this->oRequest = vsc::getEnv()->getHttpRequest(); } return $this->oRequest; }
public function testBasicGetRequest() { $o = new RwDispatcher(); $oRequest = $o->getRequest(); $oBlaReq = vsc::getEnv()->getHttpRequest(); $this->assertSame($oRequest, $oBlaReq); }
public function handleRequest(HttpRequestA $oHttpRequest) { $o404 = vsc::getEnv()->getHttpResponse(); $o404->setStatus(404); $this->getMap()->setResponse($o404); return parent::handleRequest($oHttpRequest); }
/** * @return vsc */ public static function getEnv() { if (!vsc::isValid(self::$oInstance)) { self::$oInstance = new self(); } return self::$oInstance; }
public function testBasicGetResponse() { $o = new RESTController(); $oProcessor = new RESTProcessorA_underTest_getResponse(); $r = $o->getResponse(vsc::getEnv()->getHttpRequest(), $oProcessor); $this->assertInstanceOf(HttpResponse::class, $r); }
public function testBasicHandleRequest() { date_default_timezone_set('UTC'); $o = new StaticFileProcessor(); $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(StaticFileModel::class, $oModel); }
public function testBasicDebugOutput() { $value = 'test'; $_SERVER['PHP_SELF'] = 'phpunit'; ob_start(); $this->assertContains($value, vsc::d($value)); }
public function __get($sVarName) { $sVal = vsc::getEnv()->getHttpRequest()->getVar($sVarName); if (is_null($sVal) && vsc::getEnv()->isDevelopment()) { $sVal = '<span style="font-size:0.8em">[' . $sVarName . ' does not exist in the request]</span>'; } return $sVal; }
public function test__setNotDev() { $null = new Object_underTest___set(); $env = new vsc_underTest___set(); $env->setIsDevelopment(false); vsc::setInstance($env); $this->assertNull($null->__set(uniqid('test'), uniqid('val:'))); }
public function testBasicHandleRequest() { $o = new EmptyProcessor(); $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(EmptyModel::class, $oModel); $this->assertEquals('[ null ]', $oModel->getPageTitle()); $this->assertEquals('[ NULL ]', $oModel->getPageContent()); }
public function testBasicSetPath() { $o = new StaticFileProcessor(); $o->setFilePath(__FILE__); $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(StaticFileModel::class, $oModel); $this->assertEquals(__FILE__, $oModel->getFilePath()); }
public function testBasicHandleRequest() { $o = new NotFoundProcessor(); $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(ErrorModel::class, $oModel); $this->assertInstanceOf(ExceptionResponseError::class, $oModel->getException()); $this->assertEquals(HttpResponseType::NOT_FOUND, $oModel->getException()->getErrorCode()); }
public function test__callStaticNotDev() { $env = new vsc_underTest___callStatic(); $env->setIsDevelopment(false); vsc::setInstance($env); $this->assertInstanceOf(Base::class, Object_underTest___callStatic::__callStatic('test', array())); $this->assertInstanceOf(Base::class, Object_underTest___callStatic::testCall('test')); }
public function testGetPlainResponse() { $Controller = new FrontControllerA_underTest_getResponse(); $Map = new ControllerMap('.', FrontControllerA_underTest_getResponse::class); $Controller->setMap($Map); $Response = $Controller->getResponse(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(HttpResponseA::class, $Response); }
public function testUseless() { $_SERVER['CONTENT_TYPE'] = 'application/json'; $req = new RawHttpRequest_underTest_init(); vsc::getEnv()->setHttpRequest($req); $o = new RPCProcessorA_underTest_init(); $this->assertNull($o->init()); $this->assertEquals(1, $o->getResponse()->id); }
public function testEmptyJsonRequestInitialization() { vsc::getEnv()->setHttpRequest(new RawHttpRequest_underTest___construct()); $_SERVER['CONTENT_TYPE'] = 'application/json'; $o = new JsonRPCRequest(); $this->assertEmpty($o->id); $this->assertEmpty($o->method); $this->assertEmpty($o->params); }
public function testGetProcessorController() { $sFixturePath = VSC_FIXTURE_PATH . 'config' . DIRECTORY_SEPARATOR; $o = new RwDispatcher(); $o->loadSiteMap($sFixturePath . 'map.php'); $oRequest = new PopulatedRequest(); vsc::getEnv()->setHttpRequest($oRequest); $this->assertInstanceOf(ProcessorFixture::class, $o->getProcessController()); }
public function test__getNotDev() { $null = new Object_underTest___get(); $env = new vsc_underTest___get(); $env->setIsDevelopment(false); vsc::setInstance($env); $this->assertInstanceOf(Base::class, $null->__get(uniqid('test'))); $this->assertInstanceOf(Base::class, $null->test); }
public function testSetDispatcher() { /* @var RwDispatcher $oDispatcher */ $oDispatcher = new RwDispatcher(); vsc::getEnv()->setDispatcher($oDispatcher); $oSetDispatcher = vsc::getEnv()->getDispatcher(); $this->assertInstanceOf(DispatcherA::class, $oSetDispatcher); $this->assertSame($oDispatcher, $oSetDispatcher); }
public function testBasicHandleRequest() { $e = new ExceptionResponseError('test', HttpResponseType::NO_CONTENT); $o = new ErrorProcessor($e); $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest()); $this->assertInstanceOf(ErrorModel::class, $oModel); $this->assertInstanceOf(ExceptionResponseError::class, $oModel->getException()); $this->assertEquals(HttpResponseType::NO_CONTENT, $oModel->getException()->getErrorCode()); }
public function testTemplatePath() { $sFixturePath = VSC_FIXTURE_PATH . 'config' . DIRECTORY_SEPARATOR; $o = new RwDispatcher(); $o->loadSiteMap($sFixturePath . 'map.php'); $oRequest = new PopulatedRequest(); vsc::getEnv()->setHttpRequest($oRequest); $genericTemplatePath = VSC_FIXTURE_PATH . 'templates' . DIRECTORY_SEPARATOR; $this->assertEquals($genericTemplatePath, $o->getTemplatePath()); }
/** * @param \vsc\presentation\requests\HttpRequestA $oRequest */ public function __construct($oRequest = null) { /* @var RawHttpRequest $oRequest */ if (!RawHttpRequest::isValid($oRequest)) { $oRequest = new RawHttpRequest(); vsc::getEnv()->setHttpRequest($oRequest); } $this->id = $oRequest->getVar('id'); $this->method = $oRequest->getVar('method'); $this->params = $oRequest->getVar('params'); }
public function test__getForEmptyRequests() { $_GET = []; $_POST = []; $_SERVER = []; $_SESSION = []; $_COOKIE = []; $key = 'test'; vsc::setInstance(new vsc()); $o = new RequestModel(); $this->assertEquals('<span style="font-size:0.8em">[' . $key . ' does not exist in the request]</span>', $o->__get($key)); }
public function testParentModuleMap() { vsc::getEnv()->getHttpRequest()->setUri('/'); $o = new RwDispatcher(); $this->assertTrue($o->loadSiteMap(VSC_RES_PATH . 'config/map.php')); $moduleMap = $o->getCurrentModuleMap(); $this->assertInstanceOf(MappingA::class, $moduleMap); $this->assertInstanceOf(ModuleMap::class, $moduleMap); $this->assertEquals(VSC_RES_PATH . 'templates' . DIRECTORY_SEPARATOR, $moduleMap->getTemplatePath()); $this->assertEquals(VSC_RES_PATH . 'templates' . DIRECTORY_SEPARATOR, $moduleMap->getMainTemplatePath()); $this->assertEquals('main.php', $moduleMap->getMainTemplate()); }
public function testBasicDelegateRequest() { $o = new ProcessorFixture(); $sValue = 'test'; $oHttpRequest = new PopulatedRequest(); $oNewProcessor = new ProcessorFixture(); $oNewProcessor->return = $sValue; $sMapPath = VSC_FIXTURE_PATH . 'config' . DIRECTORY_SEPARATOR . 'map.php'; vsc::getEnv()->setDispatcher(new RwDispatcher()); vsc::getEnv()->getDispatcher()->loadSiteMap($sMapPath); $this->assertEquals($sValue, $o->delegateRequest($oHttpRequest, $oNewProcessor)); }