View source
<?php
namespace Drupal\Tests\geocoder_geofield\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
class GeocoderGeofieldIntegrationTest extends KernelTestBase {
public static $modules = [
'geofield',
'field',
'geocoder_geofield',
'geocoder_geofield_test',
'geocoder',
'geocoder_field',
'entity_test',
'text',
'user',
'filter',
];
public function testGeofield() {
$this
->installEntitySchema('entity_test');
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'type' => 'text',
'field_name' => 'foo',
])
->save();
$remote_field = FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => 'foo',
])
->save();
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'type' => 'geofield',
'field_name' => 'bar',
])
->save();
$field = FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => 'bar',
'third_party_settings' => [
'geocoder_field' => [
'method' => 'source',
'geocode_field' => 'foo',
'plugins' => [
'test_provider',
],
'dumper' => 'wkt',
'delta_handling' => 'default',
'failure' => [
'handling' => 'preserve',
'status_message' => FALSE,
'log' => FALSE,
],
],
],
]);
$field
->save();
$entity = EntityTest::create([
'name' => 'Baz',
'bundle' => 'entity_test',
]);
$entity->foo->value = 'Gotham City';
$entity
->save();
$this
->assertSame('POINT(40.000000 20.000000)', $entity->bar->value);
$entity->foo->value = 'SOME MESS';
$entity
->save();
$this
->assertSame('POINT(40.000000 20.000000)', $entity->bar->value);
$field
->setThirdPartySetting('geocoder_field', 'failure', [
'handling' => 'empty',
'status_message' => FALSE,
'log' => FALSE,
])
->save();
$entity = EntityTest::load($entity
->id());
$entity->foo->value = 'SOME NEW MESS';
$entity
->save();
$this
->assertNull($entity->bar->value);
}
}