cool#10630 lok doc sign: fix Impress sign line when picking a certificate
[LibreOffice.git] / sw / qa / uitest / writer_tests5 / titlePageWizard.py
blob4146dab22d32991557adf8134d239cee93921df8
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/.
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_url_for_data_file
12 # This tests the Format->Title Page wizard, specifically the reset page number portion,
13 # replacing some pages with title pages,
14 # inserting pages in the middle of the document,
15 # and inserting at the very end of the document.
16 class tdf138907(UITestCase):
17 def test_tdf138907(self):
18 with self.ui_test.load_file(get_url_for_data_file("tdf138907_titlePageDialog.odt")) as document:
20 # Confirm the starting state. Just a page break, without a valid restart page number on page 2
21 self.assertEqual(document.CurrentController.PageCount, 5)
22 Paragraphs = document.Text.createEnumeration()
23 Para1 = Paragraphs.nextElement()
24 self.assertEqual(Para1.String, "6")
25 self.assertEqual(Para1.PageDescName, "First Page")
26 Para2 = Paragraphs.nextElement()
27 self.assertEqual(Para2.String, "7")
28 self.assertEqual(Para2.PageDescName, None)
29 Para3 = Paragraphs.nextElement()
30 self.assertEqual(Para3.String, "8")
31 self.assertEqual(Para3.PageDescName, None)
32 Para4 = Paragraphs.nextElement()
33 self.assertEqual(Para4.String, "9")
34 self.assertEqual(Para4.PageDescName, None)
35 Para5 = Paragraphs.nextElement()
36 self.assertEqual(Para5.String, "10")
37 self.assertEqual(Para5.PageDescName, None)
40 #dialog Title Page
41 with self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
42 #set restart page number to 2. With this doc, it defaults to resetting to 1.
43 xRestartNumbering = xDialog.getChild("NF_RESTART_NUMBERING")
44 xRestartNumbering.executeAction("UP", tuple()) # restart numbering at 2
46 Paragraphs = document.Text.createEnumeration()
47 Para1 = Paragraphs.nextElement()
48 self.assertEqual(Para1.String, "6")
49 self.assertEqual(Para1.PageDescName, "First Page")
50 self.assertEqual(Para2.String, "2")
51 Para2 = Paragraphs.nextElement()
52 # Without this fix, there was no PageDescName specified, just Landscape as default.
53 self.assertEqual(Para2.PageDescName, "Landscape")
55 #re-run dialog Title Page
56 with self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog"):
57 pass
59 # Without this fix, re-running the wizard was failing with the title page restarting at page 2.
60 Paragraphs = document.Text.createEnumeration()
61 Para1 = Paragraphs.nextElement()
62 self.assertEqual(Para1.String, "6")
63 self.assertEqual(Para1.PageDescName, "First Page")
64 Para2 = Paragraphs.nextElement()
65 self.assertEqual(Para2.String, "2")
66 self.assertEqual(Para2.PageDescName, "Landscape")
68 #Note: 6 virtual pages, including blank, even page seen in book view
69 self.assertEqual(document.CurrentController.PageCount, 6)
71 #Now test replacing several pages with title and index styles
73 #dialog Title Page
74 with self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
75 #Convert three pages to title/index pages starting at page two.
76 xPageCount = xDialog.getChild("NF_PAGE_COUNT")
77 for _ in range(0,2):
78 xPageCount.executeAction("UP", tuple())
79 xUseStartingPage = xDialog.getChild("RB_PAGE_START")
80 xUseStartingPage.executeAction("CLICK", tuple())
81 xStartingPage = xDialog.getChild("NF_PAGE_START")
82 xStartingPage.executeAction("UP", tuple()) #Start at page 2.
85 Paragraphs = document.Text.createEnumeration()
86 Para1 = Paragraphs.nextElement()
87 self.assertEqual(Para1.String, "6")
88 self.assertEqual(Para1.PageDescName, "First Page")
89 # Without the fix, the following results are all off by one.
90 Para2 = Paragraphs.nextElement()
91 self.assertEqual(Para2.String, "6")
92 self.assertEqual(Para2.PageDescName, "First Page")
93 Para3 = Paragraphs.nextElement()
94 self.assertEqual(Para3.String, "7")
95 self.assertEqual(Para3.PageDescName, "Index")
96 Para4 = Paragraphs.nextElement()
97 self.assertEqual(Para4.String, "8")
98 self.assertEqual(Para4.PageDescName, "Index")
99 Para5 = Paragraphs.nextElement()
100 self.assertEqual(Para5.String, "2")
101 self.assertEqual(Para5.PageDescName, "Landscape")
103 #Now test inserting at the end of the document
105 #dialog Title Page
106 with self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
107 #Insert three title/index pages at the end of the document (plus a content page).
108 newPages = xDialog.getChild("RB_INSERT_NEW_PAGES")
109 newPages.executeAction("CLICK", tuple())
110 xPageCount = xDialog.getChild("NF_PAGE_COUNT")
111 for _ in range(0,2):
112 xPageCount.executeAction("UP", tuple())
113 xUseStartingPage = xDialog.getChild("RB_PAGE_START")
114 xUseStartingPage.executeAction("CLICK", tuple())
115 xStartingPage = xDialog.getChild("NF_PAGE_START")
116 for _ in range(0,18):
117 xStartingPage.executeAction("UP", tuple()) #Start at mythical page 20.
120 # Without the fix, the pages were being inserted before the last page.
121 text = document.Text.String.replace('\r\n', '\n')
122 self.assertEqual(text[0:1], "6")
123 self.assertEqual(text[2:3], "6")
124 self.assertEqual(text[4:5], "7")
125 self.assertEqual(text[6:7], "8")
126 # Without the fix, the new pages were inserted before the last page.
127 self.assertFalse("\n" in text[8:9])
128 #Note: 13 total virtual pages, including four blanks, as seen in book view
129 self.assertEqual(document.CurrentController.PageCount, 13)
131 #Now test inserting in the middle of the document
133 #dialog Title Page
134 with self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
135 #Insert three title/index pages starting at page 2.
136 newPages = xDialog.getChild("RB_INSERT_NEW_PAGES")
137 newPages.executeAction("CLICK", tuple())
138 xPageCount = xDialog.getChild("NF_PAGE_COUNT")
139 for _ in range(0,2):
140 xPageCount.executeAction("UP", tuple())
141 xUseStartingPage = xDialog.getChild("RB_PAGE_START")
142 xUseStartingPage.executeAction("CLICK", tuple())
143 xStartingPage = xDialog.getChild("NF_PAGE_START")
144 for _ in range(0,10):
145 xStartingPage.executeAction("DOWN", tuple()) #Reset to page 1
146 xStartingPage.executeAction("UP", tuple()) #Start at page 2.
149 # Without first re-calculating the layout, the styles were applied to the wrong pages.
150 Paragraphs = document.Text.createEnumeration()
151 Para1 = Paragraphs.nextElement()
152 self.assertEqual(Para1.String, "6")
153 self.assertEqual(Para1.PageDescName, "First Page")
154 # The next three pages are the ones that were just inserted.
155 Para2 = Paragraphs.nextElement()
156 self.assertEqual(Para2.String, "")
157 self.assertEqual(Para2.PageDescName, "First Page")
158 Para3 = Paragraphs.nextElement()
159 self.assertEqual(Para3.String, "")
160 self.assertEqual(Para3.PageDescName, "Index")
161 Para4 = Paragraphs.nextElement()
162 self.assertEqual(Para4.String, "")
163 self.assertEqual(Para4.PageDescName, "Index")
164 # A bit of a quirk is that the style of the first page after the
165 # title page is still First Page - so that is used as the Normal page style.
166 # OK - this is a bit of a strange workflow, so just accept that.
167 Para5 = Paragraphs.nextElement()
168 self.assertEqual(Para5.String, "6")
169 self.assertEqual(Para5.PageDescName, "First Page")
170 Para6 = Paragraphs.nextElement()
171 self.assertEqual(Para6.String, "7")
172 self.assertEqual(Para6.PageDescName, "Index")
173 Para7 = Paragraphs.nextElement()
174 self.assertEqual(Para7.String, "8")
175 self.assertEqual(Para7.PageDescName, "Index")
176 Para8 = Paragraphs.nextElement()
177 self.assertEqual(Para8.String, "2")
178 self.assertEqual(Para8.PageDescName, "Landscape")
179 Para9 = Paragraphs.nextElement()
180 self.assertEqual(Para9.String, "")
181 self.assertEqual(Para9.PageDescName, "First Page")
182 Para10 = Paragraphs.nextElement()
183 self.assertEqual(Para10.String, "")
184 self.assertEqual(Para10.PageDescName, "Index")
185 Para11 = Paragraphs.nextElement()
186 self.assertEqual(Para11.String, "")
187 self.assertEqual(Para11.PageDescName, "Index")
188 # The quirk resets this extra content page to the "style after First page == First Page"
189 Para12 = Paragraphs.nextElement()
190 self.assertEqual(Para12.String, "")
191 self.assertEqual(Para12.PageDescName, "First Page")
192 #Note: 17 total virtual pages, including five blanks, as seen in book view
193 self.assertEqual(document.CurrentController.PageCount, 17)
195 # vim: set shiftwidth=4 softtabstop=4 expandtab: