LocationFunctionalTestTrait.php in farmOS 2.x
File
modules/core/location/tests/src/Functional/LocationFunctionalTestTrait.php
View source
<?php
namespace Drupal\Tests\farm_location\Functional;
trait LocationFunctionalTestTrait {
protected $user;
protected $location;
protected $asset;
protected $log;
public function setUp() : void {
parent::setUp();
$entity_type_manager = $this->container
->get('entity_type.manager');
$asset_storage = $entity_type_manager
->getStorage('asset');
$log_storage = $entity_type_manager
->getStorage('log');
$this->user = $this
->createUser([
'administer assets',
'administer log',
]);
$this
->drupalLogin($this->user);
$this->location = $asset_storage
->create([
'type' => 'location',
'name' => $this
->randomMachineName(),
'intrinsic_geometry' => $this
->reduceWkt(\Drupal::service('geofield.wkt_generator')
->wktGeneratePolygon(NULL, 5)),
'is_fixed' => TRUE,
]);
$this->location
->save();
$this->asset = $asset_storage
->create([
'type' => 'object',
'name' => $this
->randomMachineName(),
]);
$this->asset
->save();
$this->log = $log_storage
->create([
'type' => 'movement',
'status' => 'done',
'asset' => [
'target_id' => $this->asset
->id(),
],
'location' => [
'target_id' => $this->location
->id(),
],
'is_movement' => TRUE,
]);
$this->log
->save();
}
}