public function testGetMetadataValues() { $expectedData = (include __DIR__ . '/_files/MetaData.php'); /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleMock */ $ruleMock = $this->getMock('Magento\\SalesRule\\Model\\Rule', [], [], '', false); $this->ruleFactoryMock->expects($this->once())->method('create')->willReturn($ruleMock); $ruleMock->expects($this->once())->method('getCouponTypes')->willReturn(['key1' => 'couponType1', 'key2' => 'couponType2']); $ruleMock->expects($this->once())->method('getStoreLabels')->willReturn(['label0']); $test = $this->model->getMetadataValues($ruleMock); $this->assertEquals($expectedData, $test); }
public function testGetById() { $model = $this->getMock('\\Magento\\SalesRule\\Model\\Rule', [], [], '', false); $this->ruleFactory->expects($this->once())->method('create')->willReturn($model); $model->expects($this->once())->method('load')->with(10)->willReturnSelf(); $model->expects($this->once())->method('getId')->willReturn(10); $model->expects($this->once())->method('getStoreLabels'); $rule = $this->getMock('\\Magento\\SalesRule\\Model\\Data\\Rule', [], [], '', false); $this->toDataModelConverter->expects($this->once())->method('toDataModel')->with($model)->willReturn($rule); $this->assertEquals($rule, $this->ruleRepository->getById(10)); }
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)); }
public function testToModel() { /** * @var \Magento\SalesRule\Model\Data\Rule $dataModel */ $dataModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Data\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getData', 'getRuleId', 'getCondition', 'getActionCondition', 'getStoreLabels'])->getMock(); $dataModel->expects($this->atLeastOnce())->method('getRuleId')->willReturn(1); $dataModel->expects($this->atLeastOnce())->method('getCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getActionCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getStoreLabels')->willReturn([]); $ruleModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getId', 'getData'])->getMock(); $ruleModel->expects($this->atLeastOnce())->method('load')->willReturn($ruleModel); $ruleModel->expects($this->atLeastOnce())->method('getId')->willReturn(1); $ruleModel->expects($this->atLeastOnce())->method('getData')->willReturn(['data_1' => 1]); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->willReturn(['data_2' => 2]); $this->ruleFactory->expects($this->any())->method('create')->willReturn($ruleModel); $result = $this->model->toModel($dataModel); $this->assertEquals($ruleModel, $result); }
/** * @dataProvider expectedDatesProvider */ public function testFormattingDate($data) { /** * @var \Magento\SalesRule\Model\Data\Rule|\PHPUnit_Framework_MockObject_MockObject $dataModel */ $dataModel = $this->getMockBuilder(\Magento\SalesRule\Model\Data\Rule::class)->disableOriginalConstructor()->setMethods(['create', 'load', 'getData', 'getRuleId', 'getCondition', 'getActionCondition', 'getStoreLabels', 'getFromDate', 'setFromDate', 'getToDate', 'setToDate'])->getMock(); $dataModel->expects($this->atLeastOnce())->method('getRuleId')->willReturn(null); $dataModel->expects($this->atLeastOnce())->method('getCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getActionCondition')->willReturn(false); $dataModel->expects($this->atLeastOnce())->method('getStoreLabels')->willReturn([]); $ruleModel = $this->getMockBuilder('\\Magento\\SalesRule\\Model\\Rule')->disableOriginalConstructor()->setMethods(['create', 'load', 'getId', 'getData'])->getMock(); $ruleModel->expects($this->atLeastOnce())->method('getData')->willReturn(['data_1' => 1]); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->willReturn(['data_2' => 2]); $this->ruleFactory->expects($this->any())->method('create')->willReturn($ruleModel); $dataModel->expects($this->atLeastOnce())->method('getFromDate')->willReturn($data['from_date']); $dataModel->expects($this->atLeastOnce())->method('getToDate')->willReturn($data['to_date']); $dataModel->expects($this->atLeastOnce())->method('setFromDate')->with($data['expected_from_date']); $dataModel->expects($this->atLeastOnce())->method('setToDate')->with($data['expected_to_date']); $this->model->toModel($dataModel); }
/** * @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)); }