Skip to content

Commit 3684da4

Browse files
authored
Merge pull request #4078 from magento-borg/borg-qwerty-2.1
[borg] Bug fixes
2 parents b771a6b + e3ba8e7 commit 3684da4

File tree

11 files changed

+159
-30
lines changed

11 files changed

+159
-30
lines changed

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
*/
66
namespace Magento\Captcha\Model;
77

8+
use Magento\Framework\Math\Random;
9+
810
/**
911
* Implementation of \Zend_Captcha
1012
*
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
14+
*
1115
* @author Magento Core Team <core@magentocommerce.com>
1216
*/
1317
class DefaultModel extends \Zend_Captcha_Image implements \Magento\Captcha\Model\CaptchaInterface
@@ -68,22 +72,30 @@ class DefaultModel extends \Zend_Captcha_Image implements \Magento\Captcha\Model
6872
*/
6973
protected $_session;
7074

75+
/**
76+
* @var Random
77+
*/
78+
private $randomMath;
79+
7180
/**
7281
* @param \Magento\Framework\Session\SessionManagerInterface $session
7382
* @param \Magento\Captcha\Helper\Data $captchaData
7483
* @param \Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory
7584
* @param string $formId
85+
* @param Random $randomMath
7686
*/
7787
public function __construct(
7888
\Magento\Framework\Session\SessionManagerInterface $session,
7989
\Magento\Captcha\Helper\Data $captchaData,
8090
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
81-
$formId
91+
$formId,
92+
Random $randomMath = null
8293
) {
8394
$this->_session = $session;
8495
$this->_captchaData = $captchaData;
8596
$this->_resLogFactory = $resLogFactory;
8697
$this->_formId = $formId;
98+
$this->randomMath = $randomMath ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Random::class);
8799
}
88100

89101
/**
@@ -361,13 +373,9 @@ public function setShowCaptchaInSession($value = true)
361373
*/
362374
protected function _generateWord()
363375
{
364-
$word = '';
365-
$symbols = $this->_getSymbols();
376+
$symbols = (string)$this->_captchaData->getConfig('symbols');
366377
$wordLen = $this->_getWordLen();
367-
for ($i = 0; $i < $wordLen; $i++) {
368-
$word .= $symbols[array_rand($symbols)];
369-
}
370-
return $word;
378+
return $this->randomMath->getRandomString($wordLen, $symbols);
371379
}
372380

373381
/**

app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,41 @@ public function isShownToLoggedInUserDataProvider()
376376
[false, 'guest_checkout']
377377
];
378378
}
379+
380+
/**
381+
* @param string $string
382+
* @dataProvider generateWordProvider
383+
* @throws \ReflectionException
384+
*/
385+
public function testGenerateWord($string)
386+
{
387+
$randomMock = $this->getMock('Magento\Framework\Math\Random');
388+
$randomMock->expects($this->once())
389+
->method('getRandomString')
390+
->will($this->returnValue($string));
391+
392+
$captcha = new \Magento\Captcha\Model\DefaultModel(
393+
$this->session,
394+
$this->_getHelperStub(),
395+
$this->_resLogFactory,
396+
'user_create',
397+
$randomMock
398+
);
399+
400+
$method = new \ReflectionMethod($captcha, '_generateWord');
401+
$method->setAccessible(true);
402+
$this->assertEquals($string, $method->invoke($captcha));
403+
}
404+
405+
/**
406+
* @return array
407+
*/
408+
public function generateWordProvider()
409+
{
410+
return [
411+
['ABC123'],
412+
['1234567890'],
413+
['The quick brown fox jumps over the lazy dog.']
414+
];
415+
}
379416
}

app/code/Magento/Customer/etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
</field>
262262
<field id="html" type="textarea" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
263263
<label>HTML</label>
264+
<comment>Only 'b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul' tags are allowed</comment>
264265
</field>
265266
<field id="pdf" type="textarea" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
266267
<label>PDF</label>

app/code/Magento/Customer/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ Password:,Password:
480480
"Address Templates","Address Templates"
481481
"Online Customers Options","Online Customers Options"
482482
"Online Minutes Interval","Online Minutes Interval"
483+
"Only 'b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul' tags are allowed","Only 'b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul' tags are allowed"
483484
"Leave empty for default (15 minutes).","Leave empty for default (15 minutes)."
484485
"Enable Autocomplete on login/forgot password forms","Enable Autocomplete on login/forgot password forms"
485486
"Customer Grid","Customer Grid"

app/code/Magento/Customer/view/adminhtml/templates/tab/view/personal_info.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $lastLoginDateStore = $block->getStoreLastLoginDate();
1515

1616
$createDateAdmin = $block->getCreateDate();
1717
$createDateStore = $block->getStoreCreateDate();
18+
$allowedAddressHtmlTags = ['b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul'];
1819
?>
1920

2021
<div class="fieldset-wrapper customer-information">
@@ -65,7 +66,7 @@ $createDateStore = $block->getStoreCreateDate();
6566
<address>
6667
<strong><?php echo $block->escapeHtml(__('Default Billing Address')) ?></strong>
6768
<br/>
68-
<?php echo $block->getBillingAddressHtml() ?>
69+
<?php echo $block->escapeHtml($block->getBillingAddressHtml(), $allowedAddressHtmlTags) ?>
6970
</address>
7071

7172
</div>

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,7 @@ protected function _getAllItems()
730730
$itemWeight = $this->_getWeight($itemWeight * $item->getQty());
731731
$maxWeight = $this->_getWeight($this->_maxWeight, true);
732732
if ($itemWeight > $maxWeight) {
733-
$qtyItem = floor($itemWeight / $maxWeight);
734-
$decimalItems[] = ['weight' => $maxWeight, 'qty' => $qtyItem];
735-
$weightItem = $this->mathDivision->getExactDivision($itemWeight, $maxWeight);
736-
if ($weightItem) {
737-
$decimalItems[] = ['weight' => $weightItem, 'qty' => 1];
738-
}
733+
$this->pushDecimalItems($decimalItems, $itemWeight, $maxWeight);
739734
$checkWeight = false;
740735
}
741736
}
@@ -772,6 +767,23 @@ protected function _getAllItems()
772767
return $fullItems;
773768
}
774769

770+
/**
771+
* Pushes items into array that are decimal places on item weight
772+
*
773+
* @param array $decimalItems
774+
* @param float $itemWeight
775+
* @param float $maxWeight
776+
*/
777+
private function pushDecimalItems(array &$decimalItems, float $itemWeight, float $maxWeight)
778+
{
779+
$qtyItem = floor($itemWeight / $maxWeight);
780+
$decimalItems[] = ['weight' => $maxWeight, 'qty' => $qtyItem];
781+
$weightItem = $this->mathDivision->getExactDivision($itemWeight, $maxWeight);
782+
if ($weightItem) {
783+
$decimalItems[] = ['weight' => $weightItem, 'qty' => 1];
784+
}
785+
}
786+
775787
/**
776788
* Make pieces
777789
*
@@ -957,7 +969,7 @@ protected function _getQuotes()
957969
protected function _getQuotesFromServer($request)
958970
{
959971
$client = $this->_httpClientFactory->create();
960-
$client->setUri((string)$this->getConfigData('gateway_url'));
972+
$client->setUri($this->getGatewayURL());
961973
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
962974
$client->setRawData(utf8_encode($request));
963975

@@ -1558,7 +1570,7 @@ protected function _doRequest()
15581570
$debugData = ['request' => $request];
15591571
try {
15601572
$client = $this->_httpClientFactory->create();
1561-
$client->setUri((string)$this->getConfigData('gateway_url'));
1573+
$client->setUri($this->getGatewayURL());
15621574
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
15631575
$client->setRawData($request);
15641576
$responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody();
@@ -1751,7 +1763,7 @@ protected function _getXMLTracking($trackings)
17511763
$debugData = ['request' => $request];
17521764
try {
17531765
$client = new \Magento\Framework\HTTP\ZendClient();
1754-
$client->setUri((string)$this->getConfigData('gateway_url'));
1766+
$client->setUri($this->getGatewayURL());
17551767
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
17561768
$client->setRawData($request);
17571769
$responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody();
@@ -1959,6 +1971,8 @@ protected function _prepareShippingLabelContent(\SimpleXMLElement $xml)
19591971
}
19601972

19611973
/**
1974+
* Verify if the shipment is dutiable
1975+
*
19621976
* @param string $origCountryId
19631977
* @param string $destCountryId
19641978
*
@@ -1972,4 +1986,18 @@ protected function isDutiable($origCountryId, $destCountryId)
19721986
self::DHL_CONTENT_TYPE_NON_DOC == $this->getConfigData('content_type')
19731987
&& !$this->_isDomestic;
19741988
}
1989+
1990+
/**
1991+
* Get the gateway URL
1992+
*
1993+
* @return string
1994+
*/
1995+
private function getGatewayURL()
1996+
{
1997+
if ($this->getConfigData('sandbox_mode')) {
1998+
return (string)$this->getConfigData('sandbox_url');
1999+
} else {
2000+
return (string)$this->getConfigData('gateway_url');
2001+
}
2002+
}
19752003
}

app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Quote\Model\Quote\Address\RateRequest;
99
use Magento\Framework\Xml\Security;
10+
use Magento\Dhl\Model\Carrier;
1011

1112
class CarrierTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -305,4 +306,52 @@ public function testCollectRatesFail()
305306

306307
$this->assertFalse(false, $this->_model->collectRates($request));
307308
}
309+
310+
/**
311+
* Tests if the DHL client returns the appropriate API URL.
312+
*
313+
* @dataProvider getGatewayURLProvider
314+
* @param $sandboxMode
315+
* @param $expectedURL
316+
* @throws \ReflectionException
317+
*/
318+
public function testGetGatewayURL($sandboxMode, $expectedURL)
319+
{
320+
$scope = $this->getMockBuilder(
321+
'\Magento\Framework\App\Config\ScopeConfigInterface'
322+
)->disableOriginalConstructor()->getMock();
323+
324+
$scopeConfigValueMap = [
325+
['carriers/dhl/gateway_url', 'store', null, 'https://xmlpi-ea.dhl.com/XMLShippingServlet'],
326+
['carriers/dhl/sandbox_url', 'store', null, 'https://xmlpitest-ea.dhl.com/XMLShippingServlet'],
327+
['carriers/dhl/sandbox_mode', 'store', null, $sandboxMode]
328+
];
329+
330+
$scope->method('getValue')
331+
->willReturnMap($scopeConfigValueMap);
332+
333+
$this->model = $this->_helper->getObject(
334+
Carrier::class,
335+
[
336+
'scopeConfig' => $scope
337+
]
338+
);
339+
340+
$method = new \ReflectionMethod($this->model, 'getGatewayURL');
341+
$method->setAccessible(true);
342+
$this->assertEquals($expectedURL, $method->invoke($this->model));
343+
}
344+
345+
/**
346+
* Data provider for testGetGatewayURL
347+
*
348+
* @return array
349+
*/
350+
public function getGatewayURLProvider()
351+
{
352+
return [
353+
'standard_url' => [0, 'https://xmlpi-ea.dhl.com/XMLShippingServlet'],
354+
'sandbox_url' => [1, 'https://xmlpitest-ea.dhl.com/XMLShippingServlet']
355+
];
356+
}
308357
}

app/code/Magento/Dhl/etc/adminhtml/system.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
<label>Enabled for Checkout</label>
1515
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1616
</field>
17-
<field id="gateway_url" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
18-
<label>Gateway URL</label>
19-
</field>
2017
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
2118
<label>Title</label>
2219
</field>
@@ -150,6 +147,10 @@
150147
<label>Debug</label>
151148
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
152149
</field>
150+
<field id="sandbox_mode" translate="label" type="select" sortOrder="1960" showInDefault="1" showInWebsite="1" showInStore="0">
151+
<label>Sandbox Mode</label>
152+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
153+
</field>
153154
</group>
154155
</section>
155156
</system>

app/code/Magento/Dhl/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<doc_methods>2,5,6,7,9,B,C,D,U,K,L,G,W,I,N,O,R,S,T,X</doc_methods>
2626
<free_method>G</free_method>
2727
<gateway_url>https://xmlpi-ea.dhl.com/XMLShippingServlet</gateway_url>
28+
<sandbox_url>https://xmlpitest-ea.dhl.com/XMLShippingServlet</sandbox_url>
2829
<id backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
2930
<password backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
3031
<content_type>N</content_type>

app/code/Magento/Sales/view/adminhtml/templates/order/create/data.phtml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
// @codingStandardsIgnoreFile
88

9+
$escapeHelper = $this->helper(\Magento\Framework\EscapeHelper::class);
910
?>
1011
<div class="page-create-order">
1112
<script>
1213
require(["Magento_Sales/order/create/form"], function(){
13-
order.setCurrencySymbol('<?php /* @escapeNotVerified */ echo $block->getCurrencySymbol($block->getCurrentCurrencyCode()) ?>')
14+
order.setCurrencySymbol('<?php echo $escapeHelper->escapeJs($block->getCurrencySymbol($block->getCurrentCurrencyCode())) ?>')
1415
});
1516
</script>
1617
<div class="order-details<?php if ($block->getCustomerId()): ?> order-details-existing-customer<?php endif; ?>">
@@ -35,7 +36,7 @@
3536

3637
<section id="order-addresses" class="admin__page-section order-addresses">
3738
<div class="admin__page-section-title">
38-
<span class="title"><?php /* @escapeNotVerified */ echo __('Address Information') ?></span>
39+
<span class="title"><?php echo $block->escapeHtml(__('Address Information')) ?></span>
3940
</div>
4041
<div class="admin__page-section-content">
4142
<div id="order-billing_address" class="admin__page-section-item order-billing-address">
@@ -49,7 +50,7 @@
4950

5051
<section id="order-methods" class="admin__page-section order-methods">
5152
<div class="admin__page-section-title">
52-
<span class="title"><?php /* @escapeNotVerified */ echo __('Payment &amp; Shipping Information') ?></span>
53+
<span class="title"><?php echo $block->escapeHtml(__('Payment &amp; Shipping Information')) ?></span>
5354
</div>
5455
<div class="admin__page-section-content">
5556
<div id="order-billing_method" class="admin__page-section-item order-billing-method">
@@ -71,11 +72,11 @@
7172

7273
<section class="admin__page-section order-summary">
7374
<div class="admin__page-section-title">
74-
<span class="title"><?php /* @escapeNotVerified */ echo __('Order Total') ?></span>
75+
<span class="title"><?php echo $block->escapeHtml(__('Order Total')) ?></span>
7576
</div>
7677
<div class="admin__page-section-content">
7778
<fieldset class="admin__fieldset order-history" id="order-comment">
78-
<legend class="admin__legend"><span><?php /* @escapeNotVerified */ echo __('Order History') ?></span></legend>
79+
<legend class="admin__legend"><span><?php echo $block->escapeHtml(__('Order History')) ?></span></legend>
7980
<br>
8081
<?php echo $block->getChildHtml('comment') ?>
8182
</fieldset>
@@ -90,15 +91,15 @@
9091
<div class="order-sidebar">
9192
<div class="store-switcher order-currency">
9293
<label class="admin__field-label" for="currency_switcher">
93-
<?php /* @escapeNotVerified */ echo __('Order Currency:') ?>
94+
<?php echo $block->escapeHtml(__('Order Currency:')) ?>
9495
</label>
9596
<select id="currency_switcher"
9697
class="admin__control-select"
9798
name="order[currency]"
9899
onchange="order.setCurrencyId(this.value); order.setCurrencySymbol(this.options[this.selectedIndex].getAttribute('symbol'));">
99100
<?php foreach ($block->getAvailableCurrencies() as $_code): ?>
100-
<option value="<?php /* @escapeNotVerified */ echo $_code ?>"<?php if ($_code == $block->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?> symbol="<?php /* @escapeNotVerified */ echo $block->getCurrencySymbol($_code) ?>">
101-
<?php /* @escapeNotVerified */ echo $block->getCurrencyName($_code) ?>
101+
<option value="<?php echo $escapeHelper->escapeHtmlAttr($_code) ?>"<?php if ($_code == $block->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?> symbol="<?php echo $escapeHelper->escapeHtmlAttr($block->getCurrencySymbol($_code)) ?>">
102+
<?php echo $block->escapeHtml($block->getCurrencyName($_code)) ?>
102103
</option>
103104
<?php endforeach; ?>
104105
</select>

0 commit comments

Comments
 (0)