You are here

protected function GeolocationJavascriptTest::setUp in Geolocation Field 8

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

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/GeolocationJavascriptTest.php, line 42

Class

GeolocationJavascriptTest
Tests the JavaScript functionality.

Namespace

Drupal\Tests\geolocation\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $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();
  $this->container
    ->get('views.views_data')
    ->clear();
  ViewTestData::createTestViews(get_class($this), [
    'geolocation_test_views',
  ]);
  $node_storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $node_storage
    ->create([
    'id' => 1,
    'title' => 'foo bar baz',
    'body' => 'test test',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 52,
      'lng' => 47,
    ],
  ])
    ->save();
  $node_storage
    ->create([
    'id' => 2,
    'title' => 'foo test',
    'body' => 'bar test',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 53,
      'lng' => 48,
    ],
  ])
    ->save();
  $node_storage
    ->create([
    'id' => 3,
    'title' => 'bar',
    'body' => 'test foobar',
    'type' => 'article',
    'field_geolocation' => [
      'lat' => 54,
      'lng' => 49,
    ],
  ])
    ->save();
  $node_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();
}