コード例 #1
0
 public function testAddSalesRuleNameToOrder()
 {
     $observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getOrder'], [], '', false);
     $rule = $this->getMock('Magento\\SalesRule\\Model\\Rule', ['load', 'getName', '__wakeup'], [], '', false);
     $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCouponRuleName', 'getCouponCode', '__wakeup'], [], '', false);
     $couponCode = 'coupon code';
     $ruleId = 1;
     $observer->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $order->expects($this->once())->method('getCouponCode')->will($this->returnValue($couponCode));
     $this->couponMock->expects($this->once())->method('getRuleId')->will($this->returnValue($ruleId));
     $this->ruleFactory->expects($this->once())->method('create')->will($this->returnValue($rule));
     $rule->expects($this->once())->method('load')->with($ruleId)->will($this->returnSelf());
     $order->expects($this->once())->method('setCouponRuleName');
     $this->assertEquals($this->model, $this->model->execute($observer));
 }
コード例 #2
0
 /**
  * @param int|bool $ruleCustomerId
  * @dataProvider salesOrderAfterPlaceDataProvider
  */
 public function testSalesOrderAfterPlace($ruleCustomerId)
 {
     $observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $rule = $this->getMock('Magento\\SalesRule\\Model\\Rule', [], [], '', false);
     $ruleCustomer = $this->getMock('Magento\\SalesRule\\Model\\Rule\\Customer', ['setCustomerId', 'loadByCustomerRule', 'getId', 'setTimesUsed', 'setRuleId', 'save', '__wakeup'], [], '', false);
     $order = $this->initOrderFromEvent($observer);
     $ruleId = 1;
     $couponId = 1;
     $customerId = 1;
     $discountAmount = 10;
     $order->expects($this->once())->method('getAppliedRuleIds')->will($this->returnValue($ruleId));
     $order->expects($this->once())->method('getDiscountAmount')->will($this->returnValue($discountAmount));
     $order->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId));
     $this->ruleFactory->expects($this->once())->method('create')->will($this->returnValue($rule));
     $rule->expects($this->once())->method('getId')->will($this->returnValue($ruleId));
     $this->ruleCustomerFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCustomer));
     $ruleCustomer->expects($this->once())->method('getId')->will($this->returnValue($ruleCustomerId));
     $ruleCustomer->expects($this->any())->method('setCustomerId')->will($this->returnSelf());
     $ruleCustomer->expects($this->any())->method('setRuleId')->will($this->returnSelf());
     $this->couponMock->expects($this->any())->method('getId')->will($this->returnValue($couponId));
     $this->couponUsage->expects($this->once())->method('updateCustomerCouponTimesUsed')->with($customerId, $couponId);
     $this->assertEquals($this->model, $this->model->execute($observer));
 }