Skip to content

Commit

Permalink
Small improvements in email lib + test #35
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Feb 3, 2016
1 parent 732e251 commit a8a9e14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 3 additions & 5 deletions application/libraries/Auto_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public function cronCheck($timeOffset = 0) {
$this->checkAccuracyOneWeek($emailsMeasureSent);
$this->startANewMeasure($emailsWatchSent);

if(ENVIRONMENT === "development"){
if(ENVIRONMENT === "development" ||
ENVIRONMENT === "testing"){
$date = new DateTime("@".$this->time);
echo "<h1> Emails sent at " . $date->format('Y-m-d H:i:s') . "</h1>";

Expand Down Expand Up @@ -587,10 +588,6 @@ private function checkAccuracy(&$queuedEmail) {

if ($measureWithoutAccuracy !== FALSE) {

if(!is_array($measureWithoutAccuracy)){
$measureWithoutAccuracy = array($measureWithoutAccuracy);
}

$measureWithoutAccuracy = $this->CI->__->groupBy($measureWithoutAccuracy, 'email');

foreach ($measureWithoutAccuracy as $user) {
Expand Down Expand Up @@ -786,6 +783,7 @@ private function resetPassword($email, $token) {
*
* @param Measure $measure
* @return Base64String A googe reminder (.ics) as a Base64String.
* @codeCoverageIgnore
*/
private function createGoogleEvent($measure){

Expand Down
16 changes: 14 additions & 2 deletions application/tests/libraries/Auto_email_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function setUpBeforeClass() {

$emailBatch = new MY_Model("email_batch");
$emailBatch->delete_where(array("id >=" => "0"));
$emailBatch->insert(array("time"=>0, "amount"=>0));

$CI->measure->delete_where(array("id >=" => "0"));
$CI->Watch->delete_where(array("watchId >=" => "0"));
Expand Down Expand Up @@ -193,6 +192,14 @@ public function test_lostPassword(){
);
}

/**
* @expectedException Exception
*/
public function test_cronFail(){

$this->email->cronCheck(time()-60*60*60);
}

/**
* Nestor adds a watch and a baseMeasure.
* 24h later, he have reminder for the accuracyMeasure.
Expand All @@ -202,6 +209,9 @@ public function test_lostPassword(){
*/
public function test_AccuracyAndAddFirstWatch(){

$emailBatch = new MY_Model("email_batch");
$emailBatch->insert(array("time"=>0, "amount"=>0));

self::$watchId = $this->watchModel->addWatch(
self::$users['nestor']->userId,
'rolex',
Expand Down Expand Up @@ -415,6 +425,8 @@ public function test_comback(){
*/
public function test_addFirstMeasure(){

$this->watchModel->delete_where(array("watchId >=" => "0"));

$data = array(
'userId' => self::$users['nestor']->userId,
'brand' => 'rolex',
Expand All @@ -431,7 +443,7 @@ public function test_addFirstMeasure(){


$this->assertEquals(sizeof($emails['users']), 0);
$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['watches']), 1);
$this->assertEquals(sizeof($emails['measures']), 0);


Expand Down

0 comments on commit a8a9e14

Please sign in to comment.