You are here

function OpenLayersLayers::testOpenLayersLayers in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 tests/openlayers.test \OpenLayersLayers::testOpenLayersLayers()

File

tests/openlayers.test, line 243
Main OpenLayers Test file

Class

OpenLayersLayers
Test OpenLayers layers.

Code

function testOpenLayersLayers() {
  $user = $this
    ->drupalCreateUser(array(
    'administer openlayers',
  ));
  $this
    ->drupalLogin($user);

  // New layers to add
  $layer_inputs = array(
    'openlayers_layer_type_osm' => array(
      'name' => 'unitlayerosm',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
    'openlayers_layer_type_xyz' => array(
      'name' => 'unitlayerxyz',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
    'openlayers_layer_type_kml' => array(
      'name' => 'unitlayerkml',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
      'openlayers_layer_type_kml[method]' => 'raw',
      'openlayers_layer_type_kml[raw]' => $this
        ->randomString(32),
    ),
    'openlayers_layer_type_wms' => array(
      'name' => 'unitlayerwms',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
    'openlayers_layer_type_cloudmade' => array(
      'name' => 'unitlayercloudmade',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
    'openlayers_layer_type_bing' => array(
      'name' => 'unitlayerbing',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
    'openlayers_layer_type_google' => array(
      'name' => 'unitlayergoogle',
      'title' => 'Unit Layer',
      'description' => 'Unit Layer for Drupal',
    ),
  );

  // Basic navigation.
  $this
    ->drupalGet('admin/structure/openlayers/layers/add');
  $this
    ->assertResponse(200, t('User can reach layer add page.'));

  // Go through each new layer for testing.
  foreach ($layer_inputs as $layer_type => $input_data) {

    // Test saving new layer.
    $input_data['layer_type'] = $layer_type;
    $this
      ->drupalPost('admin/structure/openlayers/layers/add', $input_data, t('Save'));
    $this
      ->assertText(t('Layer saved.'), t('The layer was successfully saved.'));

    // Ensure that the layer shows up in the list.
    $this
      ->drupalGet('admin/structure/openlayers/layers');
    $this
      ->assertRaw($input_data['title'], t('A new layer of layer type %type_name has been added by the test', array(
      '%type_name' => $layer_type,
    )));

    // Test removing layer.
    $this
      ->drupalPost('admin/structure/openlayers/layers/list/' . $input_data['name'] . '/delete', array(), t('Delete'));
    $this
      ->assertText('Layer was deleted.', t('Layer removed succesfully.'));
  }
}