forked from icecoder/ICEcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
285 lines (261 loc) · 7.16 KB
/
index.php
File metadata and controls
285 lines (261 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<!-- Automated test suite to test some of the core functionality of ICEcoder including:
Open file, update document, save file, highlight line, add tag wrappers, duplicate line, add line break, comment line, remove line, contract, expand, unlock & lock file manager, open new tab, previous & next tab, switch tab, close tab, get remote file, move and go to line
//-->
<html>
<head>
<title>ICEcoder Test Suite</title>
<meta name="robots" content="noindex, nofollow">
<script src="object-watch.js?microtime=<?php echo microtime(true);?>"></script>
</head>
<script>
ICEcoder=top.ICEcoder;
if(ICEcoder.openFiles.length>0) {ICEcoder.closeAllTabs();}
unitTestResults = top.ICEcoder.content.contentWindow.document.getElementById('unitTestResults');
unitTestResults.innerHTML = "";
</script>
<?php
// Set test file name & location
$testFile = "test-file1.txt";
$testFileFullPath = str_replace("\\","/",dirname($_SERVER['PHP_SELF']))."/".$testFile;
// Delete any existing test file and create a new one
if (file_exists($testFile)) {unlink ($testFile);};
$fh = fopen($testFile, 'w') or die("<script>noCreate='FAIL Could not create test file';console.log(noCreate);unitTestResults.innerHTML = noCreate;</script>");
fwrite($fh, 'initial text');
fclose($fh);
?>
<body onLoad="runTests()">
<script>
function runTests() {
o = {p: 'start'}; // var used to test another var has changed
t = 0; // tries
s = 0; // successful tests
test.openFile(); // start the first test
}
test = {
openFile: function() {
title = "Open file";
o.p = ICEcoder.openFiles[0];
t = 0;
x = setInterval(function() {
wait();
cM = ICEcoder.getcMInstance();
if (cM && "undefined" != typeof ICEcoder.openFiles[0]) {
testResult("+ GOOD",title+". Took "+t+"ms",x);
ICEcoder.serverMessage();
top.ICEcoder.serverQueue("del",0);
test.updateDoc();
} else if (t==1000) {
testResult("- FAIL",title+". Took "+t+"ms",x);
testStopped();
}
o.p = ICEcoder.openFiles[0];
t++;
},1);
result = ICEcoder.openFile('<?php echo $testFileFullPath?>');
},
updateDoc: function() {
title = "Change file contents";
cM.setValue('Updated');
if (cM.getValue()=="Updated") {
testResult("+ GOOD",title);
test.saveFile();
} else {
testResult("+ FAIL",title);
testStopped();
}
},
saveFile: function() {
title = "Save file";
o.p = ICEcoder.savedPoints[0];
t = 0;
x = setInterval(function() {
wait();
cM = ICEcoder.getcMInstance();
if (cM && ICEcoder.savedPoints[0]==cM.changeGeneration()-1) {
testResult("+ GOOD",title+". Took "+t+"ms",x);
test.tagWrapper();
} else if (t==1000) {
testResult("- FAIL",title+". Took "+t+"ms",x);
testStopped();
}
o.p = ICEcoder.savedPoints[0];
t++;
},1);
result = ICEcoder.saveFile();
},
tagWrapper: function() {
title = "Highlight line and add <p> and <div> tag wrappers";
ICEcoder.highlightLine(0);
ICEcoder.tagWrapper('p');
ICEcoder.tagWrapper('div');
if (cM.getValue() == "<div>\n\t<p>Updated</p>\n</div>") {
testResult("+ GOOD",title);
test.lineDupBreakCommentRemove();
} else {
testResult("- FAIL",title);
testStopped();
}
},
lineDupBreakCommentRemove: function() {
title = "Duplicate, add break, comment and remove line";
ICEcoder.duplicateLines(1);
ICEcoder.addLineBreakAtEnd(2);
ICEcoder.lineCommentToggle();
line2 = cM.getLine(2);
ICEcoder.removeLines(2);
line2Now = cM.getLine(2);
if (line2 == "<!-- <p>Updated</p><br>//-->" && line2Now == "</div>") {
testResult("+ GOOD",title);
test.lockUnlockNav();
} else {
testResult("- FAIL",title);
testStopped();
}
},
lockUnlockNav: function() {
title = "Expand/contract and lock/unlock";
ICEcoder.lockUnlockNav();
ICEcoder.changeFilesW('contract');
setTimeout(function(){
lockChanged = top.ICEcoder.lockedNav;
widthChanged = ICEcoder.filesW;
ICEcoder.changeFilesW('expand');
setTimeout(function(){
ICEcoder.lockUnlockNav();
if (ICEcoder.lockedNav != lockChanged && ICEcoder.filesW != widthChanged) {
testResult("+ GOOD",title);
test.newTab();
} else {
testResult("- FAIL",title);
testStopped();
}
},500);
},500);
},
newTab: function() {
title = "Open new tab";
ICEcoder.newTab();
if (ICEcoder.openFiles.length==2) {
testResult("+ GOOD",title);
setTimeout(function(){
test.prevNextTab();
},500);
} else {
testResult("- FAIL",title);
testStopped();
}
},
prevNextTab: function() {
title = "Previous and next tab";
ICEcoder.previousTab();
tPrev = ICEcoder.selectedTab;
setTimeout(function(){
if (tPrev==1) {
ICEcoder.nextTab();
tNext = ICEcoder.selectedTab;
}
},300);
setTimeout(function(){
if (tPrev==1 && tNext==2) {
testResult("+ GOOD",title);
test.switchTab();
} else {
testResult("- FAIL",title);
testStopped();
}
},600);
},
switchTab: function() {
title = "Switch tab";
ICEcoder.switchTab(1);
if (ICEcoder.selectedTab==1) {
testResult("+ GOOD",title);
test.closeTab();
} else {
testResult("- FAIL",title);
testStopped();
}
},
closeTab: function() {
title = "Close tab";
ICEcoder.closeTab(2,false,true);
setTimeout(function() {
if (ICEcoder.openFiles.length==1) {
testResult("+ GOOD",title);
test.getRemoteFile();
} else {
testResult("- FAIL",title);
testStopped();
}
},200);
},
getRemoteFile: function() {
title = "Get remote file";
o.p = ICEcoder.openFiles[1];
t = 0;
x = setInterval(function() {
wait();
cM = ICEcoder.getcMInstance();
if (cM && ICEcoder.openFiles[1]== "/[NEW]") {
testResult("+ GOOD",title+". Took "+t+"ms",x);
setTimeout(function() {
ICEcoder.closeTab(2,false,true);
test.moveGoToLine();
},1000);
} else if (t==1000) {
testResult("- FAIL",title+". Took "+t+"ms",x);
testStopped();
}
o.p = ICEcoder.openFiles[1];
t++;
},1);
result = ICEcoder.getRemoteFile('http://icecoder.net/latest-version');
},
moveGoToLine: function() {
title = "Move and goto line";
cM = ICEcoder.getcMInstance();
cM.setValue('ICEcoder = "awesome";\n<script>\n<\/script>');
ICEcoder.goToLine(1);
line1Text = cM.lineInfo(cM.getCursor().line).text;
setTimeout(function() {
ICEcoder.moveLines('down');
if (cM.getValue() == '<script>\nICEcoder = "awesome";\n<\/script>') {
testResult("+ GOOD",title);
setTimeout(function() {
ICEcoder.closeTab(1,false,true);
console.log('TEST COMPLETE!');
alert('Test Complete!\n\nRan '+s+' of '+total+' tests OK.\nSee console for more details.');
},200);
} else {
testResult("- FAIL",title);
testStopped();
}
},200);
}
}
function wait() {
o.watch("p", function (id, oldval, newval) {
if (oldval != newval) {
o.unwatch('p');
return newval;
}
});
}
function testResult(result,output,timer) {
if (result=="+ GOOD") {s++};
displayResults(s);
if (timer) {clearInterval(timer)}
console.log(result+" "+output);
}
function displayResults(successful) {
total = Object.keys(test).length;
unitTestResults.innerHTML = "Ran "+successful+" of "+total+" tests OK";
}
function testStopped() {
unitTestResults.innerHTML += " - Test stopped";
alert("Test stopped, see console for details.");
}
</script>
</body>
</html>