silverstripe-framework/tests/FakeController.php

32 lines
757 B
PHP
Raw Normal View History

<?php
use SilverStripe\Core\Injector\Injector;
2016-09-09 08:43:05 +02:00
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Controller;
// Fake a current controller. Way harder than it should be
class FakeController extends Controller {
2014-08-15 08:53:05 +02:00
public function __construct() {
parent::__construct();
$session = Injector::inst()->create('SilverStripe\\Control\\Session', isset($_SESSION) ? $_SESSION : array());
$this->setSession($session);
2014-08-15 08:53:05 +02:00
$this->pushCurrent();
2016-09-09 08:43:05 +02:00
$request = new HTTPRequest(
2014-08-15 08:53:05 +02:00
(isset($_SERVER['X-HTTP-Method-Override']))
? $_SERVER['X-HTTP-Method-Override']
: $_SERVER['REQUEST_METHOD'],
'/'
);
$this->setRequest($request);
2016-09-09 08:43:05 +02:00
$this->setResponse(new HTTPResponse());
2014-08-15 08:53:05 +02:00
$this->doInit();
}
}