/
IpAddressAnonymizeTest.php
94 lines (77 loc) · 2.56 KB
/
IpAddressAnonymizeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace ls\tests;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
class IpAddressAnonymizeTest extends TestBaseClassWeb
{
/**
* Import survey in tests/surveys/.
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$surveyFile = self::$surveysFolder . '/limesurvey_survey_573837.lss';
self::importSurvey($surveyFile);
/* Login */
$username = getenv('ADMINUSERNAME');
if (!$username) {
$username = 'admin';
}
$password = getenv('PASSWORD');
if (!$password) {
$password = 'password';
}
// Browser login.
self::adminLogin($username, $password);
}
/**
* Test IP anonymization.
*/
public function testIpAnonymizeInActiveSurvey()
{
$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);
// Click "Activate survey".
$overview = self::$webDriver->findElement(WebDriverBy::id('ls-activate-survey'));
$overview->click();
sleep(1);
// Confirm.
$overview = self::$webDriver->findElement(WebDriverBy::id('activateSurvey__basicSettings--proceed'));
$overview->click();
sleep(1);
// 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(1);
// New tab with active survey.
$nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit'));
$nextButton->click();
//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'));
}
/**
* Test so that previous behaviour is still working.
*/
public function testNormalActiveSurvey()
{
// TODO: As above, but without ip anon and ip === 127.0.0.1
}
}