1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <title>ImageMap Tests</title> 6 <link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.17.1.css"> 7</head> 8<body> 9<div id="qunit"></div> 10<div id="qunit-fixture"></div> 11<script src="//code.jquery.com/qunit/qunit-1.17.1.js"></script> 12<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 13<script src="../../jquery.rwdImageMaps.js"></script> 14<script src="../../script.js"></script> 15 16 17 18<script> 19 QUnit.module( "parseInput", { 20 setup: function( ) { 21 imagemap = new Imagemap(); 22 imagemap.img = new Image(); 23 DOKU_BASE = /(.*?)lib\/plugins/.exec(window.location.href)[1]; 24 var xmlHttp = new XMLHttpRequest(); 25 xmlHttp.open( "GET", DOKU_BASE , false); 26 xmlHttp.send(); 27 JSINFO = []; 28 JSINFO['plugin_imagemap_mldummy'] = /plugin_imagemap_mldummy":"(.*?)"/.exec(xmlHttp.responseText)[1]; 29 this.nsdivider = /wiki\\?(.)dokuwiki-128.png/.exec(JSINFO['plugin_imagemap_mldummy'])[1]; 30 }, teardown: function( ) { 31 } 32 }); 33 QUnit.test( "{{:512px-catstalkprey.jpg|}} passing", function( assert ) { 34 var result = imagemap.parseInput('{{:512px-catstalkprey.jpg|}}'); 35 assert.equal(result, true, "We expect {{:512px-catstalkprey.jpg|}} to be accepted" ); 36 assert.equal(imagemap.img.src, DOKU_BASE + 'lib/exe/fetch.php?media=' + this.nsdivider + '512px-catstalkprey.jpg', 'image source'); 37 assert.equal(imagemap.filenameWiki,":512px-catstalkprey.jpg",'filenameWiki'); 38 }); 39 40 QUnit.test( "{{:512px-dogstalkprey.jpg|some title}} passing", function( assert ) { 41 var result = imagemap.parseInput('{{:512px-dogstalkprey.jpg|some title}}'); 42 assert.equal(result, true, "We expect {{:512px-dogstalkprey.jpg|some title}} to be accepted" ); 43 assert.equal(imagemap.img.src, DOKU_BASE + 'lib/exe/fetch.php?media=' + this.nsdivider + '512px-dogstalkprey.jpg', 'image source'); 44 assert.equal(imagemap.filenameWiki,":512px-dogstalkprey.jpg",'filenameWiki'); 45 }); 46 47 QUnit.test( "{{:512px-birdstalkprey.jpg}} passing", function( assert ) { 48 var result = imagemap.parseInput('{{:512px-birdstalkprey.jpg}}'); 49 assert.equal(result, true, "We expect {{:512px-birdstalkprey.jpg}} to be accepted" ); 50 assert.equal(imagemap.img.src, DOKU_BASE + 'lib/exe/fetch.php?media=' + this.nsdivider + '512px-birdstalkprey.jpg', 'image source'); 51 assert.equal(imagemap.filenameWiki,":512px-birdstalkprey.jpg",'filenameWiki'); 52 }); 53 54 QUnit.test( "{{:512px-fishstalkprey.jpg?200x300&recache}} passing", function( assert ) { 55 var result = imagemap.parseInput('{{foo:512px-fishstalkprey.jpg?200x300&recache}}'); 56 assert.equal(result, true, "We expect {{:512px-birdstalkprey.jpg}} to be accepted" ); 57 assert.equal(imagemap.img.src, DOKU_BASE + 'lib/exe/fetch.php?media=foo' + this.nsdivider + '512px-fishstalkprey.jpg&recache', 'image source'); 58 assert.equal(imagemap.filenameWiki,"foo:512px-fishstalkprey.jpg?200x300&recache",'filenameWiki'); 59 assert.equal(imagemap.setWidth,'200','imagemap.setWidth'); 60 assert.equal(imagemap.setHight,'300','imagemap.setHight'); 61 }); 62 63 QUnit.test( "{{:512px-fishstalkprey.jpg?200&nocache}} passing", function( assert ) { 64 var result = imagemap.parseInput('{{foo:512px-fishstalkprey.jpg?200&nocache}}'); 65 assert.equal(result, true, "We expect {{:512px-birdstalkprey.jpg}} to be accepted" ); 66 assert.equal(imagemap.img.src, DOKU_BASE + 'lib/exe/fetch.php?media=foo' + this.nsdivider + '512px-fishstalkprey.jpg&nocache', 'image source'); 67 assert.equal(imagemap.filenameWiki,"foo:512px-fishstalkprey.jpg?200&nocache",'filenameWiki'); 68 assert.equal(imagemap.setWidth,'200','imagemap.setWidth'); 69 assert.equal(imagemap.setHight,undefined,'imagemap.setHight'); 70 }); 71 72 QUnit.test( "link to other server passing", function( assert ) { 73 var result = imagemap.parseInput('{{http://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Tortoiseshell_she-cat.JPG/320px-Tortoiseshell_she-cat.JPG?320|By Toyah (Own work) [Public domain], via Wikimedia Commons}}'); 74 assert.equal(result, true, "We expect the result to be true" ); 75 assert.equal(imagemap.img.src, 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Tortoiseshell_she-cat.JPG/320px-Tortoiseshell_she-cat.JPG?320', 'We should get the link to the server'); 76 }); 77 78 79 QUnit.module( "getOptions", { 80 setup: function( ) { 81 imagemap = new Imagemap(); 82 imagemap.img = new Image(); 83 DOKU_BASE = 'http://127.0.0.1/~michael/dokuwiki/'; 84 }, teardown: function( ) { 85 } 86 }); 87 QUnit.test( "200&nocache", function( assert ) { 88 var result = imagemap.getOptions('200&nocache'); 89 assert.equal(result, 'nocache', "nocache" ); 90 assert.equal(imagemap.setWidth, '200', 'imagemap.setWidth'); 91 }); 92 93 QUnit.test( "recache&200x120", function( assert ) { 94 var result = imagemap.getOptions('recache&200x120'); 95 assert.equal(result, 'recache', "recache" ); 96 assert.equal(imagemap.setWidth, '200', 'imagemap.setWidth'); 97 assert.equal(imagemap.setHight, '120', 'imagemap.setHight'); 98 }); 99 100 QUnit.test( "recache&200x120&direct", function( assert ) { 101 var result = imagemap.getOptions('recache&200x120&direct'); 102 assert.equal(result, 'recache&direct', "recache&direct" ); 103 assert.equal(imagemap.setWidth, '200', 'imagemap.setWidth'); 104 assert.equal(imagemap.setHight, '120', 'imagemap.setHight'); 105 }); 106 107 QUnit.test( "recache&direct", function( assert ) { 108 var result = imagemap.getOptions('recache&direct'); 109 assert.equal(result, 'recache&direct', "recache&direct" ); 110 assert.equal(imagemap.setWidth, undefined, 'imagemap.setWidth'); 111 assert.equal(imagemap.setHight, undefined, 'imagemap.setHight'); 112 }); 113 114 115 116 QUnit.module( "capture groups", { 117 setup: function( ) { 118 //reg = new RegExp('\{\{(.*?)(\?.*?)(?:[\|]|[\}]{2})(?:(.*?)\}\})?'); 119 reg = /\{\{(.*?)(?:\?(.*?))?(?:[\|]|[\}]{2})(?:(.*?)\}\})?/; 120 }, teardown: function( ) { 121 } 122 }); 123 QUnit.test( "{{:512px-catstalkprey.jpg?200}}", function( assert ) { 124 var text = '{{:512px-catstalkprey.jpg?200}}'; 125 assert.equal( reg.test(text), true, "We expect the result to be true" ); 126 var match = reg.exec(text); 127 var wikilink = match[1]; 128 var size = match[2]; 129 var title = match[3]; 130 assert.equal(wikilink, ':512px-catstalkprey.jpg', 'wikilink'); 131 assert.equal(title, undefined, 'title'); 132 assert.equal(size, '200', 'size'); 133 assert.deepEqual(match, [ 134 "{{:512px-catstalkprey.jpg?200}}", 135 ":512px-catstalkprey.jpg", 136 '200', 137 undefined 138 ], 'complete match'); 139 }); 140 141 QUnit.test( "{{:512px-catstalkprey.jpg}}", function( assert ) { 142 var text = '{{:512px-catstalkprey.jpg}}'; 143 assert.equal( reg.test(text), true, "We expect the result to be true" ); 144 var match = reg.exec(text); 145 var wikilink = match[1]; 146 var title = match[3]; 147 assert.equal(wikilink, ':512px-catstalkprey.jpg', 'wikilink'); 148 assert.equal(title, undefined, 'title'); 149 assert.deepEqual(match, [ 150 "{{:512px-catstalkprey.jpg}}", 151 ":512px-catstalkprey.jpg", 152 undefined, 153 undefined 154 ], 'complete match'); 155 }); 156 157 QUnit.test( "{{:512px-catstalkprey.jpg|foo}}", function( assert ) { 158 var text = '{{:512px-catstalkprey.jpg|foo}}'; 159 assert.equal( reg.test(text), true, "We expect the result to be true" ); 160 var match = reg.exec(text); 161 var wikilink = match[1]; 162 var title = match[3]; 163 assert.equal(wikilink, ':512px-catstalkprey.jpg', 'wikilink'); 164 assert.equal(title, 'foo', 'title'); 165 var expected_complete_match = ["{{:512px-catstalkprey.jpg|foo}}",":512px-catstalkprey.jpg",undefined,"foo"]; 166 assert.deepEqual(match, expected_complete_match, 'complete match'); 167 }); 168 169 QUnit.test( "true false", function( assert ) { 170 assert.equal(!undefined, true, 'undefined'); 171 }); 172 173</script> 174</body> 175</html> 176 177 178 179 180 181 182 183 184<!--<?php 185$myarray=array('a'=>'b',2,3=>'k'); 186print_r($myarray); 187print('b'); 188?>--> 189