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\Controller\Mandate; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Controller\Payolution\DraftDownload as ClassToTest; |
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
31
|
|
|
use Magento\Checkout\Model\Session; |
32
|
|
|
use Payone\Core\Helper\Payment; |
33
|
|
|
use Magento\Framework\Controller\Result\RawFactory; |
34
|
|
|
use Magento\Framework\Controller\Result\Raw; |
35
|
|
|
use Magento\Framework\App\RequestInterface; |
36
|
|
|
use Magento\Framework\App\Action\Context; |
37
|
|
|
use Magento\Framework\HTTP\Client\Curl; |
38
|
|
|
|
39
|
|
|
class DraftDownloadTest extends \PHPUnit_Framework_TestCase |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var ClassToTest |
43
|
|
|
*/ |
44
|
|
|
private $classToTest; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ObjectManager |
48
|
|
|
*/ |
49
|
|
|
private $objectManager; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Payment|\PHPUnit_Framework_MockObject_MockObject |
53
|
|
|
*/ |
54
|
|
|
private $paymentHelper; |
55
|
|
|
|
56
|
|
|
protected function setUp() |
57
|
|
|
{ |
58
|
|
|
$this->objectManager = new ObjectManager($this); |
59
|
|
|
|
60
|
|
|
$aLinks = ['5' => 'http://drafturl.com']; |
61
|
|
|
|
62
|
|
|
$checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->setMethods(['getInstallmentDraftLinks'])->getMock(); |
63
|
|
|
$checkoutSession->method('getInstallmentDraftLinks')->willReturn($aLinks); |
64
|
|
|
|
65
|
|
|
$this->paymentHelper = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock(); |
66
|
|
|
|
67
|
|
|
$rawResponse = $this->getMockBuilder(Raw::class)->disableOriginalConstructor()->getMock(); |
68
|
|
|
$resultRawFactory = $this->getMockBuilder(RawFactory::class) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->setMethods(['create']) |
71
|
|
|
->getMock(); |
72
|
|
|
$resultRawFactory->method('create')->willReturn($rawResponse); |
73
|
|
|
|
74
|
|
|
$request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock(); |
75
|
|
|
$request->method('getParam')->willReturn('5'); |
76
|
|
|
|
77
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
78
|
|
|
$context->method('getRequest')->willReturn($request); |
79
|
|
|
|
80
|
|
|
$curl = $this->getMockBuilder(Curl::class)->disableOriginalConstructor()->getMock(); |
81
|
|
|
$curl->method('getBody')->willReturn('Pdf Data'); |
82
|
|
|
|
83
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
84
|
|
|
'context' => $context, |
85
|
|
|
'checkoutSession' => $checkoutSession, |
86
|
|
|
'paymentHelper' => $this->paymentHelper, |
87
|
|
|
'resultRawFactory' => $resultRawFactory, |
88
|
|
|
'curl' => $curl |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testExecute() |
93
|
|
|
{ |
94
|
|
|
$this->paymentHelper->method('getConfigParam')->willReturn('value'); |
95
|
|
|
|
96
|
|
|
$result = $this->classToTest->execute(); |
97
|
|
|
$this->assertInstanceOf(Raw::class, $result); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testExecuteNoDraft() |
101
|
|
|
{ |
102
|
|
|
$this->paymentHelper->method('getConfigParam')->willReturn(false); |
103
|
|
|
|
104
|
|
|
$result = $this->classToTest->execute(); |
105
|
|
|
$this->assertInstanceOf(Raw::class, $result); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|