xmlContentTypes_test.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package xlsx
  2. import (
  3. "encoding/xml"
  4. . "gopkg.in/check.v1"
  5. )
  6. type ContentTypesSuite struct{}
  7. var _ = Suite(&ContentTypesSuite{})
  8. func (l *ContentTypesSuite) TestMarshalContentTypes(c *C) {
  9. var types xlsxTypes = xlsxTypes{}
  10. types.Overrides = make([]xlsxOverride, 1)
  11. types.Overrides[0] = xlsxOverride{PartName: "/_rels/.rels", ContentType: "application/vnd.openxmlformats-package.relationships+xml"}
  12. output, err := xml.Marshal(types)
  13. stringOutput := xml.Header + string(output)
  14. c.Assert(err, IsNil)
  15. expectedContentTypes := `<?xml version="1.0" encoding="UTF-8"?>
  16. <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override></Types>`
  17. c.Assert(stringOutput, Equals, expectedContentTypes)
  18. }
  19. func (l *ContentTypesSuite) TestMakeDefaultContentTypes(c *C) {
  20. var types xlsxTypes = MakeDefaultContentTypes()
  21. c.Assert(len(types.Overrides), Equals, 8)
  22. c.Assert(types.Overrides[0].PartName, Equals, "/_rels/.rels")
  23. c.Assert(types.Overrides[0].ContentType, Equals, "application/vnd.openxmlformats-package.relationships+xml")
  24. c.Assert(types.Overrides[1].PartName, Equals, "/docProps/app.xml")
  25. c.Assert(types.Overrides[1].ContentType, Equals, "application/vnd.openxmlformats-officedocument.extended-properties+xml")
  26. c.Assert(types.Overrides[2].PartName, Equals, "/docProps/core.xml")
  27. c.Assert(types.Overrides[2].ContentType, Equals, "application/vnd.openxmlformats-package.core-properties+xml")
  28. c.Assert(types.Overrides[3].PartName, Equals, "/xl/_rels/workbook.xml.rels")
  29. c.Assert(types.Overrides[3].ContentType, Equals, "application/vnd.openxmlformats-package.relationships+xml")
  30. c.Assert(types.Overrides[4].PartName, Equals, "/xl/sharedStrings.xml")
  31. c.Assert(types.Overrides[4].ContentType, Equals, "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml")
  32. c.Assert(types.Overrides[5].PartName, Equals, "/xl/styles.xml")
  33. c.Assert(types.Overrides[5].ContentType, Equals, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml")
  34. c.Assert(types.Overrides[6].PartName, Equals, "/xl/workbook.xml")
  35. c.Assert(types.Overrides[6].ContentType, Equals, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
  36. c.Assert(types.Overrides[7].PartName, Equals, "/xl/theme/theme1.xml")
  37. c.Assert(types.Overrides[7].ContentType, Equals, "application/vnd.openxmlformats-officedocument.theme+xml")
  38. c.Assert(types.Defaults[0].Extension, Equals, "rels")
  39. c.Assert(types.Defaults[0].ContentType, Equals, "application/vnd.openxmlformats-package.relationships+xml")
  40. c.Assert(types.Defaults[1].Extension, Equals, "xml")
  41. c.Assert(types.Defaults[1].ContentType, Equals, "application/xml")
  42. }