context("Inserting images")
test_that("Inserting hyperlinked image", {
# Create a workbook.
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")
# Insert multiple images. Specifically one with a link before and after other
# images to test whether drawings reference the correct index of the drawing
# relationships.
img <- system.file("extdata", "einstein.jpg", package = "openxlsx")
insertImage(wb, "Sheet 1", img)
insertImage(wb, "Sheet 1", img, address = "https://github.com/ycphs/openxlsx")
insertImage(wb, "Sheet 1", img)
# Declare expectations for drawings and drawings_rels xml.
expected_drawings <- list(
"\n 0\n 0\n 0\n 0\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ",
"\n 0\n 0\n 0\n 0\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ",
"\n 0\n 0\n 0\n 0\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n "
)
expected_drawings_rels <- list(
"",
"",
"",
""
)
# Test expectations for drawings and drawings_rels xml.
expect_equal(expected_drawings, wb$drawings[[1]])
expect_equal(expected_drawings_rels, wb$drawings_rels[[1]])
# Test errors.
expect_error(
insertImage(wb, "Sheet 1", img, address = NULL),
"Invalid address"
)
expect_error(
insertImage(wb, "Sheet 1", img, address = NA),
"Invalid address"
)
expect_error(
insertImage(
wb,
"Sheet 1",
img,
address = c("https://github.com/ycphs/openxlsx", "https://github.com/ycphs/openxlsx/issues")
),
"Invalid address"
)
})