Debian Codegraph @

sw/qa/uitest/writer_tests8/tdf160170.py

raw symbols SCIP
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2 #
3 # This file is part of the LibreOffice project.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from libreoffice.linguistic.linguservice import get_lingu_service_manager
13
14 # handle tdf#160170 overshrank lines with smart justify and hyphenation
15
16 class tdf160170(UITestCase):
17 def is_supported_locale(self, language, country):
18 xLinguServiceManager = get_lingu_service_manager(self.ui_test._xContext)
19 xHyphenator = xLinguServiceManager.getHyphenator()
20 locales = xHyphenator.getLocales()
21 for locale in locales:
22 if language is not None:
23 if locale.Language != language:
24 continue
25
26 if country is not None:
27 if locale.Country != country:
28 continue
29
30 # we found the correct combination
31 return True
32
33 def set_custom_hyphenation(self):
34 with self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialog:
35
36 xPages = xDialog.getChild("pages")
37 xLanguageEntry = xPages.getChild('2') # Language Settings
38 xLanguageEntry.executeAction("EXPAND", tuple())
39 xxLanguageEntryWritingAidsEntry = xLanguageEntry.getChild('1')
40 xxLanguageEntryWritingAidsEntry.executeAction("SELECT", tuple()) # Writing Aids
41
42 # add hyphenation "phare=tra" to the custom dictionary
43 # to solve the non-accessible hyphenation patterns for the test
44
45 # Select an editable dictionary (list of Ignored words)
46 dictionaries = xDialog.getChild("lingudicts")
47 hasEditableDictionary = False
48 for i in dictionaries.getChildren():
49 entry = dictionaries.getChild(i)
50 entry_label = get_state_as_dict(entry)["Text"]
51 if entry_label == "List of Ignored Words [All]":
52 hasEditableDictionary = True
53 entry.executeAction("SELECT", tuple()) # an editable user dictionary
54 break
55
56 self.assertEqual(True, hasEditableDictionary)
57
58 # open Edit dialog window
59 edit = xDialog.getChild("lingudictsedit")
60 with self.ui_test.execute_blocking_action(edit.executeAction, args=('CLICK', ()), close_button="close") as xEdit:
61 # write phare=tra into the input box
62 inputbox = xEdit.getChild("word")
63 inputbox.executeAction("TYPE", mkPropertyValues({"TEXT": "phare=tra"}))
64 add = xEdit.getChild("newreplace")
65 add.executeAction("CLICK", tuple())
66
67 def test_tdf160170(self):
68 supported_locale = self.is_supported_locale("en", "US")
69 if not supported_locale:
70 self.skipTest("no hyphenation patterns for en_US available")
71
72 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
73 with self.ui_test.load_file(get_url_for_data_file("tdf160170.fodt")) as writer_doc:
74 # we must not depend on the installed hyphenation patterns,
75 # so extend user dictionary temporarily with the hyphenation phare=tra
76 self.set_custom_hyphenation()
77 xToolkit.processEventsToIdle()
78 # delete the text of the first line
79 self.xUITest.executeCommand(".uno:GoToEndOfLine")
80 self.xUITest.executeCommand('.uno:StartOfDocumentSel')
81 self.xUITest.executeCommand('.uno:Delete')
82 paragraphs = writer_doc.Text.createEnumeration()
83 para1 = paragraphs.nextElement()
84 # This was " pellentesque est orvi.", i.e. too much shrinking
85 self.assertEqual("tra. Fusce pellentesque est orci.", para1.String)