forked from LimeSurvey/LimeSurvey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nubisware/master
Dev: remote control export_responses_by_token test added
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
60 changes: 60 additions & 0 deletions
60
tests/unit/helpers/remotecontrol/RemoteControlExportResponsesByTokenTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace ls\tests; | ||
|
||
/** | ||
* Tests for the LimeSurvey remote API. | ||
*/ | ||
class RemoteControlExportResponsesByTokenTest extends BaseTest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $username = null; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected static $password = null; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
// Import survey | ||
$filename = self::$surveysFolder . '/survey_export_responses_by_token_955579.lsa'; | ||
self::importSurvey($filename); | ||
} | ||
|
||
/** | ||
* Export responses by token 'token2'. | ||
*/ | ||
public function testExportResponsesByToken2() | ||
{ | ||
$sessionKey = $this->handler->get_session_key($this->getUsername(), $this->getPassword()); | ||
|
||
$result = $this->handler->export_responses_by_token($sessionKey, self::$surveyId, 'json', 'token2'); | ||
$this->assertNotNull($result); | ||
|
||
$responses = json_decode(file_get_contents($result->fileName), true); | ||
$this->assertTrue(count($responses['responses']) === 1, 'One response exported was expected.'); | ||
$this->assertTrue($responses['responses'][0]['token'] === 'token2', 'Response with token2 was expected'); | ||
} | ||
|
||
/** | ||
* Export responses by token array ('token1', 'token2'). | ||
*/ | ||
public function testExportResponsesByTokensArray() | ||
{ | ||
$sessionKey = $this->handler->get_session_key($this->getUsername(), $this->getPassword()); | ||
|
||
$result = $this->handler->export_responses_by_token($sessionKey, self::$surveyId, 'json', array('token1', 'token2')); | ||
$this->assertNotNull($result); | ||
|
||
$responses = json_decode(file_get_contents($result->fileName), true); | ||
$nrresponses = count($responses['responses']); | ||
$this->assertTrue($nrresponses === 2, 'Two responses should have been exported. Found: ' . $nrresponses); | ||
$this->assertTrue($responses['responses'][0]['token'] === 'token1', 'Response with token1 was expected'); | ||
$this->assertTrue($responses['responses'][1]['token'] === 'token2', 'Response with token2 was expected'); | ||
} | ||
} |