Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: Generate simple statistics test. (#3132)
Co-authored-by: Lapiu Dev <devgit@lapiu.biz>
- Loading branch information
1 parent
fe13636
commit 96c17cf
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,57 @@ | ||
<?php | ||
|
||
namespace ls\tests; | ||
|
||
use Yii; | ||
|
||
/** | ||
* Tests for statistics_helper::generate_simple_statistics(). | ||
*/ | ||
class GenerateSimpleStatisticsTest extends TestBaseClass | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
Yii::app()->loadHelper('admin/statistics'); | ||
Yii::app()->loadHelper('common'); | ||
|
||
parent::setUpBeforeClass(); | ||
|
||
Yii::app()->setController(new DummyController('dummyid')); | ||
|
||
// Import survey | ||
$filename = self::$surveysFolder . '/survey_simple_statistics.lsa'; | ||
self::importSurvey($filename); | ||
} | ||
|
||
public function testStatisticsForThreeQuestions() | ||
{ | ||
// Form SGQA identifiers. | ||
$allQuestions = \Question::model()->getQuestionList(self::$surveyId); | ||
$summary = createCompleteSGQA(self::$surveyId, $allQuestions, 'en'); | ||
|
||
$helper = new \statistics_helper(); | ||
$statistics = $helper->generate_simple_statistics(self::$surveyId, $summary, $summary, 1, 'html', 'DD'); | ||
|
||
$doc = new \DOMDocument(); | ||
$doc->loadHtml($statistics); | ||
|
||
$scripts = $doc->getElementsByTagName('script'); | ||
|
||
$scriptQ1 = trim($scripts->item(0)->nodeValue); | ||
$scriptQ2 = trim($scripts->item(1)->nodeValue); | ||
$scriptQ3 = trim($scripts->item(2)->nodeValue); | ||
|
||
$questionId1 = $allQuestions[0]->qid; | ||
$questionId2 = $allQuestions[1]->qid; | ||
$questionId3 = $allQuestions[2]->qid; | ||
|
||
$this->assertStringContainsString("['quid'+'" . $questionId1 . "']", $scriptQ1, 'The statistics do not contain the correct question id.'); | ||
$this->assertStringContainsString("[2,2,4,0]", $scriptQ1, 'The statistics values are not correct.'); | ||
|
||
$this->assertStringContainsString("['quid'+'" . $questionId2 . "']", $scriptQ2, 'The statistics do not contain the correct question id.'); | ||
$this->assertStringContainsString("[5,3,1,0]", $scriptQ2, 'The statistics values are not correct.'); | ||
|
||
$this->assertStringContainsString("['quid'+'" . $questionId3 . "']", $scriptQ3, 'The statistics do not contain the correct question id.'); | ||
$this->assertStringContainsString("[1,5,3,0]", $scriptQ3, 'The statistics values are not correct.'); | ||
} | ||
} |