Preload images with jQuery

$(function(){
    var cache = []; // declare array to store our images
    $.preLoadImages = function(){
        var args_len = arguments.length;
        for(var i = args_len; i--;){
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    };
 }); // call our predefined function $.preLoadImages('./images/sample1.png', './images/sample2.png'); 

Reference:

http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript/

Advertisements

PHP Unit Test – part 1

Prerequisites:

  1. PHPUnit Framework installed
  2. extends class PHPUnit_Framework_TestCase

phpunit

  • Test number
class StackTest extends PHPUnit_Framework_TestCase
{
    public function testFailureNumber(){
        $this->assertEquals(1, 1);
    }
}
  • Test string
public function testFailureNumber(){
    $this->assertEquals(1, 1);
 }
  • Test xml
public function testFailureXml(){
    $expected = new DOMDocument;
    $expected->loadXML('<foo><bar/></foo>');
    $actual = new DOMDocument();
    $actual->loadXML('<foo><bar/></foo>');
    $this->assertEquals($expected, $actual);
 }
  • Test object
public function testFailureObject(){
    $expected = new stdClass();
    $expected->foo = 'foo';
    $expected->bar = 'bar';
    $actual = new stdClass();
    $actual->foo = 'foo';
    $actual->bar = 'bar';
    $this->assertEquals($expected, $actual);
 }