mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-29 16:09:23 +02:00
Improved error checking in TestSession
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60425 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
655802177c
commit
a94c7c8a2f
|
@ -18,6 +18,7 @@ class TestSession {
|
|||
*/
|
||||
function get($url) {
|
||||
$this->lastResponse = Director::test($url, null, $this->session);
|
||||
if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING);
|
||||
return $this->lastResponse;
|
||||
}
|
||||
|
||||
|
@ -26,6 +27,7 @@ class TestSession {
|
|||
*/
|
||||
function post($url, $data) {
|
||||
$this->lastResponse = Director::test($url, $data, $this->session);
|
||||
if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING);
|
||||
return $this->lastResponse;
|
||||
}
|
||||
|
||||
|
@ -35,6 +37,7 @@ class TestSession {
|
|||
*/
|
||||
function submitForm($formID, $button = null, $data = array()) {
|
||||
$page = $this->lastPage();
|
||||
if($page) {
|
||||
$form = $page->getFormById($formID);
|
||||
|
||||
foreach($data as $k => $v) {
|
||||
|
@ -49,6 +52,10 @@ class TestSession {
|
|||
$postVars = array();
|
||||
parse_str($submission->_encode(), $postVars);
|
||||
return $this->post($url, $postVars);
|
||||
|
||||
} else {
|
||||
user_error("TestSession::submitForm called when there is no form loaded. Visit the page with the form first", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,12 +106,14 @@ class TestSession {
|
|||
require_once("thirdparty/simpletest/form.php");
|
||||
|
||||
$builder = &new SimplePageBuilder();
|
||||
if($this->lastResponse) {
|
||||
$page = &$builder->parse(new TestSession_STResponseWrapper($this->lastResponse));
|
||||
$builder->free();
|
||||
unset($builder);
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current session, as a Session object
|
||||
|
|
Loading…
Reference in New Issue
Block a user