Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests9 / tdf148437.py
blobd457b232489232af90493667c36391f793c0b53e
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
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/.
10 from uitest.framework import UITestCase
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from libreoffice.calc.document import get_cell_by_position
13 from uitest.uihelper.calc import enter_text_to_cell
14 from uitest.uihelper.common import get_state_as_dict, select_pos
16 class tdf148437(UITestCase):
17 def test_tdf148437_formula_cell(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 xGridWindow = xCalcDoc.getChild("grid_window")
22 # Select a cell including a formula and insert a hyperlink
23 enter_text_to_cell(xGridWindow, "A1", "=HYPERLINK(\"www.libreoffice.org\";\"LibreOffice\")")
24 # Move focus to ensure cell is not in edit mode
25 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
26 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
27 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
28 xTab = xDialog.getChild("tabcontrol")
29 select_pos(xTab, "0")
31 # Text should contain the text of the cell
32 xTarget = xDialog.getChild("target")
33 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
34 xIndication = xDialog.getChild("indication")
35 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice")
37 # Insert a sample hyperlink
38 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "https://www.documentfoundation.org/"}))
39 xIndication.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
40 xIndication.executeAction("TYPE", mkPropertyValues({"TEXT": "LibreOffice Document Foundation"}))
42 # Move focus to ensure cell is not in edit mode
43 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
44 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
46 # Check contents of the cell
47 xCell = get_cell_by_position(document, 0, 0, 0)
48 self.assertEqual(xCell.getString(), "LibreOffice Document Foundation")
49 xTextFields = xCell.getTextFields()
50 self.assertEqual(xTextFields.getCount(), 1)
51 self.assertEqual(xTextFields.getByIndex(0).URL, "https://www.documentfoundation.org/")
53 # vim: set shiftwidth=4 softtabstop=4 expandtab: