/**
  * Setup TestCase
  */
 public function setUp()
 {
     parent::setUp();
     $this->_fixture = array('login' => 'admin' . time(), 'email' => '*****@*****.**', 'role' => Users_Model_User::ROLE_ADMIN, 'status' => Users_Model_User::STATUS_ACTIVE, 'password' => '123456');
     $manager = new Users_Model_User_Table();
     $this->_user = $manager->createRow($this->_fixture);
     $this->_user->save();
 }
示例#2
0
 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);
 }
示例#3
0
 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);
 }
示例#4
0
 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 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.
     }
 }
示例#6
0
 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());
 }
 private function _increaseReminderCount(Users_Model_User $user)
 {
     $user->reminders++;
     $user->save();
 }