Exemplo n.º 1
0
 public function testUrlPriorities()
 {
     // Our test case has setup a handler which should come before the validate login handlers.
     $request = new WebRequest();
     $request->UrlPath = "/priority-test/simple/";
     $response = Module::generateResponseForRequest($request);
     $this->assertNotInstanceOf("Rhubarb\\Crown\\Response\\RedirectResponse", $response);
 }
 public function testHandlerRedirectsToIndexPage()
 {
     HttpHeaders::clearHeaders();
     // This folder does contain an index so it should redirect.
     $this->request->UrlPath = "/nmh/SubFolder/";
     $response = Module::generateResponseForRequest($this->request);
     $headers = $response->getHeaders();
     $this->assertEquals("/nmh/SubFolder/index/", $headers["Location"]);
 }
 public function testTheLoginUrlisExcludedFromRedirect()
 {
     $_SERVER["SCRIPT_NAME"] = "/defo/not/here/login/index/";
     $request = new WebRequest();
     $context = new Context();
     $context->Request = $request;
     $request->initialise();
     $response = Module::generateResponseForRequest($request);
     $this->assertInstanceOf("\\Rhubarb\\Crown\\Response\\HtmlResponse", $response);
 }
Exemplo n.º 4
0
 public function doRequest($request)
 {
     if ($this->mockedResponse) {
         $response = $this->mockedResponse;
         $this->mockedResponse = null;
         return $response;
     }
     $_COOKIE = $request->getCookies();
     $_SERVER = $request->getServer();
     $_FILES = $this->remapFiles($request->getFiles());
     $uri = str_replace('http://localhost', '', $request->getUri());
     $_REQUEST = $this->remapRequestParameters($request->getParameters());
     if (strtoupper($request->getMethod()) == 'GET') {
         $_GET = $_REQUEST;
     } else {
         $_POST = $_REQUEST;
     }
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = $uri;
     $_SERVER['SCRIPT_URI'] = $uri;
     $_SERVER['SCRIPT_NAME'] = $uri;
     $context = new PhpContext();
     $context->SimulateNonCli = true;
     unset($context->Request);
     $request = \Rhubarb\Crown\PhpContext::createRequest();
     $response = Module::generateResponseForRequest($request);
     $headers = $response->getHeaders();
     $content = $response->getContent();
     $headers['Content-type'] = isset($headers['Content-type']) ? $headers['Content-type'] : "text/html; charset=UTF-8";
     $code = 200;
     if ($response instanceof RedirectResponse) {
         $this->redirect = $response->getUrl();
         $code = 302;
     }
     $response = new Response($content, $code, $headers);
     return $response;
 }
 public function testDisablingTrapping()
 {
     ExceptionHandler::disableExceptionTrapping();
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->UrlPath = "/test-exception/";
         $response = Module::generateResponseForRequest($request);
         $this->fail("Without exception trapping this line should not be reached.");
     } catch (RhubarbException $er) {
     }
     ExceptionHandler::setExceptionHandlerClassName('\\Rhubarb\\Crown\\Tests\\Exceptions\\Handlers\\UnitTestDisobedientExceptionHandler');
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->UrlPath = "/test-exception/";
         $response = Module::generateResponseForRequest($request);
     } catch (RhubarbException $er) {
         $this->fail("The extended exception handler should force handling of exceptions even if trapping is disabled.");
     }
     ExceptionHandler::enableExceptionTrapping();
     LayoutModule::disableLayout();
 }
Exemplo n.º 6
0
 public function testLayoutCanBeAnonymousFunction()
 {
     LayoutModule::setLayoutClassName(function () {
         return "Rhubarb\\Crown\\Tests\\Layout\\TestLayout";
     });
     $request = new WebRequest();
     $request->UrlPath = "/simple/";
     $request->IsWebRequest = true;
     $response = Module::generateResponseForRequest($request);
     $this->assertEquals("TopDon't change this content - it should match the unit test.Tail", $response->GetContent());
 }
Exemplo n.º 7
0
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * execute-http.php is the entry point for all HTTP requests for Rhubarb applications.
 * The only exceptions to this are when webserver URL rewriting goes directly to
 * a resource for performance reasons, e.g. accessing static content like images
 * and CSS files.
 */
use Rhubarb\Crown\Logging\Log;
use Rhubarb\Crown\Module;
// Change the working directory to the top level project folder.
chdir(__DIR__ . "/../../../../");
// Initiate our bootstrap script to boot all libraries required.
require_once __DIR__ . "/boot.php";
require_once __DIR__ . "/../src/Module.php";
require_once __DIR__ . "/../src/Context.php";
$request = \Rhubarb\Crown\Context::currentRequest();
try {
    // Pass control to the Module class and ask it to generate a response for the
    // incoming request.
    $response = Module::generateResponseForRequest($request);
    $response->send();
} catch (\Exception $er) {
    $context = new \Rhubarb\Crown\Context();
    if ($context->DeveloperMode) {
        Log::error($er->getMessage(), "ERROR");
        print "<pre>Exception: " . get_class($er) . "\nMessage: " . $er->getMessage() . "\nStack Trace:\n" . $er->getTraceAsString();
    }
}
Log::debug("Request Complete", "ROUTER");