-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPS Shipment Tracking: Change "Delivered On" title
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/code/Magento/Ups/Plugin/Block/DataProviders/Tracking/ChangeTitle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
app/code/Magento/Ups/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters