Skip to content

Commit

Permalink
Dev: Add second dual-scale answer options test
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Nov 27, 2017
1 parent eee9b9b commit 50dffa4
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions tests/controllers/SaveDualScaleAnswerOptionsTest.php
Expand Up @@ -47,12 +47,26 @@ public static function setupBeforeClass()
/**
*
*/
public function testBasic()
public function setup()
{
// Import survey with dual scale question type.
$surveyFile = self::$surveysFolder . '/limesurvey_survey_677328.lss';
self::importSurvey($surveyFile);
}

/**
*
*/
public function tearDown()
{
self::$survey->delete();
}

/**
*
*/
public function testBasic()
{
// Get questions.
$survey = \Survey::model()->findByPk(self::$surveyId);
$this->assertNotEmpty($survey);
Expand All @@ -61,7 +75,6 @@ public function testBasic()

$urlMan = \Yii::app()->urlManager;
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
//http://localhost/lime25/limesurvey/index.php?r=admin/questions/sa/answeroptions/surveyid/677328/gid/195/qid/576
$url = $urlMan->createUrl(
'admin/questions',
[
Expand Down Expand Up @@ -90,4 +103,52 @@ public function testBasic()
$answers = \Answer::model()->findAllByAttributes(['qid' => $survey->groups[0]->questions[0]->qid]);
$this->assertCount(2, $answers, 'Two answer options saved');
}

/**
*
*/
public function testUsingLinkToEditAnswers()
{
$surveyFile = self::$surveysFolder . '/limesurvey_survey_677328.lss';
self::importSurvey($surveyFile);

$survey = \Survey::model()->findByPk(self::$surveyId);
$this->assertNotEmpty($survey);
$this->assertCount(1, $survey->groups, 'Wrong number of groups: ' . count($survey->groups));
$this->assertCount(1, $survey->groups[0]->questions, 'We have exactly one question');

$urlMan = \Yii::app()->urlManager;
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
$url = $urlMan->createUrl(
'admin/questions',
[
'sa' => 'view',
'surveyid' => self::$surveyId,
'gid' => $survey->groups[0]->gid,
'qid' => $survey->groups[0]->questions[0]->qid
]
);

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

$button = self::$webDriver->findElement(WebDriverBy::linkText('Edit answer options'));
$button->click();

$answer1 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_0"]'));
$answer1->sendKeys('123');

$answer2 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_1"]'));
$answer2->sendKeys('abc');

$savebutton = self::$webDriver->findElement(WebDriverBy::id('save-button'));
$savebutton->click();

$notif = self::$webDriver->findElement(WebDriverBy::id('notif-container'));
$notifText = $notif->getText();
$this->assertContains('Answer options were successfully saved', $notifText);

$answers = \Answer::model()->findAllByAttributes(['qid' => $survey->groups[0]->questions[0]->qid]);
$this->assertCount(2, $answers, 'Two answer options saved');

}
}

0 comments on commit 50dffa4

Please sign in to comment.