You are here

GeolocationLeafletJavascriptTest.php in Geolocation Field 8.2

File

tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php
View source
<?php

namespace Drupal\Tests\geolocation\FunctionalJavascript;

use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityFormDisplay;

/**
 * Tests the leaflet JavaScript functionality.
 *
 * @group geolocation
 */
class GeolocationLeafletJavascriptTest extends GeolocationJavascriptTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'node',
    'user',
    'field',
    'views',
    'views_test_config',
    'geolocation',
    'geolocation_leaflet',
    'geolocation_test_views',
  ];

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'geolocation_leaflet_test',
  ];

  /**
   * {@inheritdoc}
   */
  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_latlng',
    ])
      ->save();
    EntityViewDisplay::load('node.article.default')
      ->setComponent('field_geolocation', [
      'type' => 'geolocation_latlng',
      'weight' => 1,
    ])
      ->save();
    $this->container
      ->get('views.views_data')
      ->clear();
    ViewTestData::createTestViews(get_class($this), [
      'geolocation_test_views',
    ]);
    $entity_test_storage = \Drupal::entityTypeManager()
      ->getStorage('node');
    $entity_test_storage
      ->create([
      'id' => 1,
      'title' => 'Location 1',
      'body' => 'location 1 test body',
      'type' => 'article',
      'field_geolocation' => [
        'lat' => 52,
        'lng' => 47,
      ],
    ])
      ->save();
    $entity_test_storage
      ->create([
      'id' => 2,
      'title' => 'Location 2',
      'body' => 'location 2 test body',
      'type' => 'article',
      'field_geolocation' => [
        'lat' => 53,
        'lng' => 48,
      ],
    ])
      ->save();
    $entity_test_storage
      ->create([
      'id' => 3,
      'title' => 'Location 3',
      'body' => 'location 3 test body',
      'type' => 'article',
      'field_geolocation' => [
        'lat' => 54,
        'lng' => 49,
      ],
    ])
      ->save();
  }

  /**
   * Tests the CommonMap style.
   */
  public function testLeafletMap() {
    $this
      ->drupalGet('geolocation-leaflet-test');
    $this
      ->assertSession()
      ->elementExists('css', '.geolocation-map-container');
    $this
      ->assertSession()
      ->elementExists('css', '.geolocation-location');
    $result = $this
      ->assertSession()
      ->waitForElementVisible('css', 'img[title="Location 2"]');
    $this
      ->assertNotEmpty($result);
    $this
      ->getSession()
      ->getPage()
      ->find('css', 'img[title="Location 2"]')
      ->click();
    $this
      ->assertSession()
      ->elementExists('css', '.leaflet-popup-content');
  }

}

Classes

Namesort descending Description
GeolocationLeafletJavascriptTest Tests the leaflet JavaScript functionality.