Skip to content

Commit caf8e33

Browse files
kilipSam Tuke
authored and
Sam Tuke
committed
integrated behat smtp tests into phplist3. ref phpList#412
1 parent 5900855 commit caf8e33

File tree

10 files changed

+712
-27
lines changed

10 files changed

+712
-27
lines changed

bin/fake-sendmail.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#Fake sendmail script, adapted from:
3+
#https://github.com/mrded/MNPP/blob/ee64fb2a88efc70ba523b78e9ce61f9f1ed3b4a9/init/fake-sendmail.sh
4+
5+
#Create a temp folder to put messages in
6+
7+
SCRIPT_DIR=$(cd `dirname $0` && pwd)
8+
numPath=$(cd `dirname ${SCRIPT_DIR}` && pwd)/build/mails
9+
10+
mkdir -p ${numPath}
11+
12+
DATE=`date '+%d.%H.%M.%S'`
13+
name="${numPath}/message_${DATE}.eml"
14+
while read line
15+
do
16+
echo ${line} >> ${name}
17+
done
18+
exit 0

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"njoannidi/php-lint-bash": "dev-master",
3232
"se/selenium-server-standalone": "^2.52",
3333
"enm1989/chromedriver": "^2.36",
34-
"bex/behat-screenshot": "^1.2"
34+
"bex/behat-screenshot": "^1.2",
35+
"zbateson/mail-mime-parser": "^1.1"
3536
},
3637
"prefer-stable": true,
3738
"config": {

tests/features/bootstrap/FeatureContext.php

Lines changed: 129 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ class FeatureContext extends MinkContext
2121
private $params = array();
2222
private $data = array();
2323

24+
/**
25+
* @var mysqli
26+
*/
2427
private $db;
2528

29+
/**
30+
* Null if user is not logged in
31+
* @var string
32+
*/
33+
private $token;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $currentUser;
39+
2640
/**
2741
* Initializes context.
2842
* Every scenario gets its own context object.
@@ -157,6 +171,74 @@ public function doSomethingNotThereYet()
157171
// doSomethingWith($argument);
158172
// }
159173
//
174+
/**
175+
* @Given /^I have logged in as an administrator$/
176+
*/
177+
public function iAmAuthenticatedAsAdmin() {
178+
$this->visit('/lists/admin/');
179+
$this->fillField('login', $this->params['admin_username']);
180+
$this->fillField('password', $this->params['admin_password']);
181+
$this->pressButton('Continue');
182+
183+
if (null === $this->getSession ()->getPage ()->find ('named', array('content', 'Dashboard'))) {
184+
$this->throwExpectationException('Login failed: Dashboard link not found');
185+
}
186+
187+
// store current token
188+
$link = $this->getSession()->getPage()->findLink('dashboard');
189+
$href = $link->getAttribute('href');
190+
$this->token = substr($href,strpos($href,'tk=')+3);
191+
$this->currentUser = $this->generateCurrentUserInfo($this->params['admin_username']);
192+
}
193+
194+
/**
195+
* @param $name
196+
* @return array
197+
* @throws Exception
198+
*/
199+
private function generateCurrentUserInfo($name)
200+
{
201+
$db = $this->getMysqli();
202+
$query = sprintf(
203+
'SELECT * from %s where loginname="%s"',
204+
'phplist_admin',
205+
$name
206+
);
207+
$results = $db->query($query)->fetch_assoc();
208+
if(!isset($results['id']) ){
209+
throw new \Exception($db->error);
210+
}
211+
return $results;
212+
}
213+
/**
214+
* @return bool
215+
*/
216+
public function isLoggedIn($throwsException = false)
217+
{
218+
$retVal = $this->token != null;
219+
if(!$retVal && $throwsException){
220+
throw new \Exception('Not logged in yet');
221+
}
222+
return $retVal;
223+
}
224+
225+
/**
226+
* @return array
227+
*/
228+
public function getCurrentUser()
229+
{
230+
$this->isLoggedIn(true);
231+
return $this->currentUser;
232+
}
233+
234+
/**
235+
* @return string
236+
*/
237+
public function getToken()
238+
{
239+
$this->isLoggedIn(true);
240+
return $this->token;
241+
}
160242

161243
/**
162244
* @When /^I recreate the database$/
@@ -223,16 +305,54 @@ public function iHaveNotYetCreatedCampaigns()
223305
}
224306

225307
/**
226-
* @Given /^I have logged in as an administrator$/
308+
* @Given /^I have subscriber with email "([^"]*)"/
227309
*/
228-
public function iAmAuthenticatedAsAdmin() {
229-
$this->visit('/lists/admin/');
230-
$this->fillField('login', $this->params['admin_username']);
231-
$this->fillField('password', $this->params['admin_password']);
232-
$this->pressButton('Continue');
233-
234-
if (null === $this->getSession ()->getPage ()->find ('named', array('content', 'Dashboard'))) {
235-
$this->throwExpectationException('Login failed: Dashboard link not found');
310+
public function iHaveSubscriber($email)
311+
{
312+
$this->clickLink('S');
313+
}
314+
315+
/**
316+
* @return mysqli
317+
*/
318+
public function getMysqli()
319+
{
320+
return $this->db;
321+
}
322+
323+
/**
324+
* @var array $params
325+
* @return string
326+
*/
327+
public function generateUrl($params)
328+
{
329+
$token = $this->getToken();
330+
$params['tk'] = $token;
331+
$url = $this->getSession()->getCurrentUrl();
332+
333+
$queryPath = [];
334+
foreach($params as $name=>$value){
335+
$queryPath[] = $name.'='.$value;
236336
}
337+
$link = $url.'?'.implode('&',$queryPath);
338+
return $link;
339+
}
340+
341+
/**
342+
* @param $num
343+
* @Then /^I wait for .* (second|seconds)/
344+
*/
345+
public function iWaitForSeconds($num)
346+
{
347+
$num = (int) $num;
348+
sleep($num);
349+
}
350+
351+
/**
352+
* @Then /^I wait for the ajax response$/
353+
*/
354+
public function iWaitForTheAjaxResponse()
355+
{
356+
$this->getSession()->wait(5000, '(0 === jQuery.active)');
237357
}
238358
}

0 commit comments

Comments
 (0)