Skip to content

Commit

Permalink
FIX teadDown with dataProvider 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Nov 6, 2017
1 parent 9ac538c commit 05dcbab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 113 deletions.
11 changes: 5 additions & 6 deletions tests/questions/DateTimeDefaultAnswerExpressionTest.php
Expand Up @@ -2,19 +2,18 @@

namespace ls\tests;

use PHPUnit\Framework\TestCase;

/**
* @since 2017-06-16
* @group datetimedefaultanswer
*/
class DateTimeDefaultAnswerExpressionTest extends TestBaseClass
{
public function setUp()

public static function setUpBeforeClass()
{
parent::setUp();
$fileName = $this->surveysFolder . '/limesurvey_survey_454287.lss';
$this->importSurvey($fileName);
parent::setUpBeforeClass();
$fileName = self::$surveysFolder . '/limesurvey_survey_454287.lss';
self::importSurvey($fileName);
}


Expand Down
27 changes: 2 additions & 25 deletions tests/questions/DateTimeForwardBackTest.php
Expand Up @@ -10,41 +10,18 @@
*/
class DateTimeForwardBackTest extends TestBaseClass
{
/**
* @var int
*/
public static $surveyId = null;

/**
* Import survey in tests/surveys/.
*/
public static function setUpBeforeClass()
{
parent::setUp();

parent::setUpBeforeClass();
$_POST = [];
$_SESSION = [];

\Yii::app()->session['loginID'] = 1;

$surveyFile = self::$surveysFolder.'/limesurvey_survey_917744.lss';
if (!file_exists($surveyFile)) {
die('Fatal error: found no survey file');
}

$translateLinksFields = false;
$newSurveyName = null;
$result = importSurveyFile(
$surveyFile,
$translateLinksFields,
$newSurveyName,
null
);
if ($result) {
self::$surveyId = $result['newsid'];
} else {
die('Fatal error: Could not import survey');
}
self::importSurvey($surveyFile);
}

/**
Expand Down
41 changes: 4 additions & 37 deletions tests/questions/DateTimeTest.php
Expand Up @@ -10,53 +10,20 @@
*/
class DateTimeTest extends TestBaseClass
{
/**
* @var int
*/
public static $surveyId = null;

/**
* Import survey in tests/surveys/.
*/
public function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
parent::setUpBeforeClass();

$_POST = [];
$_SESSION = [];

\Yii::app()->session['loginID'] = 1;
$surveyFile = $this->surveysFolder.'/limesurvey_survey_975622.lss';

if (!file_exists($surveyFile)) {
die('Fatal error: found no survey file');
}
$surveyFile = self::$surveysFolder.'/limesurvey_survey_975622.lss';
self::importSurvey($surveyFile);

$translateLinksFields = false;
$newSurveyName = null;
$result = importSurveyFile(
$surveyFile,
$translateLinksFields,
$newSurveyName,
null
);
if ($result) {
self::$surveyId = $result['newsid'];
} else {
die('Fatal error: Could not import survey');
}
}

/**
* Destroy what had been imported.
*/
public function tearDown()
{
parent::tearDown();
$result = \Survey::model()->deleteSurvey(self::$surveyId, true);
if (!$result) {
die('Fatal error: Could not clean up survey ' . self::$surveyId);
}
}

/**
Expand Down
56 changes: 11 additions & 45 deletions tests/questions/DateTimeValidationTest.php
Expand Up @@ -12,52 +12,18 @@
*/
class DateTimeValidationTest extends TestBaseClassWeb
{
/**
* @var int
*/
public static $surveyId = null;

/**
* Import survey in tests/surveys/.
*/
public function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
\Yii::app()->session['loginID'] = 1;

$surveyFile = $this->surveysFolder.'/limesurvey_survey_834477.lss';
if (!file_exists($surveyFile)) {
die('Fatal error: found no survey file');
}

$translateLinksFields = false;
$newSurveyName = null;
$result = importSurveyFile(
$surveyFile,
$translateLinksFields,
$newSurveyName,
null
);
if ($result) {
self::$surveyId = $result['newsid'];
} else {
die('Fatal error: Could not import survey');
}
parent::setUpBeforeClass();

$surveyFile = self::$surveysFolder.'/limesurvey_survey_834477.lss';
self::importSurvey($surveyFile);
self::$testHelper->enablePreview();
}

/**
* Destroy what had been imported.
*/
public static function teardownAfterClass()
{
$result = \Survey::model()->deleteSurvey(self::$surveyId, true);
if (!$result) {
die('Fatal error: Could not clean up survey ' . self::$surveyId);
}
}


/**
*
Expand All @@ -69,7 +35,7 @@ public function testBasic()
$domain = '';
}

$this->webDriver->get(
self::$webDriver->get(
sprintf(
'http://%s/index.php/%d?newtest=Y&lang=pt',
$domain,
Expand All @@ -78,9 +44,9 @@ public function testBasic()
);

try {
$submit = $this->webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$submit = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
} catch (NoSuchElementException $ex) {
$screenshot = $this->webDriver->takeScreenshot();
$screenshot = self::$webDriver->takeScreenshot();
file_put_contents($this->screenshotsFolder . '/tmp.png', $screenshot);
$this->assertFalse(
true,
Expand All @@ -89,23 +55,23 @@ public function testBasic()
}

$this->assertNotEmpty($submit);
$this->webDriver->wait(10, 1000)->until(
self::$webDriver->wait(10, 1000)->until(
WebDriverExpectedCondition::visibilityOf($submit)
);
$submit->click();

// After submit we should see the complete page.
try {
// Wait max 10 second to find this div.
$this->webDriver->wait(10)->until(
self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
WebDriverBy::className('completed-text')
)
);
$div = $this->webDriver->findElement(WebDriverBy::className('completed-text'));
$div = self::$webDriver->findElement(WebDriverBy::className('completed-text'));
$this->assertNotEmpty($div);
} catch (NoSuchElementException $ex) {
$screenshot = $this->webDriver->takeScreenshot();
$screenshot = self::$webDriver->takeScreenshot();
file_put_contents($this->screenshotsFolder . '/tmp.png', $screenshot);
$this->assertFalse(
true,
Expand Down

0 comments on commit 05dcbab

Please sign in to comment.