View source
<?php
namespace Drupal\Tests\geolocation_geometry\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Tests\ViewTestData;
class GeolocationGeometryViewsBoundaryTest extends BrowserTestBase {
public static $modules = [
'node',
'field',
'views',
'geolocation',
'geolocation_geometry',
'geolocation_geometry_demo',
'geolocation_geometry_test_views',
];
public static $testViews = [
'geolocation_geometry_test_boundary',
];
protected $viewsPath = 'geolocation-geometry-test-boundary';
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), [
'geolocation_geometry_test_views',
]);
}
public function testBoundaryNoLocations() {
$this
->drupalGet($this->viewsPath);
$this
->assertSession()
->statusCodeEquals(200);
}
public function testBoundaryLocations() {
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('node');
$entity_test_storage
->create([
'id' => 1,
'title' => 'Containing Polygon',
'body' => 'test test',
'type' => 'geolocation_geometry_demo',
'field_geolocation_geometry_polyg' => [
'wkt' => 'POLYGON((170 -44, 169 -44, 169 -45, 170 -45, 170 -44))',
],
])
->save();
$entity_test_storage
->create([
'id' => 2,
'title' => 'Intersecting Polygon',
'body' => 'test foobar',
'type' => 'geolocation_geometry_demo',
'field_geolocation_geometry_polyg' => [
'wkt' => 'POLYGON((171.1217044 -43.6891741, 168.1217044 -43.6891741, 168.1217044 -45.6891741, 171.1217044 -45.6891741, 171.1217044 -43.6891741))',
],
])
->save();
$entity_test_storage
->create([
'id' => 3,
'title' => 'Outside Polygon',
'body' => 'test foobar',
'type' => 'geolocation_geometry_demo',
'field_geolocation_geometry_polyg' => [
'wkt' => 'POLYGON((10 20, 8 20, 8 22, 10 22, 10 20))',
],
])
->save();
$this
->drupalGet($this->viewsPath);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('Wanaka');
$this
->assertSession()
->responseContains('Containing Polygon');
$this
->assertSession()
->responseNotContains('Intersecting Polygon');
$this
->assertSession()
->responseNotContains('Outside Polygon');
}
}