Skip to content

Commit b27e60b

Browse files
authored
Merge pull request #3 from nubisware/master
Dev: remote control export_responses_by_token test added
2 parents c3eb8eb + f6ef0dc commit b27e60b

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace ls\tests;
4+
5+
/**
6+
* Tests for the LimeSurvey remote API.
7+
*/
8+
class RemoteControlExportResponsesByTokenTest extends BaseTest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
protected static $username = null;
14+
15+
/**
16+
* @var string
17+
*/
18+
protected static $password = null;
19+
20+
public static function setUpBeforeClass(): void
21+
{
22+
parent::setUpBeforeClass();
23+
24+
// Import survey
25+
$filename = self::$surveysFolder . '/survey_export_responses_by_token_955579.lsa';
26+
self::importSurvey($filename);
27+
}
28+
29+
/**
30+
* Export responses by token 'token2'.
31+
*/
32+
public function testExportResponsesByToken2()
33+
{
34+
$sessionKey = $this->handler->get_session_key($this->getUsername(), $this->getPassword());
35+
36+
$result = $this->handler->export_responses_by_token($sessionKey, self::$surveyId, 'json', 'token2');
37+
$this->assertNotNull($result);
38+
39+
$responses = json_decode(file_get_contents($result->fileName), true);
40+
$this->assertTrue(count($responses['responses']) === 1, 'One response exported was expected.');
41+
$this->assertTrue($responses['responses'][0]['token'] === 'token2', 'Response with token2 was expected');
42+
}
43+
44+
/**
45+
* Export responses by token array ('token1', 'token2').
46+
*/
47+
public function testExportResponsesByTokensArray()
48+
{
49+
$sessionKey = $this->handler->get_session_key($this->getUsername(), $this->getPassword());
50+
51+
$result = $this->handler->export_responses_by_token($sessionKey, self::$surveyId, 'json', array('token1', 'token2'));
52+
$this->assertNotNull($result);
53+
54+
$responses = json_decode(file_get_contents($result->fileName), true);
55+
$nrresponses = count($responses['responses']);
56+
$this->assertTrue($nrresponses === 2, 'Two responses should have been exported. Found: ' . $nrresponses);
57+
$this->assertTrue($responses['responses'][0]['token'] === 'token1', 'Response with token1 was expected');
58+
$this->assertTrue($responses['responses'][1]['token'] === 'token2', 'Response with token2 was expected');
59+
}
60+
}

0 commit comments

Comments
 (0)