PHPDoc cleanup

This commit is contained in:
Damian Mooyman 2014-07-29 09:24:40 +12:00
parent 7bbc74e576
commit 08c58844ac
2 changed files with 187 additions and 90 deletions

View File

@ -27,14 +27,21 @@ class FunctionalTest extends SapphireTest {
* Set this to true on your sub-class to disable the use of themes in this test. * Set this to true on your sub-class to disable the use of themes in this test.
* This can be handy for functional testing of modules without having to worry about whether a user has changed * This can be handy for functional testing of modules without having to worry about whether a user has changed
* behaviour by replacing the theme. * behaviour by replacing the theme.
*
* @var bool
*/ */
protected static $disable_themes = false; protected static $disable_themes = false;
/** /**
* Set this to true on your sub-class to use the draft site by default for every test in this class. * Set this to true on your sub-class to use the draft site by default for every test in this class.
*
* @var bool
*/ */
protected static $use_draft_site = false; protected static $use_draft_site = false;
/**
* @var TestSession
*/
protected $mainSession = null; protected $mainSession = null;
/** /**
@ -48,16 +55,20 @@ class FunctionalTest extends SapphireTest {
* If this is true, then 30x Location headers will be automatically followed. * If this is true, then 30x Location headers will be automatically followed.
* If not, then you will have to manaully call $this->mainSession->followRedirection() to follow them. * If not, then you will have to manaully call $this->mainSession->followRedirection() to follow them.
* However, this will let you inspect the intermediary headers * However, this will let you inspect the intermediary headers
*
* @var bool
*/ */
protected $autoFollowRedirection = true; protected $autoFollowRedirection = true;
/** /**
* @var String * @var string
*/ */
protected $originalTheme = null; protected $originalTheme = null;
/** /**
* Returns the {@link Session} object for this test * Returns the {@link Session} object for this test
*
* @return Session
*/ */
public function session() { public function session() {
return $this->mainSession->session(); return $this->mainSession->session();
@ -102,6 +113,12 @@ class FunctionalTest extends SapphireTest {
/** /**
* Submit a get request * Submit a get request
* @uses Director::test() * @uses Director::test()
*
* @param string $url
* @param Session $session
* @param array $headers
* @param array $cookies
* @return SS_HTTPResponse
*/ */
public function get($url, $session = null, $headers = null, $cookies = null) { public function get($url, $session = null, $headers = null, $cookies = null) {
$this->cssParser = null; $this->cssParser = null;
@ -114,7 +131,15 @@ class FunctionalTest extends SapphireTest {
/** /**
* Submit a post request * Submit a post request
*
* @uses Director::test() * @uses Director::test()
* @param string $url
* @param array $data
* @param array $headers
* @param Session $session
* @param string $body
* @param array $cookies
* @return SS_HTTPResponse
*/ */
public function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) { public function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) {
$this->cssParser = null; $this->cssParser = null;
@ -139,9 +164,9 @@ class FunctionalTest extends SapphireTest {
* *
* @see http://www.simpletest.org/en/form_testing_documentation.html * @see http://www.simpletest.org/en/form_testing_documentation.html
* *
* @param String $formID HTML 'id' attribute of a form (loaded through a previous response) * @param string $formID HTML 'id' attribute of a form (loaded through a previous response)
* @param String $button HTML 'name' attribute of the button (NOT the 'id' attribute) * @param string $button HTML 'name' attribute of the button (NOT the 'id' attribute)
* @param Array $data Map of GET/POST data. * @param array $data Map of GET/POST data.
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function submitForm($formID, $button = null, $data = array()) { public function submitForm($formID, $button = null, $data = array()) {
@ -155,6 +180,8 @@ class FunctionalTest extends SapphireTest {
/** /**
* Return the most recent content * Return the most recent content
*
* @return string
*/ */
public function content() { public function content() {
return $this->mainSession->lastContent(); return $this->mainSession->lastContent();
@ -162,7 +189,7 @@ class FunctionalTest extends SapphireTest {
/** /**
* Find an attribute in a SimpleXMLElement object by name. * Find an attribute in a SimpleXMLElement object by name.
* @param SimpleXMLElement object * @param SimpleXMLElement $object
* @param string $attribute Name of attribute to find * @param string $attribute Name of attribute to find
* @return SimpleXMLElement object of the attribute * @return SimpleXMLElement object of the attribute
*/ */
@ -339,20 +366,23 @@ class FunctionalTest extends SapphireTest {
/** /**
* Return a static variable from this class. * Return a static variable from this class.
*
* @param string $varName
* @return mixed
*/ */
public function stat($varName) { public function stat($varName) {
return static::$varName; return static::$varName;
} }
/** /**
* @return Boolean * @return bool
*/ */
public static function get_disable_themes() { public static function get_disable_themes() {
return static::$disable_themes; return static::$disable_themes;
} }
/** /**
* @return Boolean * @return bool
*/ */
public static function get_use_draft_site() { public static function get_use_draft_site() {
return static::$use_draft_site; return static::$use_draft_site;

View File

@ -7,18 +7,30 @@
* @subpackage testing * @subpackage testing
*/ */
class TestSession { class TestSession {
/**
* @var Session
*/
private $session; private $session;
/**
* @var SS_HTTPResponse
*/
private $lastResponse; private $lastResponse;
/** /**
* @param Controller $controller Necessary to use the mock session * Necessary to use the mock session
* created in {@link session} in the normal controller stack, * created in {@link session} in the normal controller stack,
* e.g. to overwrite Member::currentUser() with custom login data. * e.g. to overwrite Member::currentUser() with custom login data.
*
* @var Controller
*/ */
protected $controller; protected $controller;
/** /**
* @var string $lastUrl Fake HTTP Referer Tracking, set in {@link get()} and {@link post()}. * Fake HTTP Referer Tracking, set in {@link get()} and {@link post()}.
*
* @var string
*/ */
private $lastUrl; private $lastUrl;
@ -39,7 +51,13 @@ class TestSession {
/** /**
* Submit a get request * Submit a get request
*
* @uses Director::test() * @uses Director::test()
* @param string $url
* @param Session $session
* @param array $headers
* @param array $cookies
* @return SS_HTTPResponse
*/ */
public function get($url, $session = null, $headers = null, $cookies = null) { public function get($url, $session = null, $headers = null, $cookies = null) {
$headers = (array) $headers; $headers = (array) $headers;
@ -53,7 +71,15 @@ class TestSession {
/** /**
* Submit a post request * Submit a post request
*
* @uses Director::test() * @uses Director::test()
* @param string $url
* @param array $data
* @param array $headers
* @param Session $session
* @param string $body
* @param array $cookies
* @return SS_HTTPResponse
*/ */
public function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) { public function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) {
$headers = (array) $headers; $headers = (array) $headers;
@ -79,9 +105,9 @@ class TestSession {
* *
* @see http://www.simpletest.org/en/form_testing_documentation.html * @see http://www.simpletest.org/en/form_testing_documentation.html
* *
* @param String $formID HTML 'id' attribute of a form (loaded through a previous response) * @param string $formID HTML 'id' attribute of a form (loaded through a previous response)
* @param String $button HTML 'name' attribute of the button (NOT the 'id' attribute) * @param string $button HTML 'name' attribute of the button (NOT the 'id' attribute)
* @param Array $data Map of GET/POST data. * @param array $data Map of GET/POST data.
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function submitForm($formID, $button = null, $data = array()) { public function submitForm($formID, $button = null, $data = array()) {
@ -117,6 +143,8 @@ class TestSession {
/** /**
* If the last request was a 3xx response, then follow the redirection * If the last request was a 3xx response, then follow the redirection
*
* @return SS_HTTPResponse The response given, or null if no redirect occurred
*/ */
public function followRedirection() { public function followRedirection() {
if($this->lastResponse->getHeader('Location')) { if($this->lastResponse->getHeader('Location')) {
@ -128,6 +156,8 @@ class TestSession {
/** /**
* Returns true if the last response was a 3xx redirection * Returns true if the last response was a 3xx redirection
*
* @return bool
*/ */
public function wasRedirected() { public function wasRedirected() {
$code = $this->lastResponse->getStatusCode(); $code = $this->lastResponse->getStatusCode();
@ -135,7 +165,9 @@ class TestSession {
} }
/** /**
* Get the most recent response, as an SS_HTTPResponse object * Get the most recent response
*
* @return SS_HTTPResponse
*/ */
public function lastResponse() { public function lastResponse() {
return $this->lastResponse; return $this->lastResponse;
@ -152,19 +184,27 @@ class TestSession {
/** /**
* Get the most recent response's content * Get the most recent response's content
*
* @return string
*/ */
public function lastContent() { public function lastContent() {
if(is_string($this->lastResponse)) return $this->lastResponse; if(is_string($this->lastResponse)) return $this->lastResponse;
else return $this->lastResponse->getBody(); else return $this->lastResponse->getBody();
} }
/**
* Return a CSSContentParser containing the most recent response
*
* @return CSSContentParser
*/
public function cssParser() { public function cssParser() {
return new CSSContentParser($this->lastContent()); return new CSSContentParser($this->lastContent());
} }
/** /**
* Get the last response as a SimplePage object * Get the last response as a SimplePage object
*
* @return SimplePage The response if available
*/ */
public function lastPage() { public function lastPage() {
require_once("thirdparty/simpletest/http.php"); require_once("thirdparty/simpletest/http.php");
@ -183,6 +223,8 @@ class TestSession {
/** /**
* Get the current session, as a Session object * Get the current session, as a Session object
*
* @return Session
*/ */
public function session() { public function session() {
return $this->session; return $this->session;
@ -196,36 +238,61 @@ class TestSession {
* @subpackage testing * @subpackage testing
*/ */
class TestSession_STResponseWrapper { class TestSession_STResponseWrapper {
/**
* @var SS_HTTPResponse
*/
private $response; private $response;
public function __construct(SS_HTTPResponse $response) { public function __construct(SS_HTTPResponse $response) {
$this->response = $response; $this->response = $response;
} }
/**
* @return string
*/
public function getContent() { public function getContent() {
return $this->response->getBody(); return $this->response->getBody();
} }
/**
* @return string
*/
public function getError() { public function getError() {
return ""; return "";
} }
/**
* @return null
*/
public function getSent() { public function getSent() {
return null; return null;
} }
/**
* @return string
*/
public function getHeaders() { public function getHeaders() {
return ""; return "";
} }
/**
* @return string 'GET'
*/
public function getMethod() { public function getMethod() {
return "GET"; return "GET";
} }
/**
* @return string
*/
public function getUrl() { public function getUrl() {
return ""; return "";
} }
/**
* @return null
*/
public function getRequestData() { public function getRequestData() {
return null; return null;
} }