Skip to content

Commit

Permalink
Dev: Add new test for save dual scale answer options
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Nov 24, 2017
1 parent 4f57496 commit 0365a17
Show file tree
Hide file tree
Showing 2 changed files with 521 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/controllers/SaveDualScaleAnswerOptionsTest.php
@@ -0,0 +1,93 @@
<?php

namespace ls\tests;

use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\StaleElementReferenceException;
use Facebook\WebDriver\Exception\UnknownServerException;
use Facebook\WebDriver\Exception\TimeOutException;
use Facebook\WebDriver\Exception\ElementNotVisibleException;

/**
* @since 2017-11-24
* @group dualscale
*/
class SaveDualScaleAnswerOptionsTest extends TestBaseClassWeb
{
/**
*
*/
public static function setupBeforeClass()
{
parent::setupBeforeClass();

// Permission to everything.
\Yii::app()->session['loginID'] = 1;

$username = getenv('ADMINUSERNAME');
if (!$username) {
$username = 'admin';
}

$password = getenv('PASSWORD');
if (!$password) {
$password = 'password';
}

// Permission to everything.
\Yii::app()->session['loginID'] = 1;

// Browser login.
self::adminLogin($username, $password);
}

/**
*
*/
public function testBasic()
{
// Import survey with dual scale question type.
$surveyFile = self::$surveysFolder . '/limesurvey_survey_677328.lss';
self::importSurvey($surveyFile);

// Get questions.
$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');
//http://localhost/lime25/limesurvey/index.php?r=admin/questions/sa/answeroptions/surveyid/677328/gid/195/qid/576
$url = $urlMan->createUrl(
'admin/questions',
[
'sa' => 'answeroptions',
'surveyid' => self::$surveyId,
'gid' => $survey->groups[0]->gid,
'qid' => $survey->groups[0]->questions[0]->qid
]
);

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

$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 0365a17

Please sign in to comment.