WebformElementLocationPlacesTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementLocationPlacesTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
class WebformElementLocationPlacesTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_loc_places',
];
public function testLocationPlaces() {
$webform = Webform::load('test_element_loc_places');
$this
->drupalGet('/webform/test_element_loc_places');
$this
->assertRaw('<input class="webform-location-places form-text" data-drupal-selector="edit-location-default-value" type="text" id="edit-location-default-value" name="location_default[value]" value="" size="60" maxlength="255" placeholder="Enter a location" />');
$this
->assertRaw('<input data-webform-location-places-attribute="lat" data-drupal-selector="edit-location-default-lat" type="hidden" name="location_default[lat]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="lng" data-drupal-selector="edit-location-default-lng" type="hidden" name="location_default[lng]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="name" data-drupal-selector="edit-location-default-name" type="hidden" name="location_default[name]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="city" data-drupal-selector="edit-location-default-city" type="hidden" name="location_default[city]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="country" data-drupal-selector="edit-location-default-country" type="hidden" name="location_default[country]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="country_code" data-drupal-selector="edit-location-default-country-code" type="hidden" name="location_default[country_code]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="administrative" data-drupal-selector="edit-location-default-administrative" type="hidden" name="location_default[administrative]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="county" data-drupal-selector="edit-location-default-county" type="hidden" name="location_default[county]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="suburb" data-drupal-selector="edit-location-default-suburb" type="hidden" name="location_default[suburb]" value="" />');
$this
->assertRaw('<input data-webform-location-places-attribute="postcode" data-drupal-selector="edit-location-default-postcode" type="hidden" name="location_default[postcode]" value="" />');
$this
->assertRaw('<input class="webform-location-places form-text" data-drupal-selector="edit-location-attributes-value" type="text" id="edit-location-attributes-value" name="location_attributes[value]" value="" size="60" maxlength="255" />');
$this
->assertRaw('<input data-webform-location-places-attribute="lat" data-drupal-selector="edit-location-attributes-lat" type="text" id="edit-location-attributes-lat" name="location_attributes[lat]" value="" size="60" maxlength="255" class="form-text" />');
$edit = [
'location_attributes_required[value]' => 'test',
];
$this
->postSubmission($webform, $edit);
$this
->assertRaw('The location_attributes_required is not valid.');
$edit = [
'location_attributes_required[value]' => 'test',
'location_attributes_required[lat]' => 1,
];
$this
->postSubmission($webform, $edit);
$this
->assertNoRaw('The location_attributes_required is not valid.');
$this
->assertNoRaw('"app_id"');
$this
->assertNoRaw('"api_key"');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('element.default_algolia_places_app_id', '{default_algolia_places_app_id}')
->set('element.default_algolia_places_api_key', '{default_algolia_places_api_key}')
->save();
$this
->drupalGet('/webform/test_element_loc_places');
$this
->assertRaw('"app_id"');
$this
->assertRaw('"api_key"');
$this
->assertRaw('"webform":{"location":{"places":{"app_id":"{default_algolia_places_app_id}","api_key":"{default_algolia_places_api_key}"}}}');
}
}