TrackingTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Test\Unit\Block\Adminhtml\Order;
  7. class TrackingTest extends \PHPUnit\Framework\TestCase
  8. {
  9. public function testLookup()
  10. {
  11. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  12. $shipment = new \Magento\Framework\DataObject(['store_id' => 1]);
  13. $registry = $this->createPartialMock(\Magento\Framework\Registry::class, ['registry']);
  14. $registry->expects(
  15. $this->once()
  16. )->method(
  17. 'registry'
  18. )->with(
  19. 'current_shipment'
  20. )->will(
  21. $this->returnValue($shipment)
  22. );
  23. $carrier = $this->createPartialMock(
  24. \Magento\OfflineShipping\Model\Carrier\Freeshipping::class,
  25. ['isTrackingAvailable', 'getConfigData']
  26. );
  27. $carrier->expects($this->once())->method('isTrackingAvailable')->will($this->returnValue(true));
  28. $carrier->expects(
  29. $this->once()
  30. )->method(
  31. 'getConfigData'
  32. )->with(
  33. 'title'
  34. )->will(
  35. $this->returnValue('configdata')
  36. );
  37. $config = $this->createPartialMock(\Magento\Shipping\Model\Config::class, ['getAllCarriers']);
  38. $config->expects(
  39. $this->once()
  40. )->method(
  41. 'getAllCarriers'
  42. )->with(
  43. 1
  44. )->will(
  45. $this->returnValue(['free' => $carrier])
  46. );
  47. /** @var \Magento\Shipping\Block\Adminhtml\Order\Tracking $model */
  48. $model = $helper->getObject(
  49. \Magento\Shipping\Block\Adminhtml\Order\Tracking::class,
  50. ['registry' => $registry, 'shippingConfig' => $config]
  51. );
  52. $this->assertEquals(['custom' => 'Custom Value', 'free' => 'configdata'], $model->getCarriers());
  53. }
  54. }