diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-04-12 08:25:16 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-04-12 09:06:47 +0200 |
commit | b40f9c536c1cefae8404a3f1c0080473151913d2 (patch) | |
tree | 59da9bd4be86d2e3b8d5415c4158bede7b5c66ba /sw/qa | |
parent | 618d40799d25474c48d984ce1d52b0f08f220958 (diff) |
sw content controls: add initial DOCX export
Wrap the text portions inside the content control inside <w:sdtContent>
and <w:sdt>. Also map the (so far) single property of it to
<w:showingPlcHdr>.
This is just initial export for inline text content controls, more
properties are to be added in follow-up commits.
Change-Id: I21e085496b4c79114b158656c5611aff8ffdd08a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132875
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index e592e376336e..0c357607be22 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -13,6 +13,8 @@ #include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/util/XRefreshable.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/frame/XStorable.hpp> #include <comphelper/scopeguard.hxx> #include <officecfg/Office/Common.hxx> @@ -125,6 +127,38 @@ CPPUNIT_TEST_FIXTURE(Test, testClearingBreak) assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:br", "clear", "all"); } +CPPUNIT_TEST_FIXTURE(Test, testContentControlExport) +{ + // Given a document with a content control around one or more text portions: + mxComponent = loadFromDesktop("private:factory/swriter"); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::makeAny(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to DOCX: + save("Office Open XML Text", maTempFile); + mbExported = true; + + // Then make sure the expected markup is used: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // XPath '//w:sdt/w:sdtPr/w:showingPlcHdr' number of nodes is incorrect + // i.e. the SDT elements were missing on export. + assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:showingPlcHdr", 1); + assertXPath(pXmlDoc, "//w:sdt/w:sdtContent", 1); +} + DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx") { xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); |