You are here

public function SimpleGmapTest::testSettingsForm in Simple Google Maps 8

Same name and namespace in other branches
  1. 3.0.x tests/src/FunctionalJavascript/SimpleGmapTest.php \Drupal\Tests\simple_gmap\FunctionalJavascript\SimpleGmapTest::testSettingsForm()

Fill out the settings form for the 'blank' field on the stress test page.

The make assertions about the population of the blank settings summary column of the fields display table.

File

tests/src/FunctionalJavascript/SimpleGmapTest.php, line 85

Class

SimpleGmapTest
Creates a page to look at to test the Simple Google Maps module.

Namespace

Drupal\Tests\simple_gmap\FunctionalJavascript

Code

public function testSettingsForm() {
  $session = $this
    ->getSession();
  $assert_session = $this
    ->assertSession();

  // To visiting the settings form we must first visitng the page
  // listing all its fields.
  $this
    ->drupalGet('admin/structure/types/manage/simple_gmap_stress_test/display');

  // Click on the row's edit button (styled with a gear icon).
  $blank_row_button = $assert_session
    ->waitForElementVisible('css', 'tr#field-blank input[alt="Edit"]');
  $this
    ->assertNotNull($blank_row_button);
  $blank_row_button
    ->click();

  // Wait for the settings form associated with the 'blank' field to appear
  // by waiting for the update button.
  $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');

  // Checking the 'static map" options causes the API key field to appear.
  $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();

  // As the update button completes the edit "gears" icon associated with
  // the 'blank' will reappear.
  $visible_gears1 = $assert_session
    ->waitForElementVisible('css', "#field-blank input[alt=\"Edit\"]");
  $this
    ->assertNotNull($visible_gears1);

  // Re-examine the field row containing field1.
  $display_page_updated = $session
    ->getPage();
  $field_row_updated = $display_page_updated
    ->find('css', "#field-blank");

  // Make assertions about the summary column.
  $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")'));
}