Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit c16e31c

Browse files
MAGETWO-87449: [EngCom Team] Batch 30. Forwardports to 2.3-develop #1353
2 parents 408cd32 + a5f1902 commit c16e31c

File tree

18 files changed

+341
-59
lines changed

18 files changed

+341
-59
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ public function getFieldHtml()
186186
'max_date' => '-1d',
187187
'change_month' => 'true',
188188
'change_year' => 'true',
189-
'show_on' => 'both'
189+
'show_on' => 'both',
190+
'first_day' => $this->getFirstDay()
190191
]);
191192
return $this->dateElement->getHtml();
192193
}
@@ -208,17 +209,14 @@ public function getHtmlId()
208209
*/
209210
public function getHtmlExtraParams()
210211
{
211-
$extraParams = [
212-
"'validate-date-au':true"
213-
];
214-
212+
$validators = [];
215213
if ($this->isRequired()) {
216-
$extraParams[] = 'required:true';
214+
$validators['required'] = true;
217215
}
218-
219-
$extraParams = implode(', ', $extraParams);
220-
221-
return 'data-validate="{' . $extraParams . '}"';
216+
$validators['validate-date'] = [
217+
'dateFormat' => $this->getDateFormat()
218+
];
219+
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
222220
}
223221

224222
/**
@@ -307,4 +305,17 @@ public function getMaxDateRange()
307305
}
308306
return null;
309307
}
308+
309+
/**
310+
* Return first day of the week
311+
*
312+
* @return int
313+
*/
314+
public function getFirstDay()
315+
{
316+
return (int)$this->_scopeConfig->getValue(
317+
'general/locale/firstday',
318+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
319+
);
320+
}
310321
}

app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ class DobTest extends \PHPUnit\Framework\TestCase
5757
*/
5858
protected $filterFactory;
5959

60+
/**
61+
* @var \Magento\Framework\Escaper
62+
*/
63+
private $escaper;
64+
65+
/**
66+
* @var \Magento\Framework\View\Element\Template\Context
67+
*/
68+
private $context;
69+
6070
protected function setUp()
6171
{
6272
$zendCacheCore = new \Zend_Cache_Core();
@@ -82,8 +92,13 @@ protected function setUp()
8292
['localeResolver' => $localeResolver]
8393
);
8494

85-
$context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
86-
$context->expects($this->any())->method('getLocaleDate')->will($this->returnValue($timezone));
95+
$this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
96+
$this->context->expects($this->any())->method('getLocaleDate')->will($this->returnValue($timezone));
97+
$this->escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class)
98+
->disableOriginalConstructor()
99+
->setMethods(['escapeHtml'])
100+
->getMock();
101+
$this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper));
87102

88103
$this->attribute = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
89104
->getMockForAbstractClass();
@@ -100,7 +115,7 @@ protected function setUp()
100115
->getMock();
101116

102117
$this->_block = new \Magento\Customer\Block\Widget\Dob(
103-
$context,
118+
$this->context,
104119
$this->createMock(\Magento\Customer\Helper\Address::class),
105120
$this->customerMetadata,
106121
$this->createMock(\Magento\Framework\View\Element\Html\Date::class),
@@ -454,25 +469,37 @@ public function testGetMaxDateRangeWithException()
454469
);
455470
$this->assertNull($this->_block->getMaxDateRange());
456471
}
457-
472+
458473
public function testGetHtmlExtraParamsWithoutRequiredOption()
459474
{
475+
$this->escaper->expects($this->any())
476+
->method('escapeHtml')
477+
->with('{"validate-date":{"dateFormat":"M\/d\/yy"}}')
478+
->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/yy"}}'));
460479
$this->attribute->expects($this->once())
461480
->method("isRequired")
462481
->willReturn(false);
463482

464-
$this->assertEquals($this->_block->getHtmlExtraParams(), 'data-validate="{\'validate-date-au\':true}"');
483+
$this->assertEquals(
484+
$this->_block->getHtmlExtraParams(),
485+
'data-validate="{"validate-date":{"dateFormat":"M\/d\/yy"}}"'
486+
);
465487
}
466488

467489
public function testGetHtmlExtraParamsWithRequiredOption()
468490
{
469491
$this->attribute->expects($this->once())
470492
->method("isRequired")
471493
->willReturn(true);
494+
$this->escaper->expects($this->any())
495+
->method('escapeHtml')
496+
->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}')
497+
->will($this->returnValue('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}'));
498+
$this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper));
472499

473500
$this->assertEquals(
474-
$this->_block->getHtmlExtraParams(),
475-
'data-validate="{\'validate-date-au\':true, required:true}"'
501+
'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}"',
502+
$this->_block->getHtmlExtraParams()
476503
);
477504
}
478505
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<fax_show/>
5757
</address>
5858
<startup>
59-
<redirect_dashboard>1</redirect_dashboard>
59+
<redirect_dashboard>0</redirect_dashboard>
6060
</startup>
6161
<address_templates>
6262
<text>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}

app/code/Magento/Developer/Console/Command/DevTestsRunCommand.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Command\Command;
99
use Symfony\Component\Console\Input\InputArgument;
1010
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213

1314
/**
@@ -22,6 +23,12 @@ class DevTestsRunCommand extends Command
2223
*/
2324
const INPUT_ARG_TYPE = 'type';
2425

26+
/**
27+
* PHPUnit arguments parameter
28+
*/
29+
const INPUT_OPT_COMMAND_ARGUMENTS = 'arguments';
30+
const INPUT_OPT_COMMAND_ARGUMENTS_SHORT = 'c';
31+
2532
/**
2633
* command name
2734
*/
@@ -56,7 +63,13 @@ protected function configure()
5663
'Type of test to run. Available types: ' . implode(', ', array_keys($this->types)),
5764
'default'
5865
);
59-
66+
$this->addOption(
67+
self::INPUT_OPT_COMMAND_ARGUMENTS,
68+
self::INPUT_OPT_COMMAND_ARGUMENTS_SHORT,
69+
InputOption::VALUE_REQUIRED,
70+
'Additional arguments for PHPUnit. Example: "-c\'--filter=MyTest\'" (no spaces)',
71+
''
72+
);
6073
parent::configure();
6174
}
6275

@@ -87,6 +100,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
87100
$dirName = realpath(BP . '/dev/tests/' . $dir);
88101
chdir($dirName);
89102
$command = PHP_BINARY . ' ' . BP . '/' . $vendorDir . '/phpunit/phpunit/phpunit ' . $options;
103+
if ($commandArguments = $input->getOption(self::INPUT_OPT_COMMAND_ARGUMENTS)) {
104+
$command .= ' ' . $commandArguments;
105+
}
90106
$message = $dirName . '> ' . $command;
91107
$output->writeln(['', str_pad("---- {$message} ", 70, '-'), '']);
92108
passthru($command, $returnVal);

app/code/Magento/Developer/Test/Unit/Console/Command/DevTestsRunCommandTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ public function testExecuteBadType()
3434
$commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']);
3535
$this->assertContains('Invalid type: "bad"', $commandTester->getDisplay());
3636
}
37+
38+
public function testPassArgumentsToPHPUnit()
39+
{
40+
$commandTester = new CommandTester($this->command);
41+
$commandTester->execute(
42+
[
43+
DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
44+
'-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
45+
]
46+
);
47+
$this->assertContains(
48+
'phpunit --list-suites',
49+
$commandTester->getDisplay(),
50+
'Parameters should be passed to PHPUnit'
51+
);
52+
}
3753
}

app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/AddressTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testPrepareDataSource()
4747
{
4848
$itemName = 'itemName';
4949
$oldItemValue = "itemValue\n";
50-
$newItemValue = 'itemValue<br/>';
50+
$newItemValue = "itemValue<br />\n";
5151
$dataSource = [
5252
'data' => [
5353
'items' => [
@@ -57,7 +57,7 @@ public function testPrepareDataSource()
5757
];
5858

5959
$this->model->setData('name', $itemName);
60-
$this->escaper->expects($this->once())->method('escapeHtml')->with($newItemValue)->willReturnArgument(0);
60+
$this->escaper->expects($this->any())->method('escapeHtml')->with($oldItemValue)->willReturnArgument(0);
6161
$dataSource = $this->model->prepareDataSource($dataSource);
6262
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
6363
}

app/code/Magento/Sales/Ui/Component/Listing/Column/Address.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public function prepareDataSource(array $dataSource)
4949
{
5050
if (isset($dataSource['data']['items'])) {
5151
foreach ($dataSource['data']['items'] as & $item) {
52-
$item[$this->getData('name')] = $this->escaper->escapeHtml(
53-
str_replace("\n", '<br/>', $item[$this->getData('name')])
54-
);
52+
$item[$this->getData('name')] = nl2br($this->escaper->escapeHtml($item[$this->getData('name')]));
5553
}
5654
}
5755

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
4242

4343
const TYPE_URL = 'url';
4444

45+
/**
46+
* Last mode date min value
47+
*/
48+
const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00';
49+
4550
/**
4651
* Real file path
4752
*
@@ -177,6 +182,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
177182
*/
178183
private $sitemapItemFactory;
179184

185+
/**
186+
* Last mode min timestamp value
187+
*
188+
* @var int
189+
*/
190+
private $lastModMinTsVal;
191+
180192
/**
181193
* Initialize dependencies.
182194
*
@@ -694,7 +706,11 @@ protected function _getMediaUrl($url)
694706
*/
695707
protected function _getFormattedLastmodDate($date)
696708
{
697-
return date('c', strtotime($date));
709+
if ($this->lastModMinTsVal === null) {
710+
$this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL);
711+
}
712+
$timestamp = max(strtotime($date), $this->lastModMinTsVal);
713+
return date('c', $timestamp);
698714
}
699715

700716
/**

app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ protected function getModelMock($mockBeforeSave = false)
527527
->willReturn([
528528
new SitemapItem('category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
529529
new SitemapItem('/category/sub-category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
530-
new SitemapItem('product.html', '0.5', 'monthly', '2012-12-21 00:00:00'),
530+
new SitemapItem('product.html', '0.5', 'monthly', '0000-00-00 00:00:00'),
531531
new SitemapItem(
532532
'product2.html',
533533
'0.5',

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
1111
<url>
1212
<loc>http://store.com/product.html</loc>
13-
<lastmod>2012-12-21T00:00:00-08:00</lastmod>
13+
<lastmod>0000-01-01T00:00:00-08:00</lastmod>
1414
<changefreq>monthly</changefreq>
1515
<priority>0.5</priority>
1616
</url>

0 commit comments

Comments
 (0)