-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWikiLongTest.java
More file actions
800 lines (689 loc) · 33.9 KB
/
WikiLongTest.java
File metadata and controls
800 lines (689 loc) · 33.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*
* Copyright (c) 2011-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.tests.wiki;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.Locators;
import org.labkey.test.TestTimeoutException;
import org.labkey.test.WebTestHelper;
import org.labkey.test.categories.Daily;
import org.labkey.test.categories.Wiki;
import org.labkey.test.pages.LabkeyErrorPage;
import org.labkey.test.util.PortalHelper;
import org.labkey.test.util.WikiHelper;
import org.openqa.selenium.WebElement;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.util.PermissionsHelper.EDITOR_ROLE;
import static org.labkey.test.util.PermissionsHelper.PROJECT_ADMIN_ROLE;
import static org.labkey.test.util.PermissionsHelper.READER_ROLE;
@Category({Daily.class, Wiki.class})
@BaseWebDriverTest.ClassTimeout(minutes = 11)
public class WikiLongTest extends BaseWebDriverTest
{
PortalHelper portalHelper = new PortalHelper(this);
private static final String PROJECT_NAME = "WikiVerifyProject";
private static final String PROJECT2_NAME = "WikiCopied";
private static final String WIKI_PAGE1_TITLE = "Page 1 Wiki Title " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE1_NAME= "Page 1 Wiki Name " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE2_NAME = "Page 2 Wiki Name " + BaseWebDriverTest.INJECT_CHARS_2;
private static final String WIKI_PAGE2_TITLE = "Page 2 Wiki Title " + BaseWebDriverTest.INJECT_CHARS_2;
private static final String WIKI_PAGE3_ALTTITLE = "PageBBB has HTML";
private static final String WIKI_PAGE3_NAME_TITLE = "Page 3 Wiki " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE4_TITLE = "New Wiki " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE5_NAME = "Malformed " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE5_TITLE = "Malformed JavaScript Elements Should Work " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE6_NAME = "Index " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE6_TITLE = "Indexed Wiki Page Test " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE7_TITLE = "Page 7 Title For Markdown Test " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE7_NAME= "Page 7 Name For Markdown Test " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE8_TITLE = "Page 8 Title For Delete Subtree Test " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE8_NAME= "Page 8 Name For Delete Subtree Test " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String WIKI_PAGE9_NAME= "Page 9 _blank " + BaseWebDriverTest.INJECT_CHARS_1;
private static final String RESP1_TITLE = "Let's Keep Talking";
private static final String RESP1_BODY = "I disagree";
private static final String USER1 = "wikilong_user1@wikilong.test";
private static final String USER2 = "wikilong_user2@wikilong.test";
private static final String USERS_GROUP = "Users";
private static final String WIKI_PAGE3_WEBPART_TEST = "Best Gene Name";
private static final String WIKI_NAVTREE_TITLE = "NavTree";
private static final String WIKI_TERMS_TITLE = "Terms of Use";
private static final String WIKI_SEARCH_TERM = "okapi";
private static final String WIKI_INDEX_EDIT_CHECKBOX = "wiki-input-shouldIndex";
private static final String WIKI_INDEX_MANAGE_CHECKBOX = "shouldIndex";
private static final String WIKI_DELETE_SUBTREE_CHECKBOX = "isDeletingSubtree";
private final PortalHelper _portalHelper = new PortalHelper(this);
private final WikiHelper _wikiHelper = new WikiHelper(this);
private static final String WIKI_PAGE1_CONTENT =
"1 Title\n" +
"1.1 Subtitle\n" +
"normal normal normal\n" +
"\n" +
"new paragraph\\\\\n" +
"[" + WIKI_PAGE2_NAME + "]";
private static final String WIKI_PAGE2_CONTENT =
"1 Page AAA\n" +
"[Welcome to the WikiLongTest|" + WIKI_PAGE1_NAME + "]";
private static final String WIKI_PAGE3_CONTENT =
"""
<b>Some HTML content</b>
<b>${labkey.webPart(partName='Query', title='My Proteins', schemaName='ms2', queryName='Sequences', allowChooseQuery='true', allowChooseView='true')}</b>
""";
private static final String WIKI_PAGE3_CONTENT_NO_QUERY =
"""
<b>Some HTML content</b>
<b>No query part</b>
""";
private static final String WIKI_PAGE4_CONTENT =
"This is wiki page <i>4</i><br/>${labkey.webPart(partName='Wiki TOC')}";
private static final String WIKI_PAGE5_CONTENT =
"""
<script>
var foo = "<form>Test</form>";
</script>
""";
private static final String WIKI_PAGE6_CONTENT =
"The " + WIKI_SEARCH_TERM +
" was called the African unicorn by Europeans and wasn't widely known to exist until 1901.\n";
private static final String WIKI_PAGE7_WEBPART_SUBSTITUTION = "${labkey.webPart(partName='Lists')}";
private static final String WIKI_PAGE7_CONTENT =
"""
# Title MD
## Subtitle MD
*italic text MD*
<b>escaped</b>
""" + WIKI_PAGE7_WEBPART_SUBSTITUTION;
private static final String SAFE_LINK_HTML = "<a href=\"http://labkey.com\">Safe link</a>";
private static final String FIXUP_LINK_HTML = "<a href=\"http://labkey.com\" target=\"_blank\">Fixup</a>";
private static final String WIKI_PAGE9_CONTENT = SAFE_LINK_HTML + "\n" + FIXUP_LINK_HTML;
private static final String NAVBAR1_CONTENT =
"{labkey:tree|name=core.currentProject}";
private static final String NAVBAR2_CONTENT =
"""
{labkey:tree|name=core.currentProject}
{labkey:tree|name=core.projects}
{labkey:tree|name=core.folderAdmin}
{labkey:tree|name=core.projectAdmin}
{labkey:tree|name=core.siteAdmin}
""";
private static final String HEADER_CONTENT = "Yo! This is the header!";
private static final String RADEOX_LINK_NAME = "radeox";
private static final String RADEOX_LINK_TITLE = "Test Radeox links";
private static final String RADEOX_LINK_CONTENT = """
You want to click on {link:Menu > Storage|/home/project-begin.view}
Isn't this (font)awesome? {link:{span:class=fa fa-sitemap}{span} Sample Finder|/home/project-begin.view}
Consider {link:using <isHidden>true</isHidden> in the XML metadata|/home/project-begin.view}
""";
private static final String RADEOX_HTML_CONTENT = "<div class=\"labkey-wiki\">You want to click on <span class=\"nobr\"><a href=\"/home/project-begin.view\">Menu > Storage</a></span><p class=\"paragraph\">Isn't this (font)awesome? <span class=\"nobr\"><a href=\"/home/project-begin.view\"><span class=\"fa fa-sitemap\"></span> Sample Finder</a></span></p><p class=\"paragraph\">Consider <span class=\"nobr\"><a href=\"/home/project-begin.view\">using <isHidden>true</isHidden> in the XML metadata</a></span></p></div>";
@Override
public List<String> getAssociatedModules()
{
return Arrays.asList("wiki");
}
@Override
protected String getProjectName()
{
return PROJECT_NAME;
}
@Test
public void testSteps()
{
enableEmailRecorder();
_containerHelper.createProject(PROJECT2_NAME, null);
_containerHelper.enableModule(PROJECT2_NAME, "MS2");
_permissionsHelper.setPermissions(USERS_GROUP, EDITOR_ROLE);
clickButton("Save and Finish");
_containerHelper.createProject(PROJECT_NAME, null);
_containerHelper.enableModule(PROJECT_NAME, "MS2");
_permissionsHelper.createPermissionsGroup("testers");
_permissionsHelper.setPermissions("testers", EDITOR_ROLE);
_permissionsHelper.setPermissions(USERS_GROUP, EDITOR_ROLE);
clickButton("Save and Finish");
goToFolderManagement();
clickAndWait(Locator.linkWithText("Folder Type"));
checkCheckbox(Locator.checkboxByTitle("Wiki"));
submit();
goToAdminConsole().clickFullTextSearch();
if (isTextPresent("pause crawler"))
clickButton("pause crawler");
beginAt(getDriver().getCurrentUrl().replace("admin.view", "waitForIdle.view"), 10 * defaultWaitForPage);
clickProject(PROJECT2_NAME);
goToFolderManagement();
clickAndWait(Locator.linkWithText("Folder Type"));
checkCheckbox(Locator.checkboxByTitle("Wiki"));
submit();
clickProject(PROJECT_NAME);
_portalHelper.addWebPart("Wiki");
_portalHelper.addWebPart("Search");
log("Test new wiki page");
_wikiHelper.createNewWikiPage("RADEOX");
_wikiHelper.setWikiName(WIKI_PAGE1_NAME);
_wikiHelper.setWikiTitle(WIKI_PAGE1_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE1_CONTENT);
_wikiHelper.saveWikiPage();
searchFor(PROJECT_NAME, "normal normal normal", 1, WIKI_PAGE1_TITLE);
log("Test adding content to linked but missing wiki.");
WebElement wikiLink = Locator.linkWithText(WIKI_PAGE2_NAME).findElement(getDriver());
clickAndWait(wikiLink);
assertEquals("Page title.", WIKI_PAGE2_NAME, getText(Locators.bodyTitle()));
assertTextPresent("page has no content");
clickAndWait(Locator.linkWithText("add content"));
_wikiHelper.convertWikiFormat("RADEOX");
_wikiHelper.setWikiTitle(WIKI_PAGE2_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE2_CONTENT);
_wikiHelper.saveWikiPage();
clickAndWait(Locator.linkWithText("Welcome to the WikiLongTest"));
assertElementNotPresent(Locator.linkWithText(WIKI_PAGE2_NAME));
searchFor(PROJECT_NAME, "\"Page AAA\"", 1, WIKI_PAGE2_TITLE);
log("Test new wiki page using markdown");
_wikiHelper.createNewWikiPage("MARKDOWN");
_wikiHelper.setWikiName(WIKI_PAGE7_NAME);
_wikiHelper.setWikiTitle(WIKI_PAGE7_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE7_CONTENT);
_wikiHelper.saveWikiPage();
// verify that after saving the markdown that it is rendered as html that does not include the markdown symbols
assertElementPresent(Locator.tagWithText("h1", "Title MD"));
assertElementPresent(Locator.tagWithText("p", "<b>escaped</b>"));
assertElementPresent(Locator.tagWithText("p", WIKI_PAGE7_WEBPART_SUBSTITUTION));
assertTextNotPresent("# Title MD");
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.convertWikiFormat("HTML");
// verify that after converting the markdown to html that it is rendered as html that does not include the markdown symbols
_wikiHelper.saveWikiPage();
assertElementPresent(Locator.tagWithText("h1", "Title MD"));
assertElementPresent(Locator.tagWithText("p", "<b>escaped</b>"));
// Webpart macro
assertTextNotPresent("# Title MD");
searchFor(PROJECT_NAME, "italic text MD", 1, WIKI_PAGE7_TITLE);
log("test html wiki containing malformed javascript entities... we should allow this, see #12268");
_wikiHelper.createNewWikiPage();
_wikiHelper.setWikiName(WIKI_PAGE5_NAME);
_wikiHelper.setWikiTitle(WIKI_PAGE5_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE5_CONTENT);
_wikiHelper.saveWikiPage();
assertTextNotPresent("New Page"); // Should not be an error, so should have left the editor
log("test create new html page with a webpart");
_wikiHelper.createNewWikiPage("HTML");
_wikiHelper.setWikiName(WIKI_PAGE3_NAME_TITLE);
_wikiHelper.setWikiTitle(WIKI_PAGE3_NAME_TITLE);
selectOptionByText(Locator.name("parent"), WIKI_PAGE2_TITLE + " (" + WIKI_PAGE2_NAME + ")");
_wikiHelper.setWikiBody(WIKI_PAGE3_CONTENT);
log("test attachments in wiki");
click(Locator.linkWithText("Attach a file"));
File file = _wikiHelper.getSampleFile();
setFormElement(Locator.name("formFiles[00]"), file);
_wikiHelper.saveWikiPage();
waitForElement(Locator.linkContainingText(file.getName()));
assertTextPresent(WIKI_PAGE3_WEBPART_TEST,
"Some HTML content");
searchFor(PROJECT_NAME, "Wiki", 3, WIKI_PAGE3_NAME_TITLE);
log("test edit");
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.setWikiTitle(WIKI_PAGE3_ALTTITLE);
String wikiPage3ContentEdited =
"<b>Some HTML content</b><br>\n" +
"<b>More HTML content</b><br>\n" +
"<a href='" + WebTestHelper.getContextPath() + "/wiki/" + PROJECT_NAME + "/page.view?name=PageAAA'>Page AAA</a><br>\n";
_wikiHelper.setWikiBody(wikiPage3ContentEdited);
_wikiHelper.saveWikiPage();
assertTextPresent("More HTML content");
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.setWikiBody(WIKI_PAGE3_CONTENT_NO_QUERY);
_wikiHelper.setWikiTitle(WIKI_PAGE3_NAME_TITLE);
_wikiHelper.saveWikiPage();
log("test change renderer type");
assertTextPresent("Some HTML content");
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.convertWikiFormat("TEXT_WITH_LINKS");
_wikiHelper.saveWikiPage();
assertTextPresent("<b>");
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.convertWikiFormat("HTML");
_wikiHelper.saveWikiPage();
log("Check Start Page series works");
searchFor(PROJECT_NAME, "Some HTML", 1, WIKI_PAGE3_NAME_TITLE);
assertElementPresent(Locator.linkWithText(WIKI_PAGE2_TITLE), 2);
log("Check Pages menu works");
clickAndWait(Locator.linkWithText(WIKI_PAGE2_TITLE));
clickAndWait(Locator.linkWithText("next"));
assertTextPresent("Some HTML content");
clickAndWait(Locator.linkWithText("previous"));
assertTextPresent("Welcome to the WikiLongTest");
log("Check sibling order edit works");
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
clickAndWait(Locator.linkWithText("Manage"));
clickButton("Move Down", 0);
clickButton("Save");
clickAndWait(Locator.linkWithText(WIKI_PAGE2_TITLE));
clickAndWait(Locator.linkWithText("next"));
assertElementPresent(Locator.css(".labkey-wiki").containing("Some HTML content"));
clickAndWait(Locator.linkWithText("next"));
assertElementPresent(Locator.css(".labkey-wiki").containing("normal normal normal"));
clickAndWait(Locator.linkWithText("Manage"));
clickButton("Move Up", 0);
clickButton("Save");
clickAndWait(Locator.linkWithText("next"));
assertTextPresent("Page AAA");
log("Check parent reset works");
click(Locator.navTreeExpander(WIKI_PAGE2_TITLE));
clickAndWait(Locator.linkWithText(WIKI_PAGE3_NAME_TITLE));
clickAndWait(Locator.linkWithText("Manage"));
doAndWaitForPageToLoad(() -> selectOptionByText(Locator.name("parent"), WIKI_PAGE1_TITLE + " (" + WIKI_PAGE1_NAME + ")"));
clickButton("Save");
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
clickAndWait(Locator.linkWithText("next"));
assertTextPresent("Some HTML content");
log("test navTree and header");
_wikiHelper.createNewWikiPage("RADEOX");
_wikiHelper.setWikiName("_navTree");
_wikiHelper.setWikiTitle(WIKI_NAVTREE_TITLE);
_wikiHelper.setWikiBody(NAVBAR1_CONTENT);
_wikiHelper.saveWikiPage();
assertElementNotPresent(Locator.linkWithText("Home"));
assertElementPresent(Locator.linkWithText(PROJECT_NAME));
clickAndWait(Locator.linkWithText("Edit"));
_wikiHelper.setWikiBody(NAVBAR2_CONTENT);
_wikiHelper.saveWikiPage();
assertElementPresent(Locator.linkWithText("Projects"));
assertElementPresent(Locator.linkWithText("Manage Project"));
assertElementPresent(Locator.linkWithText("Manage Site"));
//test deleting via edit page
clickAndWait(Locator.linkWithText("Edit"));
deleteWikiPage(false);
assertElementNotPresent(Locator.linkWithText(WIKI_NAVTREE_TITLE));
_wikiHelper.createNewWikiPage("HTML");
_wikiHelper.setWikiName("_header");
_wikiHelper.setWikiTitle("Header");
_wikiHelper.setWikiBody(HEADER_CONTENT);
_wikiHelper.saveWikiPage();
clickAndWait(Locator.linkWithText("Header"));
assertTextPresent(HEADER_CONTENT);
clickAndWait(Locator.linkWithText("Edit").index(0));
deleteWikiPage(false);
assertTextNotPresent(HEADER_CONTENT);
log("Return to where we were...");
click(Locator.navTreeExpander(WIKI_PAGE1_TITLE));
clickAndWait(Locator.linkWithText(WIKI_PAGE3_NAME_TITLE));
log("test versions");
clickAndWait(Locator.linkWithText("History"));
clickAndWait(Locator.linkWithText("2"));
clickButton("Make Current");
assertTextPresent("6");
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
clickAndWait(Locator.linkWithText("next"));
assertTextPresent("More HTML content", WIKI_PAGE3_ALTTITLE);
log("test copy wiki");
portalHelper.clickWebpartMenuItem("Pages", true, "Copy");
clickAndWait(Locator.linkWithText(PROJECT2_NAME));
clickButton("Copy Pages");
log("test wiki customize link");
clickTab("Portal");
_portalHelper.addWebPart("Wiki");
portalHelper.clickWebpartMenuItem("Wiki", true, "Customize");
log("check that container is set to current project");
selectOptionByText(Locator.name("webPartContainer"), "/" + PROJECT_NAME);
click(Locator.linkWithText("restore to this folder's default page."));
assertOptionEquals(Locator.name("webPartContainer"), "/" + PROJECT2_NAME);
log("set container and page");
//page names are fetched via AJAX, so wait for them to be populated
waitForText(WIKI_PAGE2_NAME + " (" + WIKI_PAGE2_TITLE + ")");
selectOptionByText(Locator.name("name"), WIKI_PAGE2_NAME + " (" + WIKI_PAGE2_TITLE + ")");
sleep(500);
clickButton("Submit");
clickAndWait(Locator.linkWithText("Welcome to the WikiLongTest"));
log("make sure it all got copied");
click(Locator.navTreeExpander(WIKI_PAGE1_TITLE));
clickAndWait(Locator.linkWithText(WIKI_PAGE3_ALTTITLE));
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
log("Check Permissions");
log("Create fake user for permissions check");
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.clickManageGroup(USERS_GROUP);
uncheckCheckbox(Locator.name("sendEmail"));
setFormElement(Locator.name("names"), USER1);
clickButton("Update Group Membership");
log("Check if permissions work");
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.setPermissions(USERS_GROUP, READER_ROLE);
clickButton("Save and Finish");
impersonate(USER1);
clickProject(PROJECT2_NAME);
pushLocation();
assertTextPresent(WIKI_PAGE2_TITLE);
clickTab("Wiki");
assertTextNotPresent("copy pages");
stopImpersonating();
clickProject(PROJECT2_NAME);
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.removePermission(USERS_GROUP, EDITOR_ROLE);
clickButton("Save and Finish");
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.removePermission(USERS_GROUP, READER_ROLE);
clickButton("Save and Finish");
impersonate(USER1);
assertElementNotPresent(Locator.linkWithText(PROJECT2_NAME)); // Project should not be visible
popLocation();
new LabkeyErrorPage(getDriver()).assertUnauthorized(checker());
goToHome();
stopImpersonating();
log("Check if readers can read from other projects");
clickProject(PROJECT2_NAME);
portalHelper.clickWebpartMenuItem(WIKI_PAGE2_TITLE, true, "Customize");
selectOptionByText(Locator.name("webPartContainer"), "/" + PROJECT_NAME);
//page names are now fetched via AJAX, so wait for them to be populated
waitForText(WIKI_PAGE2_NAME + " (" + WIKI_PAGE2_TITLE + ")");
selectOptionByText(Locator.name("name"), WIKI_PAGE2_NAME + " (" + WIKI_PAGE2_TITLE + ")");
submit();
assertTextPresent(WIKI_PAGE2_TITLE);
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.setPermissions(USERS_GROUP, PROJECT_ADMIN_ROLE);
clickButton("Save and Finish");
impersonate(USER1);
clickProject(PROJECT2_NAME);
assertTextNotPresent("Welcome to the WikiLongTest");
log("Also check copying permission");
clickTab("Wiki");
portalHelper.clickWebpartMenuItem("Pages", true, "Copy");
assertTextNotPresent(PROJECT_NAME);
stopImpersonating();
clickProject(PROJECT_NAME);
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.clickManageGroup(USERS_GROUP);
setFormElement(Locator.name("names"), USER1);
uncheckCheckbox(Locator.checkboxByName("sendEmail"));
clickButton("Update Group Membership");
impersonate(USER1);
clickProject(PROJECT2_NAME);
assertTextPresent(WIKI_PAGE2_TITLE);
log("Also check copying permission");
clickTab("Wiki");
portalHelper.clickWebpartMenuItem("Pages", true, "Copy");
assertElementNotPresent(Locator.linkWithText(PROJECT_NAME));
stopImpersonating();
clickProject(PROJECT_NAME);
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.setPermissions(USERS_GROUP, PROJECT_ADMIN_ROLE);
clickButtonContainingText("Save and Finish");
log("make sure the changes went through");
impersonate(USER1);
clickProject(PROJECT2_NAME);
clickTab("Wiki");
portalHelper.clickWebpartMenuItem("Pages", true, "Copy");
assertElementPresent(Locator.linkWithText(PROJECT_NAME));
log("test fixup for unsafe _blank targets, see #33356");
_wikiHelper.createNewWikiPage();
_wikiHelper.setWikiName(WIKI_PAGE9_NAME);
_wikiHelper.setWikiBody(WIKI_PAGE9_CONTENT);
_wikiHelper.saveWikiPage();
assertTextNotPresent("New Page"); // Should not be an error, so should have left the editor
String renderedPage9 = getHtmlSource();
assertFalse("Link needing fixup wasn't fixed up", renderedPage9.contains(FIXUP_LINK_HTML));
assertTrue("Fixed up link not present", renderedPage9.contains("<a href=\"http://labkey.com\" rel=\"noopener noreferrer\" target=\"_blank\">Fixup</a>"));
assertTrue("Safe link mangled", renderedPage9.contains(SAFE_LINK_HTML));
log("Ensure non-developer can't save script");
_wikiHelper.createNewWikiPage();
_wikiHelper.setWikiName("Unsaveable");
_wikiHelper.setWikiBody(WIKI_PAGE5_CONTENT);
_wikiHelper.saveWikiPage(false);
waitForText("There was a problem while saving: Illegal element <script>. For permissions to use this element, contact your system administrator.");
_wikiHelper.setWikiBody("<a onclick=\"alert('test');\">test</a>");
_wikiHelper.saveWikiPage(false);
waitForText("There was a problem while saving: Illegal attribute 'onclick' on element <a>");
stopImpersonating(false);
log("delete wiki web part");
clickProject(PROJECT2_NAME);
clickTab("Portal");
portalHelper.removeWebPart(WIKI_PAGE2_TITLE);
log("test wiki TOC customize link");
_portalHelper.addWebPart("Wiki Table of Contents");
portalHelper.clickWebpartMenuItem("Pages", true, "Customize");
_wikiHelper.setWikiTitle("Test Customize TOC");
log("check that container is set to current project");
assertOptionEquals(Locator.name("webPartContainer"), "/" + PROJECT2_NAME);
selectOptionByText(Locator.name("webPartContainer"), "/" + PROJECT_NAME);
submit();
log("check that TOC title is set correctly");
assertTextPresent("Test Customize TOC",
WIKI_PAGE2_TITLE);
log("Check that 'Copy Pages' in TOC works");
portalHelper.clickWebpartMenuItem("Test Customize TOC", true, "Copy");
clickAndWait(Locator.linkWithText(PROJECT2_NAME));
clickButton("Copy Pages");
assertElementPresent(Locator.linkWithText(WIKI_PAGE1_TITLE), 2);
log("Check that 'New Page' works");
clickProject(PROJECT2_NAME);
clickTab("Portal");
portalHelper.clickWebpartMenuItem("Test Customize TOC", true, "New");
_wikiHelper.convertWikiFormat("HTML");
_wikiHelper.setWikiName(WIKI_PAGE4_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE4_CONTENT);
_wikiHelper.saveWikiPage();
clickProject(PROJECT_NAME);
clickTab("Wiki");
assertTextPresent(WIKI_PAGE4_TITLE);
log("test delete");
clickAndWait(Locator.linkWithText(WIKI_PAGE2_TITLE));
clickAndWait(Locator.linkWithText("Edit"));
deleteWikiPage(false);
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
assertElementPresent(Locator.linkWithText(WIKI_PAGE2_NAME), 1);
/* TODO: re-enable when this blocking issue is resolved:
https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=31184
indexTest();
*/
log("test delete subtree");
// create child first
_wikiHelper.createNewWikiPage();
_wikiHelper.setWikiName(WIKI_PAGE8_NAME);
_wikiHelper.setWikiTitle(WIKI_PAGE8_TITLE);
selectOptionByText(Locator.name("parent"), " " + WIKI_PAGE3_ALTTITLE + " (" + WIKI_PAGE3_NAME_TITLE + ")");
_wikiHelper.saveWikiPage();
clickAndWait(Locator.linkWithText(WIKI_PAGE3_ALTTITLE));
clickAndWait(Locator.linkWithText("Edit"));
deleteWikiPage(true);
clickAndWait(Locator.linkWithText(WIKI_PAGE1_TITLE));
assertElementPresent(Locator.linkWithText(WIKI_PAGE1_TITLE), 2);
assertElementNotPresent(Locator.linkWithText(WIKI_PAGE3_ALTTITLE));
assertElementNotPresent(Locator.linkWithText(WIKI_PAGE8_TITLE));
testRadeoxLinkEncoding();
//extended wiki test -- generate 2000 pages
// clickProject(PROJECT_NAME);
// clickTab("Wiki");
// for (int i = 0; i <= 1999; i++)
// {
// //test create new html page
// clickAndWait(Locator.linkWithText("new page"));
// _wikiHelper.setWikiName("Page" + Integer.toString(i));
// _wikiHelper.setWikiTitle("Page" + Integer.toString(i));
//
// if (i > 99)
// {
// String parent = Integer.toString(i);
// parent = parent.substring(2);
// selectOption("parent", "Page" + parent + " (Page" + parent + ")");
// }
// setFormElement("body", "Page" + Integer.toString(i));
// submit();
// }
}
// Regression test for Issue 51488
private void testRadeoxLinkEncoding()
{
log("Test Radeox link encoding");
_wikiHelper.createNewWikiPage("RADEOX");
_wikiHelper.setWikiName(RADEOX_LINK_NAME);
_wikiHelper.setWikiTitle(RADEOX_LINK_TITLE);
_wikiHelper.setWikiBody(RADEOX_LINK_CONTENT);
_wikiHelper.saveWikiPage();
// Ensure link content is properly encoded (but not double encoded)
assertTrue(getHtmlSource().contains(RADEOX_HTML_CONTENT));
}
private void deleteWikiPage(boolean isDeletingSubtree)
{
waitForElementToDisappear(Locator.xpath("//a[contains(@class, 'disabled')]/span[text()='Delete Page']"), WAIT_FOR_JAVASCRIPT);
clickButton("Delete Page");
if(isDeletingSubtree)
checkCheckbox(Locator.id(WIKI_DELETE_SUBTREE_CHECKBOX));
clickButton("Delete");
}
//
// Verify a wiki page can be indexed and unindexed via create, edit, and manage
// functionality.
//
private void indexTest()
{
//
// verify that the default option for a new page
// is indexed and content on page can be found
//
log("test index option: default is indexed");
createIndexWiki(true);
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 1, null);
deleteIndexWiki();
//
// create a new page without the index option and verify
// content cannot be found
//
log("test index option: create new page unindexed");
createIndexWiki(false);
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 0, null);
//
// Edit an existing page that was unindexed and turn on the index
//
log("test index option: edit and turn on indexing for a page that was created unindexed");
editIndexWiki(false);
checkCheckbox(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
_wikiHelper.saveWikiPage();
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 1, null);
//
// Edit an existing page that was indexed and turn off the index
//
log("test index option: edit and turn off indexing for a page that was created indexed");
editIndexWiki(true);
uncheckCheckbox(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
_wikiHelper.saveWikiPage();
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 0, null);
//
// manage an existing page: turn on indexing
//
log("test index option: manage and turn on indexing for a page that is unindexed");
// note that this also tests that the index option persisted from the edit page is loaded correctly
// into the manage page
manageIndexWiki(false);
checkCheckbox(Locator.id(WIKI_INDEX_MANAGE_CHECKBOX));
clickButton("Save");
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 1, null);
//
// manage an existing page: turn off indexing
//
log("test index option: manage and turn off indexing for a page that is indexed");
manageIndexWiki(true);
uncheckCheckbox(Locator.id(WIKI_INDEX_MANAGE_CHECKBOX));
clickButton("Save");
searchFor(PROJECT_NAME, WIKI_SEARCH_TERM, 0, null);
//
// final sanity check: make sure the shouldIndex setting persists correctly and is correct
// in the edit page
//
log("test index option: edit and turn off indexing for a page that was created indexed");
editIndexWiki(false);
clickButton("Cancel");
//
// cleanup
//
deleteIndexWiki();
}
//
// helper functions used by indexTest() above
//
private void createIndexWiki(boolean shouldIndex)
{
_wikiHelper.createNewWikiPage("RADEOX");
//
// verify that the index option is checked by default
//
assertChecked(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
_wikiHelper.setWikiName(WIKI_PAGE6_NAME);
_wikiHelper.setWikiTitle(WIKI_PAGE6_TITLE);
_wikiHelper.setWikiBody(WIKI_PAGE6_CONTENT);
if (!shouldIndex)
{
uncheckCheckbox(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
}
_wikiHelper.saveWikiPage();
}
private void editIndexWiki(boolean expectedShouldIndex)
{
clickTab("Wiki");
clickAndWait(Locator.linkWithText(WIKI_PAGE6_TITLE));
clickAndWait(Locator.linkWithText("Edit"));
if (expectedShouldIndex)
{
assertChecked(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
}
else
{
assertNotChecked(Locator.id(WIKI_INDEX_EDIT_CHECKBOX));
}
}
private void manageIndexWiki(boolean expectedShouldIndex)
{
clickTab("Wiki");
clickAndWait(Locator.linkWithText(WIKI_PAGE6_TITLE));
clickAndWait(Locator.linkWithText("Manage"));
if (expectedShouldIndex)
{
assertChecked(Locator.id(WIKI_INDEX_MANAGE_CHECKBOX));
}
else
{
assertNotChecked(Locator.id(WIKI_INDEX_MANAGE_CHECKBOX));
}
}
private void deleteIndexWiki()
{
clickAndWait(Locator.linkWithText(WIKI_PAGE6_TITLE));
clickAndWait(Locator.linkWithText("Edit"));
deleteWikiPage(false);
}
protected void selectRenderType(String renderType)
{
if (!renderType.equals(getSelectedOptionText(Locator.name("rendererType"))))
{
selectOptionByText(Locator.name("rendererType"), renderType);
}
if ("HTML".equals(renderType) && isButtonPresent("Use HTML Source Editor"))
clickButton("Use HTML Source Editor");
}
@Override
protected void doCleanup(boolean afterTest) throws TestTimeoutException
{
deleteUsersIfPresent(USER1);
_containerHelper.deleteProject(PROJECT2_NAME, afterTest);
_containerHelper.deleteProject(PROJECT_NAME, afterTest);
}
@Override
public BrowserType bestBrowser()
{
return BrowserType.CHROME;
}
}