mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-29 07:59:31 +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) {
|
function get($url) {
|
||||||
$this->lastResponse = Director::test($url, null, $this->session);
|
$this->lastResponse = Director::test($url, null, $this->session);
|
||||||
|
if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING);
|
||||||
return $this->lastResponse;
|
return $this->lastResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ class TestSession {
|
||||||
*/
|
*/
|
||||||
function post($url, $data) {
|
function post($url, $data) {
|
||||||
$this->lastResponse = Director::test($url, $data, $this->session);
|
$this->lastResponse = Director::test($url, $data, $this->session);
|
||||||
|
if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING);
|
||||||
return $this->lastResponse;
|
return $this->lastResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,20 +37,25 @@ class TestSession {
|
||||||
*/
|
*/
|
||||||
function submitForm($formID, $button = null, $data = array()) {
|
function submitForm($formID, $button = null, $data = array()) {
|
||||||
$page = $this->lastPage();
|
$page = $this->lastPage();
|
||||||
$form = $page->getFormById($formID);
|
if($page) {
|
||||||
|
$form = $page->getFormById($formID);
|
||||||
|
|
||||||
foreach($data as $k => $v) {
|
foreach($data as $k => $v) {
|
||||||
$form->setField(new SimpleByName($k), $v);
|
$form->setField(new SimpleByName($k), $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($button) $submission = $form->submitButton(new SimpleByName($button));
|
||||||
|
else $submission = $form->submit();
|
||||||
|
|
||||||
|
$url = Director::makeRelative($form->getAction()->asString());
|
||||||
|
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($button) $submission = $form->submitButton(new SimpleByName($button));
|
|
||||||
else $submission = $form->submit();
|
|
||||||
|
|
||||||
$url = Director::makeRelative($form->getAction()->asString());
|
|
||||||
|
|
||||||
$postVars = array();
|
|
||||||
parse_str($submission->_encode(), $postVars);
|
|
||||||
return $this->post($url, $postVars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,11 +106,13 @@ class TestSession {
|
||||||
require_once("thirdparty/simpletest/form.php");
|
require_once("thirdparty/simpletest/form.php");
|
||||||
|
|
||||||
$builder = &new SimplePageBuilder();
|
$builder = &new SimplePageBuilder();
|
||||||
$page = &$builder->parse(new TestSession_STResponseWrapper($this->lastResponse));
|
if($this->lastResponse) {
|
||||||
$builder->free();
|
$page = &$builder->parse(new TestSession_STResponseWrapper($this->lastResponse));
|
||||||
unset($builder);
|
$builder->free();
|
||||||
|
unset($builder);
|
||||||
|
|
||||||
return $page;
|
return $page;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user