Esempio n. 1
0
 /**
  * @param int $configValue
  * @param bool|null $forceSyncMode
  * @param bool|null $customerNoteNotify
  * @param bool|null $emailSendingResult
  * @dataProvider sendDataProvider
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
 {
     $comment = 'comment_test';
     $address = 'address_test';
     $configPath = 'sales_email/general/async_sending';
     $this->creditmemoMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with($configPath)->willReturn($configValue);
     if (!$configValue || $forceSyncMode) {
         $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
         $this->addressRenderer->expects($this->any())->method('format')->with($addressMock, 'html')->willReturn($address);
         $this->orderMock->expects($this->any())->method('getBillingAddress')->willReturn($addressMock);
         $this->orderMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
         $this->creditmemoMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn($customerNoteNotify);
         $this->creditmemoMock->expects($this->any())->method('getCustomerNote')->willReturn($comment);
         $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'creditmemo' => $this->creditmemoMock, 'comment' => $customerNoteNotify ? $comment : '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $address, 'formattedBillingAddress' => $address]);
         $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn($emailSendingResult);
         if ($emailSendingResult) {
             $this->senderBuilderFactoryMock->expects($this->once())->method('create')->willReturn($this->senderMock);
             $this->senderMock->expects($this->once())->method('send');
             $this->senderMock->expects($this->once())->method('sendCopyTo');
             $this->creditmemoMock->expects($this->once())->method('setEmailSent')->with(true);
             $this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, ['send_email', 'email_sent']);
             $this->assertTrue($this->sender->send($this->creditmemoMock));
         } else {
             $this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
             $this->assertFalse($this->sender->send($this->creditmemoMock));
         }
     } else {
         $this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
         $this->assertFalse($this->sender->send($this->creditmemoMock));
     }
 }
Esempio n. 2
0
 /**
  * @param int $configValue
  * @param array|null $collectionItems
  * @param bool|null $emailSendingResult
  * @dataProvider executeDataProvider
  * @return void
  */
 public function testExecute($configValue, $collectionItems, $emailSendingResult)
 {
     $path = 'sales_email/general/async_sending';
     $this->globalConfig->expects($this->once())->method('getValue')->with($path)->willReturn($configValue);
     if ($configValue) {
         $this->entityCollection->expects($this->at(0))->method('addFieldToFilter')->with('send_email', ['eq' => 1]);
         $this->entityCollection->expects($this->at(1))->method('addFieldToFilter')->with('email_sent', ['null' => true]);
         $this->entityCollection->expects($this->any())->method('getItems')->willReturn($collectionItems);
         if ($collectionItems) {
             /** @var \Magento\Sales\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject $collectionItem */
             $collectionItem = $collectionItems[0];
             $this->emailSender->expects($this->once())->method('send')->with($collectionItem, true)->willReturn($emailSendingResult);
             if ($emailSendingResult) {
                 $collectionItem->expects($this->once())->method('setEmailSent')->with(true)->willReturn($collectionItem);
                 $this->entityResource->expects($this->once())->method('save')->with($collectionItem);
             }
         }
     }
     $this->object->execute();
 }
Esempio n. 3
0
 /**
  * @param bool $isVirtualOrder
  * @param int $formatCallCount
  * @param string|null $expectedShippingAddress
  * @dataProvider sendVirtualOrderDataProvider
  */
 public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
 {
     $billingAddress = 'address_test';
     $this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
     $this->creditmemoMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with('sales_email/general/async_sending')->willReturn(false);
     $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
     $this->addressRenderer->expects($this->exactly($formatCallCount))->method('format')->with($addressMock, 'html')->willReturn($billingAddress);
     $this->stepAddressFormat($addressMock, $isVirtualOrder);
     $this->creditmemoMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn(true);
     $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'creditmemo' => $this->creditmemoMock, 'comment' => '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $expectedShippingAddress, 'formattedBillingAddress' => $billingAddress]);
     $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn(false);
     $this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
     $this->assertFalse($this->sender->send($this->creditmemoMock));
 }