Overriding the logger


Using Mocks


Createing Mocks


Examples

ToDo Embed test scripts and links to run them

/OpenForum/Triggers/TimerTrigger/TaskScheduler //OpenForum/Triggers/TimerTrigger/TaskScheduler/TaskScheduler.test.sjs

/* * Author: * Description: */ var pageName="/OpenForum/Triggers/TimerTrigger/TaskScheduler"; var scriptFileName="trigger.sjs"; //test.log = function(message) { println("[Test Log] "+message); }; //test.logFailed = function(message) { println("[Test FAILED] "+message); }; //test.logPassed = function(message) { println("[Test PASSED] "+message); }; var script = file.getAttachment(pageName,scriptFileName); // Wrap trigger.sjs in a function, inject mocks and return the schedule var TaskSchedulerBuilder = eval( "function(log,file,Date,trigger,js){ return function() {"+script+"; return {schedule: schedule};}; };" ); var mockLog = js.getObject("/OpenForum/AddOn/Tester","MockLog.sjs").getMock(test); var mockFile = js.getObject("/OpenForum/AddOn/Tester","MockFile.sjs").getMock(test); var mockDate = js.getObject("/OpenForum/AddOn/Tester","MockDate.sjs").getMock(test,1000); var mockTimerTrigger = js.getObject("/OpenForum/AddOn/Tester","MockTimerTrigger.sjs").getMock(test); var mockJS = js.getObject("/OpenForum/AddOn/Tester","MockJS.sjs").getMock(test); var mockDB = js.getObject("/OpenForum/AddOn/Tester","MockDB.sjs").getMock(test); var mockAlert = js.getObject("/OpenForum/AddOn/Tester","MockAlert.sjs").getMock(test); mockJS.includeRealObject( "/OpenForum/Javascript","Common.sjs" ); mockJS.addMockObject( "/OpenForum/AddOn/SQL","DB.sjs", mockDB ); mockJS.addMockObject( "/OpenForum/AddOn/Alert","Alert.sjs", mockAlert ); //Not used as now uses DB table /*var schedule = [ { "id": "task1", "name": "Manage Queues", "pageName": "/TestTask", "scriptFile": "trigger.sjs", "lastRun": "", "scheduledTime": "Every ten seconds", "enabled": true, "debug": true } ];*/ mockFile.addMockFile( "/TestTask","trigger.sjs","function() {}",0 ); //mockFile.addMockFile( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); //Not used as now uses DB table mockFile.addMockFile( "/Test","script-true.sjs","result = true;",0 ); mockFile.addMockFile( "/Test","script-false.sjs","result = false;",0 ); var taskScheduler = TaskSchedulerBuilder(mockLog,mockFile,mockDate,mockTimerTrigger,mockJS); test.setDebug(false); test.registerTestInstance( "taskScheduler" , taskScheduler ); //=========================== mockTimerTrigger.resetMock(); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every ten seconds","t","t"]] ); test.log("Running tests in "+pageName+"/"+scriptFileName); test.unitTest("Every 10 seconds"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Thu Jan 01 1970 00:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every minute"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every minute","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); test.unitTest("Every minute run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Thu Jan 01 1970 00:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every minute"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every minute","t","t"]] ); mockTimerTrigger.isMinutePeriod(false); //println("imp:"+mockTimerTrigger.isMinutePeriod()); test.unitTest("Every minute not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every ten minutes"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every ten minutes","t","t"]] ); mockTimerTrigger.isTenMinutePeriod(true); test.unitTest("Every ten minutes run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Thu Jan 01 1970 00:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule.scheduledTime="Every ten minutes"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every ten minutes","t","t"]] ); mockTimerTrigger.isTenMinutePeriod(false); test.unitTest("Every ten minutes not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every hour"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every hour","t","t"]] ); mockTimerTrigger.isHourPeriod(true); test.unitTest("Every hour run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Thu Jan 01 1970 00:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every hour"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every hour","t","t"]] ); mockTimerTrigger.isHourPeriod(false); test.unitTest("Every hour not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every month"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); //name (text) pagename (text) scriptfile (text) lastrun (text) scheduledtime (text) enabled (bool) debug (bool) mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every month","t","t"]] ); mockTimerTrigger.isHourPeriod(true); var date = new Date(1000); date.setMonth(4); date.setDate(1); date.setHours(8); mockDate.setMockTime( date.getTime() ); test.unitTest("Every month run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Fri May 01 1970 08:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every month"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every month","t","t"]] ); mockTimerTrigger.isHourPeriod(true); date.setHours(9); mockDate.setMockTime( date.getTime() ); test.unitTest("Every month not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every year"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every year","t","t"]] ); mockTimerTrigger.isHourPeriod(true); var date = new Date(1000); date.setMonth(0); date.setDate(1); date.setHours(8); mockDate.setMockTime( date.getTime() ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every year","t","t"]] ); test.unitTest("Every year run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Thu Jan 01 1970 08:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every year"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every year","t","t"]] ); mockTimerTrigger.isHourPeriod(true); date.setMonth(1); date.setDate(1); date.setHours(8); mockDate.setMockTime( date.getTime() ); test.unitTest("Every year not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every week on Tuesday"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every week on Tuesday","t","t"]] ); mockTimerTrigger.isHourPeriod(true); var date = new Date(1000); date.setMonth(0); date.setDate(6); date.setHours(8); mockDate.setMockTime( date.getTime() ); test.unitTest("Every week on Tuesday run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Tue Jan 06 1970 08:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every week on Tuesday"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every week on Tuesday","t","t"]] ); mockTimerTrigger.isHourPeriod(true); date.setMonth(0); date.setDate(4); date.setHours(8); mockDate.setMockTime( date.getTime() ); test.unitTest("Every week on Tuesday not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every day at 15:00"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every day at 15:00","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); var date = new Date(1000); date.setMonth(5); date.setDate(7); date.setHours(15); date.setMinutes(0); mockDate.setMockTime( date.getTime() ); test.unitTest("Every day at 15:00 run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Sun Jun 07 1970 15:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="Every day at 15:00"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","Every day at 15:00","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); date.setMonth(5); date.setDate(7); date.setHours(3); date.setMinutes(0); mockDate.setMockTime( date.getTime() ); test.unitTest("Every day at 15:00 not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="On 06/02/2010 at 13:22"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","On 06/02/2010 at 13:22","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); var date = new Date(1000); date.setMonth(3); date.setDate(6); date.setHours(13); date.setMinutes(22); mockDate.setMockTime( date.getTime() ); test.unitTest("On 06/02/2010 13:22 run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Mon Apr 06 1970 13:22:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="On 06/02/2010 at 13:22"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","On 06/02/2010 at 13:22","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); date.setMonth(3); date.setDate(6); date.setHours(13); date.setMinutes(27); mockDate.setMockTime( date.getTime() ); test.unitTest("On 06/02/2010 at 13:22 not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="On 06/02/2010"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","On 06/02/2010","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); var date = new Date(1000); date.setMonth(3); date.setDate(6); date.setHours(8); date.setMinutes(0); mockDate.setMockTime( date.getTime() ); test.unitTest("On 06/02/2010 run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Mon Apr 06 1970 08:00:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="On 06/02/2010 at 13:22"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","On 06/02/2010 at 13:22","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); date.setMonth(3); date.setDate(6); date.setHours(13); date.setMinutes(27); mockDate.setMockTime( date.getTime() ); test.unitTest("On 06/02/2010 at 13:22 not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="script:{pageName:'/Test', fileName:'script-true.sjs'}"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","script:{pageName:'/Test', fileName:'script-true.sjs'}","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); date.setMonth(3); date.setDate(6); date.setHours(13); date.setMinutes(27); mockDate.setMockTime( date.getTime() ); test.unitTest("On script: /Test/script-true.sjs run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","Mon Apr 06 1970 13:27:01 GMT-0000 (GMT)" ). run(); //=========================== mockTimerTrigger.resetMock(); //schedule[0].scheduledTime="script:{pageName:'/Test', fileName:'script-false.sjs'}"; //schedule[0].lastRun=""; //mockFile.saveAttachment( "/OpenForum/Triggers/TimerTrigger/TaskScheduler","schedule.json",JSON.stringify(schedule),0 ); mockDB.setMockQuery( "select * from triggerSchedule", [["task1","/TestTask","trigger.sjs","","script:{pageName:'/Test', fileName:'script-false.sjs'}","t","t"]] ); mockTimerTrigger.isMinutePeriod(true); date.setMonth(3); date.setDate(6); date.setHours(13); date.setMinutes(27); mockDate.setMockTime( date.getTime() ); test.unitTest("On script: /Test/script-false.sjs not run"). //given(null). when("taskScheduler()"). thenEvaluationEquals( "schedule[0].lastRun","" ). run(); var results = test.getResults(); test.log("Completed tests in /OpenForum/Javascript/PageBuilder/default-page-builder.sjs Tests:"+results.tests+" Passed:"+results.passed+" Failed:"+results.failed); Run It

/OpenForum/Javascript/Renderer //OpenForum/Javascript/Renderer/DefaultRenderer.test.sjs

var renderer = js.getObject("/OpenForum/Javascript/Renderer","DefaultRenderer.sjs"); /*if(typeof println != "undefined") { var oldFn = test.postMessage; test.postMessage = function(message) { oldFn( "<(xmp)>"+message+"</(xmp)>" ); }; }*/ renderer.setAliases( [ {alias: "wiki", prefix: "http://www.wikipedia.org/"}, {alias: "bbc", prefix: "http://www.bbc.co.uk/"} ] ); test.registerTestInstance( "renderer",renderer ); test.log("Running tests in /OpenForum/Javascript/Renderer/DefaultRenderer.sjs"); //================================================================== test.unitTest("Can render unordered list"). given("pageName","MyPage"). and("content","* A \n* B \n* C \n"). when( "renderer.render(pageName,content)" ). then("<ul><li> A </li>\n<li> B </li>\n<li> C </li>\n</ul>"). run(); //================================================================== test.unitTest("Can render unordered list offset from page"). given("pageName","MyPage"). and("content"," * A \n * B \n * C \n"). when( "renderer.render(pageName,content)" ). then("<ul><li> A </li>\n<li> B </li>\n<li> C </li>\n</ul>"). run(); //================================================================== test.unitTest("Can render unordered list followed by text"). given("pageName","MyPage"). and("content","* A \n* B \n* C \n\nsome trailing text"). when( "renderer.render(pageName,content)" ). then("<ul><li> A </li>\n<li> B </li>\n<li> C </li>\n</ul>\nsome trailing text"). run(); //================================================================== test.unitTest("Can render ordered list"). given("pageName","MyPage"). and("content","# A \n# B \n# C \n"). when( "renderer.render(pageName,content)" ). then("<ol><li> A </li>\n<li> B </li>\n<li> C </li>\n</ol>"). run(); //================================================================== test.unitTest("Can render ordered list followed by text"). given("pageName","MyPage"). and("content","# A \n# B \n# C \n\nsome trailing text"). when( "renderer.render(pageName,content)" ). then("<ol><li> A </li>\n<li> B </li>\n<li> C </li>\n</ol>\nsome trailing text"). run(); //================================================================== test.unitTest("Can render bold"). given("pageName","MyPage"). and("content"," __Title__ "). when( "renderer.render(pageName,content)" ). then(" <b>Title</b> "). run(); //================================================================== test.unitTest("Can render mixed markup"). given("pageName","MyPage"). and("content"," __Title__ \n\n* A \n* B \n* C \n"). when( "renderer.render(pageName,content)" ). then(" <b>Title</b> \n\n<ul><li> A </li>\n<li> B </li>\n<li> C </li>\n</ul>"). run(); //================================================================== test.unitTest("Can render heading"). given("pageName","MyPage"). and("content","!!Title"). when( "renderer.render(pageName,content)" ). then("<h3>Title</h3>"). run(); //================================================================== test.unitTest("Can render headings with blank line"). given("pageName","MyPage"). and("content","!!Title 1\n\n!!Title 2\n"). when( "renderer.render(pageName,content)" ). then("<h3>Title 1</h3>\n\n<h3>Title 2</h3>\n"). run(); //================================================================== test.unitTest("Can render rule"). given("pageName","MyPage"). and("content","----"). when( "renderer.render(pageName,content)" ). then("<hr/>"). run(); //================================================================== test.unitTest("Can render heading and rule"). given("pageName","MyPage"). and("content","!!Title\n----\nSome Text"). when( "renderer.render(pageName,content)" ). then("<h3>Title</h3>\n<hr/>\nSome Text"). run(); //================================================================== test.unitTest("Can render local absolute link"). given("pageName","MyPage"). and("content","[/TheLab]"). when( "renderer.render(pageName,content)" ). then("<a href=\"/TheLab\">/TheLab</a>"). run(); //================================================================== test.unitTest("Can render link with parameter"). given("pageName","MyPage"). and("content","[/TheLab?edit]"). when( "renderer.render(pageName,content)" ). then("<a href=\"/TheLab?edit\">/TheLab?edit</a>"). run(); //================================================================== test.unitTest("Can render local absolute links with blank line"). given("pageName","MyPage"). and("content","[/TheLab]\n\n[/TheLab]"). when( "renderer.render(pageName,content)" ). then("<a href=\"/TheLab\">/TheLab</a>\n\n<a href=\"/TheLab\">/TheLab</a>"). run(); //================================================================== test.unitTest("Can render local absolute link with label"). given("pageName","MyPage"). and("content","[Title|/TheLab]"). when( "renderer.render(pageName,content)" ). then("<a href=\"/TheLab\">Title</a>"). run(); //================================================================== test.unitTest("Can render local relative link with label"). given("pageName","/OpenForum/Javascript"). and("content","[Title|Renderer]"). when( "renderer.render(pageName,content)" ). then("<a href=\"/OpenForum/Javascript/Renderer\">Title</a>"). run(); //================================================================== test.unitTest("Can render external link with label"). given("pageName","MyPage"). and("content","[The BBC|http://www.bbc.co.uk]"). when( "renderer.render(pageName,content)" ). then("<a href=\"http://www.bbc.co.uk\" target=\"external_page\">The BBC</a>"). run(); //================================================================== test.unitTest("Can render external link with alias"). given("pageName","MyPage"). and("content","[Helicopter|wiki:helicopter]"). when( "renderer.render(pageName,content)" ). then("<a href=\"http://www.wikipedia.org/helicopter\" target=\"external_page\">Helicopter</a>"). run(); //================================================================== test.unitTest("Can render an image"). given("pageName","MyPage"). and("content","[A Picture|/OpenForum/Images/open-forum-dog-small.png]"). when( "renderer.render(pageName,content)" ). then("<img src=\"/OpenForum/Images/open-forum-dog-small.png\" alt=\"A Picture\" title=\"A Picture\"/>"). run(); //================================================================== test.unitTest("Can render a table"). given("pageName","MyPage"). and("content","|A|B|C\n|1|2|3\n|x|y|z"). when( "renderer.render(pageName,content)" ). then("<table><tr><td>A</td><td>B</td><td>C</td></tr>\n<tr><td>1</td><td>2</td><td>3</td></tr>\n<tr><td>x</td><td>y</td><td>z</td></tr></table>"). run(); test.unitTest("Can render extension"). given("pageName","MyPage"). and("content","[{Icon name=\"chart pie\"}]"). when( "renderer.render(pageName,content)" ). then("<!--Extension Icon name=\"chart pie\" --><img src=\"/OpenForum/Images/icons/png/chart_pie.png\"><!--End Extension Icon name=\"chart pie\" -->"). run(); var results = test.getResults(); test.log("Completed tests in /OpenForum/Javascript/Renderer/DefaultRenderer.sjs Tests:"+results.tests+" Passed:"+results.passed+" Failed:"+results.failed); Run It

/OpenForum/AddOn/DataLogger //OpenForum/AddOn/DataLogger/DataLogger.test.sjs

/* * Author: * Description: */ var dataLogger = js.getObject("/OpenForum/AddOn/DataLogger","DataLogger.sjs"); var tester = js.getObject("/OpenForum/Javascript/Tester","Test.sjs"); tester.log("Running tests in /OpenForum/AddOn/DataLogger/DataLogger.sjs"); tester.unitTest("Can create pageName for dot separated file"). given(""). when( dataLogger.getPathFor("a.bee.cee.d.txt",dataLogger.NAME_MODE_PATH) ). thenAttributeEquals( "pageName","/a/bee/cee/d/" ). run(); tester.unitTest("Can create fileName for dot separated file name"). given(""). when( dataLogger.getPathFor("a.bee.cee.d.txt",dataLogger.NAME_MODE_PATH) ). thenAttributeEquals( "fileName","a.bee.cee.d.txt"). run(); tester.unitTest("Can create pageName for text file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT) ). thenAttributeEquals("pageName","/a/ab/abcd/"). run(); tester.unitTest("Can create fileName for text file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT) ). thenAttributeEquals("fileName","abcde.txt"). run(); var time = new Date(); time.setTime(0); time.setYear(2016); time.setMonth(4); time.setDate(15); time.setHours(3); time.setMinutes(15); time.setSeconds(7); tester.unitTest("Can create pageName for day log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_DAY,time) ). thenAttributeEquals("pageName","/a/ab/abcd/2016/05/"). run(); tester.unitTest("Can create fileName for day log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_DAY,time) ). thenAttributeEquals("fileName","abcde-2016-05-15.txt"). run(); tester.unitTest("Can create pageName for time log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_TIME,time) ). thenAttributeEquals("pageName","/a/ab/abcd/2016/05/15/"). run(); tester.unitTest("Can create fileName for time log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_TIME,time) ). thenAttributeEquals("fileName","abcde-2016-05-15-03-15-07.txt"). run(); tester.unitTest("Can create pageName for timestamp log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_TIMESTAMP,time) ). thenAttributeEquals("pageName","/a/ab/abcd/2016/05/15/"). run(); tester.unitTest("Can create fileName for timestamp log file name"). given(""). when( dataLogger.getPathFor("abcde.txt",dataLogger.NAME_MODE_TEXT,dataLogger.TIME_MODE_TIMESTAMP,time) ). thenAttributeEquals("fileName","abcde-1463282107000.txt"). run(); var results = tester.getResults(); tester.log("Completed tests in /OpenForum/AddOn/DataLogger/DataLogger.sjs Tests:"+results.tests+ " Passed:"+results.passed+ " Failed:"+results.failed ); Run It