Skip to content

Commit

Permalink
Dev: Two more tests for mandatory multiple choice with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 8, 2018
1 parent 48e8024 commit 5eed47a
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions tests/questions/MultipleChoiceMandatoryWithCommentTest.php
Expand Up @@ -55,7 +55,6 @@ public function testNoComment()

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

$query = "SELECT * FROM {{survey_$sid}}";
$answers = $dbo->createCommand($query)->queryAll();
Expand All @@ -81,7 +80,79 @@ public function testNoComment()
*/
public function testOnlyComment()
{

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

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

$web->answerTextQuestion($sgqa . 'SQ001comment', 'some comment');

$web->submit();

$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->assertEquals('some comment', $answers[0][$sgqa . 'SQ001comment'], 'No comment');

} catch (\Exception $ex) {
self::$testHelper->takeScreenshot($web, 'MultipleChoiceMandatoryWithComment');
$this->assertFalse(
true,
'Url: ' . $url . PHP_EOL
. 'Screenshot taken.' . PHP_EOL
. self::$testHelper->javaTrace($ex)
);
}
}

/**
* Test so that the mandatory warning pops up.
*/
public function testAbuseMandatory()
{
$web = self::$webDriver;
list($sgqa, $subquestions) = $this->getSgqa();
$url = $this->getSurveyUrl();
$sid = self::$testSurvey->sid;
$dbo = \Yii::app()->getDb();

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

// Write a comment.
$web->answerTextQuestion($sgqa . 'SQ001comment', 'some comment');

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

// Check so that comment is empty.
$commentField = $web->findElement(WebDriverBy::id('answer' . $sgqa . 'SQ001comment'));
$comment = $commentField->getText();
$this->assertEmpty($comment);

$web->submit();

// Get alert box.
$modal = $web->findElement(WebDriverBy::id('bootstrap-alert-box-modal'));
$warningMessage = $modal->getText();
$this->assertNotEmpty($warningMessage, 'There is a mandatory warning message');

} catch (\Exception $ex) {
self::$testHelper->takeScreenshot($web, 'MultipleChoiceMandatoryWithComment');
$this->assertFalse(
true,
'Url: ' . $url . PHP_EOL
. 'Screenshot taken.' . PHP_EOL
. self::$testHelper->javaTrace($ex)
);
}
}

/**
Expand Down

0 comments on commit 5eed47a

Please sign in to comment.