protected function Initialise() { parent::Initialise(); $login = new ValidateLoginUrlHandler(new UnitTestingLoginProvider(), "/login/index"); $login->SetPriority(20); $this->AddUrlHandlers(["/cant/be/here" => $login]); $login = new ValidateLoginUrlHandler(new UnitTestingLoginProvider(), "/defo/not/here/login/index/", ["login/index/" => new ClassMappedUrlHandler("\\Rhubarb\\Crown\\Tests\\Fixtures\\SimpleContent")]); $login->SetPriority(20); $this->AddUrlHandlers(["/defo/not/here/" => $login]); $this->AddUrlHandlers(["/" => new ClassMappedUrlHandler("\\Rhubarb\\Crown\\Tests\\Fixtures\\SimpleContent", ["nmh/" => new NamespaceMappedUrlHandler("Rhubarb\\Crown\\Tests\\UrlHandlers\\Fixtures\\NamespaceMappedHandlerTests"), "simple/" => new ClassMappedUrlHandler("\\Rhubarb\\Crown\\Tests\\Fixtures\\SimpleContent"), "files/" => new StaticResourceUrlHandler(__DIR__ . "/UrlHandlers/Fixtures/")])]); /* $this->AddUrlHandlers( [ "/" => new NamespaceMappedUrlHandler("Rhubarb\Leaf\Presenters", [ "nmh/" => new NamespaceMappedUrlHandler("Rhubarb\Crown\Tests\NamespaceMappedHandlerTests"), "files/" => new StaticResourceUrlHandler(__DIR__ . "/UrlHandlers/Fixtures/") ]) ]); */ $this->AddUrlHandlers("/priority-test/", new ValidateLoginUrlHandler(new UnitTestingLoginProvider(), "/login/index")); $test = new NamespaceMappedUrlHandler("Rhubarb\\Leaf\\Presenters"); $test->SetPriority(100); $this->AddUrlHandlers("/priority-test/", $test); EmailProvider::setDefaultEmailProviderClassName('\\Rhubarb\\Crown\\Tests\\Fixtures\\UnitTestingEmailProvider'); }
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); }
protected function initialise() { require_once __DIR__ . '/../../unit/UrlHandlers/UrlHandlerTestUnitTest.php'; parent::initialise(); $login = new ValidateLoginUrlHandler(UnitTestingLoginProvider::singleton(), "/login/index"); $login->SetPriority(20); $this->addUrlHandlers(["/cant/be/here" => $login]); $login = new ValidateLoginUrlHandler(UnitTestingLoginProvider::singleton(), "/defo/not/here/login/index/", ["login/index/" => new ClassMappedUrlHandler(SimpleContent::class)]); $login->setPriority(20); $this->addUrlHandlers(["/defo/not/here/" => $login]); $this->addUrlHandlers([new UnitTestComputedUrlHandler()]); $this->addUrlHandlers(["/" => new ClassMappedUrlHandler(SimpleContent::class, ["nmh/" => new NamespaceMappedUrlHandler('Rhubarb\\Crown\\Tests\\Fixtures\\UrlHandlers\\NamespaceMappedHandlerTests'), "simple/" => new ClassMappedUrlHandler(SimpleContent::class), "files/" => new StaticResourceUrlHandler(__DIR__ . "/../UrlHandlers/")])]); $this->addUrlHandlers("/priority-test/", new ValidateLoginUrlHandler(UnitTestingLoginProvider::singleton(), "/login/index")); $test = new NamespaceMappedUrlHandler('Rhubarb\\Leaf\\Presenters'); $test->setPriority(100); $this->addUrlHandlers("/priority-test/", $test); EmailProvider::setProviderClassName(UnitTestingEmailProvider::class); }
/** * Executes an HTTP transaction and returns the response. * * @param HttpRequest $request * @return HttpResponse */ public function getResponse(HttpRequest $request) { $context = new Context(); $context->SimulatedRequestBody = ""; $headers = $request->getHeaders(); foreach ($headers as $header => $value) { $_SERVER["HTTP_" . strtoupper($header)] = $value; } $_SERVER["REQUEST_METHOD"] = "GET"; switch ($request->getMethod()) { case "head": $_SERVER["REQUEST_METHOD"] = "HEAD"; break; case "delete": $_SERVER["REQUEST_METHOD"] = "DELETE"; break; case "post": $_SERVER["REQUEST_METHOD"] = "POST"; $context->SimulatedRequestBody = $request->getPayload(); break; case "put": $_SERVER["REQUEST_METHOD"] = "PUT"; $context->SimulatedRequestBody = $request->getPayload(); break; } switch ($headers["Accept"]) { case "application/xml": $simulatedRequest = new JsonRequest(); break; default: $simulatedRequest = new WebRequest(); break; } $simulatedRequest->URI = $request->getUrl(); $simulatedRequest->UrlPath = $request->getUrl(); $context->Request = $simulatedRequest; $rawResponse = Module::GenerateResponseForRequest($simulatedRequest); $response = new HttpResponse(); $response->setResponseBody($rawResponse->formatContent()); return $response; }
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; }
protected function registerDependantModules() { Module::registerModule(new LayoutModule('\\Your\\WebApp\\Layouts\\DefaultLayout')); }
use Rhubarb\Crown\Module; error_reporting(E_ALL | E_STRICT); // As we preform our own exception handling we need to stop fatal errors from showing stack traces. ini_set("display_errors", "off"); // Include the composer autoloader /** @noinspection PhpIncludeInspection */ include "vendor/autoload.php"; // Initially we don't have an auto loader as this is handled by the modules. We need to load this first // module 'core' so that we have an auto loader for subsequent modules. There are also some other classes // that might be needed by this booting script so we load them aswell. include __DIR__ . "/../src/Module.php"; include __DIR__ . "/../src/Exceptions/ImplementationException.php"; include __DIR__ . "/../src/Exceptions/Handlers/ExceptionHandler.php"; // Register to handle exceptions and PHP errors. However we don't do this if we are unit testing. It's // best to let the exceptions report unhindered to phpunit. if (!isset($unitTesting) || !$unitTesting) { ExceptionHandler::EnableExceptionTrapping(); } $appName = "app"; // Is there an app environment setting? This allows the same project to serve multiple solutions // with one code base (e.g. tenant and landlord together). This is very rare in production systems, however // for the initial project phase this can be very useful. if ($envAppSetting = getenv("rhubarb_app")) { $appName .= "-" . $envAppSetting; } if (file_exists("settings/" . $appName . ".config.php")) { include "settings/" . $appName . ".config.php"; } // Now auto loaders are in place we can initialise the modules properly. Module::InitialiseModules();
protected function initialise() { parent::initialise(); SolutionSchema::registerSchema("RepositoryLog", Model\RepositoryLogSchema::class); }
protected function registerDependantModules() { Module::registerModule(new LayoutModule('\\Project\\Liberty\\Layouts\\DefaultLayout')); HashProvider::setHashProviderClassName('Rhubarb\\Crown\\Encryption\\Sha512HashProvider'); }
public function __construct() { parent::__construct(); $this->namespace = __NAMESPACE__; }
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()); }
protected function registerDependantModules() { Module::registerModule(new LayoutModule('\\Your\\WebApp\\Layouts\\DefaultLayout')); Module::registerModule(new AuthenticationWithRolesModule(CustomLoginProvider::class)); HashProvider::setHashProviderClassName('Rhubarb\\Crown\\Encryption\\Sha512HashProvider'); }
protected function RegisterDependantModules() { Module::RegisterModule(new TestModule5()); }
/** * Register a module with the application. * * Also registers the dependencies of the application also * * @param Module $module */ public final function registerModule(Module $module) { $dependencies = $module->getModules(); foreach ($dependencies as $dependency) { $this->registerModule($dependency); } $this->modules[$module->getModuleName()] = $module; }
protected function initialise() { parent::initialise(); $this->responseFilters[] = new LayoutFilter(); }
<?php // Here you can initialize variables that will be available to your tests namespace Rhubarb\Scaffolds\Communications\Tests; use Rhubarb\Crown\Module; use Rhubarb\Scaffolds\Communications\CommunicationsModule; use Rhubarb\Stem\StemModule; include __DIR__ . "/../vendor/rhubarbphp/rhubarb/platform/boot.php"; Module::registerModule(new CommunicationsModule()); Module::initialiseModules();
* 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");
/** * Register a module with the Core. * * @static * @param Module $module */ public static function registerModule(Module $module) { // We must register dependant modules first! $module->registerDependantModules(); $moduleClassName = get_class($module); // If a module has already been registered the old one should be deregistered and this // one registered in its place as it may have settings that superseed the old one. if (isset(self::$modules[$moduleClassName])) { unset(self::$modules[$moduleClassName]); } self::$modules[$moduleClassName] = $module; }