You are here

protected function LocationTest::setUp in farmOS 2.x

Same name in this branch
  1. 2.x modules/core/location/tests/src/Functional/LocationTest.php \Drupal\Tests\farm_location\Functional\LocationTest::setUp()
  2. 2.x modules/core/location/tests/src/Kernel/LocationTest.php \Drupal\Tests\farm_location\Kernel\LocationTest::setUp()

Overrides KernelTestBase::setUp

File

modules/core/location/tests/src/Kernel/LocationTest.php, line 74

Class

LocationTest
Tests for farmOS location logic.

Namespace

Drupal\Tests\farm_location\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this->wktGenerator = \Drupal::service('geofield.wkt_generator');
  $this->assetLocation = \Drupal::service('asset.location');
  $this->logLocation = \Drupal::service('log.location');
  $this
    ->installEntitySchema('asset');
  $this
    ->installEntitySchema('log');
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig([
    'farm_location_test',
  ]);

  // Generate random WKT polygons.
  for ($i = 0; $i < 3; $i++) {
    $segments = rand(3, 7);
    $this->polygons[] = $this
      ->reduceWkt($this->wktGenerator
      ->wktGeneratePolygon(NULL, $segments));
  }

  // Generate location assets.
  for ($i = 0; $i < 3; $i++) {
    $location = Asset::create([
      'type' => 'location',
      'name' => $this
        ->randomMachineName(),
      'status' => 'active',
      'intrinsic_geometry' => $this->polygons[$i],
      'is_fixed' => TRUE,
    ]);
    $location
      ->save();
    $this->locations[] = $location;
  }
}