openlayers_test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @file
  3. * OpenLayers JS test file, utilizing QUnit.
  4. */
  5. (function ($) {
  6. $(document).ready(function() {
  7. module('Utility Functions');
  8. // Test the relate path function
  9. test('Testing Drupal.openlayers.relatePath correctness', function() {
  10. var root_path = '/this/is/path.js';
  11. var domain_path = 'http://www.test.com/this/is/path.js';
  12. var relative_path = 'this/is/path.js';
  13. equals(root_path,
  14. Drupal.openlayers.relatePath(root_path, 'foo'), 'Root path is correct' );
  15. equals(domain_path,
  16. Drupal.openlayers.relatePath(domain_path, 'foo'), 'Domain path is correct' );
  17. equals('http://foo.com/this/is/path.js',
  18. Drupal.openlayers.relatePath(relative_path, 'http://foo.com/'), 'Relative path is correct' )});
  19. // Test the object from feature function
  20. test('Testing object_from_feature correctness', function() {
  21. var latlonobject = {lat: 5, lon: 10};
  22. var llobj = Drupal.openlayers.objectFromFeature(latlonobject);
  23. equals(10, llobj.geometry.x, 'Latitude is correct');
  24. equals(5, llobj.geometry.y, 'Latitude is correct');
  25. var wktobject = {wkt: 'POINT(50 40)'};
  26. var wktobj = Drupal.openlayers.objectFromFeature(wktobject);
  27. equals(50, wktobj.geometry.x, 'Latitude is correct');
  28. equals(40, wktobj.geometry.y, 'Latitude is correct');
  29. });
  30. module('Rendering');
  31. test('Testing basic rendering', function() {
  32. // Remove stop_render
  33. $('.openlayers-map:not(.openlayers-processed)').each(function() {
  34. var map_id = $(this).attr('id');
  35. Drupal.settings.openlayers.maps[map_id].stop_render = false;
  36. Drupal.attachBehaviors($('body'), Drupal.settings);
  37. ok($('#' + map_id).children().hasClass('olMapViewport'), 'Map ' + map_id + ' rendered');
  38. });
  39. });
  40. });
  41. })(jQuery);