Skip to content

Commit 88b59de

Browse files
author
Andrei
committed
Merge pull request #123 from nicola/directoryListingTests
Further tests for directory listing, fix #98
2 parents 619c640 + 4c988a7 commit 88b59de

1 file changed

Lines changed: 91 additions & 7 deletions

File tree

‎test/ldp.js‎

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var rm = require('./test-utils').rm;
88
var write = require('./test-utils').write;
99
var cp = require('./test-utils').cp;
1010
var read = require('./test-utils').read;
11+
var fs = require('fs');
1112

1213
describe('LDP', function () {
1314
var ldp = new LDP();
@@ -83,26 +84,109 @@ describe('LDP', function () {
8384
});
8485

8586
describe('listContainer', function () {
86-
it('should ldp:contains the same amount of files in dir', function(done) {
87+
it('should inherit type if file is .ttl', function(done) {
88+
write('@prefix dcterms: <http://purl.org/dc/terms/>.' +
89+
'@prefix o: <http://example.org/ontology>.' +
90+
'<> a <http://www.w3.org/ns/ldp#MagicType> ;' +
91+
' dcterms:title "This is a magic type" ;' +
92+
' o:limit 500000.00 .', 'sampleContainer/magicType.ttl');
93+
8794
ldp.listContainer(__dirname + '/resources/sampleContainer/', 'https://server.tld', '', function (err, data) {
95+
var graph = $rdf.graph();
96+
$rdf.parse(
97+
data,
98+
graph,
99+
'https://server.tld/sampleContainer',
100+
'text/turtle');
101+
102+
var statements = graph
103+
.each(
104+
$rdf.sym('https://server.tld/magicType.ttl'),
105+
ns.rdf('type'),
106+
undefined)
107+
.map(function(d) {
108+
return d.uri;
109+
});
110+
111+
assert.equal(statements.length, 2);
112+
assert.isAbove(statements.indexOf('http://www.w3.org/ns/ldp#MagicType'), -1);
113+
assert.isAbove(statements.indexOf('http://www.w3.org/ns/posix/stat#File'), -1);
114+
115+
rm('sampleContainer/magicType.ttl');
116+
done();
117+
});
118+
});
119+
120+
it('should not inherit type of BasicContainer/Container if type is File', function(done) {
121+
write('@prefix dcterms: <http://purl.org/dc/terms/>.' +
122+
'@prefix o: <http://example.org/ontology>.' +
123+
'<> a <http://www.w3.org/ns/ldp#Container> ;' +
124+
' dcterms:title "This is a container" ;' +
125+
' o:limit 500000.00 .', 'sampleContainer/containerFile.ttl');
126+
127+
write('@prefix dcterms: <http://purl.org/dc/terms/>.' +
128+
'@prefix o: <http://example.org/ontology>.' +
129+
'<> a <http://www.w3.org/ns/ldp#BasicContainer> ;' +
130+
' dcterms:title "This is a container" ;' +
131+
' o:limit 500000.00 .', 'sampleContainer/basicContainerFile.ttl');
88132

133+
ldp.listContainer(__dirname + '/resources/sampleContainer/', 'https://server.tld', '', function (err, data) {
89134
var graph = $rdf.graph();
90135
$rdf.parse(
91136
data,
92137
graph,
93138
'https://server.tld/sampleContainer',
94139
'text/turtle');
95140

96-
var statements = graph.each(
97-
undefined,
98-
ns.ldp('contains'),
141+
var basicContainerStatements = graph.each(
142+
$rdf.sym('https://server.tld/basicContainerFile.ttl'),
143+
ns.rdf('type'),
99144
undefined);
100145

101-
assert.notEqual(graph.statements.length, 0);
102-
assert.equal(statements.length, 8);
103-
assert.notOk(err);
146+
assert.equal(basicContainerStatements.length, 1);
147+
148+
var containerStatements = graph.each(
149+
$rdf.sym('https://server.tld/containerFile.ttl'),
150+
ns.rdf('type'),
151+
undefined);
152+
153+
assert.equal(containerStatements.length, 1);
154+
155+
basicContainerStatements.forEach(function(statement) {
156+
assert.equal(statement.uri, ns.stat('File').uri);
157+
});
158+
159+
containerStatements.forEach(function(statement) {
160+
assert.equal(statement.uri, ns.stat('File').uri);
161+
});
162+
163+
rm('sampleContainer/containerFile.ttl');
164+
rm('sampleContainer/basicContainerFile.ttl');
104165
done();
105166
});
106167
});
168+
169+
it('should ldp:contains the same amount of files in dir', function(done) {
170+
ldp.listContainer(__dirname + '/resources/sampleContainer/', 'https://server.tld', '', function (err, data) {
171+
fs.readdir(__dirname + '/resources/sampleContainer/', function(err, files) {
172+
var graph = $rdf.graph();
173+
$rdf.parse(
174+
data,
175+
graph,
176+
'https://server.tld/sampleContainer',
177+
'text/turtle');
178+
179+
var statements = graph.each(
180+
undefined,
181+
ns.ldp('contains'),
182+
undefined);
183+
184+
assert.notEqual(graph.statements.length, 0);
185+
assert.equal(statements.length, files.length);
186+
assert.notOk(err);
187+
done();
188+
});
189+
});
190+
});
107191
});
108192
});

0 commit comments

Comments
 (0)