summaryrefslogtreecommitdiff
path: root/sw/qa/uibase/shells
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-01-13 08:20:48 +0100
committerMiklos Vajna <vmiklos@collabora.com>2023-01-13 09:55:20 +0000
commit402ab3d145a1e8e123caabf4567aef7b6631fc3c (patch)
tree6ac57bdfb9293c64b9a3b91d4d4a99cc9c24e706 /sw/qa/uibase/shells
parent55b534660e3fc99a4e4e07cf05df7798e9ba0726 (diff)
sw: add a new .uno:UpdateField UNO command
This is similar to commit ea208f6004770eb4b81d28e6930cd0c7bd5d8f12 (sw: add a new .uno:UpdateBookmark UNO command, 2023-01-11, but that was for the bookmark under cursor, and this is for fields (refmarks as a start). Change-Id: I3e547b668361898b7ed734ea325fdf1d74e5dbb2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145427 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa/uibase/shells')
-rw-r--r--sw/qa/uibase/shells/shells.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 8a7d7fce4f87..22cd709378cb 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -809,6 +809,58 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateBookmark)
CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd());
}
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmark)
+{
+ // Given a document with a refmark:
+ createSwDoc();
+ SwDoc* pDoc = getSwDoc();
+ uno::Sequence<css::beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))),
+ comphelper::makePropertyValue(
+ "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} old refmark"))),
+ comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))),
+ };
+ dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+
+ // When updating that refmark:
+ std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json(
+{
+ "TypeName": {
+ "type": "string",
+ "value": "SetRef"
+ },
+ "NamePrefix": {
+ "type": "string",
+ "value": "ZOTERO_ITEM CSL_CITATION"
+ },
+ "Field": {
+ "type": "[]com.sun.star.beans.PropertyValue",
+ "value": {
+ "Name": {
+ "type": "string",
+ "value": "ZOTERO_ITEM CSL_CITATION {} new refmark"
+ },
+ "Content": {
+ "type": "string",
+ "value": "new content"
+ }
+ }
+ }
+}
+)json");
+ aArgs = comphelper::containerToSequence(aArgsVec);
+ dispatchCommand(mxComponent, ".uno:UpdateField", aArgs);
+
+ // Then make sure that the document text features the new content:
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: new content
+ // - Actual : old content
+ // i.e. the content was not updated.
+ CPPUNIT_ASSERT_EQUAL(OUString("new content"), pTextNode->GetText());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */