Skip to content

Commit

Permalink
UPS Shipment Tracking: Change "Delivered On" title
Browse files Browse the repository at this point in the history
  • Loading branch information
danbtl committed Aug 20, 2020
1 parent 18da36b commit 5031159
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
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>

0 comments on commit 5031159

Please sign in to comment.