| 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 libreoffice.uno.propertyvalue import mkPropertyValues |
| 11 |
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file |
| 12 |
|
| 13 |
class findReplace(UITestCase): |
| 14 |
def test_find_impress(self): |
| 15 |
with self.ui_test.load_file(get_url_for_data_file("findReplace.odp")) as impress_doc: |
| 16 |
|
| 17 |
# check current slide is 1 |
| 18 |
self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 1) |
| 19 |
|
| 20 |
self.assertEqual("First first first", impress_doc.DrawPages[0][1].String) |
| 21 |
self.assertEqual("second", impress_doc.DrawPages[1][1].String) |
| 22 |
self.assertEqual("Third", impress_doc.DrawPages[2][1].String) |
| 23 |
self.assertEqual("Text size 16", impress_doc.DrawPages[3][1].String) |
| 24 |
|
| 25 |
# search for string "second" |
| 26 |
with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="close") as xDialog: |
| 27 |
searchterm = xDialog.getChild("searchterm") |
| 28 |
searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"})) #2nd slide |
| 29 |
xsearch = xDialog.getChild("search") |
| 30 |
xsearch.executeAction("CLICK", tuple()) |
| 31 |
|
| 32 |
# verify we moved to slide 2 |
| 33 |
self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 2) |
| 34 |
|
| 35 |
# search for string "third" |
| 36 |
searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) |
| 37 |
searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) |
| 38 |
searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"third"})) |
| 39 |
xsearch.executeAction("CLICK", tuple()) |
| 40 |
|
| 41 |
#verify we moved to slide 3 |
| 42 |
self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 3) #3rd slide |
| 43 |
|
| 44 |
self.assertEqual("First first first", impress_doc.DrawPages[0][1].String) |
| 45 |
self.assertEqual("second", impress_doc.DrawPages[1][1].String) |
| 46 |
self.assertEqual("Third", impress_doc.DrawPages[2][1].String) |
| 47 |
self.assertEqual("Text size 16", impress_doc.DrawPages[3][1].String) |
| 48 |
|
| 49 |
# now open dialog and verify find="third" (remember last value); |
| 50 |
# replace value with "First" (click match case) with word "Replace" |
| 51 |
# click twice the Replace button, check "Replace first first" |
| 52 |
|
| 53 |
# open the dialog again |
| 54 |
with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="close") as xDialog: |
| 55 |
|
| 56 |
# verify search string is still "third" from previous search |
| 57 |
searchterm = xDialog.getChild("searchterm") |
| 58 |
self.assertEqual(get_state_as_dict(searchterm)["Text"], "third") |
| 59 |
|
| 60 |
# replace it with "First" |
| 61 |
searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) |
| 62 |
searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) |
| 63 |
searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"First"})) |
| 64 |
|
| 65 |
# click "match case" |
| 66 |
matchcase = xDialog.getChild("matchcase") |
| 67 |
matchcase.executeAction("CLICK", tuple()) #click match case |
| 68 |
|
| 69 |
# set the replace string to "Replace" |
| 70 |
replaceterm = xDialog.getChild("replaceterm") |
| 71 |
replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace"})) #replace textbox |
| 72 |
|
| 73 |
# hit replace button 2 times |
| 74 |
replace = xDialog.getChild("replace") |
| 75 |
|
| 76 |
replace.executeAction("CLICK", tuple()) |
| 77 |
replace.executeAction("CLICK", tuple()) #click twice Replace button (one selects, second replaces) |
| 78 |
|
| 79 |
# now replace first (uncheck match case) with word "aaa" - click once Replace All button, check "Replace aaa aaa" |
| 80 |
matchcase = xDialog.getChild("matchcase") |
| 81 |
matchcase.executeAction("CLICK", tuple()) # uncheck match case |
| 82 |
|
| 83 |
self.assertEqual("Replace first first", impress_doc.DrawPages[0][1].String) |
| 84 |
self.assertEqual("second", impress_doc.DrawPages[1][1].String) |
| 85 |
# tdf#145868 - Third was search for earlier, but never should have been replaced |
| 86 |
self.assertEqual("Third", impress_doc.DrawPages[2][1].String) |
| 87 |
self.assertEqual("Text size 16", impress_doc.DrawPages[3][1].String) |
| 88 |
|
| 89 |
replaceterm = xDialog.getChild("replaceterm") |
| 90 |
replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) |
| 91 |
replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) |
| 92 |
replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"})) |
| 93 |
replaceall = xDialog.getChild("replaceall") |
| 94 |
replaceall.executeAction("CLICK", tuple()) # click on replace all button |
| 95 |
|
| 96 |
self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 1) |
| 97 |
|
| 98 |
# tdf#122788: Without the fix in place, this test would have failed with |
| 99 |
# AssertionError: 'Replace aaa aaa' != 'Replace first first' |
| 100 |
self.assertEqual("Replace aaa aaa", impress_doc.DrawPages[0][1].String) |
| 101 |
self.assertEqual("second", impress_doc.DrawPages[1][1].String) |
| 102 |
self.assertEqual("Third", impress_doc.DrawPages[2][1].String) |
| 103 |
self.assertEqual("Text size 16", impress_doc.DrawPages[3][1].String) |
| 104 |
|
| 105 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |