View source
<?php
namespace Drupal\Tests\geolocation\FunctionalJavascript;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
class GeolocationTokenFormatterTest extends GeolocationJavascriptTestBase {
public static $modules = [
'node',
'field',
'filter',
'geolocation',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
FieldStorageConfig::create([
'field_name' => 'field_geolocation',
'entity_type' => 'node',
'type' => 'geolocation',
])
->save();
FieldConfig::create([
'field_name' => 'field_geolocation',
'label' => 'Geolocation',
'entity_type' => 'node',
'bundle' => 'article',
])
->save();
EntityFormDisplay::load('node.article.default')
->setComponent('field_geolocation', [
'type' => 'geolocation_latlng',
])
->save();
EntityViewDisplay::load('node.article.default')
->setComponent('field_geolocation', [
'type' => 'geolocation_latlng',
'weight' => 1,
])
->save();
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('node');
$entity_test_storage
->create([
'id' => 1,
'title' => 'Test node 1',
'body' => 'test test',
'type' => 'article',
'field_geolocation' => [
'lat' => 52,
'lng' => 47,
'data' => [
'title' => 'My home',
'extraconfig' => 'myvalue',
],
],
])
->save();
}
public function testGeocoderTokenizedTestReplacement() {
$this
->drupalGet('node/1');
$this
->assertSession()
->responseContains('<span class="geolocation-latlng">52, 47</span>');
EntityViewDisplay::load('node.article.default')
->setComponent('field_geolocation', [
'type' => 'geolocation_token',
'settings' => [
'tokenized_text' => [
'value' => 'Title: [geolocation_current_item:data:title] Lat/Lng: [geolocation_current_item:lat]/[geolocation_current_item:lng]',
'format' => filter_default_format(),
],
],
'weight' => 1,
])
->save();
$this
->drupalGet('node/1');
$this
->assertSession()
->responseContains('Lat/Lng: 52/47');
$this
->assertSession()
->responseContains('Title: My home');
}
}