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\Payolution\InstallmentPlan 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 InstallmentPlanTest 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
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$this->objectManager = new ObjectManager($this); |
69
|
|
|
|
70
|
|
|
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock(); |
71
|
|
|
|
72
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
73
|
|
|
$context->method('getUrlBuilder')->willReturn($this->urlBuilder); |
74
|
|
|
|
75
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, ['context' => $context]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testFormatPrice() |
79
|
|
|
{ |
80
|
|
|
$result = $this->classToTest->formatPrice(50000.95); |
81
|
|
|
$expected = '50000,95'; |
82
|
|
|
$this->assertEquals($expected, $result); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetSelectLinkText() |
86
|
|
|
{ |
87
|
|
|
$aInstallment = [ |
88
|
|
|
'currency' => 'EUR', |
89
|
|
|
'duration' => '12', |
90
|
|
|
'installment' => [ |
91
|
|
|
'1' => ['amount' => 5] |
92
|
|
|
] |
93
|
|
|
]; |
94
|
|
|
$expected = '5,00 EUR per month - 12 installments'; |
95
|
|
|
$result = $this->classToTest->getSelectLinkText($aInstallment); |
96
|
|
|
$this->assertEquals($expected, $result); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testGetPaymentInfoText() |
100
|
|
|
{ |
101
|
|
|
$aInstallment = ['currency' => 'EUR']; |
102
|
|
|
$aPayment = ['amount' => 10, 'due' => '01.01.2018']; |
103
|
|
|
$expected = '5. Installment: 10,00 EUR (due 01.01.2018)'; |
104
|
|
|
$result = $this->classToTest->getPaymentInfoText(5, $aInstallment, $aPayment); |
105
|
|
|
$this->assertEquals($expected, $result); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
public function testGetDraftDownloadLink() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$expected = 'http://testdomain.com'; |
111
|
|
|
$this->urlBuilder->method('getUrl')->willReturn($expected); |
112
|
|
|
|
113
|
|
|
$result = $this->classToTest->getDraftDownloadLink(5); |
114
|
|
|
$this->assertEquals($expected, $result); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.