You are here

public function ShipmentAdminTest::testShipmentListing in Commerce Shipping 8.2

Tests the Shipments listing with and without the view.

File

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

Class

ShipmentAdminTest
Tests the shipment admin UI.

Namespace

Drupal\Tests\commerce_shipping\FunctionalJavascript

Code

public function testShipmentListing() {
  $this
    ->drupalGet($this->order
    ->toUrl());
  $this
    ->assertSession()
    ->linkExists('Shipments');
  $this
    ->assertSession()
    ->linkByHrefExists($this->shipmentUri);
  $this
    ->clickLink('Shipments');
  $this
    ->assertSession()
    ->pageTextContains('There are no shipments yet.');
  $shipment = $this
    ->createEntity('commerce_shipment', [
    'type' => 'default',
    'title' => $this
      ->randomString(16),
    'package_type_id' => 'package_type_a',
    'order_id' => $this->order
      ->id(),
    'amount' => new Price('10', 'USD'),
    'items' => [
      new ShipmentItem([
        'order_item_id' => 1,
        'title' => 'Test shipment item label',
        'quantity' => 1,
        'weight' => new Weight(0, 'g'),
        'declared_value' => new Price('1', 'USD'),
      ]),
    ],
    'tracking_code' => 'CODE',
  ]);
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->pageTextNotContains('There are no shipments yet.');
  $this
    ->assertSession()
    ->pageTextContains($shipment
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($shipment
    ->getTrackingCode());

  // Ensure the listing works without the view.
  View::load('order_shipments')
    ->delete();
  \Drupal::service('router.builder')
    ->rebuild();
  $this
    ->drupalGet($this->shipmentUri);
  $this
    ->assertSession()
    ->pageTextNotContains('There are no shipments yet.');
  $this
    ->assertSession()
    ->pageTextContains($shipment
    ->label());
  $shipment
    ->delete();
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->pageTextContains('There are no shipments yet.');
}