You are here

public function TrackingLinkFormatterTest::testRender in Commerce Shipping 8.2

Tests the rendered output.

File

tests/src/Kernel/Formatter/TrackingLinkFormatterTest.php, line 40

Class

TrackingLinkFormatterTest
Tests the tracking link formatter.

Namespace

Drupal\Tests\commerce_shipping\Kernel\Formatter

Code

public function testRender() {
  $shipment = Shipment::create([
    'type' => 'default',
    'state' => 'ready',
    'title' => 'Shipment',
  ]);

  /** @var \Drupal\commerce_shipping\Entity\ShippingMethodInterface $shipping_method */
  $shipping_method = ShippingMethod::create([
    'name' => $this
      ->randomString(),
    'status' => 1,
    'plugin' => [
      'target_plugin_id' => 'test',
      'target_plugin_configuration' => [],
    ],
  ]);
  $shipping_method
    ->save();
  $shipment
    ->setShippingMethod($shipping_method);

  // No tracking code, no link.
  $this
    ->renderEntityFields($shipment, $this->display);
  $this
    ->assertNoRaw('https://www.drupal.org/');
  $tracking_code = 'TEST';
  $shipment
    ->setTrackingCode($tracking_code);
  $this
    ->renderEntityFields($shipment, $this->display);
  $this
    ->assertRaw('https://www.drupal.org/' . $tracking_code);
}