geolocation-8.x-3.x-dev/tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php
tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php
<?php
namespace Drupal\Tests\geolocation\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the leaflet JavaScript functionality.
*
* @group geolocation
*/
class GeolocationLeafletJavascriptTest extends GeolocationJavascriptTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'user',
'field',
'views',
'views_test_config',
'geolocation',
'geolocation_leaflet',
'geolocation_test_views',
];
/**
* Views used by this test.
*
* @var array
*/
public static array $testViews = ['geolocation_leaflet_test'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
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(): void {
$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);
}
}
