Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPS Shipment Tracking: Show "Delivered On" only when package has actually been delivered #29080

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Ups\Plugin\Block\DataProviders\Tracking;

use Magento\Ups\Model\Carrier;
use Magento\Shipping\Model\Tracking\Result\Status;
use Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle as Subject;

/**
* Plugin to change the "Delivery on" title to a customized value for UPS
*/
class ChangeTitle
{
/**
* Modify title only when UPS is used as carrier
*
* @param Subject $subject
* @param \Magento\Framework\Phrase|string $result
* @param Status $trackingStatus
* @return \Magento\Framework\Phrase|string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetTitle(Subject $subject, $result, Status $trackingStatus)
{
if ($trackingStatus->getCarrier() === Carrier::CODE) {
$result = __('Status Updated On:');
}
return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Ups\Test\Unit\Plugin\Block\DataProviders\Tracking;

use Magento\Ups\Model\Carrier;
use Magento\Ups\Plugin\Block\DataProviders\Tracking\ChangeTitle;
use Magento\Framework\Phrase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle;
use Magento\Shipping\Model\Tracking\Result\Status;
use Magento\Ups\Model\Carrier as UpsCarrier;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Unit Test for @see ChangeTitle
*/
class ChangeTitleTest extends TestCase
{
/**
* @var ChangeTitle|MockObject
*/
private $plugin;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManagerHelper = new ObjectManager($this);
$this->plugin = $objectManagerHelper->getObject(ChangeTitle::class);
}

/**
* Check if DeliveryDateTitle was changed if the carrier is UPS
*
* @param string $carrierCode
* @param string $originalResult
* @param Phrase|string $finalResult
* @dataProvider testAfterGetTitleDataProvider
*/
public function testAfterGetTitle(string $carrierCode, string $originalResult, $finalResult)
{
/** @var DeliveryDateTitle|MockObject $subjectMock */
$subjectMock = $this->getMockBuilder(DeliveryDateTitle::class)
->disableOriginalConstructor()
->getMock();

/** @var Status|MockObject $trackingStatusMock */
$trackingStatusMock = $this->getMockBuilder(Status::class)
->disableOriginalConstructor()
->setMethods(['getCarrier'])
->getMock();
$trackingStatusMock->expects($this::once())
->method('getCarrier')
->willReturn($carrierCode);

$actual = $this->plugin->afterGetTitle($subjectMock, $originalResult, $trackingStatusMock);

$this->assertEquals($finalResult, $actual);
}

/**
* Data provider
*
* @return array
*/
public function testAfterGetTitleDataProvider(): array
{
return [
[Carrier::CODE, 'Original Title', __('Status Updated On:')],
['not-fedex', 'Original Title', 'Original Title'],
];
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Ups/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle">
<plugin name="ups_update_delivery_date_title" type="Magento\Ups\Plugin\Block\DataProviders\Tracking\ChangeTitle"/>
</type>
</config>