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
|
var assert = require("assert");
var readContentTypesFromXml = require("../../lib/docx/content-types-reader").readContentTypesFromXml;
var XmlElement = require("../../lib/xml").Element;
var test = require("../testing").test;
describe('readContentTypesFromXml', function() {
test('reads default-per-extension from XML', function() {
var contentTypes = readContentTypesFromXml({
root: new XmlElement("content-types:Types", {}, [
new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"})
])
});
assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png");
});
test('reads overrides in preference to defaults', function() {
var contentTypes = readContentTypesFromXml({
root: new XmlElement("content-types:Types", {}, [
new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"}),
new XmlElement("content-types:Override", {PartName: "/word/media/hat.png", ContentType: "image/hat"})
])
});
assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/hat");
});
test('fallback content types have common image types', function() {
var contentTypes = readContentTypesFromXml({
root: new XmlElement("content-types:Types", {}, [])
});
assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png");
assert.equal(contentTypes.findContentType("word/media/hat.gif"), "image/gif");
assert.equal(contentTypes.findContentType("word/media/hat.jpg"), "image/jpeg");
assert.equal(contentTypes.findContentType("word/media/hat.jpeg"), "image/jpeg");
assert.equal(contentTypes.findContentType("word/media/hat.bmp"), "image/bmp");
assert.equal(contentTypes.findContentType("word/media/hat.tif"), "image/tiff");
assert.equal(contentTypes.findContentType("word/media/hat.tiff"), "image/tiff");
});
test('fallback content types are case insensitive on extension', function() {
var contentTypes = readContentTypesFromXml({
root: new XmlElement("content-types:Types", {}, [])
});
assert.equal(contentTypes.findContentType("word/media/hat.PnG"), "image/png");
});
});
|