<html>
  <head>
    <script type="text/javascript" src="../OLLoader.js"></script>
    <script type="text/javascript">
    
      // use an arcims map service against Avencia Inc.'s global sample map services
      var serviceName = "OpenLayers_Sample";
      var layerName = "Global Sample Map";
      var imsUrl = "http://sample.avencia.com/servlet/com.esri.esrimap.Esrimap";
      
      //
      // create an arcims layer
      //
      function test_Layer_ArcIMS_constructor( t ) {
        t.plan(11);
        
        var options = {
          serviceName: serviceName,
          async: false,
          displayOutsideMaxExtent: true
        };
            
        var layer = new OpenLayers.Layer.ArcIMS( layerName, imsUrl, options );
          
        // check layer & properties
        t.ok( layer instanceof OpenLayers.Layer.ArcIMS, "new OpenLayers.Layer.ArcIMS returns object" );
        t.eq( layer.url, imsUrl, "layer.url is correct (HTTPRequest inited)" );
        t.eq( layer.name, layerName, "layer.name is correct" );
        t.eq( layer.displayOutsideMaxExtent, options.displayOutsideMaxExtent, 
          "displayOutsideMaxExtent property set correctly from options" );
         
        // check request parameters
        t.eq( layer.params.ServiceName, serviceName, "ServiceName set properly" );
        t.eq( layer.params.ClientVersion, "9.2", "ClientVersion set properly" );
        
        // check request options
        t.eq( layer.options.async, options.async, "async property set correctly from options" );
        t.eq( layer.options.serviceName, serviceName, "serviceName property set correctly from options" );
        t.eq( layer.options.layers.length, 0, "layers option is the correct length" );
        t.eq( layer.options.tileSize.w, 512, "default tile width set correctly" );
        t.eq( layer.options.tileSize.h, 512, "default tile height set correctly" );
      } 
      
      
      
      /*
       * how to test getURL, getURLasync, and getFeatureInfo without a proxy?
       *
       */
      
      
      //
      // Create an arcims layer, and verify that the query changes properly
      //
      function test_Layer_ArcIMS_setLayerQuery(t) {
        t.plan(9);
        
        var options = { serviceName: serviceName };
        var layer = new OpenLayers.Layer.ArcIMS( layerName, imsUrl, options );
        var querydef = {
          where: "FIPS_CNTRY = 'US'"
        };
        
        t.eq( layer.options.layers.length, 0, "layer definitions are empty" );
        
        layer.setLayerQuery( "layerID", querydef );
        
        t.eq( layer.options.layers.length, 1, "layers definitions contain one layerdef" );
        t.ok( layer.options.layers[0].query !== null, "layer query exists" );
        t.eq( typeof layer.options.layers[0].query.where, "string", "where query is a string" );
        t.eq( layer.options.layers[0].query.where, querydef.where, "where query matches" );
        
        // change the definition
        querydef = {
          where: "FIPS_CNTRY = 'UV'",
          spatialfilter:true
        }
        
        layer.setLayerQuery( "layerID", querydef );
        
        t.eq( layer.options.layers.length, 1, "layers definitions contain one layerdef" );
        t.ok( layer.options.layers[0].query !== null, "layer query exists" );
        t.eq( typeof layer.options.layers[0].query.where, "string", "where query is a string" );
        t.eq( layer.options.layers[0].query.where, querydef.where, "where query matches" );
      }
      function test_Layer_ArcIMS_clone (t) {
          t.plan(5);
  
          var url = imsUrl;
          var options = {
            serviceName: serviceName,
            async: false,
            displayOutsideMaxExtent: true
          };
          var map = new OpenLayers.Map('map', {controls: []});
          var layer = new OpenLayers.Layer.ArcIMS(name, url, options);
          map.addLayer(layer);
  
          layer.grid = [ [6, 7],
                         [8, 9]];
  
          var clone = layer.clone();
  
          t.ok( clone.grid != layer.grid, "clone does not copy grid");
  
          t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
  
          t.eq( clone.params.serviceName, layer.params.serviceName, "serviceName copied correctly");
  
          t.eq( clone.async, layer.async, "async copied correctly");
  
          t.eq( clone.url, layer.url, "url copied correctly");
  
          layer.grid = null;
          map.destroy();
      }
      
    </script>
  </head>
  <body>
    <div id="map" style="width:500px;height:550px"></div> 
  </body>  
</html>