Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Jan 11, 2018
1 parent 896712c commit 8b814bc
Showing 1 changed file with 4 additions and 50 deletions.
54 changes: 4 additions & 50 deletions tests/acceptance/admin/CreateSurveyTest.php
Expand Up @@ -31,7 +31,7 @@
class CreateSurveyTest extends TestBaseClassWeb
{
/**
*
*
*/
public static function setupBeforeClass()
{
Expand All @@ -40,26 +40,22 @@ public static function setupBeforeClass()
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 static function teardownAfterClass()
{
parent::tearDownAfterClass();

// Delete survey.
$criteria = new \CDbCriteria;
$criteria->compare('correct_relation_defaultlanguage.surveyls_title', 'test survey 1', true, 'AND');
Expand All @@ -83,9 +79,7 @@ public function testCreateSurvey()
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
$url = $urlMan->createUrl('admin');
self::$webDriver->get($url);

sleep(1);

// Ignore welcome modal.
try {
$button = self::$webDriver->wait(1)->until(
Expand All @@ -99,9 +93,7 @@ public function testCreateSurvey()
} catch (TimeOutException $ex) {
// Do nothing.
}

sleep(1);

// Ignore password warning.
try {
$button = self::$webDriver->wait(1)->until(
Expand All @@ -115,38 +107,28 @@ public function testCreateSurvey()
} catch (NoSuchElementException $ex) {
// Do nothing.
}


sleep(1);

// Click on big "Create survey" button.
$link = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
WebDriverBy::cssSelector('#panel-1 .panel-body-link a')
)
);
$link->click();

// Fill in title.
$title = self::$webDriver->findElement(WebDriverBy::id('surveyls_title'));
$title->clear()->sendKeys('test survey 1');

// Click save.
$save = self::$webDriver->findElement(WebDriverBy::id('save-form-button'));
$save->click();

sleep(1);

// Remove notification.
$save = self::$webDriver->findElement(WebDriverBy::cssSelector('button.close.limebutton'));
$save->click();

sleep(1);

// Go to structure sidebar
$selectStructureSidebar = self::$webDriver->findElement(WebDriverBy::id('adminpanel__sidebar--selectorStructureButton'));
$selectStructureSidebar->click();


// Click "Add group".
$addgroup = self::$webDriver->wait(10)->until(
Expand All @@ -155,77 +137,59 @@ public function testCreateSurvey()
)
);
$addgroup->click();

// Fill in group title.
$groupname = self::$webDriver->findElement(WebDriverBy::id('group_name_en'));
$groupname->clear()->sendKeys('group1');

sleep(1);

// Click save and add question.
$save = self::$webDriver->findElement(WebDriverBy::id('save-and-new-question-button'));
$save->click();
sleep(3);

// Add question title.
$groupname = self::$webDriver->findElement(WebDriverBy::id('title'));
$groupname->clear()->sendKeys('question1');

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

sleep(1);

$selectSettingsSidebar = self::$webDriver->findElement(WebDriverBy::id('adminpanel__sidebar--selectorSettingsButton'));
$selectSettingsSidebar->click();

// Click "Overview".
$overview = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
WebDriverBy::id('sidemenu_1_1')
)
);
$overview->click();

sleep(1);

// Click "Activate survey".
$overview = self::$webDriver->findElement(WebDriverBy::id('ls-activate-survey'));
$overview->click();

// Confirm.
$overview = self::$webDriver->findElement(WebDriverBy::id('activateSurvey__basicSettings--proceed'));
$overview->click();

// Click "Overview".
$overview = self::$webDriver->findElement(WebDriverBy::id('sidemenu_1_1'));
$overview->click();

sleep(1);

// Click "Execute survey".
$execute = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
WebDriverBy::linkText('Execute survey')
)
);
$execute->click();

sleep(1);

// Switch to new tab.
$windowHandles = self::$webDriver->getWindowHandles();
self::$webDriver->switchTo()->window(
end($windowHandles)
);

sleep(1);

// New tab with active survey.
$nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$nextButton->click();

// Get questions.
$dbo = \Yii::app()->getDb();
$query = 'SELECT sid FROM {{surveys}} ORDER BY datecreated DESC LIMIT 1';
Expand All @@ -242,26 +206,21 @@ public function testCreateSurvey()
}
$this->assertCount(1, $questions, 'We have exactly one question');
$this->assertTrue(isset($questions['question1']), json_encode(array_keys($questions)));

// Enter answer text.
$sgqa = $sid . 'X' . $survey->groups[0]->gid . 'X' . $questions['question1']->qid;
$question = self::$webDriver->findElement(WebDriverBy::id('answer' . $sgqa));
$question->sendKeys('foo bar');

sleep(1);

// Click submit.
$submitButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$submitButton->click();

// Check so that we see end page.
$completed = self::$webDriver->findElement(WebDriverBy::cssSelector('div.completed-text'));
$this->assertEquals(
$completed->getText(),
"Thank you!\nYour survey responses have been recorded.",
'I can see completed text'
);

// Check so that response is recorded in database.
$query = sprintf(
'SELECT * FROM {{survey_%d}}',
Expand All @@ -270,13 +229,11 @@ public function testCreateSurvey()
$result = $dbo->createCommand($query)->queryAll();
$this->assertCount(1, $result, 'Exactly one response');
$this->assertEquals('foo bar', $result[0][$sgqa], '"foo bar" response');

// Switch to first window.
$windowHandles = self::$webDriver->getWindowHandles();
self::$webDriver->switchTo()->window(
reset($windowHandles)
);

// Delete survey.
$execute = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
Expand All @@ -296,14 +253,11 @@ public function testCreateSurvey()
)
);
$execute->click();

sleep(1);

// Make sure the survey can't be found.
$query = 'SELECT sid FROM {{surveys}} WHERE sid = ' . $sid;
$sids = $dbo->createCommand($query)->queryAll();
$this->assertCount(0, $sids);

} catch (NoSuchElementException $ex) {
// TODO :Duplicated code.
self::$testHelper->takeScreenshot(self::$webDriver, __CLASS__ . '_' . __FUNCTION__);
Expand Down Expand Up @@ -337,4 +291,4 @@ public function testCreateSurvey()
);
}
}
}
}

0 comments on commit 8b814bc

Please sign in to comment.