View source
<?php
namespace Drupal\Tests\uc_fulfillment\Functional;
class FulfillmentTest extends FulfillmentTestBase {
public function testFulfillmentProcess() {
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$method = $this
->createPaymentMethod('other');
$order = $this
->createOrder([
'uid' => 0,
'payment_method' => $method['id'],
'primary_email' => $this
->randomMachineName() . '@example.org',
]);
$order->products[1]->data->shippable = 1;
$order
->save();
uc_payment_enter($order
->id(), 'other', $order
->getTotal());
$this
->drupalGet('admin/store/orders/' . $order
->id());
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages');
$this
->clickLink('Packages');
$assert
->statusCodeEquals(200);
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains("This order's products have not been organized into packages.", 'Packages tab found.');
$this
->drupalGet('admin/store/orders/' . $order
->id());
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments');
$this
->clickLink('Shipments');
$assert
->statusCodeEquals(200);
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains("This order's products have not been organized into packages.", 'Shipments tab found.');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$assert
->pageTextContains($order->products[1]->title->value, 'Product title found.');
$assert
->pageTextContains($order->products[1]->model->value, 'Product sku found.');
$assert
->fieldValueEquals('shipping_types[small_package][table][' . $order
->id() . '][checked]', '');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Create one package');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages');
$assert
->pageTextContains($order->products[1]->qty->value . ' x ' . $order->products[1]->model->value, 'Product quantity x SKU found.');
$this
->drupalGet('admin/store/orders/' . $order
->id());
$this
->clickLink('Shipments');
$assert
->statusCodeEquals(200);
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/shipments/new');
$assert
->pageTextContains('No shipments have been made for this order.', 'New shipments page reached.');
$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());
$assert
->pageTextContains('Tracking numbers:', 'Tracking order pane found.');
$assert
->pageTextContains('1234567890ABCD', 'Tracking number found.');
}
}