Skip to content

Commit

Permalink
Dev: Add first complete test for mandatory multiple choice with comment
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 8, 2018
1 parent 9002db2 commit 48e8024
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/LimeSurveyWebDriver.php
Expand Up @@ -84,4 +84,12 @@ public function next()
$nextButton = $this->findElement(WebDriverBy::id('ls-button-submit'));
$nextButton->click();
}

/**
* Alias for next().
*/
public function submit()
{
$this->next();
}
}
18 changes: 18 additions & 0 deletions tests/TestBaseClassWeb.php
Expand Up @@ -103,6 +103,24 @@ public static function getUrl(array $view)
return $url;
}

/**
* @return string
*/
protected function getSurveyUrl($lang = 'en')
{
$urlMan = \Yii::app()->urlManager;
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
$url = $urlMan->createUrl(
'survey/index',
[
'sid' => self::$surveyId,
'newtest' => 'Y',
'lang' => $lang
]
);
return $url;
}

/**
* @param string $userName
* @param string $password
Expand Down
52 changes: 47 additions & 5 deletions tests/questions/MultipleChoiceMandatoryWithCommentTest.php
Expand Up @@ -11,25 +11,60 @@
*/
class MultipleChoiceMandatoryWithComment extends TestBaseClassWeb
{

/**
* Test submit question without comment.
* Import and activate survey at every test.
*/
public function testNoComment()
public function setup()
{
// Import survey.
$surveyFile = self::$surveysFolder . '/limesurvey_survey_479717.lss';
self::importSurvey($surveyFile);
self::$testHelper->activateSurvey(self::$surveyId);
}

/**
* Delete test survey after every test.
*/
public function tearDown()
{
if (self::$testSurvey) {
self::$testSurvey->delete();
self::$testSurvey = null;
}
}
/**
* Test submit question without comment.
*/
public function testNoComment()
{
// To make writing shorter.
$web = self::$webDriver;

$sgqa = $this->getSgqa();
$url = $this->getSurveyUrl();
list($sgqa, $subquestions) = $this->getSgqa();
$url = $this->getSurveyUrl();
$sid = self::$testSurvey->sid;
$dbo = \Yii::app()->getDb();

try {
self::$webDriver->get($url);

// Click "First"
$label = $web->findElement(WebDriverBy::id('label-answer' . $sgqa . 'SQ001'));
$label->click();

// Submit
$web->submit();
sleep(2);

$query = "SELECT * FROM {{survey_$sid}}";
$answers = $dbo->createCommand($query)->queryAll();

$this->assertCount(1, $answers, 'Exactly one answer');
$this->assertEquals('Y', $answers[0][$sgqa . 'SQ001'], 'Checkbox is Y');
$this->assertEmpty($answers[0][$sgqa . 'SQ001comment'], 'No comment');

// Check db
} catch (\Exception $ex) {
self::$testHelper->takeScreenshot($web, 'MultipleChoiceMandatoryWithComment');
$this->assertFalse(
Expand All @@ -39,7 +74,14 @@ public function testNoComment()
. self::$testHelper->javaTrace($ex)
);
}
}

/**
* Never check the box, just write a comment. The box should check automatically.
*/
public function testOnlyComment()
{

}

/**
Expand All @@ -60,6 +102,6 @@ protected function getSgqa()
$subquestions[$subq->title] = $subq;
}
$sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q1']->qid;
return $sgqa;
return [$sgqa, $subquestions];
}
}

0 comments on commit 48e8024

Please sign in to comment.