<commit_before><html>
<head>
    <script src="../../lib/OpenLayers.js"></script>
    <script type="text/javascript">
    function test_Control_SelectFeature_constructor(t) {
        t.plan(2);
        var options = {
//            geometryTypes: "foo"
        };
        var layer = "bar";
        var control = new OpenLayers.Control.SelectFeature(layer, options);
        t.ok(control instanceof OpenLayers.Control.SelectFeature,
             "new OpenLayers.Control.SelectFeature returns an instance");
        t.eq(control.layers[0], "bar",
             "constructor sets layer correctly");        
//        t.eq(control.handlers.feature.geometryTypes, "foo",
//             "constructor sets options correctly on feature handler");
    }
    
    function test_Control_SelectFeature_destroy(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.SelectFeature(layer, {box: true});
        control.handlers.feature.deactivate = function() {
            t.ok(true,
                 "control.deactivate calls deactivate on feature handler");
        }
        control.handlers.box.deactivate = function() {
            t.ok(true,
                 "control.deactivate calls deactivate on box handler");
        }
// should nullify the layer property here
        control.destroy();
        
    }
    
    function test_Control_SelectFeature_select(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.SelectFeature(layer);
        var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0));
        layer.addFeatures(feature);
        layer.drawFeature = function(feature, style) {
            layer.styleMap.createSymbolizer(feature, style);
        }
        control.select(feature);
        t.eq(feature.renderIntent, "select", "render intent is set to select");
        control.unselect(feature);
        t.eq(feature.renderIntent, "default", "render intent is set back to default");
    }
    
    function test_Control_SelectFeature_clickFeature(t) {
        t.plan(4);
        // mock up layer
        var layer = {
            selectedFeatures: [],
            drawFeature: function() {},
            events: {
                triggerEvent: function() {}
            }
        };
        // mock up active control
        var control = new OpenLayers.Control.SelectFeature(layer);
        control.handlers.feature = {
            evt: {}
        };
        // mock up features
        var features = new Array(4);
        for(var i=0; i<features.length; ++i) {
            features[i] = {
                id: Math.random(),
                tested: 0,
                style: "",
                layer: layer
            };
        }
        
        // test that onSelect gets called properly
        control.onSelect = function(feature) {
            feature.tested += 1;
            t.eq(feature.id, features[feature.index].id,
                 "onSelect called with proper feature (" + feature.index + ")");
            t.eq(feature.tested, feature.test,
                 "onSelect called only once for feature (" + feature.index + ")");
        }

        // test that onUnselect gets called properly
        control.onUnselect = function(feature) {
            feature.tested += 1;
            t.eq(feature.id, features[feature.index].id,
                 "onUnselect called with proper feature (" + feature.index + ")");
            t.eq(feature.tested, feature.test, 
                 "onUnselect called only once for feature (" + feature.index + ")");
        }
        
        // mock up first click on first feature (runs 2 tests from onSelect)<commit_msg>Reverting changes from r8664 that were inadvertently committed to the trunk.  This gets the SelectFeature control tests passing again.  (see #1666)<commit_after><html>
<head>
    <script src="../../lib/OpenLayers.js"></script>
    <script type="text/javascript">
    function test_Control_SelectFeature_constructor(t) {
        t.plan(2);
        var options = {
//            geometryTypes: "foo"
        };
        var layer = "bar";
        var control = new OpenLayers.Control.SelectFeature(layer, options);
        t.ok(control instanceof OpenLayers.Control.SelectFeature,
             "new OpenLayers.Control.SelectFeature returns an instance");
        t.eq(control.layer, "bar",
             "constructor sets layer correctly");        
//        t.eq(control.handlers.feature.geometryTypes, "foo",
//             "constructor sets options correctly on feature handler");
    }
    
    function test_Control_SelectFeature_destroy(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.SelectFeature(layer, {box: true});
        control.handlers.feature.deactivate = function() {
            t.ok(true,
                 "control.deactivate calls deactivate on feature handler");
        }
        control.handlers.box.deactivate = function() {
            t.ok(true,
                 "control.deactivate calls deactivate on box handler");
        }
// should nullify the layer property here
        control.destroy();
        
    }
    
    function test_Control_SelectFeature_select(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.SelectFeature(layer);
        var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0));
        layer.addFeatures(feature);
        layer.drawFeature = function(feature, style) {
            layer.styleMap.createSymbolizer(feature, style);
        }
        control.select(feature);
        t.eq(feature.renderIntent, "select", "render intent is set to select");
        control.unselect(feature);
        t.eq(feature.renderIntent, "default", "render intent is set back to default");
    }
    
    function test_Control_SelectFeature_clickFeature(t) {
        t.plan(4);
        // mock up layer
        var layer = {
            selectedFeatures: [],
            drawFeature: function() {},
            events: {
                triggerEvent: function() {}
            }
        };
        // mock up active control
        var control = new OpenLayers.Control.SelectFeature(layer);
        control.handlers.feature = {
            evt: {}
        };
        // mock up features
        var features = new Array(4);
        for(var i=0; i<features.length; ++i) {
            features[i] = {
                id: Math.random(),
                tested: 0,
                style: ""
            };
        }
        
        // test that onSelect gets called properly
        control.onSelect = function(feature) {
            feature.tested += 1;
            t.eq(feature, features[feature.index],
                 "onSelect called with proper feature (" + feature.index + ")");
            t.eq(feature.tested, feature.test,
                 "onSelect called only once for feature (" + feature.index + ")");
        }

        // test that onUnselect gets called properly
        control.onUnselect = function(feature) {
            feature.tested += 1;
            t.eq(feature, features[feature.index],
                 "onUnselect called with proper feature (" + feature.index + ")");
            t.eq(feature.tested, feature.test, 
                 "onUnselect called only once for feature (" + feature.index + ")");
        }
        
        // mock up first click on first feature (runs 2 tests from onSelect)
{'fraction_non_alphanumeric': 0.11308006119326874, 'fraction_numerical': 0.004207037225905151, 'mean_word_length': 1.9131080579279613, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7037148', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2036, 'n_words': 501}