Skip to content

Commit

Permalink
Merge pull request #174 from magento-extensibility/time-zone-pr
Browse files Browse the repository at this point in the history
[Extensibility] MAGETWO-45241, MAGETWO-45240, MAGETWO-45251, MAGETWO-45237, MAGETWO-45274
  • Loading branch information
He, Joan(johe) committed Nov 13, 2015
2 parents 50c33e5 + 624469b commit a87cf5b
Show file tree
Hide file tree
Showing 19 changed files with 356 additions and 59 deletions.
16 changes: 3 additions & 13 deletions app/code/Magento/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public function checkUpdate()

if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
foreach ($feedXml->channel->item as $item) {
if ($installDate <= strtotime((string)$item->pubDate)) {
$itemPublicationDate = strtotime((string)$item->pubDate);
if ($installDate <= $itemPublicationDate) {
$feedData[] = [
'severity' => (int)$item->severity,
'date_added' => $this->getDate((string)$item->pubDate),
'date_added' => date('Y-m-d H:i:s', $itemPublicationDate),
'title' => (string)$item->title,
'description' => (string)$item->description,
'url' => (string)$item->link,
Expand All @@ -161,17 +162,6 @@ public function checkUpdate()
return $this;
}

/**
* Retrieve DB date from RSS date
*
* @param string $rssDate
* @return string YYYY-MM-DD YY:HH:SS
*/
public function getDate($rssDate)
{
return gmdate('Y-m-d H:i:s', strtotime($rssDate));
}

/**
* Retrieve Update Frequency
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @author Magento Core Team <[email protected]>
*/
class PredispathAdminActionControllerObserver implements ObserverInterface
class PredispatchAdminActionControllerObserver implements ObserverInterface
{
/**
* @var \Magento\AdminNotification\Model\FeedFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch">
<observer name="adminnotification" instance="Magento\AdminNotification\Observer\PredispathAdminActionControllerObserver" />
<observer name="adminnotification" instance="Magento\AdminNotification\Observer\PredispatchAdminActionControllerObserver" />
</event>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function getChartUrl($directUrl = true)
*/
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
if ($_label != '') {
$period = new \DateTime($_label);
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
switch ($this->getDataHelper()->getParam('period')) {
case '24h':
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ public function setValue($value)
*/
protected function _convertDate($date)
{
$adminTimeZone = new \DateTimeZone(
$this->_localeDate->getConfigTimezone()
);
$timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC';
$adminTimeZone = new \DateTimeZone($timezone);
$formatter = new \IntlDateFormatter(
$this->localeResolver->getLocale(),
\IntlDateFormatter::SHORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ protected function _convertDate($date)
{
if ($this->getColumn()->getFilterTime()) {
try {
$adminTimeZone = new \DateTimeZone(
$this->_localeDate->getConfigTimezone()
);
$timezone = $this->getColumn()->getTimezone() !== false
? $this->_localeDate->getConfigTimezone() : 'UTC';
$adminTimeZone = new \DateTimeZone($timezone);
$simpleRes = new \DateTime($date, $adminTimeZone);
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
return $simpleRes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;

/**
* Class DateTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
*
*/
class DateTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Backend\Block\Widget\Grid\Column\Filter\Date */
protected $model;

/** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
protected $mathRandomMock;

/** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $localeResolverMock;

/** @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $dateTimeFormatterMock;

/** @var \Magento\Backend\Block\Widget\Grid\Column|\PHPUnit_Framework_MockObject_MockObject */
protected $columnMock;

/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $localeDateMock;

protected function setUp()
{
$this->mathRandomMock = $this->getMockBuilder('Magento\Framework\Math\Random')
->disableOriginalConstructor()
->setMethods(['getUniqueHash'])
->getMock();

$this->localeResolverMock = $this->getMockBuilder('Magento\Framework\Locale\ResolverInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->dateTimeFormatterMock = $this
->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->columnMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column')
->disableOriginalConstructor()
->setMethods(['getTimezone', 'getHtmlId', 'getId'])
->getMock();

$this->localeDateMock = $this->getMockBuilder('\Magento\Framework\Stdlib\DateTime\TimezoneInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $objectManagerHelper->getObject(
'Magento\Backend\Block\Widget\Grid\Column\Filter\Date',
[
'mathRandom' => $this->mathRandomMock,
'localeResolver' => $this->localeResolverMock,
'dateTimeFormatter' => $this->dateTimeFormatterMock,
'localeDate' => $this->localeDateMock
]
);
$this->model->setColumn($this->columnMock);
}

public function testGetHtmlSuccessfulTimestamp()
{
$uniqueHash = 'H@$H';
$id = 3;
$format = 'mm/dd/yyyy';
$yesterday = new \DateTime();
$yesterday->add(\DateInterval::createFromDateString('yesterday'));
$tomorrow = new \DateTime();
$tomorrow->add(\DateInterval::createFromDateString('tomorrow'));
$value = [
'locale' => 'en_US',
'from' => $yesterday->getTimestamp(),
'to' => $tomorrow->getTimestamp()
];

$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
$this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format);
$this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false);
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US');
$this->model->setColumn($this->columnMock);
$this->model->setValue($value);

$output = $this->model->getHtml();
$this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output);
$this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;

/**
* Class DateTimeTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
*
*/
class DatetimeTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime */
protected $model;

/** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
protected $mathRandomMock;

/** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $localeResolverMock;

/** @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $dateTimeFormatterMock;

/** @var \Magento\Backend\Block\Widget\Grid\Column|\PHPUnit_Framework_MockObject_MockObject */
protected $columnMock;

/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $localeDateMock;

protected function setUp()
{
$this->mathRandomMock = $this->getMockBuilder('Magento\Framework\Math\Random')
->disableOriginalConstructor()
->setMethods(['getUniqueHash'])
->getMock();

$this->localeResolverMock = $this->getMockBuilder('Magento\Framework\Locale\ResolverInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->dateTimeFormatterMock = $this
->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->columnMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column')
->disableOriginalConstructor()
->setMethods(['getTimezone', 'getHtmlId', 'getId'])
->getMock();

$this->localeDateMock = $this->getMockBuilder('\Magento\Framework\Stdlib\DateTime\TimezoneInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $objectManagerHelper->getObject(
'Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime',
[
'mathRandom' => $this->mathRandomMock,
'localeResolver' => $this->localeResolverMock,
'dateTimeFormatter' => $this->dateTimeFormatterMock,
'localeDate' => $this->localeDateMock
]
);
$this->model->setColumn($this->columnMock);
}

public function testGetHtmlSuccessfulTimestamp()
{
$uniqueHash = 'H@$H';
$id = 3;
$format = 'mm/dd/yyyy';
$yesterday = new \DateTime();
$yesterday->add(\DateInterval::createFromDateString('yesterday'));
$tomorrow = new \DateTime();
$tomorrow->add(\DateInterval::createFromDateString('tomorrow'));
$value = [
'locale' => 'en_US',
'from' => $yesterday->getTimestamp(),
'to' => $tomorrow->getTimestamp()
];

$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
$this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format);
$this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false);
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US');
$this->model->setColumn($this->columnMock);
$this->model->setValue($value);

$output = $this->model->getHtml();
$this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output);
$this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<argument name="align" xsi:type="string">left</argument>
<argument name="width" xsi:type="string">100px</argument>
<argument name="type" xsi:type="string">date</argument>
<argument name="timezone" xsi:type="boolean">false</argument>
<argument name="index" xsi:type="string">date_from</argument>
</arguments>
</block>
Expand All @@ -60,6 +61,7 @@
<argument name="align" xsi:type="string">left</argument>
<argument name="width" xsi:type="string">100px</argument>
<argument name="type" xsi:type="string">date</argument>
<argument name="timezone" xsi:type="boolean">false</argument>
<argument name="index" xsi:type="string">date_to</argument>
</arguments>
</block>
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Integration/Model/Oauth/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ protected function _construct()
*/
public function beforeSave()
{
$this->setUpdatedAt(time());
$this->validate();
parent::beforeSave();
return $this;
Expand Down
9 changes: 0 additions & 9 deletions app/code/Magento/User/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ class User extends AbstractModel implements StorageInterface, UserInterface
*/
protected $_encryptor;

/**
* @var \Magento\Framework\Stdlib\DateTime
*/
protected $dateTime;

/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
Expand All @@ -122,7 +117,6 @@ class User extends AbstractModel implements StorageInterface, UserInterface
* @param \Magento\Authorization\Model\RoleFactory $roleFactory
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param UserValidationRules $validationRules
Expand All @@ -139,15 +133,13 @@ public function __construct(
\Magento\Authorization\Model\RoleFactory $roleFactory,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Framework\Stdlib\DateTime $dateTime,
\Magento\Store\Model\StoreManagerInterface $storeManager,
UserValidationRules $validationRules,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->_encryptor = $encryptor;
$this->dateTime = $dateTime;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
$this->_userData = $userData;
$this->_config = $config;
Expand Down Expand Up @@ -216,7 +208,6 @@ public function __wakeup()
public function beforeSave()
{
$data = [
'modified' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
'extra' => serialize($this->getExtra()),
];

Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/User/Test/Unit/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ public function testBeforeSave()
$this->eventManagerMock->expects($this->any())->method('dispatch');
$this->model->setIsActive(1);
$actualData = $this->model->beforeSave()->getData();
$this->assertArrayHasKey('modified', $actualData);
$this->assertArrayHasKey('extra', $actualData);
$this->assertArrayHasKey('password', $actualData);
$this->assertArrayHasKey('is_active', $actualData);
Expand Down
Loading

0 comments on commit a87cf5b

Please sign in to comment.