You are here

public function ShipmentAdminTest::testShipmentTabAndOperation in Commerce Shipping 8.2

Tests that Shipments tab and operation visibility.

File

tests/src/FunctionalJavascript/ShipmentAdminTest.php, line 241

Class

ShipmentAdminTest
Tests the shipment admin UI.

Namespace

Drupal\Tests\commerce_shipping\FunctionalJavascript

Code

public function testShipmentTabAndOperation() {
  $this
    ->drupalGet($this->order
    ->toUrl());
  $this
    ->assertSession()
    ->linkExists('Shipments');
  $this
    ->assertSession()
    ->linkByHrefExists($this->shipmentUri);

  // Make the order type non shippable, and make sure the "Shipments" tab
  // doesn't show up.
  $order_type = OrderType::load('default');
  $order_type
    ->unsetThirdPartySetting('commerce_shipping', 'shipment_type');
  $order_type
    ->save();
  $this
    ->drupalGet($this->order
    ->toUrl());
  $this
    ->assertSession()
    ->linkNotExists('Shipments');
  $this
    ->assertSession()
    ->linkByHrefNotExists($this->shipmentUri);
  $order_type
    ->setThirdPartySetting('commerce_shipping', 'shipment_type', 'default');
  $order_type
    ->save();
  $this
    ->drupalGet($this->order
    ->toUrl());
  $this
    ->assertSession()
    ->linkExists('Shipments');

  // Ensure the "Shipments" operation is shown on the listing page.
  $this
    ->drupalGet($this->order
    ->toUrl('collection'));
  $this
    ->assertSession()
    ->linkByHrefExists($this->shipmentUri);
  $order_edit_link = $this->order
    ->toUrl('edit-form')
    ->toString();
  $this
    ->assertSession()
    ->linkByHrefExists($order_edit_link);

  // Make sure the "Shipments" tab isn't shown for cart orders.
  $this->order
    ->set('cart', TRUE);
  $this->order
    ->save();
  $this
    ->drupalGet($this->order
    ->toUrl());
  $this
    ->assertSession()
    ->linkNotExists('Shipments');

  // Ensure the "Shipments" operation is not shown on the cart listing page.
  $this
    ->drupalGet($this->order
    ->toUrl('collection'));

  // The order will have moved to the cart listing.
  $this
    ->assertSession()
    ->linkByHrefNotExists($order_edit_link);
  $this
    ->clickLink('Carts');
  $this
    ->assertSession()
    ->linkByHrefExists($order_edit_link);
  $this
    ->assertSession()
    ->linkNotExists('Shipments');
  $this
    ->assertSession()
    ->linkByHrefNotExists($this->shipmentUri);
}