/** * @return Zend_Mail * @throws Zend_Mail_Protocol_Exception */ public static function getMail(Users_Model_User $user, $subject) { $file = CommunityID_Resources::getResourcePath('reminder_mail.txt'); $emailTemplate = file_get_contents($file); $emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate); $currentUrl = Zend_OpenId::selfURL(); preg_match('#(.*)/manageusers/sendreminder#', $currentUrl, $matches); $emailTemplate = str_replace('{registrationURL}', $matches[1] . '/register/eula?token=' . $user->token, $emailTemplate); // can't use $this->_config 'cause it's a static function $configEmail = Zend_Registry::get('config')->email; switch (strtolower($configEmail->transport)) { case 'smtp': Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($configEmail->host, $configEmail->toArray())); break; case 'mock': Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock()); break; default: Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail()); } $mail = new Zend_Mail('UTF-8'); $mail->setBodyText($emailTemplate); $mail->setFrom($configEmail->supportemail); $mail->addTo($user->email); $mail->setSubject($subject); return $mail; }
public function testCreateOrder() { //Fake data $userId = '123456789'; $amount = '50'; $txnId = 'test-txn-id'; //Create user $account = new Users_Model_User(); $account->avatar = null; $account->login = '******' . date('YmdHis'); $account->email = 'autotest3' . time() . '@example.org'; $account->password = md5('password'); $account->role = Users_Model_User::ROLE_USER; $account->status = Users_Model_User::STATUS_ACTIVE; $account->id = $userId; $account->save(); $orderManager = new Payments_Model_Order_Manager(); $order = $orderManager->createOrder($userId, $amount); //Is created order $this->assertNotEmpty($order); $response = $orderManager->payOrder($order->id, $txnId, Payments_Model_Order::PAYMENT_SYSTEM_PAYPAL); //Is payed order $this->assertTrue($response); //Incorrect orderId $response = $orderManager->payOrder('123456789', $txnId, Payments_Model_Order::PAYMENT_SYSTEM_PAYPAL); $this->assertFalse($response); }
/** * @see Zend_Form::isValid() * @param $data * @return bool */ public function isValid($data) { if ($currentPassword = $this->getElement('currentPassword')) { if (!$this->_row->isEmail($data['email'])) { $currentPassword->setRequired(true); } elseif (!empty($data['password'])) { $currentPassword->setRequired(true); } } return parent::isValid($data); }
public function testGetExpirationDate() { //Create user $account = new Users_Model_User(); $account->avatar = null; $account->login = '******' . date('YmdHis'); $account->email = 'testGetExpirationDate' . time() . '@example.org'; $account->password = md5('password'); $account->role = Users_Model_User::ROLE_USER; $account->status = Users_Model_User::STATUS_ACTIVE; $account->save(); //Get subscription plan $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table(); $subscriptionManager = new Subscriptions_Model_Subscription_Manager(); //Get plan with infinite subscription $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_INFINITE); $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id); $this->assertNull($expirationDate); //Get plan with monthly subscription $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_MONTHLY); $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id); $this->assertEquals(date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 30, date("Y"))), $expirationDate); }
public function testIndexActionByUserCorrectOrder() { //Fake data $price = '50'; //Create user $account = new Users_Model_User(); $account->avatar = null; $account->login = '******' . date('YmdHis'); $account->email = 'testIndexActionByUserCorrectOrder' . time() . '@example.org'; $account->password = md5('password'); $account->role = Users_Model_User::ROLE_USER; $account->status = Users_Model_User::STATUS_ACTIVE; $account->save(); //Create order $orderManager = new Payments_Model_Order_Manager(); $order = $orderManager->createOrder($account->id, $price); //Test correct order $this->resetResponse(); $this->request->setMethod('GET')->setPost(array('orderId' => $order->id, 'callFrom' => 'view')); $this->dispatch('/payments/index/create'); $this->assertModule('payments'); $this->assertController('index'); $this->assertAction('create'); }
public function resetAction() { $users = new Users_Model_Users(); $user = $users->getUserWithToken($this->_getParam('token')); if (!$user) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Wrong Token')); $this->_redirect(''); return; } $newPassword = $user->generateRandomPassword(); $user->setClearPassword($newPassword); // reset token $user->token = Users_Model_User::generateToken(); $user->save(); $file = CommunityID_Resources::getResourcePath('passwordreset2_mail.txt'); $emailTemplate = file_get_contents($file); $emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate); $emailTemplate = str_replace('{password}', $newPassword, $emailTemplate); $this->_sendMail($user->email, $this->view->translate('Community-ID password reset'), $emailTemplate); $this->_helper->FlashMessenger->addMessage($this->view->translate('You\'ll receive your new password via E-mail')); $this->_redirect(''); }
/** * tear Down */ public function tearDown() { $this->_user->delete(); parent::tearDown(); }
/** * Save user details service * @param mixed $data */ public function saveUserDetails($data) { $user = new Users_Model_User(); /* $data['user_perms'] = serialize( array( 'roles' => array($data['role']), 'acl_resources' => $data['acl_resources'] ) ); */ unset($data['role']); unset($data['acl_resources']); if (!isset($data['user_id'])) { return $user->getDbTable()->insert($data); } else { if (empty($data['user_password'])) { unset($data['user_password']); } unset($data['user_username']); $user->getDbTable()->update($data, array('user_id = ?' => $data['user_id'])); } }
public function testCallbackActionCorrectTxnId() { //Fake data $orderType = Subscriptions_Model_Subscription::ORDER_TYPE_SUBSCRIPTION; $planId = '3'; $price = '50'; //Create user $account = new Users_Model_User(); $account->avatar = null; $account->login = '******' . date('YmdHis'); $account->email = 'testCallbackActionCorrectTxnId' . time() . '@example.org'; $account->password = md5('password'); $account->role = Users_Model_User::ROLE_USER; $account->status = Users_Model_User::STATUS_ACTIVE; $account->save(); //Create order $orderManager = new Payments_Model_Order_Manager(); $order = $orderManager->createOrder($account->id, $price); $mock = $this->getMock('Payments_Model_Order_Manager', array('checkPaypalPostParams')); $mock->expects($this->any())->method('checkPaypalPostParams')->will($this->returnValue(true)); $mock->setDbTable('Payments_Model_Order_Table'); //Create custom param $customParam = implode('-', array($orderType, $order->id)); $params = array('custom' => '111', 'subscr_id' => 111, 'mc_gross' => 0, 'txn_type' => 111, 'txn_id' => 111); $subscriptionManager = new Subscriptions_Model_Subscription_Manager(); $subscriptionManager->createPaidSubscription($account->id, $planId, $order->id); //Test incorrect custom param try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test ok. } //Test incorrect custom param $params['custom'] = '0-0'; try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test ok. } $params['custom'] = $customParam; try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test empty $amount. } $params['mc_gross'] = $price; $this->assertTrue($mock->handlePaypalRequest($params)); //Test payOrder() incorrect orderType $params['custom'] = implode('-', array('incorrect', $order->id)); try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test ok. } //Test payOrder() incorrect orderId $params['custom'] = implode('-', array('incorrect', '12345678')); try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test ok. } //Test Cancel Subscription $params['txn_type'] = 'subscr_cancel'; $params['custom'] = $customParam; $this->assertTrue($mock->handlePaypalRequest($params)); //Test Cancel Subscription incorrect orderType $params['custom'] = implode('-', array('incorrect', $order->id)); try { $mock->handlePaypalRequest($params); $this->fail('An expected exception has not been raised.'); } catch (Exception $ex) { // Test ok. } }
public function testCompleteAction() { //Save fake user to DB $account = new Users_Model_User(); $account->avatar = null; $account->login = '******' . date('YmdHis'); $account->email = 'testCompleteAction' . time() . '@example.org'; $account->password = md5('password'); $account->role = Users_Model_User::ROLE_USER; $account->status = Users_Model_User::STATUS_ACTIVE; $account->save(); //Login Zend_Auth::getInstance()->getStorage()->write($account); $subscriptionManager = new Subscriptions_Model_Subscription_Manager(); $subscriptionManager->createFreeSubscription($account->id, 1); $this->dispatch('/subscriptions/index/complete'); $this->assertModule('subscriptions'); $this->assertController('index'); $this->assertAction('complete'); $this->assertContains('Current plan', $this->getResponse()->getBody()); }