Shipping a product from the Magento admin UI
Today marks a new feature in the Magium Magento library. Now you can easily automate the shipping of a product in your functional test.
To do so you need to use a new action: Magium\Magento\Actions\Admin\Orders\Ship
.
Basic order shipping can be done with a single line of code, if you are on the order view information page.
$this->getAction(Ship::ACTION)->execute();
Adding a tracking number requires the use of a SubAction called AddTrackingNumber. Using it is quite simple.
$action = $this->getAction(Ship::ACTION);
/* @var $action \Magium\Magento\Actions\Admin\Orders\Ship */
$addTrackingNumber = $this->getAction(Ship\AddTrackingNumber::ACTION);
$addTrackingNumber->setCarrier(Ship\AddTrackingNumber::CARRIER_UPS);
$addTrackingNumber->setTitle('UPS');
$addTrackingNumber->setNumber('abcdefg12345678');
$action->addSubAction($addTrackingNumber);
$action->execute();
You can also use carrier labels of you like
$action = $this->getAction(Ship::ACTION);
/* @var $action \Magium\Magento\Actions\Admin\Orders\Ship */
$addTrackingNumber = $this->getAction(Ship\AddTrackingNumber::ACTION);
$addTrackingNumber->setCarrier('label=UPS);
$addTrackingNumber->setTitle('UPS');
$addTrackingNumber->setNumber('abcdefg12345678');
$action->addSubAction($addTrackingNumber);
$action->execute();
Piece of cake.
The last thing you might want to do is validate that the information has been properly entered. You can do that with a little bit of Magium script afterwards
// Navigate to the Shipments tab
$this->getNavigator(Tab::NAVIGATOR)->navigateTo('Shipments::');
// Find the first shipment row
$this->webdriver->byXpath('//table[@id="order_shipments_table"]/descendant::tr[@title]')->click();
// Find the tracking ID (helpfully wrapped in an HTML element
$this->byText('abcdefg12345678');