mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
SurveyService - add method that allows to get the "start survey url" using participant's token (instead of whole participant's object)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"description": "Client of LimeSurvey API",
|
"description": "Client of LimeSurvey API",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.10",
|
"version": "0.0.11",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo",
|
"name": "Meritoo",
|
||||||
|
|||||||
@@ -189,6 +189,23 @@ class SurveyService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns url used to start survey for given survey and participant's token
|
||||||
|
*
|
||||||
|
* @param int $surveyId ID of survey to start
|
||||||
|
* @param string $participantToken Token of participant who would like to start survey
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStartSurveyUrlByToken($surveyId, $participantToken)
|
||||||
|
{
|
||||||
|
$baseUrl = $this
|
||||||
|
->client
|
||||||
|
->getConfiguration()
|
||||||
|
->getBaseUrl();
|
||||||
|
|
||||||
|
return sprintf($this->startSurveyUrlTemplate, $baseUrl, $surveyId, $participantToken);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns url used to start survey for given survey and participant
|
* Returns url used to start survey for given survey and participant
|
||||||
*
|
*
|
||||||
@@ -198,12 +215,7 @@ class SurveyService
|
|||||||
*/
|
*/
|
||||||
public function getStartSurveyUrl($surveyId, Participant $participant)
|
public function getStartSurveyUrl($surveyId, Participant $participant)
|
||||||
{
|
{
|
||||||
$baseUrl = $this
|
return $this->getStartSurveyUrlByToken($surveyId, $participant->getToken());
|
||||||
->client
|
|
||||||
->getConfiguration()
|
|
||||||
->getBaseUrl();
|
|
||||||
|
|
||||||
return sprintf($this->startSurveyUrlTemplate, $baseUrl, $surveyId, $participant->getToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -181,6 +181,22 @@ class SurveyServiceTest extends BaseTestCase
|
|||||||
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(4, true));
|
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(4, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetStartSurveyUrlByToken()
|
||||||
|
{
|
||||||
|
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||||
|
$sessionManager = $this->getSessionManager();
|
||||||
|
|
||||||
|
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||||
|
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||||
|
|
||||||
|
$surveyId = 123;
|
||||||
|
$token = uniqid();
|
||||||
|
$expectedUrl = sprintf('%s/%d?token=%s', $this->connectionBaseUrl, $surveyId, $token);
|
||||||
|
|
||||||
|
static::assertEquals($expectedUrl, $this->serviceWithoutSurveys->getStartSurveyUrlByToken($surveyId, $token));
|
||||||
|
static::assertEquals($expectedUrl, $this->serviceWithSurveys->getStartSurveyUrlByToken($surveyId, $token));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetStartSurveyUrl()
|
public function testGetStartSurveyUrl()
|
||||||
{
|
{
|
||||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user