Skip to content

Commit

Permalink
DEV: tried to write another acceptance test for ipanonymize
Browse files Browse the repository at this point in the history
  • Loading branch information
Trischi80 committed Apr 21, 2020
1 parent faf257b commit 3cf362f
Show file tree
Hide file tree
Showing 6 changed files with 2,146 additions and 5 deletions.
Expand Up @@ -28,6 +28,7 @@ public static function setUpBeforeClass()
}
// Browser login.
self::adminLogin($username, $password);

}

/**
Expand Down Expand Up @@ -72,16 +73,34 @@ public function testIpAnonymizeInActiveSurvey()
// New tab with active survey.
$nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$nextButton->click();
sleep(2);

//now check if ip was anonymized (ipv4, last digit should be 0)
//get ipadr from table survey_573837 ...
$models = \Response::model(self::$surveyId)->findAll();
/*
if(isset($models[0]->ipaddr)){
$this->assertTrue($models[0]->ipaddr==='127.0.0.0');
}
*/

$this->assertTrue((isset($models[0]->ipaddr)) && ($models[0]->ipaddr==='127.0.0.0'));

//after this deactivate survey for next test ...
// Switch to first window.
$windowHandles = self::$webDriver->getWindowHandles();
self::$webDriver->switchTo()->window(
reset($windowHandles)
);

//click button stop this survey
$stopSurveyButton = self::$webDriver->findElement(WebDriverBy::id('ls-stop-survey'));
$stopSurveyButton->click();
sleep(1);

//click to deactivate survey
$execute = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
WebDriverBy::cssSelector('input[type="submit"][value="Deactivate survey"]')
)
);
$execute->click();
sleep(2);
}

/**
Expand All @@ -90,5 +109,83 @@ public function testIpAnonymizeInActiveSurvey()
public function testNormalActiveSurvey()
{
// TODO: As above, but without ip anon and ip === 127.0.0.1
$urlMan = \Yii::app()->urlManager;
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
$url = $urlMan->createUrl(
'admin/survey/sa/view/surveyid/'.self::$surveyId
);
self::$webDriver->get($url);
sleep(1);


//set ipanonymize to off ...
$survey = \Survey::model()->findByPk(self::$surveyId);
$survey->ipanonymize = 'N';
$survey->save();

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

sleep(3);

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

sleep(3);

// Click "Execute survey".
$exceuteBtn = self::$webDriver->findById('execute_survey_button') ;
$exceuteBtn->click();

sleep(1);

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

sleep(2);

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

sleep(2);

/*
// Enter answer text. (this must be only for the second test, i don't know why?!?!
$survey = \Survey::model()->findByPk(self::$surveyId);
$questionObjects = $survey->groups[0]->questions;
$questions = [];
foreach ($questionObjects as $q) {
$questions[$q->title] = $q;
}
$sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['G01Q01']->qid;
$question = self::$webDriver->findElement(WebDriverBy::id('answer' . $sgqa));
$question->sendKeys('foo bar');
sleep(2);
// Click submit.
/*
$submitButton = self::$webDriver->wait(10)->until(
WebDriverExpectedCondition::elementToBeClickable(
WebDriverBy::cssSelector('input[type="submit"][value="movesubmit"]')
)
);
$submitButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$submitButton->click();
sleep(2); */

//now check if ip was anonymized (ipv4, last digit should be 0)
//get ipadr from table survey_573837 ...
$models = \Response::model(self::$surveyId)->findAll();

$this->assertTrue((isset($models[0]->ipaddr)) && ($models[0]->ipaddr==='127.0.0.1'));
}
}

0 comments on commit 3cf362f

Please sign in to comment.