View source
<?php
namespace Drupal\Tests\uc_fulfillment\Functional;
use Drupal\uc_order\Entity\Order;
use Drupal\uc_order\Entity\OrderProduct;
class PackageTest extends FulfillmentTestBase {
public function testPackagesUi() {
$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/view');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages');
$this
->clickLink('Package');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains("This order's products have not been organized into packages.", 'Package action found.');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
foreach ($order->products as $sequence => $item) {
$assert
->pageTextContains($item->title->value, 'Product title found.');
$assert
->pageTextContains($item->model->value, 'Product SKU found.');
$assert
->fieldValueEquals('shipping_types[small_package][table][' . $sequence . '][checked]', '');
}
$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,
], 'Cancel');
$assert
->addressEquals('admin/store/orders/' . $order
->id());
$this
->clickLink('Packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains("This order's products have not been organized into packages.", 'Package action found.');
$this
->submitForm([], 'Create one package');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains('Packages must contain at least one product.', 'Validation that there must be products in a package.');
$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');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages');
foreach ($order->products as $sequence => $item) {
$assert
->pageTextContains($item->qty->value . ' x ' . $item->model->value, 'Product quantity x SKU found.');
}
$assert
->linkExists('Create packages');
$this
->clickLink('Create packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains('There are no products available for this type of package.', 'Create packages local action found.');
$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.');
}
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages/1/edit');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages/1/edit');
foreach ($order->products as $sequence => $item) {
$assert
->fieldValueEquals('products[' . $sequence . '][checked]', 1);
}
$this
->submitForm([], 'Save');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$assert
->linkExists('Delete');
$this
->clickLink('Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/1/delete');
$assert
->pageTextContains('The products it contains will be available for repackaging.', 'Deletion confirm question found.');
$this
->clickLink('Cancel');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages');
$this
->clickLink('Delete');
$this
->submitForm([], 'Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains('Package 1 has been deleted.', 'Package deleted message found.');
foreach ($order->products as $sequence => $item) {
$assert
->fieldValueEquals('shipping_types[small_package][table][' . $sequence . '][checked]', '');
}
$this
->submitForm([
'shipping_types[small_package][table][1][checked]' => 1,
'shipping_types[small_package][table][2][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.');
$assert
->pageTextContains($order->products[2]->qty->value . ' x ' . $order->products[2]->model->value, 'Product quantity x SKU found.');
$assert
->pageTextNotContains($order->products[3]->qty->value . ' x ' . $order->products[3]->model->value, 'Product quantity x SKU not found.');
$assert
->pageTextNotContains($order->products[4]->qty->value . ' x ' . $order->products[4]->model->value, 'Product quantity x SKU not found.');
$assert
->linkExists('Create packages');
$this
->clickLink('Create packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextNotContains($order->products[1]->model->value, 'Product SKU not found.');
$assert
->pageTextNotContains($order->products[2]->model->value, 'Product SKU not found.');
$assert
->pageTextContains($order->products[3]->model->value, 'Product SKU found.');
$assert
->pageTextContains($order->products[4]->model->value, 'Product SKU found.');
$this
->submitForm([
'shipping_types[small_package][table][3][checked]' => 1,
'shipping_types[small_package][table][4][checked]' => 1,
], 'Create one package');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/packages');
foreach ($order->products as $sequence => $item) {
$assert
->pageTextContains($item->qty->value . ' x ' . $item->model->value, 'Product quantity x SKU found.');
}
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/new?pkgs=2');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/shipments/new?pkgs=3');
$this
->clickLink('Delete');
$this
->submitForm([], 'Delete');
$assert
->pageTextContains('Package 2 has been deleted.', 'Package deleted message found.');
$this
->clickLink('Delete');
$this
->submitForm([], 'Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages/new');
$assert
->pageTextContains('Package 3 has been deleted.', 'Package deleted message found.');
$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,
], 'Make packages');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/packages');
foreach ($order->products as $sequence => $item) {
$assert
->pageTextContains($item->qty->value . ' x ' . $item->model->value, 'Product quantity x SKU found.');
}
}
}