Ejemplo n.º 1
0
 public function testShouldSendEmail()
 {
     if (!$this->_testsEnabled) {
         return;
     }
     $pwless = new Garp_Auth_Adapter_Passwordless();
     $pwless->requestToken(array('email' => self::TEST_EMAIL));
     $userModel = new Model_User();
     $theUser = $userModel->fetchRow();
     $authModel = new Model_AuthPasswordless();
     $authRecord = $authModel->fetchRow();
     $tokenUrl = new Garp_Util_FullUrl(array(array('method' => 'passwordless'), 'auth_submit')) . '?uid=' . $theUser->id . '&token=' . $authRecord->token;
     $storedMessage = file_get_contents(GARP_APPLICATION_PATH . '/../tests/tmp/' . self::TEST_EMAIL . '.tmp');
     $expectedMessage = Garp_Util_String::interpolate($this->_getMockEmailMessage(), array('LOGIN_URL' => $tokenUrl));
     // Pass thru actual Mime part, otherwise the two wil never be the same
     $mp = new Zend_Mime_Part($expectedMessage);
     $mp->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
     $mp->type = Zend_Mime::TYPE_TEXT;
     $mp->disposition = Zend_Mime::DISPOSITION_INLINE;
     $mp->charset = 'iso-8859-1';
     // Just check for the token url. Message is encoded so checking for entire message to be
     // correct is overly complex (and not the responsibility of this unit test).
     $this->assertTrue(strpos($storedMessage, $mp->getContent("\r\n")) !== false);
 }
Ejemplo n.º 2
0
 protected function _createOrUpdateAuthRecord($userId)
 {
     $token = $this->_getToken();
     $authPwlessModel = new Model_AuthPasswordless();
     $select = $authPwlessModel->select()->where('user_id = ?', $userId);
     if ($authRecord = $authPwlessModel->fetchRow($select)) {
         $authPwlessModel->update(array('token' => $token, 'token_expiration_date' => $this->_getExpirationDate(), 'claimed' => 0), 'id = ' . $authRecord->id);
         return $token;
     }
     $authPwlessModel->insert(array('user_id' => $userId, 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate()));
     return $token;
 }