Completed
Push — master ( e9e4a5...b10356 )
by Florian
14s
created

PaymentTest::testGetKlarnaStoreIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
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\Helper;
28
29
use Payone\Core\Helper\Payment;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Store\Model\StoreManagerInterface;
32
use Magento\Store\Api\Data\StoreInterface;
33
use Magento\Framework\App\Helper\Context;
34
use Magento\Store\Model\ScopeInterface;
35
use Magento\Framework\App\Config\ScopeConfigInterface;
36
use Payone\Core\Model\PayoneConfig;
37
use Payone\Core\Helper\Toolkit;
38
use Payone\Core\Test\Unit\BaseTestCase;
39
use Payone\Core\Model\Test\PayoneObjectManager;
40
41
class PaymentTest extends BaseTestCase
42
{
43
    /**
44
     * @var ObjectManager|PayoneObjectManager
45
     */
46
    private $objectManager;
47
48
    /**
49
     * @var Payment
50
     */
51
    private $payment;
52
53
    /**
54
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private $scopeConfig;
57
58
    /**
59
     * @var Toolkit
60
     */
61
    private $toolkitHelper;
62
63 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
64
    {
65
        $this->objectManager = $this->getObjectManager();
66
67
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
68
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);
69
70
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
71
        $store->method('getCode')->willReturn(null);
72
73
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
74
        $storeManager->method('getStore')->willReturn($store);
75
76
        $this->toolkitHelper = $this->objectManager->getObject(Toolkit::class);
77
78
        $this->payment = $this->objectManager->getObject(Payment::class, [
79
            'context' => $context,
80
            'storeManager' => $storeManager,
81
            'toolkitHelper' => $this->toolkitHelper
82
        ]);
83
    }
84
85
    public function testGetAvailablePaymentTypes()
86
    {
87
        $result = $this->payment->getAvailablePaymentTypes();
88
        $this->assertContains(PayoneConfig::METHOD_CREDITCARD, $result);
89
    }
90
91 View Code Duplication
    public function testGetAvailableCreditcardTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
92
    {
93
        $creditcardTypes = 'V,M';
94
        $expected = [
95
            ['id' => 'V', 'title' => 'Visa'],
96
            ['id' => 'M', 'title' => 'Mastercard']
97
        ];
98
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
            ->method('getValue')
100
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_CREDITCARD.'/types', ScopeInterface::SCOPE_STORE, null, $creditcardTypes]]);
101
102
        $result = $this->payment->getAvailableCreditcardTypes();
103
        $this->assertEquals($expected, $result);
104
    }
105
106 View Code Duplication
    public function testIsCheckCvcActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
107
    {
108
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
            ->method('getValue')
110
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_CREDITCARD.'/check_cvc', ScopeInterface::SCOPE_STORE, null, 1]]);
111
        $result = $this->payment->isCheckCvcActive();
112
        $this->assertTrue($result);
113
    }
114
115 View Code Duplication
    public function testIsMandateManagementActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
116
    {
117
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
118
            ->method('getValue')
119
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/sepa_mandate_enabled', ScopeInterface::SCOPE_STORE, null, 1]]);
120
        $result = $this->payment->isMandateManagementActive();
121
        $this->assertTrue($result);
122
    }
123
124 View Code Duplication
    public function testIsMandateManagementDownloadActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
125
    {
126
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
            ->method('getValue')
128
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/sepa_mandate_download_enabled', ScopeInterface::SCOPE_STORE, null, 1]]);
129
        $result = $this->payment->isMandateManagementDownloadActive();
130
        $this->assertTrue($result);
131
    }
132
133
    public function testGetStatusMappingByCode()
134
    {
135
        $mapping = [
136
            'key' => [
137
                'txaction' => 'appointed',
138
                'state_status' => 'processing'
139
            ]
140
        ];
141
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
142
            ->method('getValue')
143
            ->willReturnMap([['payone_general/statusmapping/'.PayoneConfig::METHOD_CREDITCARD, ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($mapping)]]);
144
        $result = $this->payment->getStatusMappingByCode(PayoneConfig::METHOD_CREDITCARD);
145
        $expected = ['appointed' => 'processing'];
146
        $this->assertEquals($expected, $result);
147
    }
148
149
    public function testGetBankaccountCheckBlockedMessage()
150
    {
151
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
            ->method('getValue')
153
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/message_response_blocked/', ScopeInterface::SCOPE_STORE, null, '']]);
154
        $result = $this->payment->getBankaccountCheckBlockedMessage();
155
        $expected = 'Bankdata invalid.';
156
        $this->assertEquals($expected, $result);
157
    }
158
159 View Code Duplication
    public function testIsPayPalExpressActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
160
    {
161
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
162
            ->method('getValue')
163
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_PAYPAL.'/express_active', ScopeInterface::SCOPE_STORE, null, 1]]);
164
        $result = $this->payment->isPayPalExpressActive();
165
        $this->assertTrue($result);
166
    }
167
168
    public function testGetPaymentAbbreviation()
169
    {
170
        $result = $this->payment->getPaymentAbbreviation(PayoneConfig::METHOD_CREDITCARD);
171
        $expected = 'cc';
172
        $this->assertEquals($expected, $result);
173
174
        $result = $this->payment->getPaymentAbbreviation('not_existing');
175
        $expected = 'unknown';
176
        $this->assertEquals($expected, $result);
177
    }
178
179 View Code Duplication
    public function testGetKlarnaStoreIds()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
180
    {
181
        $storeIds = ['key' => ['store_id' => '123', 'countries' => ['DE', 'AT']]];
182
183
        $this->scopeConfig->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Magento\Framework...g\ScopeConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
184
            ->method('getValue')
185
            ->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_KLARNA.'/klarna_config', ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($storeIds)]]);
186
187
        $expected = ['DE' => '123', 'AT' => '123'];
188
        $result = $this->payment->getKlarnaStoreIds();
189
        $this->assertEquals($expected, $result);
190
    }
191
}
192