You are here

public function GeofieldWidgetTest::testDmsWidget in Geofield 8

Tests the DMS widget.

File

tests/src/Functional/GeofieldWidgetTest.php, line 250

Class

GeofieldWidgetTest
Tests the Geofield widgets.

Namespace

Drupal\Tests\geofield\Functional

Code

public function testDmsWidget() {
  EntityFormDisplay::load('entity_test.entity_test.default')
    ->setComponent($this->fieldStorage
    ->getName(), [
    'type' => 'geofield_dms',
  ])
    ->save();

  // Create an entity.
  $entity = EntityTest::create([
    'user_id' => 1,
    'name' => $this
      ->randomMachineName(),
  ]);
  $entity
    ->save();

  // Check basic data.
  $this
    ->drupalGet('entity_test/manage/' . $entity
    ->id() . '/edit');
  $this->assertSession
    ->pageTextContains('geofield_field');

  // Add valid data.
  $edit = [
    'name[0][value]' => 'Arnedo',
    'geofield_field[0][value][lat][orientation]' => 'N',
    'geofield_field[0][value][lat][degrees]' => 42,
    'geofield_field[0][value][lat][minutes]' => 13,
    'geofield_field[0][value][lat][seconds]' => 32,
    'geofield_field[0][value][lon][orientation]' => 'W',
    'geofield_field[0][value][lon][degrees]' => 2,
    'geofield_field[0][value][lon][minutes]' => 6,
    'geofield_field[0][value][lon][seconds]' => 7,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertFieldValues($entity, 'geofield_field', [
    'POINT (-2.1019444444 42.2255555556)',
  ]);

  // Add invalid data.
  $edit = [
    'name[0][value]' => 'Arnedo',
    'geofield_field[0][value][lat][orientation]' => 'N',
    'geofield_field[0][value][lat][degrees]' => 72,
    'geofield_field[0][value][lat][minutes]' => 555,
    'geofield_field[0][value][lat][seconds]' => 32.5,
    'geofield_field[0][value][lon][orientation]' => 'W',
    'geofield_field[0][value][lon][degrees]' => 2,
    'geofield_field[0][value][lon][minutes]' => 'non numeric',
    'geofield_field[0][value][lon][seconds]' => 7,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this->assertSession
    ->pageTextContains('geofield_field must be lower than or equal to 59.');
  $this->assertSession
    ->pageTextContains('geofield_field is not a valid number.');
  $this->assertSession
    ->pageTextContains('geofield_field must be a number.');
}