예제 #1
0
 public function testBasicSetHttpRequest()
 {
     $r = new RwHttpRequest();
     $o = new vsc();
     $o->setHttpRequest($r);
     $this->assertSame($r, $o->getHttpRequest());
 }
예제 #2
0
 public function testGetCurrentModuleMapWithoutAMap()
 {
     $o = new vsc();
     try {
         $o->getCurrentModuleMap();
     } catch (\Exception $e) {
         $this->assertInstanceOf(ExceptionSitemap::class, $e);
     }
 }
예제 #3
0
 /**
  * @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;
 }
예제 #4
0
 public function testBasicGetResponse()
 {
     $o = new ContentTypeController();
     $p = new EmptyProcessor();
     $r = $o->getResponse(vsc::getEnv()->getHttpRequest(), $p);
     $this->assertNull($r);
 }
예제 #5
0
 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());
 }
예제 #6
0
 /**
  * @returns HttpRequestA
  */
 public function getRequest()
 {
     if (!HttpRequestA::isValid($this->oRequest)) {
         $this->oRequest = vsc::getEnv()->getHttpRequest();
     }
     return $this->oRequest;
 }
예제 #7
0
 public function testBasicGetRequest()
 {
     $o = new RwDispatcher();
     $oRequest = $o->getRequest();
     $oBlaReq = vsc::getEnv()->getHttpRequest();
     $this->assertSame($oRequest, $oBlaReq);
 }
예제 #8
0
 public function handleRequest(HttpRequestA $oHttpRequest)
 {
     $o404 = vsc::getEnv()->getHttpResponse();
     $o404->setStatus(404);
     $this->getMap()->setResponse($o404);
     return parent::handleRequest($oHttpRequest);
 }
예제 #9
0
파일: vsc.php 프로젝트: bogdananton/vsc
 /**
  * @return vsc
  */
 public static function getEnv()
 {
     if (!vsc::isValid(self::$oInstance)) {
         self::$oInstance = new self();
     }
     return self::$oInstance;
 }
예제 #10
0
 public function testBasicGetResponse()
 {
     $o = new RESTController();
     $oProcessor = new RESTProcessorA_underTest_getResponse();
     $r = $o->getResponse(vsc::getEnv()->getHttpRequest(), $oProcessor);
     $this->assertInstanceOf(HttpResponse::class, $r);
 }
예제 #11
0
 public function testBasicHandleRequest()
 {
     date_default_timezone_set('UTC');
     $o = new StaticFileProcessor();
     $oModel = $o->handleRequest(vsc::getEnv()->getHttpRequest());
     $this->assertInstanceOf(StaticFileModel::class, $oModel);
 }
예제 #12
0
파일: dTest.php 프로젝트: bogdananton/vsc
 public function testBasicDebugOutput()
 {
     $value = 'test';
     $_SERVER['PHP_SELF'] = 'phpunit';
     ob_start();
     $this->assertContains($value, vsc::d($value));
 }
예제 #13
0
 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;
 }
예제 #14
0
 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:')));
 }
예제 #15
0
 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());
 }
예제 #16
0
 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());
 }
예제 #17
0
 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());
 }
예제 #18
0
 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'));
 }
예제 #19
0
 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);
 }
예제 #20
0
 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);
 }
예제 #21
0
 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);
 }
예제 #22
0
 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());
 }
예제 #23
0
 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);
 }
예제 #24
0
 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);
 }
예제 #25
0
 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());
 }
예제 #26
0
 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());
 }
예제 #27
0
 /**
  * @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');
 }
예제 #28
0
 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));
 }
예제 #29
0
파일: mapTest.php 프로젝트: bogdananton/vsc
 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());
 }
예제 #30
0
 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));
 }