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\Block\Onepage; |
28
|
|
|
|
29
|
|
|
use Magento\Sales\Model\Order; |
30
|
|
|
use Payone\Core\Block\Onepage\Success as ClassToTest; |
31
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
32
|
|
|
use Magento\Checkout\Model\Session; |
33
|
|
|
use Magento\Framework\View\Element\Template\Context; |
34
|
|
|
use Magento\Framework\UrlInterface; |
35
|
|
|
use Payone\Core\Helper\Payment; |
36
|
|
|
use Magento\Framework\Event\ManagerInterface; |
37
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
38
|
|
|
|
39
|
|
|
class SuccessTest 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 UrlInterface|\PHPUnit_Framework_MockObject_MockObject |
53
|
|
|
*/ |
54
|
|
|
private $urlBuilder; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Session|\PHPUnit_Framework_MockObject_MockObject |
58
|
|
|
*/ |
59
|
|
|
private $checkoutSession; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Payment|\PHPUnit_Framework_MockObject_MockObject |
63
|
|
|
*/ |
64
|
|
|
private $paymentHelper; |
65
|
|
|
|
66
|
|
|
protected function setUp() |
67
|
|
|
{ |
68
|
|
|
$this->objectManager = new ObjectManager($this); |
69
|
|
|
|
70
|
|
|
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock(); |
71
|
|
|
|
72
|
|
|
$eventManager = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); |
73
|
|
|
|
74
|
|
|
$scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); |
75
|
|
|
$scopeConfig->method('getValue')->willReturn(true); |
76
|
|
|
|
77
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
78
|
|
|
$context->method('getUrlBuilder')->willReturn($this->urlBuilder); |
79
|
|
|
$context->method('getEventManager')->willReturn($eventManager); |
80
|
|
|
$context->method('getScopeConfig')->willReturn($scopeConfig); |
81
|
|
|
|
82
|
|
|
$this->checkoutSession = $this->getMockBuilder(Session::class) |
83
|
|
|
->disableOriginalConstructor() |
84
|
|
|
->setMethods(['getLastRealOrder', 'getPayoneInstructionNotes', 'unsPayoneInstructionNotes']) |
85
|
|
|
->getMock(); |
86
|
|
|
|
87
|
|
|
$this->paymentHelper = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock(); |
88
|
|
|
|
89
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
90
|
|
|
'context' => $context, |
91
|
|
|
'checkoutSession' => $this->checkoutSession, |
92
|
|
|
'paymentHelper' => $this->paymentHelper |
93
|
|
|
]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function testShowMandateLink() |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
$this->paymentHelper->method('isMandateManagementDownloadActive')->willReturn(true); |
|
|
|
|
99
|
|
|
|
100
|
|
|
$order = $this->getMockBuilder(Order::class) |
101
|
|
|
->disableOriginalConstructor() |
102
|
|
|
->setMethods(['getPayoneMandateId']) |
103
|
|
|
->getMock(); |
104
|
|
|
$order->method('getPayoneMandateId')->willReturn('15'); |
105
|
|
|
|
106
|
|
|
$this->checkoutSession->method('getLastRealOrder')->willReturn($order); |
107
|
|
|
|
108
|
|
|
$result = $this->classToTest->showMandateLink(); |
109
|
|
|
$this->assertTrue($result); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testShowMandateLinkFalse() |
113
|
|
|
{ |
114
|
|
|
$this->paymentHelper->method('isMandateManagementDownloadActive')->willReturn(false); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$result = $this->classToTest->showMandateLink(); |
117
|
|
|
$this->assertFalse($result); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
public function testGetMandateDownloadUrl() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$expected = 'http://testdomain.com'; |
123
|
|
|
$this->urlBuilder->method('getUrl')->willReturn($expected); |
|
|
|
|
124
|
|
|
|
125
|
|
|
$result = $this->classToTest->getMandateDownloadUrl(); |
126
|
|
|
$this->assertEquals($expected, $result); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
public function testGetInstructionNotes() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$expected = 'Instruction text'; |
132
|
|
|
$this->checkoutSession->method('getPayoneInstructionNotes')->willReturn($expected); |
133
|
|
|
|
134
|
|
|
$result = $this->classToTest->getInstructionNotes(); |
135
|
|
|
$this->assertEquals($expected, $result); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
View Code Duplication |
public function testToHtml() |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
$this->checkoutSession->method('getPayoneInstructionNotes')->willReturn('Dummy text'); |
141
|
|
|
|
142
|
|
|
$result = $this->classToTest->toHtml(); |
143
|
|
|
$expected = ''; |
144
|
|
|
$this->assertEquals($expected, $result); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testToHtmlEmpty() |
148
|
|
|
{ |
149
|
|
|
$this->paymentHelper->method('isMandateManagementDownloadActive')->willReturn(false); |
|
|
|
|
150
|
|
|
$this->checkoutSession->method('getPayoneInstructionNotes')->willReturn(null); |
151
|
|
|
|
152
|
|
|
$result = $this->classToTest->toHtml(); |
153
|
|
|
$expected = ''; |
154
|
|
|
$this->assertEquals($expected, $result); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.