View source
<?php
namespace Drupal\Tests\uc_fulfillment\Functional;
use Drupal\uc_order\Entity\Order;
use Drupal\uc_order\Entity\OrderProduct;
class ShipmentTest extends FulfillmentTestBase {
public function testShipmentsUi() {
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$method = $this
->createPaymentMethod('other');
$order = Order::create([
'uid' => 0,
'primary_email' => $this
->randomMachineName() . '@example.org',
'payment_method' => $method['id'],
]);
$products = [];
for ($i = 1; $i <= 4; $i++) {
$product = $this
->createProduct([
'uid' => $this->adminUser
->id(),
'promote' => 0,
]);
$order->products[$i] = OrderProduct::create([
'nid' => $product->nid->target_id,
'title' => $product->title->value,
'model' => $product->model,
'qty' => 1,
'cost' => $product->cost->value,
'price' => $product->price->value,
'weight' => $product->weight,
'data' => [],
]);
$order->products[$i]->data->shippable = 1;
}
$order
->save();
$order = Order::load($order
->id());
uc_payment_enter($order
->id(), 'other', $order
->getTotal());
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$this
->submitForm([
'shipping_types[small_package][table][1][checked]' => 1,
'shipping_types[small_package][table][2][checked]' => 1,
'shipping_types[small_package][table][3][checked]' => 1,
'shipping_types[small_package][table][4][checked]' => 1,
], 'Create one package');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$assert
->linkExists('Ship');
$this
->clickLink('Ship');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/new?pkgs=1');
foreach ($order->products as $sequence => $item) {
$assert
->pageTextContains($item->qty->value . ' x ' . $item->model->value, 'Product quantity x SKU found.');
}
foreach ($order->products as $sequence => $item) {
$assert
->fieldValueEquals('shipping_types[small_package][table][1][checked]', 1);
}
$assert
->fieldValueEquals('method', 'manual');
$this
->drupalGet('admin/store/orders/view');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments');
$this
->clickLink('Ship');
$assert
->statusCodeEquals(200);
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/new');
$assert
->pageTextContains('No shipments have been made for this order.', 'Ship action found.');
$assert
->pageTextContains($order->products[1]->qty->value . ' x ' . $order->products[1]->model->value, 'Product quantity x SKU found.');
$assert
->fieldValueEquals('method', 'manual');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Ship packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/ship?method_id=manual&0=1');
$assert
->pageTextContains('Origin address', 'Origin address pane found.');
$assert
->pageTextContains('Destination address', 'Destination address pane found.');
$assert
->pageTextContains('Package 1', 'Packages data pane found.');
$assert
->pageTextContains('Shipment data', 'Shipment data pane found.');
$edit = $this
->populateShipmentForm();
$this
->submitForm($edit, 'Save shipment');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->pageTextContains('Shipment ID', 'Shipment summary found.');
$assert
->pageTextContains('1234567890ABCD', 'Shipment data present.');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments/1');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1/edit');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1/packing_slip');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1/print');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/1/edit');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments/1/edit');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->linkExists('Print');
$this
->clickLink('Print');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/1/print');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->linkExists('Packing slip');
$this
->clickLink('Packing slip');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/1/packing_slip');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments');
$assert
->linkExists('Delete');
$this
->clickLink('Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/1/delete');
$assert
->pageTextContains('The shipment will be canceled and the packages it contains will be available for reshipment.', 'Deletion confirm question found.');
$this
->clickLink('Cancel');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments');
$this
->clickLink('Delete');
$this
->submitForm([], 'Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/new');
$assert
->pageTextContains('Shipment 1 has been deleted.', 'Shipment deleted message found.');
}
}