encode.js
1.65 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
/*eslint strict:0*/
var fs = require('fs');
casper.test.begin('base64encode() and download() tests', 8, function(test) {
// FIXME: https://github.com/ariya/phantomjs/pull/364 has been merged, update scheme
casper.start('file://' + phantom.casperPath + '/tests/site/index.html', function() {
var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png',
image = this.base64encode(imageUrl);
test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents');
this.download(imageUrl, '__test_logo.png');
test.assert(fs.exists('__test_logo.png'), 'Casper.download() downloads a file');
if (fs.exists('__test_logo.png')) {
fs.remove('__test_logo.png');
}
})
.then(function() {
var csvFile = 'file://' + phantom.casperPath + '/tests/site/csv/base64encode.csv';
this.download(csvFile, '__base64encode.csv');
test.assert(fs.exists('__base64encode.csv'), 'Casper.download() downloads a file');
var stream = fs.open('__base64encode.csv', 'r'),
expectedValues = [
'إختبار,',
'آزمایشی,',
'测试',
'испытание',
'परीकi'
],
i = 0,
lines = stream.read().split(/[\n]/);
expectedValues.forEach(function(value) {
test.assertEquals(lines[i], value, 'Casper.base64encode() can retrieve base64 complex strings');
i++;
});
if (fs.exists('__base64encode.csv')) {
fs.remove('__base64encode.csv');
}
}).run(function() {
test.done();
});
});