You are here

public function LocationTest::testLocationFieldVisibility in farmOS 2.x

Test geometry and location field visibility.

File

modules/core/location/tests/src/Functional/LocationTest.php, line 68

Class

LocationTest
Tests for farmOS location logic.

Namespace

Drupal\Tests\farm_location\Functional

Code

public function testLocationFieldVisibility() {

  // Go to the asset edit form.
  $this
    ->drupalGet('asset/' . $this->asset
    ->id() . '/edit');

  // Test that current geometry and current location fields are all hidden.
  $this
    ->assertSession()
    ->fieldNotExists('geometry[0][value]');
  $this
    ->assertSession()
    ->fieldNotExists('location[0][target_id]');

  // Test that intrinsic_geometry field is hidden.
  $page = $this
    ->getSession()
    ->getPage();
  $intrinsic_geometry_field = $page
    ->findById('edit-intrinsic-geometry-wrapper');
  $this
    ->assertNotEmpty($intrinsic_geometry_field);
  $this
    ->assertFalse($intrinsic_geometry_field
    ->isVisible());

  // Go to the asset view page.
  $this
    ->drupalGet('asset/' . $this->asset
    ->id());

  // Test that current geometry and location fields are visible.
  $this
    ->assertSession()
    ->pageTextContains("Current geometry");
  $this
    ->assertSession()
    ->pageTextContains("Current location");

  // Test that the intrinsic geometry field is hidden.
  $this
    ->assertSession()
    ->pageTextNotContains("Intrinsic geometry");

  // Make the asset fixed.
  $this->asset->is_fixed = TRUE;
  $this->asset
    ->save();

  // Go back to the edit form.
  $this
    ->drupalGet('asset/' . $this->asset
    ->id() . '/edit');

  // Test that the intrinsic geometry field is visible.
  $page = $this
    ->getSession()
    ->getPage();
  $intrinsic_geometry_field = $page
    ->findById('edit-intrinsic-geometry-wrapper');
  $this
    ->assertNotEmpty($intrinsic_geometry_field);
  $this
    ->assertTrue($intrinsic_geometry_field
    ->isVisible());
}