Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #18814: Array question statistics fail for Remote Control (…
…#3191) * Dev: Remote Control export statistics tests. Tests added for surveys with one single question and with multiple questions. * Dev: Remote Control export statistics tests. Asserts added to cope with error. * Dev: Remote Control export statistics tests. Echo added to check the html string returned by export statistics. * Dev: Remote Control export statistics tests. Statistics tables are now fetched depending on the question id. * Dev: Remote Control export statistics wit array questions tests. Tests added for surveys with array questions. * Fixed issue #18814: Array question statistics fail for Remote Control. Bug fixed. * Dev: Remote Control export statistics wit array questions tests. Asserts for specific questions added. * Dev: Remote Control export statistics wit array questions tests. Undefined variable bug fixed. --------- Co-authored-by: Lapiu Dev <devgit@lapiu.biz>
- Loading branch information
1 parent
068f9ba
commit a5e20dc
Showing
3 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
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
Binary file not shown.
131 changes: 131 additions & 0 deletions
131
tests/unit/helpers/remotecontrol/ExportStatisticsArrayQuestionsTest.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,131 @@ | ||
<?php | ||
|
||
namespace ls\tests; | ||
|
||
/** | ||
* Tests for the LimeSurvey remote API. | ||
*/ | ||
class RemoteControlExportStatisticsArrayQuestionsTest extends BaseTest | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
\Yii::app()->setController(new DummyController('dummyid')); | ||
} | ||
|
||
public function testSurveyWithOneQuestion() | ||
{ | ||
// Import survey | ||
$filename = self::$surveysFolder . '/survey_statistics_three.lsa'; | ||
self::importSurvey($filename); | ||
|
||
$sessionKey = $this->handler->get_session_key($this->getUsername(), $this->getPassword()); | ||
$htmlStatistics = $this->handler->export_statistics($sessionKey, self::$surveyId, 'html'); | ||
$htmlStatistics = base64_decode($htmlStatistics); | ||
|
||
// Q00 | ||
$questionData = $this->getTableData($htmlStatistics); | ||
|
||
// Subquestion one | ||
|
||
// Option one row. | ||
$this->assertSame($questionData[0][0], 'Option one (AO01)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[0][1], '3', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[0][2], '30.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// Option two row. | ||
$this->assertSame($questionData[1][0], 'Option two (AO02)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[1][1], '4', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[1][2], '40.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// No answer row. | ||
$this->assertSame($questionData[2][0], 'No answer', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[2][1], '0', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[2][2], '0.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// Not completed row. | ||
$this->assertSame($questionData[3][0], 'Not completed or Not displayed', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[3][1], '3', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[3][2], '30.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// A row is left empty. | ||
$this->assertEmpty($questionData[4], 'This row should be empty.'); | ||
|
||
// Total row. | ||
$this->assertSame($questionData[5][0], 'Total(gross)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[5][1], '10', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[5][2], '100.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
|
||
// Subquestion two | ||
|
||
// Option one row. | ||
$this->assertSame($questionData[6][0], 'Option one (AO01)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[6][1], '4', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[6][2], '40.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// Option two row. | ||
$this->assertSame($questionData[7][0], 'Option two (AO02)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[7][1], '3', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[7][2], '30.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// No answer row. | ||
$this->assertSame($questionData[8][0], 'No answer', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[8][1], '0', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[8][2], '0.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// Not completed row. | ||
$this->assertSame($questionData[9][0], 'Not completed or Not displayed', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[9][1], '3', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[9][2], '30.00%', 'The Percentage is incorrect for this option.'); | ||
|
||
// A row is left empty. | ||
$this->assertEmpty($questionData[10], 'This row should be empty.'); | ||
|
||
// Total row. | ||
$this->assertSame($questionData[11][0], 'Total(gross)', 'The Answer text is incorrect for this option.'); | ||
$this->assertSame($questionData[11][1], '10', 'The Count is incorrect for this option.'); | ||
$this->assertSame($questionData[11][2], '100.00%', 'The Percentage is incorrect for this option.'); | ||
} | ||
|
||
/** | ||
* Get the statistics data from the table with the | ||
* id specified. | ||
*/ | ||
private function getTableData($htmlStatistics) | ||
{ | ||
$options = array(); | ||
|
||
// Get the table. | ||
$doc = new \DOMDocument(); | ||
$doc->loadHtml($htmlStatistics); | ||
|
||
$tables = $doc->getElementsByTagName('table'); | ||
|
||
if ($tables === null) { | ||
return $options; | ||
} | ||
|
||
foreach ($tables as $table) { | ||
$thead = $table->getElementsByTagName('thead')->item(0); | ||
// The td tags should be identified with the opening tbody tag but it is not added by export_statistics. | ||
$table->removeChild($thead); | ||
|
||
$rows = $table->getElementsByTagName('tr'); | ||
|
||
foreach ($rows as $rowKey => $row) { | ||
$tds = $row->getElementsByTagName('td'); | ||
$option = array(); | ||
|
||
foreach ($tds as $td) { | ||
$option[] = trim($td->nodeValue); | ||
} | ||
|
||
$options[] = $option; | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
} |