3 from org
.libreoffice
.unotest
import UnoInProcess
4 from com
.sun
.star
.text
.ControlCharacter
import PARAGRAPH_BREAK
6 class TestVarFields(unittest
.TestCase
):
12 cls
._uno
= UnoInProcess()
14 cls
._xDoc
= cls
._uno
.openEmptyWriterDoc()
17 def tearDownClass(cls
):
20 def test_var_fields(self
):
21 """Reproduce fdo#55814.
23 Note: this test was migrated from java (the steps numbering too)
24 sw/qa/complex/writer/VarFields.java
27 xDoc
= self
.__class
__._xDoc
28 xBodyText
= xDoc
.getText()
29 xCursor
= xBodyText
.createTextCursor()
30 # 0. create text field
31 xField
= xDoc
.createInstance("com.sun.star.text.textfield.SetExpression")
32 # 1. fill it with properties
33 self
.__class
__._uno
.setProperties(xField
,
36 "Hint": "trying to reproduce fdo#55814",
40 # 2. create master field
41 xMaster
= xDoc
.createInstance("com.sun.star.text.fieldmaster.SetExpression")
42 # 3. set name of the master field to "foo"
43 xMaster
.setPropertyValue("Name", "foo")
44 # 4. get Dependent Field
46 # 5. connect real field to the master
47 xField
.attachTextFieldMaster(xMaster
)
48 # 6. insert text field into the document
49 xBodyText
.insertTextContent(xCursor
, xField
, False)
50 # 7. retrieve paragraph cursor
51 xParagraphCursor
= xCursor
52 xParagraphCursor
.gotoEndOfParagraph(False) # not selectd
54 xBodyText
.insertControlCharacter(xCursor
, PARAGRAPH_BREAK
, False)
55 # 9. create new text section
56 xTextSection
= xDoc
.createInstance("com.sun.star.text.TextSection")
57 # 10. fill the properties of section
58 self
.__class
__._uno
.checkProperties(
60 {"Condition": "foo EQ 1",
65 # 11. Insert some text to be content on the section
66 xBodyText
.insertString(xCursor
,
67 "The quick brown fox jumps over the lazy dog",
70 xBodyText
.insertTextContent(xCursor
, xTextSection
, True)
71 # 12.1 insert new paragraph. Note: that's here the difference
72 xParagraphCursor
.gotoEndOfParagraph(False) # not select
73 # TODO: how to leave the section now?
74 xBodyText
.insertControlCharacter(xCursor
, PARAGRAPH_BREAK
, False )
75 xBodyText
.insertString(xCursor
, "new paragraph", False)
76 # 13. Access fields to refresh the document
77 xEnumerationAccess
= xDoc
.getTextFields()
78 # 14. refresh document to update the fields
79 xEnumerationAccess
.refresh()
80 # 15. retrieve the field
81 xFieldEnum
= xEnumerationAccess
.createEnumeration()
82 # Note: we have only one field here, that why nextElement() is just fine here
83 xPropSet
= xFieldEnum
.nextElement()
85 readContent
= xPropSet
.getPropertyValue("Content")
86 self
.assertEqual("0", readContent
)
87 readContent
= xPropSet
.getPropertyValue("Value")
88 self
.assertEqual(0.0, readContent
)
89 # 16. change the value of the field from 0 to 1 and check
90 self
.__class
__._uno
.checkProperties(
97 # 17. refresh document to update the fields again
98 xEnumerationAccess
.refresh()
100 url
= os
.path
.join(os
.environ
["TestUserDir"], "VarFields.odt")
101 xDoc
.storeToURL(url
, tuple(list(range(0))))
102 # 19. retrieve the section
103 xPropSet
= xDoc
.getTextSections().getByIndex(0)
104 # 20. retrieve the condition property of that section
105 readContent
= xPropSet
.getPropertyValue("Condition")
108 #self.assertEqual("foo EQ 1", readContent)
110 self
.assertEqual("0", readContent
)
112 if __name__
== '__main__':