Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / writerperfect / qa / uitest / epubexport / epubexport.py
blobb8e7d3f52fd9b496591a7d800c4a478341611b47
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from com.sun.star.beans import PropertyValue
8 from libreoffice.uno.propertyvalue import mkPropertyValues
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict
11 import uno
14 # Test for EPUBExportDialog and EPUBExportUIComponent.
15 class EPUBExportTest(UITestCase):
17 def testUIComponent(self):
18 def handleDialog(dialog):
19 # Select the second entry to request EPUB2, not EPUB3.
20 dialog.getChild("versionlb").executeAction("SELECT", mkPropertyValues({"POS": "1"}))
21 dialog.getChild("ok").executeAction("CLICK", tuple())
23 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
25 # Make sure we get what we asked for.
26 self.assertEqual("com.sun.star.comp.Writer.EPUBExportUIComponent", uiComponent.getImplementationName())
27 self.assertEqual(True, uiComponent.supportsService("com.sun.star.ui.dialogs.FilterOptionsDialog"))
28 # Just make sure this doesn't fail.
29 uiComponent.setTitle(str())
31 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
32 propertyValues = uiComponent.getPropertyValues()
33 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
34 epubVersion = [i.Value for i in filterData if i.Name == "EPUBVersion"][0]
35 # This was 30, EPUBExportDialog::VersionSelectHdl() did not set the version.
36 self.assertEqual(20, epubVersion)
38 def testCustomProperties(self):
39 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
41 # Make sure that by default the version is not altered.
42 propertyValues = uiComponent.getPropertyValues()
43 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
44 self.assertEqual(0, len([i.Value for i in filterData if i.Name == "EPUBVersion"]))
46 # But if we set it explicitly, then it's retained, even without interacting with the UI.
47 filterData = (PropertyValue(Name="EPUBVersion", Value=30),)
48 propertyValues = (PropertyValue(Name="FilterData", Value=uno.Any("[]com.sun.star.beans.PropertyValue", filterData)),)
49 uiComponent.setPropertyValues(propertyValues)
50 propertyValues = uiComponent.getPropertyValues()
51 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
52 epubVersion = [i.Value for i in filterData if i.Name == "EPUBVersion"][0]
53 self.assertEqual(30, epubVersion)
55 def testDialogVersionInput(self):
56 def handleDialog(dialog):
57 versionlb = get_state_as_dict(dialog.getChild("versionlb"))
58 # Log the state of the versionlb widget and exit.
59 positions.append(versionlb["SelectEntryPos"])
60 dialog.getChild("ok").executeAction("CLICK", tuple())
62 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
63 positions = []
64 for version in (20, 30):
65 filterData = (PropertyValue(Name="EPUBVersion", Value=version),)
66 propertyValues = (PropertyValue(Name="FilterData", Value=uno.Any("[]com.sun.star.beans.PropertyValue", filterData)),)
67 uiComponent.setPropertyValues(propertyValues)
68 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
69 # Make sure that initializing with 2 different versions results in 2 different widget states.
70 self.assertEqual(2, len(set(positions)))
72 def testCoverImage(self):
73 def handleDialog(dialog):
74 dialog.getChild("coverpath").executeAction("TYPE", mkPropertyValues({"TEXT": "cover.png"}))
75 dialog.getChild("ok").executeAction("CLICK", tuple())
77 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
79 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
80 propertyValues = uiComponent.getPropertyValues()
81 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
82 # The RVNGCoverImage key was missing, EPUBExportDialog::OKClickHdl() did not set it.
83 coverImage = [i.Value for i in filterData if i.Name == "RVNGCoverImage"][0]
84 self.assertEqual("cover.png", coverImage)
86 def testMediaDir(self):
87 def handleDialog(dialog):
88 dialog.getChild("mediadir").executeAction("TYPE", mkPropertyValues({"TEXT": "file:///foo/bar"}))
89 dialog.getChild("ok").executeAction("CLICK", tuple())
91 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
93 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
94 propertyValues = uiComponent.getPropertyValues()
95 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
96 # The RVNGMediaDir key was missing, EPUBExportDialog::OKClickHdl() did not set it.
97 mediaDir = [i.Value for i in filterData if i.Name == "RVNGMediaDir"][0]
98 self.assertEqual("file:///foo/bar", mediaDir)
100 def testFixedLayout(self):
101 def handleDialog(dialog):
102 # Select the second entry to request fixed, not reflowable layout.
103 dialog.getChild("layoutlb").executeAction("SELECT", mkPropertyValues({"POS": "1"}))
104 dialog.getChild("ok").executeAction("CLICK", tuple())
106 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
108 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
109 propertyValues = uiComponent.getPropertyValues()
110 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
111 # The EPUBLayoutMethod key was missing, EPUBExportDialog::OKClickHdl() did not set it.
112 layout = [i.Value for i in filterData if i.Name == "EPUBLayoutMethod"][0]
113 # 1 stands for libepubgen::EPUB_LAYOUT_METHOD_FIXED.
114 self.assertEqual(1, layout)
116 def testMeta(self):
117 def handleDialog(dialog):
118 dialog.getChild("identifier").executeAction("TYPE", mkPropertyValues({"TEXT": "baddcafe-e394-4cd6-9b83-7172794612e5"}))
119 dialog.getChild("title").executeAction("TYPE", mkPropertyValues({"TEXT": "unknown title from ui"}))
120 dialog.getChild("author").executeAction("TYPE", mkPropertyValues({"TEXT": "unknown author from ui"}))
121 dialog.getChild("language").executeAction("TYPE", mkPropertyValues({"TEXT": "sk"}))
122 dialog.getChild("date").executeAction("TYPE", mkPropertyValues({"TEXT": "2013-11-20T17:16:07Z"}))
123 dialog.getChild("ok").executeAction("CLICK", tuple())
125 uiComponent = self.ui_test._xContext.ServiceManager.createInstanceWithContext("com.sun.star.comp.Writer.EPUBExportUIComponent", self.ui_test._xContext)
127 self.ui_test.execute_blocking_action(action=uiComponent.execute, dialog_handler=handleDialog)
128 propertyValues = uiComponent.getPropertyValues()
129 filterData = [i.Value for i in propertyValues if i.Name == "FilterData"][0]
130 # These keys were missing, EPUBExportDialog::OKClickHdl() did not set them.
131 identifier = [i.Value for i in filterData if i.Name == "RVNGIdentifier"][0]
132 self.assertEqual("baddcafe-e394-4cd6-9b83-7172794612e5", identifier)
133 title = [i.Value for i in filterData if i.Name == "RVNGTitle"][0]
134 self.assertEqual("unknown title from ui", title)
135 initialCreator = [i.Value for i in filterData if i.Name == "RVNGInitialCreator"][0]
136 self.assertEqual("unknown author from ui", initialCreator)
137 language = [i.Value for i in filterData if i.Name == "RVNGLanguage"][0]
138 self.assertEqual("sk", language)
139 date = [i.Value for i in filterData if i.Name == "RVNGDate"][0]
140 self.assertEqual("2013-11-20T17:16:07Z", date)
142 # vim: set shiftwidth=4 softtabstop=4 expandtab: