adding two methods to RestContext in behat
This commit is contained in:
@@ -124,6 +124,7 @@ Feature: Getting started with Behat tests
|
|||||||
And the type is "object"
|
And the type is "object"
|
||||||
And that "tri_param" is set to "PRIVATE"
|
And that "tri_param" is set to "PRIVATE"
|
||||||
And store "tri_uid" in session array
|
And store "tri_uid" in session array
|
||||||
|
And store "tri_uid" in session array as variable "trigger1"
|
||||||
|
|
||||||
Scenario: re-post a new trigger, to get an error
|
Scenario: re-post a new trigger, to get an error
|
||||||
Given that I have a valid access_token
|
Given that I have a valid access_token
|
||||||
@@ -141,7 +142,7 @@ Feature: Getting started with Behat tests
|
|||||||
Then the response status code should be 400
|
Then the response status code should be 400
|
||||||
And the content type is "application/json"
|
And the content type is "application/json"
|
||||||
And the type is "object"
|
And the type is "object"
|
||||||
#message: "Bad Request: There is a triggers with the same name in this process"
|
#message: "Bad Request: There is a previously created trigger with the same name in this process"
|
||||||
|
|
||||||
Scenario: modify a Trigger
|
Scenario: modify a Trigger
|
||||||
Given that I have a valid access_token
|
Given that I have a valid access_token
|
||||||
@@ -161,6 +162,35 @@ Feature: Getting started with Behat tests
|
|||||||
And the content type is "application/json"
|
And the content type is "application/json"
|
||||||
And the type is "object"
|
And the type is "object"
|
||||||
And that "tri_title" is set to "Trigger #1-modified"
|
And that "tri_title" is set to "Trigger #1-modified"
|
||||||
|
And that "tri_description" is set to "Trigger #1 - -modified"
|
||||||
|
And that "tri_type" is set to "script"
|
||||||
|
And that "tri_webbot" is set to "print 'hello modified world!!'; "
|
||||||
|
And that "tri_param" is set to "private"
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: get a previously created trigger
|
||||||
|
Given that I have a valid access_token
|
||||||
|
And that I want to get a resource with the key "tri_uid" stored in session array
|
||||||
|
And I request "project/14414793652a5d718b65590036026581/trigger"
|
||||||
|
Then the response status code should be 200
|
||||||
|
And the content type is "application/json"
|
||||||
|
And that "tri_title" is set to "Trigger #1-modified"
|
||||||
|
And that "tri_description" is set to "Trigger #1 - -modified"
|
||||||
|
And that "tri_type" is set to "script"
|
||||||
|
And that "tri_webbot" is set to "print 'hello modified world!!'; "
|
||||||
|
And that "tri_param" is set to "private"
|
||||||
|
|
||||||
|
Scenario: get a previously created trigger using alternative variable
|
||||||
|
Given that I have a valid access_token
|
||||||
|
And that I want to get a resource with the key "trigger1" stored in session array
|
||||||
|
And I request "project/14414793652a5d718b65590036026581/trigger"
|
||||||
|
Then the response status code should be 200
|
||||||
|
And the content type is "application/json"
|
||||||
|
And that "tri_title" is set to "Trigger #1-modified"
|
||||||
|
And that "tri_description" is set to "Trigger #1 - -modified"
|
||||||
|
And that "tri_type" is set to "script"
|
||||||
|
And that "tri_webbot" is set to "print 'hello modified world!!'; "
|
||||||
|
And that "tri_param" is set to "private"
|
||||||
|
|
||||||
Scenario: delete a previously created trigger
|
Scenario: delete a previously created trigger
|
||||||
Given that I have a valid access_token
|
Given that I have a valid access_token
|
||||||
|
|||||||
@@ -224,6 +224,26 @@ class RestContext extends BehatContext
|
|||||||
$this->_restObjectMethod = 'put';
|
$this->_restObjectMethod = 'put';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given /^that I want to get a resource with the key "([^"]*)" stored in session array$/
|
||||||
|
*/
|
||||||
|
public function thatIWantToGetAResourceWithTheKeyStoredInSessionArray($varName)
|
||||||
|
{
|
||||||
|
if (file_exists("session.data")) {
|
||||||
|
$sessionData = json_decode(file_get_contents("session.data"));
|
||||||
|
} else {
|
||||||
|
$sessionData = array();
|
||||||
|
}
|
||||||
|
if (!isset($sessionData->$varName) ) {
|
||||||
|
$varValue = '';
|
||||||
|
} else {
|
||||||
|
$varValue = $sessionData->$varName;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_restGetQueryStringSuffix = "/" . $varValue;
|
||||||
|
$this->_restObjectMethod = 'get';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Given /^that "([^"]*)" header is set to "([^"]*)"$/
|
* @Given /^that "([^"]*)" header is set to "([^"]*)"$/
|
||||||
* @Given /^that "([^"]*)" header is set to (\d+)$/
|
* @Given /^that "([^"]*)" header is set to (\d+)$/
|
||||||
@@ -331,6 +351,10 @@ class RestContext extends BehatContext
|
|||||||
$this->_response = $this->_request->send();
|
$this->_response = $this->_request->send();
|
||||||
break;
|
break;
|
||||||
case 'GET':
|
case 'GET':
|
||||||
|
if (isset($this->_restGetQueryStringSuffix) &&
|
||||||
|
$this->_restGetQueryStringSuffix != '') {
|
||||||
|
$url .= $this->_restGetQueryStringSuffix;
|
||||||
|
}
|
||||||
$this->_request = $this->_client
|
$this->_request = $this->_client
|
||||||
->get($url, $this->_headers);
|
->get($url, $this->_headers);
|
||||||
$this->_response = $this->_request->send();
|
$this->_response = $this->_request->send();
|
||||||
@@ -937,8 +961,8 @@ class RestContext extends BehatContext
|
|||||||
$this->_headers['Content-Type'] = 'application/json; charset=UTF-8';
|
$this->_headers['Content-Type'] = 'application/json; charset=UTF-8';
|
||||||
$this->_requestBody = $string;
|
$this->_requestBody = $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -975,7 +999,25 @@ class RestContext extends BehatContext
|
|||||||
$sessionData->$varName = $varValue;
|
$sessionData->$varName = $varValue;
|
||||||
file_put_contents("session.data", json_encode($sessionData));
|
file_put_contents("session.data", json_encode($sessionData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given /^store "([^"]*)" in session array as variable "([^"]*)"$/
|
||||||
|
*/
|
||||||
|
public function storeInAsVariable($varName, $sessionVarName)
|
||||||
|
{
|
||||||
|
if (!isset($this->_data->$varName)) {
|
||||||
|
throw new \Exception("JSON Response does not have '$varName' property\n\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$varValue = $this->_data->$varName;
|
||||||
|
if (file_exists("session.data")) {
|
||||||
|
$sessionData = json_decode(file_get_contents("session.data"));
|
||||||
|
} else {
|
||||||
|
$sessionData = new StdClass();
|
||||||
|
}
|
||||||
|
$sessionData->$sessionVarName = $varValue;
|
||||||
|
file_put_contents("session.data", json_encode($sessionData));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then /^echo last response$/
|
* @Then /^echo last response$/
|
||||||
@@ -984,17 +1026,17 @@ class RestContext extends BehatContext
|
|||||||
{
|
{
|
||||||
$this->printDebug("$this->_request\n$this->_response");
|
$this->printDebug("$this->_request\n$this->_response");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//*********** WEN
|
//*********** WEN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Given /^POST data from file "([^"]*)"$/
|
* @Given /^POST data from file "([^"]*)"$/
|
||||||
*/
|
*/
|
||||||
public function postDataFromFile($jsonFile)
|
public function postDataFromFile($jsonFile)
|
||||||
{
|
{
|
||||||
$filePath = __DIR__ . "/../json/" . $jsonFile;
|
$filePath = __DIR__ . "/../json/" . $jsonFile;
|
||||||
|
|
||||||
if(file_exists($filePath))
|
if(file_exists($filePath))
|
||||||
{
|
{
|
||||||
$fileData = file_get_contents($filePath);
|
$fileData = file_get_contents($filePath);
|
||||||
@@ -1006,14 +1048,14 @@ class RestContext extends BehatContext
|
|||||||
}
|
}
|
||||||
// throw new PendingException();
|
// throw new PendingException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Given /^PUT data from file "([^"]*)"$/
|
* @Given /^PUT data from file "([^"]*)"$/
|
||||||
*/
|
*/
|
||||||
public function putDataFromFile($jsonFile)
|
public function putDataFromFile($jsonFile)
|
||||||
{
|
{
|
||||||
$filePath = __DIR__ . "/../json/" . $jsonFile;
|
$filePath = __DIR__ . "/../json/" . $jsonFile;
|
||||||
|
|
||||||
if(file_exists($filePath))
|
if(file_exists($filePath))
|
||||||
{
|
{
|
||||||
$fileData = file_get_contents($filePath);
|
$fileData = file_get_contents($filePath);
|
||||||
@@ -1033,6 +1075,6 @@ class RestContext extends BehatContext
|
|||||||
{
|
{
|
||||||
throw new PendingException();
|
throw new PendingException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user