View source
<?php
namespace Drupal\Tests\simple_gmap\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
class SimpleGmapTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $apiKey = 'Static maps will not work unless you put in a key';
protected $node;
public static $modules = [
'node',
'menu_ui',
'path',
'field',
'field_ui',
'simple_gmap_stress_test',
'text',
'user',
];
protected function setUp() {
parent::setUp();
$auth_user = $this
->drupalCreateUser([
'access content',
'administer node display',
]);
$this
->drupalLogin($auth_user);
$this->node = Node::create([
'type' => 'simple_gmap_stress_test',
'title' => 'A three field node',
]);
$this->node
->save();
}
public function testSettingsForm() {
$session = $this
->getSession();
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/structure/types/manage/simple_gmap_stress_test/display');
$blank_row_button = $assert_session
->waitForElementVisible('css', 'tr#field-blank input[alt="Edit"]');
$this
->assertNotNull($blank_row_button);
$blank_row_button
->click();
$update_visible = $assert_session
->waitForElementVisible('css', 'form input[value="Update"]');
$this
->assertNotNull($update_visible);
$edit_form = $session
->getPage();
$edit_form
->checkField('Include embedded dynamic map');
$edit_form
->checkField('Include embedded static map');
$visible_key = $assert_session
->waitForElementVisible('css', 'label:contains("Google Maps API key")');
$this
->assertNotNull($visible_key);
$edit_form2 = $session
->getPage();
$edit_form2
->fillField('Google Maps API key', $this->apiKey);
$edit_form2
->fillField('Link text', 'use_address');
$edit_form2
->fillField('Zoom level', '5');
$edit_form2
->selectFieldOption('Map type', 'Satellite');
$edit_form2
->fillField('Language', 'xyz');
$edit_form2
->checkField('Include link to map');
$edit_form2
->checkField('Include original address text');
$edit_form2
->find('css', 'input[value="Update"]')
->click();
$visible_gears1 = $assert_session
->waitForElementVisible('css', "#field-blank input[alt=\"Edit\"]");
$this
->assertNotNull($visible_gears1);
$display_page_updated = $session
->getPage();
$field_row_updated = $display_page_updated
->find('css', "#field-blank");
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Dynamic map")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Static map")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Map link: use_address")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Map Type: Satellite")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Zoom Level: 5")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Language: xyz")'));
$this
->assertTrue($field_row_updated
->has('css', 'div:contains("Original text displayed")'));
}
}