From d03d8e1e2a705e8677e680f01f0e04e899daa305 Mon Sep 17 00:00:00 2001 From: Priya Panchal Date: Sat, 29 Feb 2020 13:24:39 +0530 Subject: [PATCH 1/3] Fix Report date doesn't matching in configuration setting --- .../Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php index 4ac12501aa90f..1b44728870035 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php @@ -23,8 +23,10 @@ protected function _getElementHtml(AbstractElement $element) { $_months = []; for ($i = 1; $i <= 12; $i++) { - $_months[$i] = $this->_localeDate->date(mktime(null, null, null, $i, 1))->format('m'); + $month = $this->_localeDate->date(mktime(null, null, null, $i, 1))->format('m'); + $_months[$month] = $month; } + ksort($_months); $_days = []; for ($i = 1; $i <= 31; $i++) { $_days[$i] = $i < 10 ? '0' . $i : $i; From 2ec8bf5d59cc858979e83d3786b7cb7ee563ad1b Mon Sep 17 00:00:00 2001 From: Priya Panchal Date: Sat, 29 Feb 2020 16:15:33 +0530 Subject: [PATCH 2/3] Added Code Optimization --- .../Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php index 1b44728870035..a64cb14ed9862 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php @@ -15,6 +15,8 @@ class YtdStart extends \Magento\Config\Block\System\Config\Form\Field { /** + * Get Month and Day Element + * * @param AbstractElement $element * @return string * @SuppressWarnings(PHPMD.NPathComplexity) From 2410cbb760e1e88fa5c0681fa35baaf3686dd64a Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Mon, 16 Mar 2020 14:25:19 +0200 Subject: [PATCH 3/3] fix static, test coverage --- .../Adminhtml/Config/Form/Field/YtdStart.php | 38 +++++------- .../Config/Form/Field/YtdStartTest.php | 58 +++++++++++++++++++ 2 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStartTest.php diff --git a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php index a64cb14ed9862..b564e582943ac 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php @@ -5,14 +5,13 @@ */ namespace Magento\Reports\Block\Adminhtml\Config\Form\Field; +use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; /** * Dashboard Year-To-Date Month and Day starts Field Renderer - * - * @author Magento Core Team */ -class YtdStart extends \Magento\Config\Block\System\Config\Form\Field +class YtdStart extends Field { /** * Get Month and Day Element @@ -25,38 +24,29 @@ protected function _getElementHtml(AbstractElement $element) { $_months = []; for ($i = 1; $i <= 12; $i++) { - $month = $this->_localeDate->date(mktime(null, null, null, $i, 1))->format('m'); + $month = $this->_localeDate->date(mktime(null, null, null, $i, 1)) + ->format('m'); $_months[$month] = $month; } ksort($_months); + $_days = []; for ($i = 1; $i <= 31; $i++) { $_days[$i] = $i < 10 ? '0' . $i : $i; } - if ($element->getValue()) { - $values = explode(',', $element->getValue()); - } else { - $values = []; - } - + $values = $element->getValue() ? explode(',', $element->getValue()) : []; $element->setName($element->getName() . '[]'); - $_monthsHtml = $element->setStyle( - 'width:100px;' - )->setValues( - $_months - )->setValue( - isset($values[0]) ? $values[0] : null - )->getElementHtml(); + $_monthsHtml = $element->setStyle('width:100px;') + ->setValues($_months) + ->setValue(isset($values[0]) ? $values[0] : null) + ->getElementHtml(); - $_daysHtml = $element->setStyle( - 'width:50px;' - )->setValues( - $_days - )->setValue( - isset($values[1]) ? $values[1] : null - )->getElementHtml(); + $_daysHtml = $element->setStyle('width:50px;') + ->setValues($_days) + ->setValue(isset($values[1]) ? $values[1] : null) + ->getElementHtml(); return sprintf('%s %s', $_monthsHtml, $_daysHtml); } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStartTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStartTest.php new file mode 100644 index 0000000000000..d378b3e7344e1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStartTest.php @@ -0,0 +1,58 @@ +dispatch('backend/admin/system_config/edit/section/reports/'); + $body = $this->getResponse()->getBody(); + + $this->assertContains($this->getOptionsHtml('01'), $body); + } + + /** + * Options html + * + * @param string $selected + * @return string + */ + private function getOptionsHtml(string $selected): string + { + $html = ''; + foreach ($this->monthNumbers as $number) { + $html .= $number === $selected + ? '' + : ''; + + $html .= PHP_EOL; + } + + return $html; + } +}