You are here

protected function GeolocationGoogleGeocoderWidgetTest::setUp in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php \Drupal\Tests\geolocation\FunctionalJavascript\GeolocationGoogleGeocoderWidgetTest::setUp()
  2. 8.2 tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php \Drupal\Tests\geolocation\FunctionalJavascript\GeolocationGoogleGeocoderWidgetTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php, line 33

Class

GeolocationGoogleGeocoderWidgetTest
Tests the Google Geocoder Widget functionality.

Namespace

Drupal\Tests\geolocation\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $this->adminUser = $this
    ->drupalCreateUser([
    'bypass node access',
    'administer nodes',
  ]);
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);

  // Add the geolocation field to the article content type.
  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_googlegeocoder',
    'settings' => [
      'allow_override_map_settings' => TRUE,
    ],
  ])
    ->save();
  EntityViewDisplay::load('node.article.default')
    ->setComponent('field_geolocation', [
    'type' => 'geolocation_map',
    'settings' => [
      'use_overridden_map_settings' => TRUE,
    ],
    'weight' => 1,
  ])
    ->save();
  $entity_test_storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $entity_test_storage
    ->create([
    'id' => 1,
    'title' => 'foo bar baz',
    'body' => 'test test',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 52,
      'lng' => 47,
    ],
  ])
    ->save();
  $entity_test_storage
    ->create([
    'id' => 2,
    'title' => 'foo test',
    'body' => 'bar test',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 53,
      'lng' => 48,
    ],
  ])
    ->save();
  $entity_test_storage
    ->create([
    'id' => 3,
    'title' => 'bar',
    'body' => 'test foobar',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 54,
      'lng' => 49,
    ],
  ])
    ->save();
  $entity_test_storage
    ->create([
    'id' => 4,
    'title' => 'Custom map settings',
    'body' => 'This content tests if the custom map settings are respected',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 54,
      'lng' => 49,
      'data' => [
        'google_map_settings' => [
          'height' => '376px',
          'width' => '229px',
        ],
      ],
    ],
  ])
    ->save();
}