LocationTest.php in farmOS 2.x
File
modules/core/location/tests/src/Functional/LocationTest.php
View source
<?php
namespace Drupal\Tests\farm_location\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\farm_geo\Traits\WktTrait;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait;
class LocationTest extends WebDriverTestBase {
use StringTranslationTrait;
use WktTrait;
use JsonApiRequestTestTrait;
use LocationFunctionalTestTrait {
setUp as locationSetup;
}
protected $profile = 'farm';
protected $defaultTheme = 'stark';
protected static $modules = [
'basic_auth',
'farm_location',
'farm_location_test',
'farm_api',
];
protected function setUp() : void {
$GLOBALS['farm_test'] = TRUE;
$this
->locationSetup();
}
public function testComputedAssetLocation() {
$location = $this->asset
->get('location')
->referencedEntities();
$this
->assertEquals($this->location
->id(), $location[0]
->id(), 'Computed asset location is the location asset.');
$this
->assertEquals($this->location
->get('intrinsic_geometry')->value, $this->asset
->get('geometry')->value, 'Computed asset geometry is the location asset geometry.');
}
public function testLocationFieldVisibility() {
$this
->drupalGet('asset/' . $this->asset
->id() . '/edit');
$this
->assertSession()
->fieldNotExists('geometry[0][value]');
$this
->assertSession()
->fieldNotExists('location[0][target_id]');
$page = $this
->getSession()
->getPage();
$intrinsic_geometry_field = $page
->findById('edit-intrinsic-geometry-wrapper');
$this
->assertNotEmpty($intrinsic_geometry_field);
$this
->assertFalse($intrinsic_geometry_field
->isVisible());
$this
->drupalGet('asset/' . $this->asset
->id());
$this
->assertSession()
->pageTextContains("Current geometry");
$this
->assertSession()
->pageTextContains("Current location");
$this
->assertSession()
->pageTextNotContains("Intrinsic geometry");
$this->asset->is_fixed = TRUE;
$this->asset
->save();
$this
->drupalGet('asset/' . $this->asset
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$intrinsic_geometry_field = $page
->findById('edit-intrinsic-geometry-wrapper');
$this
->assertNotEmpty($intrinsic_geometry_field);
$this
->assertTrue($intrinsic_geometry_field
->isVisible());
}
}