From e69745364ea483e65eac65ab2b9a55e2cc0ac82f Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Wed, 17 Jan 2018 15:27:59 +0100 Subject: [PATCH] Dev: Add test for language changer --- tests/surveys/LanguageChangerTest.php | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/surveys/LanguageChangerTest.php diff --git a/tests/surveys/LanguageChangerTest.php b/tests/surveys/LanguageChangerTest.php new file mode 100644 index 00000000000..43bab3ccfef --- /dev/null +++ b/tests/surveys/LanguageChangerTest.php @@ -0,0 +1,129 @@ +activateSurvey(self::$surveyId); + } + + /** + * + */ + public function testBasic() + { + // To make writing shorter. + $web = self::$webDriver; + $sgqa = $this->getSgqa(); + $url = $this->getSurveyUrl(); + + try { + // Open survey. + $web->get($url); + + // Change to Deutsch. + $web->changeLanguageSelect('de'); + + // Check so that we see German text. + $text = $web->findElement( + WebDriverBy::cssSelector('.question-count-text') + ); + $this->assertContains($text->getText(), 'In dieser Umfrage sind 2 Fragen enthalten.'); + + // Click next. + $web->next(); + + // Fill in first question. + $web->answerTextQuestion($sgqa, 'This is an answer'); + + // Change to English. + $web->changeLanguage('en'); + + // Go to second question group. + $web->next(); + + // Submit survey. + $web->next(); + + $query = sprintf( + 'SELECT * FROM {{survey_%d}}', + self::$surveyId + ); + $db = \Yii::app()->getDb(); + $rows = $db->createCommand($query)->queryAll(); + $this->assertCount(1, $rows); + $this->assertEquals($rows[0][$sgqa], 'This is an answer'); + + } catch (\Exception $ex) { + self::$testHelper->takeScreenshot($web, 'LanguageChangerTest'); + $this->assertFalse( + true, + 'Url: ' . $url . PHP_EOL + . 'Screenshot taken.' . PHP_EOL + . self::$testHelper->javaTrace($ex) + ); + } + + // Change language + // Check so that text is still present. + // Next and submit + // Check database values. + } + + /** + */ + protected function getSgqa() + { + // Get questions. + // TODO: Use \createFieldMap instead? + $survey = \Survey::model()->findByPk(self::$surveyId); + $questionObjects = $survey->groups[0]->questions; + $questions = []; + foreach ($questionObjects as $q) { + $questions[$q->title] = $q; + } + $subquestions = []; + foreach ($questions['q1']->subquestions as $subq) { + $subquestions[$subq->title] = $subq; + } + $sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q1']->qid; + return $sgqa; + } + + /** + * @return string + */ + protected function getSurveyUrl() + { + $urlMan = \Yii::app()->urlManager; + $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); + $url = $urlMan->createUrl( + 'survey/index', + [ + 'sid' => self::$surveyId, + 'newtest' => 'Y', + 'lang' => 'pt' + ] + ); + return $url; + } +}