Skip to content

Commit d19d8dd

Browse files
committed
MC-16365: [2.1.x] Fix CompanyUserManagerInterfaceTest failing on mainline
1 parent 675f2b9 commit d19d8dd

File tree

4 files changed

+140
-32
lines changed

4 files changed

+140
-32
lines changed

app/code/Magento/Backend/Test/Unit/Model/UrlTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
4646
/**
4747
* @var \PHPUnit_Framework_MockObject_MockObject
4848
*/
49-
private $_requestMock;
49+
private $requestMock;
5050

5151
/**
5252
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -64,7 +64,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
6464
private $encryptor;
6565

6666
/**
67-
* @return void
67+
* @inheritdoc
6868
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6969
*/
7070
protected function setUp()
@@ -144,8 +144,8 @@ protected function setUp()
144144
$this->getMock(\Magento\Framework\Url\RouteParamsResolver::class, [], [], '', false)
145145
);
146146

147-
$this->_requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
148-
$this->model->setRequest($this->_requestMock);
147+
$this->requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
148+
$this->model->setRequest($this->requestMock);
149149
}
150150

151151
public function testFindFirstAvailableMenuDenied()
@@ -259,11 +259,11 @@ public function testGetSecretKeyGenerationWithRouteNameInRequest()
259259

260260
$keyFromParams = $this->model->getSecretKey($routeName, $controllerName, $actionName);
261261

262-
$this->_requestMock->expects($this->exactly(3))->method('getBeforeForwardInfo')->willReturn(null);
263-
$this->_requestMock->expects($this->once())->method('getRouteName')->willReturn($routeName);
264-
$this->_requestMock->expects($this->once())->method('getControllerName')->willReturn($controllerName);
265-
$this->_requestMock->expects($this->once())->method('getActionName')->willReturn($actionName);
266-
$this->model->setRequest($this->_requestMock);
262+
$this->requestMock->expects($this->exactly(3))->method('getBeforeForwardInfo')->willReturn(null);
263+
$this->requestMock->expects($this->once())->method('getRouteName')->willReturn($routeName);
264+
$this->requestMock->expects($this->once())->method('getControllerName')->willReturn($controllerName);
265+
$this->requestMock->expects($this->once())->method('getActionName')->willReturn($actionName);
266+
$this->model->setRequest($this->requestMock);
267267

268268
$keyFromRequest = $this->model->getSecretKey();
269269
$this->assertEquals($keyFromParams, $keyFromRequest);
@@ -280,32 +280,32 @@ public function testGetSecretKeyGenerationWithRouteNameInForwardInfo()
280280

281281
$keyFromParams = $this->model->getSecretKey($routeName, $controllerName, $actionName);
282282

283-
$this->_requestMock->expects($this->at(0))
283+
$this->requestMock->expects($this->at(0))
284284
->method('getBeforeForwardInfo')
285285
->with('route_name')
286286
->willReturn('adminhtml');
287-
$this->_requestMock->expects($this->at(1))
287+
$this->requestMock->expects($this->at(1))
288288
->method('getBeforeForwardInfo')
289289
->with('route_name')
290290
->willReturn('adminhtml');
291-
$this->_requestMock->expects($this->at(2))
291+
$this->requestMock->expects($this->at(2))
292292
->method('getBeforeForwardInfo')
293293
->with('controller_name')
294294
->willReturn('catalog');
295-
$this->_requestMock->expects($this->at(3))
295+
$this->requestMock->expects($this->at(3))
296296
->method('getBeforeForwardInfo')
297297
->with('controller_name')
298298
->willReturn('catalog');
299-
$this->_requestMock->expects($this->at(4))
299+
$this->requestMock->expects($this->at(4))
300300
->method('getBeforeForwardInfo')
301301
->with('action_name')
302302
->willReturn('index');
303-
$this->_requestMock->expects($this->at(5))
303+
$this->requestMock->expects($this->at(5))
304304
->method('getBeforeForwardInfo')
305305
->with('action_name')
306306
->willReturn('index');
307307

308-
$this->model->setRequest($this->_requestMock);
308+
$this->model->setRequest($this->requestMock);
309309
$keyFromRequest = $this->model->getSecretKey();
310310
$this->assertEquals($keyFromParams, $keyFromRequest);
311311
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Test\Unit\Model\Rss;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
use Magento\Sales\Model\Rss\Signature;
11+
12+
/**
13+
* Test signature class.
14+
*/
15+
class SignatureTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\DeploymentConfig
19+
*/
20+
private $encryptorMock;
21+
22+
/**
23+
* @var ObjectManagerHelper
24+
*/
25+
private $objectManagerHelper;
26+
27+
/**
28+
* @var \Magento\Sales\Model\Rss\Signature
29+
*/
30+
private $model;
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
protected function setUp()
36+
{
37+
$this->encryptorMock = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class)
38+
->disableOriginalConstructor()
39+
->getMockForAbstractClass();
40+
$this->objectManagerHelper = new ObjectManagerHelper($this);
41+
$this->model = $this->objectManagerHelper->getObject(
42+
Signature::class,
43+
[
44+
'encryptor' => $this->encryptorMock,
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test sign data.
51+
*
52+
* @param string $data
53+
* @param string $expected
54+
* @return void
55+
* @dataProvider checkSignatureDataProvider
56+
*/
57+
public function testSignData($data, $expected)
58+
{
59+
$this->encryptorMock->expects($this->any())->method('hash')->with($data)->willReturn($expected);
60+
$this->assertEquals($expected, $this->model->signData($data));
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function checkSignatureDataProvider()
67+
{
68+
return [
69+
[
70+
'eyJvcmRlcl9pZCI6IjEiLCJjdXN0b21lcl9pZCI6IjEiLCJpbmNyZW1lbnRfaWQiOiIwMDAwMDAwMDEifQ==',
71+
'651932dfc862406b72628d95623bae5ea18242be757b3493b337942d61f834be',
72+
],
73+
];
74+
}
75+
76+
/**
77+
* Test signature validation.
78+
*
79+
* @param string $data
80+
* @param string $signature
81+
* @param bool $expected
82+
* @return void
83+
* @dataProvider checkIsValidDataProvider
84+
*/
85+
public function testIsValid($data, $signature, $expected)
86+
{
87+
$this->encryptorMock->expects($this->any())
88+
->method('validateHash')
89+
->with($data, $signature)
90+
->willReturn($expected);
91+
92+
$this->assertEquals($expected, $this->model->isValid($data, $signature));
93+
}
94+
95+
/**
96+
* @return array
97+
*/
98+
public function checkIsValidDataProvider()
99+
{
100+
return [
101+
[
102+
'eyJvcmRlcl9pZCI6IjEiLCJjdXN0b21lcl9pZCI6IjEiLCJpbmNyZW1lbnRfaWQiOiIwMDAwMDAwMDEifQ==',
103+
'651932dfc862406b72628d95623bae5ea18242be757b3493b337942d61f834be',
104+
true,
105+
],
106+
[
107+
'eyJvcmRlcl9pZCI6IjEiLCJjdXN0b21lcl9pZCI6IjEiLCJpbmNyZW1lbnRfaWQiOiIwMDAwMDAwMDEifQ==',
108+
'blabla',
109+
false,
110+
],
111+
];
112+
}
113+
}

dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
class ProductTest extends \PHPUnit_Framework_TestCase
1616
{
17-
/**
18-
* Base product image path
19-
*/
20-
const BASE_IMAGE_PATH = '#http\:\/\/localhost\/pub\/media\/catalog\/product\/cache\/[a-z0-9]{32}:path:#';
21-
2217
/**
2318
* Test getCollection None images
2419
* 1) Check that image attributes were not loaded

lib/internal/Magento/Framework/Encryption/Test/Unit/EncryptorTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class EncryptorTest extends \PHPUnit_Framework_TestCase
1313
{
14-
const CRYPT_KEY = 'g9mY9KLrcuAVJfsmVUSRkKFLDdUPVkaZ';
14+
private $cryptKey = 'g9mY9KLrcuAVJfsmVUSRkKFLDdUPVkaZ';
1515

1616
/**
1717
* @var \Magento\Framework\Encryption\Encryptor
@@ -28,8 +28,8 @@ class EncryptorTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected function setUp()
3030
{
31-
$this->_randomGenerator = $this->getMock('Magento\Framework\Math\Random', [], [], '', false);
32-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
31+
$this->_randomGenerator = $this->getMock(\Magento\Framework\Math\Random::class, [], [], '', false);
32+
$deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
3333
$deploymentConfigMock->expects($this->any())
3434
->method('get')
3535
->with(Encryptor::PARAM_CRYPT_KEY)
@@ -127,7 +127,7 @@ public function validateHashDataProvider()
127127
*/
128128
public function testEncryptWithEmptyKey($key)
129129
{
130-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
130+
$deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
131131
$deploymentConfigMock->expects($this->any())
132132
->method('get')
133133
->with(Encryptor::PARAM_CRYPT_KEY)
@@ -154,7 +154,7 @@ public function emptyKeyDataProvider()
154154
*/
155155
public function testDecryptWithEmptyKey($key)
156156
{
157-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
157+
$deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
158158
$deploymentConfigMock->expects($this->any())
159159
->method('get')
160160
->with(Encryptor::PARAM_CRYPT_KEY)
@@ -208,7 +208,7 @@ public function testDecrypt()
208208
*/
209209
public function testEncryptDecryptNewKeyAdded()
210210
{
211-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
211+
$deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
212212
$deploymentConfigMock->expects($this->at(0))
213213
->method('get')
214214
->with(Encryptor::PARAM_CRYPT_KEY)
@@ -255,25 +255,25 @@ public function testUseSpecifiedHashingAlgoDataProvider()
255255
'password',
256256
'salt',
257257
Encryptor::HASH_VERSION_MD5,
258-
'/^[a-z0-9]{32}\:salt\:0$/'
258+
'/^[a-z0-9]{32}\:salt\:0$/',
259259
],
260260
[
261261
'password',
262262
'salt',
263263
Encryptor::HASH_VERSION_SHA256,
264-
'/^[a-z0-9]{64}\:salt\:1$/'
264+
'/^[a-z0-9]{64}\:salt\:1$/',
265265
],
266266
[
267267
'password',
268268
false,
269269
Encryptor::HASH_VERSION_MD5,
270-
'/^[0-9a-z]{32}$/'
270+
'/^[0-9a-z]{32}$/',
271271
],
272272
[
273273
'password',
274274
false,
275275
Encryptor::HASH_VERSION_SHA256,
276-
'/^[0-9a-z]{64}$/'
276+
'/^[0-9a-z]{64}$/',
277277
]
278278
];
279279
}
@@ -308,7 +308,7 @@ public function testHash()
308308
$this->assertTrue($this->_model->isValidHash($value, $hash1));
309309

310310
//Checking that key matters.
311-
$this->_model->setNewKey(self::CRYPT_KEY);
311+
$this->_model->setNewKey($this->cryptKey);
312312
$hash3 = $this->_model->hash($value);
313313
$this->assertNotEquals($hash3, $hash1);
314314
//Validation still works

0 commit comments

Comments
 (0)