TrackingLinkFormatterTest.php in Commerce Shipping 8.2
File
tests/src/Kernel/Formatter/TrackingLinkFormatterTest.php
View source
<?php
namespace Drupal\Tests\commerce_shipping\Kernel\Formatter;
use Drupal\commerce_shipping\Entity\Shipment;
use Drupal\commerce_shipping\Entity\ShippingMethod;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Tests\commerce_shipping\Kernel\ShippingKernelTestBase;
class TrackingLinkFormatterTest extends ShippingKernelTestBase {
protected $display;
protected function setUp() : void {
parent::setUp();
$this->display = commerce_get_entity_display('commerce_shipment', 'default', 'view');
$this->display
->setComponent('tracking_code', [
'type' => 'commerce_tracking_link',
'settings' => [],
]);
$this->display
->save();
}
public function testRender() {
$shipment = Shipment::create([
'type' => 'default',
'state' => 'ready',
'title' => 'Shipment',
]);
$shipping_method = ShippingMethod::create([
'name' => $this
->randomString(),
'status' => 1,
'plugin' => [
'target_plugin_id' => 'test',
'target_plugin_configuration' => [],
],
]);
$shipping_method
->save();
$shipment
->setShippingMethod($shipping_method);
$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);
}
protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display) {
$content = $display
->build($entity);
$content = $this
->render($content);
return $content;
}
}