| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * it under the terms of the GNU Lesser General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * GNU Lesser General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * You should have received a copy of the GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * PHP version 5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @category  Payone | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package   Payone_Magento2_Plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @author    FATCHIP GmbH <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @copyright 2003 - 2017 Payone GmbH | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @link      http://www.payone.de | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | namespace Payone\Core\Test\Unit\Model\Api\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Magento\Sales\Model\Order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Payone\Core\Helper\Database; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use Payone\Core\Model\Api\Request\Debit as ClassToTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use Payone\Core\Model\Methods\PayoneMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use Magento\Payment\Model\Info; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use Payone\Core\Helper\Api; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use Magento\Sales\Model\Order\Creditmemo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use Magento\Sales\Model\Order\Invoice; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use Payone\Core\Helper\Toolkit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use Payone\Core\Helper\Shop; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | class DebitTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @var ClassToTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     private $classToTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var Api|\PHPUnit_Framework_MockObject_MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     private $apiHelper; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     protected function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $objectManager = new ObjectManager($this); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $databaseHelper->method('getSequenceNumber')->willReturn('0'); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $toolkitHelper->method('handleSubstituteReplacement')->willReturn('test text'); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $shopHelper->method('getConfigParam')->willReturn('test'); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $this->classToTest = $objectManager->getObject(ClassToTest::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             'databaseHelper' => $databaseHelper, | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             'apiHelper' => $this->apiHelper, | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             'toolkitHelper' => $toolkitHelper, | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             'shopHelper' => $shopHelper | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function testSendRequest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $invoice = $this->getMockBuilder(Invoice::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $invoice->method('getIncrementId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $invoice->method('getId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $creditmemo = $this->getMockBuilder(Creditmemo::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $creditmemo->method('getInvoice')->willReturn($invoice); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $creditmemo->method('getIncrementId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $payment = $this->getMockBuilder(PayoneMethod::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ->setMethods(['getOperationMode', 'getCreditmemo']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $payment->method('getOperationMode')->willReturn('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $payment->method('getCreditmemo')->willReturn($creditmemo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $order = $this->getMockBuilder(Order::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ->setMethods(['getRealOrderId', 'getOrderCurrencyCode', 'getIncrementId', 'getId', 'getCustomerId']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $order->method('getRealOrderId')->willReturn('54321'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $order->method('getOrderCurrencyCode')->willReturn('EUR'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $order->method('getIncrementId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $order->method('getId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $order->method('getCustomerId')->willReturn('12345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $paymentInfo = $this->getMockBuilder(Info::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             ->setMethods(['getOrder', 'getParentTransactionId']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $paymentInfo->method('getOrder')->willReturn($order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $paymentInfo->method('getParentTransactionId')->willReturn('12-345'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $response = ['status' => 'VALID']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->apiHelper->method('sendApiRequest')->willReturn($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $result = $this->classToTest->sendRequest($payment, $paymentInfo, 100); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $this->assertEquals($response, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  |