| | 263 | } |
|---|
| | 264 | |
|---|
| | 265 | function test_Map_getLayersBy(t) { |
|---|
| | 266 | |
|---|
| | 267 | var map = { |
|---|
| | 268 | getBy: OpenLayers.Map.prototype.getBy, |
|---|
| | 269 | getLayersBy: OpenLayers.Map.prototype.getLayersBy, |
|---|
| | 270 | layers: [ |
|---|
| | 271 | {foo: "foo", id: Math.random()}, |
|---|
| | 272 | {foo: "bar", id: Math.random()}, |
|---|
| | 273 | {foo: "foobar", id: Math.random()}, |
|---|
| | 274 | {foo: "foo bar", id: Math.random()}, |
|---|
| | 275 | {foo: "foo", id: Math.random()} |
|---|
| | 276 | ] |
|---|
| | 277 | }; |
|---|
| | 278 | |
|---|
| | 279 | var cases = [ |
|---|
| | 280 | { |
|---|
| | 281 | got: map.getLayersBy("foo", "foo"), |
|---|
| | 282 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 283 | message: "(string literal) got two layers matching foo" |
|---|
| | 284 | }, { |
|---|
| | 285 | got: map.getLayersBy("foo", "bar"), |
|---|
| | 286 | expected: [map.layers[1]], |
|---|
| | 287 | message: "(string literal) got one layer matching foo" |
|---|
| | 288 | }, { |
|---|
| | 289 | got: map.getLayersBy("foo", "barfoo"), |
|---|
| | 290 | expected: [], |
|---|
| | 291 | message: "(string literal) got empty array for no foo match" |
|---|
| | 292 | }, { |
|---|
| | 293 | got: map.getLayersBy("foo", /foo/), |
|---|
| | 294 | expected: [map.layers[0], map.layers[2], map.layers[3], map.layers[4]], |
|---|
| | 295 | message: "(regexp literal) got three layers containing string" |
|---|
| | 296 | }, { |
|---|
| | 297 | got: map.getLayersBy("foo", /foo$/), |
|---|
| | 298 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 299 | message: "(regexp literal) got three layers ending with string" |
|---|
| | 300 | }, { |
|---|
| | 301 | got: map.getLayersBy("foo", /\s/), |
|---|
| | 302 | expected: [map.layers[3]], |
|---|
| | 303 | message: "(regexp literal) got layer containing space" |
|---|
| | 304 | }, { |
|---|
| | 305 | got: map.getLayersBy("foo", new RegExp("BAR", "i")), |
|---|
| | 306 | expected: [map.layers[1], map.layers[2], map.layers[3]], |
|---|
| | 307 | message: "(regexp object) got layers ignoring case" |
|---|
| | 308 | }, { |
|---|
| | 309 | got: map.getLayersBy("foo", {test: function(str) {return str.length > 3;}}), |
|---|
| | 310 | expected: [map.layers[2], map.layers[3]], |
|---|
| | 311 | message: "(custom object) got layers with foo length greater than 3" |
|---|
| | 312 | } |
|---|
| | 313 | ]; |
|---|
| | 314 | t.plan(cases.length); |
|---|
| | 315 | for(var i=0; i<cases.length; ++i) { |
|---|
| | 316 | t.eq(cases[i].got, cases[i].expected, cases[i].message); |
|---|
| | 317 | } |
|---|
| | 318 | |
|---|
| | 319 | } |
|---|
| | 320 | |
|---|
| | 321 | function test_Map_getLayersByName(t) { |
|---|
| | 322 | |
|---|
| | 323 | var map = { |
|---|
| | 324 | getBy: OpenLayers.Map.prototype.getBy, |
|---|
| | 325 | getLayersBy: OpenLayers.Map.prototype.getLayersBy, |
|---|
| | 326 | getLayersByName: OpenLayers.Map.prototype.getLayersByName, |
|---|
| | 327 | layers: [ |
|---|
| | 328 | {name: "foo", id: Math.random()}, |
|---|
| | 329 | {name: "bar", id: Math.random()}, |
|---|
| | 330 | {name: "foobar", id: Math.random()}, |
|---|
| | 331 | {name: "foo bar", id: Math.random()}, |
|---|
| | 332 | {name: "foo", id: Math.random()} |
|---|
| | 333 | ] |
|---|
| | 334 | }; |
|---|
| | 335 | |
|---|
| | 336 | var cases = [ |
|---|
| | 337 | { |
|---|
| | 338 | got: map.getLayersByName("foo"), |
|---|
| | 339 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 340 | message: "(string literal) got two layers matching name" |
|---|
| | 341 | }, { |
|---|
| | 342 | got: map.getLayersByName("bar"), |
|---|
| | 343 | expected: [map.layers[1]], |
|---|
| | 344 | message: "(string literal) got one layer matching name" |
|---|
| | 345 | }, { |
|---|
| | 346 | got: map.getLayersByName("barfoo"), |
|---|
| | 347 | expected: [], |
|---|
| | 348 | message: "(string literal) got empty array for no match" |
|---|
| | 349 | }, { |
|---|
| | 350 | got: map.getLayersByName(/foo/), |
|---|
| | 351 | expected: [map.layers[0], map.layers[2], map.layers[3], map.layers[4]], |
|---|
| | 352 | message: "(regexp literal) got three layers containing string" |
|---|
| | 353 | }, { |
|---|
| | 354 | got: map.getLayersByName(/foo$/), |
|---|
| | 355 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 356 | message: "(regexp literal) got three layers ending with string" |
|---|
| | 357 | }, { |
|---|
| | 358 | got: map.getLayersByName(/\s/), |
|---|
| | 359 | expected: [map.layers[3]], |
|---|
| | 360 | message: "(regexp literal) got layer containing space" |
|---|
| | 361 | }, { |
|---|
| | 362 | got: map.getLayersByName(new RegExp("BAR", "i")), |
|---|
| | 363 | expected: [map.layers[1], map.layers[2], map.layers[3]], |
|---|
| | 364 | message: "(regexp object) got layers ignoring case" |
|---|
| | 365 | }, { |
|---|
| | 366 | got: map.getLayersByName({test: function(str) {return str.length > 3;}}), |
|---|
| | 367 | expected: [map.layers[2], map.layers[3]], |
|---|
| | 368 | message: "(custom object) got layers with name length greater than 3" |
|---|
| | 369 | } |
|---|
| | 370 | ]; |
|---|
| | 371 | t.plan(cases.length); |
|---|
| | 372 | for(var i=0; i<cases.length; ++i) { |
|---|
| | 373 | t.eq(cases[i].got, cases[i].expected, cases[i].message); |
|---|
| | 374 | } |
|---|
| | 375 | |
|---|
| | 376 | } |
|---|
| | 377 | |
|---|
| | 378 | function test_Map_getLayersByType(t) { |
|---|
| | 379 | |
|---|
| | 380 | var map = { |
|---|
| | 381 | getBy: OpenLayers.Map.prototype.getBy, |
|---|
| | 382 | getLayersBy: OpenLayers.Map.prototype.getLayersBy, |
|---|
| | 383 | getLayersByType: OpenLayers.Map.prototype.getLayersByType, |
|---|
| | 384 | layers: [ |
|---|
| | 385 | {CLASS_NAME: "foo", id: Math.random()}, |
|---|
| | 386 | {CLASS_NAME: "bar", id: Math.random()}, |
|---|
| | 387 | {CLASS_NAME: "foobar", id: Math.random()}, |
|---|
| | 388 | {CLASS_NAME: "foo bar", id: Math.random()}, |
|---|
| | 389 | {CLASS_NAME: "foo", id: Math.random()} |
|---|
| | 390 | ] |
|---|
| | 391 | }; |
|---|
| | 392 | |
|---|
| | 393 | var cases = [ |
|---|
| | 394 | { |
|---|
| | 395 | got: map.getLayersByType("foo"), |
|---|
| | 396 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 397 | message: "(string literal) got two layers matching type" |
|---|
| | 398 | }, { |
|---|
| | 399 | got: map.getLayersByType("bar"), |
|---|
| | 400 | expected: [map.layers[1]], |
|---|
| | 401 | message: "(string literal) got one layer matching type" |
|---|
| | 402 | }, { |
|---|
| | 403 | got: map.getLayersByType("barfoo"), |
|---|
| | 404 | expected: [], |
|---|
| | 405 | message: "(string literal) got empty array for no match" |
|---|
| | 406 | }, { |
|---|
| | 407 | got: map.getLayersByType(/foo/), |
|---|
| | 408 | expected: [map.layers[0], map.layers[2], map.layers[3], map.layers[4]], |
|---|
| | 409 | message: "(regexp literal) got three layers containing string" |
|---|
| | 410 | }, { |
|---|
| | 411 | got: map.getLayersByType(/foo$/), |
|---|
| | 412 | expected: [map.layers[0], map.layers[4]], |
|---|
| | 413 | message: "(regexp literal) got three layers ending with string" |
|---|
| | 414 | }, { |
|---|
| | 415 | got: map.getLayersByType(/\s/), |
|---|
| | 416 | expected: [map.layers[3]], |
|---|
| | 417 | message: "(regexp literal) got layer containing space" |
|---|
| | 418 | }, { |
|---|
| | 419 | got: map.getLayersByType(new RegExp("BAR", "i")), |
|---|
| | 420 | expected: [map.layers[1], map.layers[2], map.layers[3]], |
|---|
| | 421 | message: "(regexp object) got layers ignoring case" |
|---|
| | 422 | }, { |
|---|
| | 423 | got: map.getLayersByType({test: function(str) {return str.length > 3;}}), |
|---|
| | 424 | expected: [map.layers[2], map.layers[3]], |
|---|
| | 425 | message: "(custom object) got layers with type length greater than 3" |
|---|
| | 426 | } |
|---|
| | 427 | ]; |
|---|
| | 428 | t.plan(cases.length); |
|---|
| | 429 | for(var i=0; i<cases.length; ++i) { |
|---|
| | 430 | t.eq(cases[i].got, cases[i].expected, cases[i].message); |
|---|
| | 431 | } |
|---|
| | 432 | |
|---|
| | 433 | } |
|---|
| | 434 | |
|---|
| | 435 | function test_Map_getControlsBy(t) { |
|---|
| | 436 | |
|---|
| | 437 | var map = { |
|---|
| | 438 | getBy: OpenLayers.Map.prototype.getBy, |
|---|
| | 439 | getControlsBy: OpenLayers.Map.prototype.getControlsBy, |
|---|
| | 440 | controls: [ |
|---|
| | 441 | {foo: "foo", id: Math.random()}, |
|---|
| | 442 | {foo: "bar", id: Math.random()}, |
|---|
| | 443 | {foo: "foobar", id: Math.random()}, |
|---|
| | 444 | {foo: "foo bar", id: Math.random()}, |
|---|
| | 445 | {foo: "foo", id: Math.random()} |
|---|
| | 446 | ] |
|---|
| | 447 | }; |
|---|
| | 448 | |
|---|
| | 449 | var cases = [ |
|---|
| | 450 | { |
|---|
| | 451 | got: map.getControlsBy("foo", "foo"), |
|---|
| | 452 | expected: [map.controls[0], map.controls[4]], |
|---|
| | 453 | message: "(string literal) got two controls matching foo" |
|---|
| | 454 | }, { |
|---|
| | 455 | got: map.getControlsBy("foo", "bar"), |
|---|
| | 456 | expected: [map.controls[1]], |
|---|
| | 457 | message: "(string literal) got one control matching foo" |
|---|
| | 458 | }, { |
|---|
| | 459 | got: map.getControlsBy("foo", "barfoo"), |
|---|
| | 460 | expected: [], |
|---|
| | 461 | message: "(string literal) got empty array for no foo match" |
|---|
| | 462 | }, { |
|---|
| | 463 | got: map.getControlsBy("foo", /foo/), |
|---|
| | 464 | expected: [map.controls[0], map.controls[2], map.controls[3], map.controls[4]], |
|---|
| | 465 | message: "(regexp literal) got three controls containing string" |
|---|
| | 466 | }, { |
|---|
| | 467 | got: map.getControlsBy("foo", /foo$/), |
|---|
| | 468 | expected: [map.controls[0], map.controls[4]], |
|---|
| | 469 | message: "(regexp literal) got three controls ending with string" |
|---|
| | 470 | }, { |
|---|
| | 471 | got: map.getControlsBy("foo", /\s/), |
|---|
| | 472 | expected: [map.controls[3]], |
|---|
| | 473 | message: "(regexp literal) got control containing space" |
|---|
| | 474 | }, { |
|---|
| | 475 | got: map.getControlsBy("foo", new RegExp("BAR", "i")), |
|---|
| | 476 | expected: [map.controls[1], map.controls[2], map.controls[3]], |
|---|
| | 477 | message: "(regexp object) got layers ignoring case" |
|---|
| | 478 | }, { |
|---|
| | 479 | got: map.getControlsBy("foo", {test: function(str) {return str.length > 3;}}), |
|---|
| | 480 | expected: [map.controls[2], map.controls[3]], |
|---|
| | 481 | message: "(custom object) got controls with foo length greater than 3" |
|---|
| | 482 | } |
|---|
| | 483 | ]; |
|---|
| | 484 | t.plan(cases.length); |
|---|
| | 485 | for(var i=0; i<cases.length; ++i) { |
|---|
| | 486 | t.eq(cases[i].got, cases[i].expected, cases[i].message); |
|---|
| | 487 | } |
|---|
| | 488 | |
|---|
| | 489 | } |
|---|
| | 490 | |
|---|
| | 491 | function test_Map_getControlsByType(t) { |
|---|
| | 492 | |
|---|
| | 493 | var map = { |
|---|
| | 494 | getBy: OpenLayers.Map.prototype.getBy, |
|---|
| | 495 | getControlsBy: OpenLayers.Map.prototype.getControlsBy, |
|---|
| | 496 | getControlsByType: OpenLayers.Map.prototype.getControlsByType, |
|---|
| | 497 | controls: [ |
|---|
| | 498 | {CLASS_NAME: "foo", id: Math.random()}, |
|---|
| | 499 | {CLASS_NAME: "bar", id: Math.random()}, |
|---|
| | 500 | {CLASS_NAME: "foobar", id: Math.random()}, |
|---|
| | 501 | {CLASS_NAME: "foo bar", id: Math.random()}, |
|---|
| | 502 | {CLASS_NAME: "foo", id: Math.random()} |
|---|
| | 503 | ] |
|---|
| | 504 | }; |
|---|
| | 505 | |
|---|
| | 506 | var cases = [ |
|---|
| | 507 | { |
|---|
| | 508 | got: map.getControlsByType("foo"), |
|---|
| | 509 | expected: [map.controls[0], map.controls[4]], |
|---|
| | 510 | message: "(string literal) got two controls matching type" |
|---|
| | 511 | }, { |
|---|
| | 512 | got: map.getControlsByType("bar"), |
|---|
| | 513 | expected: [map.controls[1]], |
|---|
| | 514 | message: "(string literal) got one control matching type" |
|---|
| | 515 | }, { |
|---|
| | 516 | got: map.getControlsByType("barfoo"), |
|---|
| | 517 | expected: [], |
|---|
| | 518 | message: "(string literal) got empty array for no match" |
|---|
| | 519 | }, { |
|---|
| | 520 | got: map.getControlsByType(/foo/), |
|---|
| | 521 | expected: [map.controls[0], map.controls[2], map.controls[3], map.controls[4]], |
|---|
| | 522 | message: "(regexp literal) got three controls containing string" |
|---|
| | 523 | }, { |
|---|
| | 524 | got: map.getControlsByType(/foo$/), |
|---|
| | 525 | expected: [map.controls[0], map.controls[4]], |
|---|
| | 526 | message: "(regexp literal) got three controls ending with string" |
|---|
| | 527 | }, { |
|---|
| | 528 | got: map.getControlsByType(/\s/), |
|---|
| | 529 | expected: [map.controls[3]], |
|---|
| | 530 | message: "(regexp literal) got control containing space" |
|---|
| | 531 | }, { |
|---|
| | 532 | got: map.getControlsByType(new RegExp("BAR", "i")), |
|---|
| | 533 | expected: [map.controls[1], map.controls[2], map.controls[3]], |
|---|
| | 534 | message: "(regexp object) got controls ignoring case" |
|---|
| | 535 | }, { |
|---|
| | 536 | got: map.getControlsByType({test: function(str) {return str.length > 3;}}), |
|---|
| | 537 | expected: [map.controls[2], map.controls[3]], |
|---|
| | 538 | message: "(custom object) got controls with type length greater than 3" |
|---|
| | 539 | } |
|---|
| | 540 | ]; |
|---|
| | 541 | t.plan(cases.length); |
|---|
| | 542 | for(var i=0; i<cases.length; ++i) { |
|---|
| | 543 | t.eq(cases[i].got, cases[i].expected, cases[i].message); |
|---|
| | 544 | } |
|---|
| | 545 | |
|---|