Issues (547)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Test/Unit/Helper/CustomerTest.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Customer;
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\Framework\App\Config\ScopeConfigInterface;
35
use Magento\Checkout\Model\Session;
36
use Magento\Customer\Api\Data\CustomerInterface;
37
use Magento\Quote\Model\Quote;
38
use Magento\Sales\Model\Order\Address;
39
use Magento\Directory\Model\RegionFactory;
40
use Magento\Directory\Model\Region;
41
use Payone\Core\Test\Unit\BaseTestCase;
42
use Payone\Core\Model\Test\PayoneObjectManager;
43
44
class CustomerTest extends BaseTestCase
45
{
46
    /**
47
     * @var ObjectManager|PayoneObjectManager
48
     */
49
    private $objectManager;
50
51
    /**
52
     * @var Customer
53
     */
54
    private $customer;
55
56
    /**
57
     * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $scopeConfig;
60
61
    /**
62
     * @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject
63
     */
64
    private $coreCustomer;
65
66
    /**
67
     * @var Region|\PHPUnit_Framework_MockObject_MockObject
68
     */
69
    private $region;
70
71
    protected function setUp()
72
    {
73
        $this->objectManager = $this->getObjectManager();
74
75
        $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
76
        $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);
77
78
        $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
79
        $store->method('getCode')->willReturn(null);
80
81
        $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
82
        $storeManager->method('getStore')->willReturn($store);
83
84
        $this->coreCustomer = $this->getMockBuilder(CustomerInterface::class)->disableOriginalConstructor()->getMock();
85
86
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
87
        $quote->method('getCustomer')->willReturn($this->coreCustomer);
88
89
        $checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
90
        $checkoutSession->method('getQuote')->willReturn($quote);
91
92
        $this->region = $this->getMockBuilder(Region::class)
93
            ->disableOriginalConstructor()
94
            ->setMethods(['getId', 'getCode', 'loadByName', 'loadByCode'])
95
            ->getMock();
96
        $regionFactory = $this->getMockBuilder(RegionFactory::class)->disableOriginalConstructor()->getMock();
97
        $regionFactory->method('create')->willReturn($this->region);
98
99
        $this->customer = $this->objectManager->getObject(Customer::class, [
100
            'context' => $context,
101
            'storeManager' => $storeManager,
102
            'checkoutSession' => $checkoutSession,
103
            'regionFactory' => $regionFactory
104
        ]);
105
    }
106
107 View Code Duplication
    public function testCustomerHasGivenGender()
0 ignored issues
show
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...
108
    {
109
        $this->coreCustomer->method('getGender')->willReturn('m');
110
        $result = $this->customer->customerHasGivenGender();
111
        $expected = true;
112
        $this->assertEquals($expected, $result);
113
    }
114
115 View Code Duplication
    public function testCustomerHasGivenGenderFalse()
0 ignored issues
show
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->coreCustomer->method('getGender')->willReturn(null);
118
        $result = $this->customer->customerHasGivenGender();
119
        $expected = false;
120
        $this->assertEquals($expected, $result);
121
    }
122
123 View Code Duplication
    public function testCustomerHasGivenBirthday()
0 ignored issues
show
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...
124
    {
125
        $this->coreCustomer->method('getDob')->willReturn('1999-19-09');
126
        $result = $this->customer->customerHasGivenBirthday();
127
        $expected = true;
128
        $this->assertEquals($expected, $result);
129
    }
130
131 View Code Duplication
    public function testCustomerHasGivenBirthdayFalse()
0 ignored issues
show
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...
132
    {
133
        $this->coreCustomer->method('getDob')->willReturn(null);
134
        $result = $this->customer->customerHasGivenBirthday();
135
        $expected = false;
136
        $this->assertEquals($expected, $result);
137
    }
138
139 View Code Duplication
    public function testGetRegionCode()
0 ignored issues
show
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...
140
    {
141
        $expected = 'CA';
142
143
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
144
        $address->method('getRegionCode')->willReturn('California');
145
        $address->method('getCountryId')->willReturn('US');
146
147
        $this->region->method('getId')->willReturn('5');
148
        $this->region->method('getCode')->willReturn($expected);
149
150
        $result = $this->customer->getRegionCode($address);
151
        $this->assertEquals($expected, $result);
152
    }
153
154
    public function testGetRegionCodeDirectPass()
155
    {
156
        $expected = 'CA';
157
158
        $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
159
        $address->method('getRegionCode')->willReturn($expected);
160
161
        $result = $this->customer->getRegionCode($address);
162
        $this->assertEquals($expected, $result);
163
    }
164
165
    public function testGetRegion()
166
    {
167
        $this->region->method('getId')->willReturn('5');
168
        $result = $this->customer->getRegion('US', 'CA');
169
        $this->assertInstanceOf(Region::class, $result);
170
    }
171
172
    public function testGetRegionFalse()
173
    {
174
        $result = $this->customer->getRegion('US', 'CA');
175
        $this->assertFalse($result);
176
    }
177
178
    /**
179
     * @return array
180
     */
181
    public function getGenders()
182
    {
183
        return [
184
            ['1', 'm'],
185
            ['2', 'f'],
186
            ['x', '']
187
        ];
188
    }
189
190
    /**
191
     * @param int $gender
192
     * @param string $expected
193
     *
194
     * @dataProvider getGenders
195
     */
196
    public function testGetGenderParameter($gender, $expected)
197
    {
198
        $result = $this->customer->getGenderParameter($gender);
199
        $this->assertEquals($expected, $result);
200
    }
201
202
    /**
203
     * @return array
204
     */
205
    public function getSalutations()
206
    {
207
        return [
208
            ['1', 'Mr'],
209
            ['2', 'Mrs'],
210
            ['x', '']
211
        ];
212
    }
213
214
    /**
215
     * @param int $gender
216
     * @param string $expected
217
     *
218
     * @dataProvider getSalutations
219
     */
220
    public function testGetSalutationParameter($gender, $expected)
221
    {
222
        $result = $this->customer->getSalutationParameter($gender);
223
        $this->assertEquals($expected, $result);
224
    }
225
}
226