public function GeofieldWidgetTest::testBoundsWidget in Geofield 8
Tests the bounds widget.
File
- tests/
src/ Functional/ GeofieldWidgetTest.php, line 200
Class
- GeofieldWidgetTest
- Tests the Geofield widgets.
Namespace
Drupal\Tests\geofield\FunctionalCode
public function testBoundsWidget() {
EntityFormDisplay::load('entity_test.entity_test.default')
->setComponent($this->fieldStorage
->getName(), [
'type' => 'geofield_bounds',
])
->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');
$this->assertSession
->pageTextContains('Top');
$this->assertSession
->pageTextContains('Right');
$this->assertSession
->pageTextContains('Bottom');
$this->assertSession
->pageTextContains('Left');
// Add valid bounds.
$edit = [
'name[0][value]' => 'Arnedo - Valladolid',
'geofield_field[0][value][top]' => 42.2257,
'geofield_field[0][value][right]' => -2.1021,
'geofield_field[0][value][bottom]' => 41.6523,
'geofield_field[0][value][left]' => -4.7245,
];
$this
->submitForm($edit, 'Save');
$this
->assertFieldValues($entity, 'geofield_field', [
'POLYGON ((-2.1021 42.2257, -2.1021 41.6523, -4.7245 41.6523, -4.7245 42.2257, -2.1021 42.2257))',
]);
// Add invalid bounds.
$edit = [
'name[0][value]' => 'Invalid',
'geofield_field[0][value][top]' => 42.2257,
'geofield_field[0][value][right]' => 'non numeric',
'geofield_field[0][value][bottom]' => 45.2257,
'geofield_field[0][value][left]' => 750,
];
$this
->submitForm($edit, 'Save');
$this->assertSession
->pageTextContains('geofield_field: Right is not valid.');
$this->assertSession
->pageTextContains('geofield_field: Left is out of bounds');
$this->assertSession
->pageTextContains('geofield_field: Top must be greater than Bottom.');
}