|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Shipping\Block\Adminhtml\Order; |
| 7 | + |
| 8 | +use Magento\Backend\Block\Template; |
| 9 | +use Magento\Framework\ObjectManagerInterface; |
| 10 | +use Magento\Framework\Registry; |
| 11 | +use Magento\Sales\Api\Data\OrderInterfaceFactory; |
| 12 | +use Magento\Sales\Api\Data\ShipmentTrackInterface; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Class verifies packaging popup. |
| 18 | + * |
| 19 | + * @magentoAppArea adminhtml |
| 20 | + */ |
| 21 | +class AddToPackageTest extends TestCase |
| 22 | +{ |
| 23 | + /** @var ObjectManagerInterface */ |
| 24 | + private $objectManager; |
| 25 | + |
| 26 | + /** @var Registry */ |
| 27 | + private $registry; |
| 28 | + /** |
| 29 | + * @var OrderInterfaceFactory|mixed |
| 30 | + */ |
| 31 | + private $orderFactory; |
| 32 | + |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 36 | + $this->registry = $this->objectManager->get(Registry::class); |
| 37 | + $this->orderFactory = $this->objectManager->get(OrderInterfaceFactory::class); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test that Packaging popup renders |
| 42 | + * |
| 43 | + * @magentoDataFixture Magento/GraphQl/Sales/_files/customer_order_with_ups_shipping.php |
| 44 | + */ |
| 45 | + public function testGetCommentsHtml() |
| 46 | + { |
| 47 | + /** @var Template $block */ |
| 48 | + $block = $this->objectManager->get(Packaging::class); |
| 49 | + |
| 50 | + $order = $this->orderFactory->create()->loadByIncrementId('100000001'); |
| 51 | + |
| 52 | + /** @var ShipmentTrackInterface $track */ |
| 53 | + $shipment = $order->getShipmentsCollection()->getFirstItem(); |
| 54 | + |
| 55 | + $this->registry->register('current_shipment', $shipment); |
| 56 | + |
| 57 | + $block->setTemplate('Magento_Shipping::order/packaging/popup.phtml'); |
| 58 | + $html = $block->toHtml(); |
| 59 | + $expectedNeedle = "packaging.setItemQtyCallback(function(itemId){ |
| 60 | + var item = $$('[name=\"shipment[items]['+itemId+']\"]')[0], |
| 61 | + itemTitle = $('order_item_' + itemId + '_title'); |
| 62 | + if (!itemTitle && !item) { |
| 63 | + return 0; |
| 64 | + } |
| 65 | + if (item && !isNaN(item.value)) { |
| 66 | + return item.value; |
| 67 | + } |
| 68 | + });"; |
| 69 | + $this->assertStringContainsString($expectedNeedle, $html); |
| 70 | + } |
| 71 | +} |
0 commit comments