/xwiki-enterprise-test/xwiki-enterprise-test-ui/src/test/it/org/xwiki/test/ui/EditInlineTest.java

https://github.com/ntallapa/xwiki-enterprise · Java · 132 lines · 88 code · 9 blank · 35 comment · 2 complexity · 306246a6e4255422f9c8aefc1732bb49 MD5 · raw file

  1. /*
  2. * See the NOTICE file distributed with this work for additional
  3. * information regarding copyright ownership.
  4. *
  5. * This is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU Lesser General Public License as
  7. * published by the Free Software Foundation; either version 2.1 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this software; if not, write to the Free
  17. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  19. */
  20. package org.xwiki.test.ui;
  21. import org.apache.commons.lang.RandomStringUtils;
  22. import org.junit.Assert;
  23. import org.junit.Test;
  24. import org.xwiki.test.po.AbstractAdminAuthenticatedTest;
  25. import org.xwiki.test.po.administration.ProfileUserProfilePage;
  26. import org.xwiki.test.po.platform.InlinePage;
  27. import org.xwiki.test.po.platform.ViewPage;
  28. import org.xwiki.test.po.platform.editor.WikiEditPage;
  29. import org.xwiki.test.po.tag.TaggablePage;
  30. /**
  31. * Test Inline editing.
  32. *
  33. * @version $Id: 51d737b06a52caeb6e3c5fc960d6970a5c2f5bdf $
  34. * @since 3.0M2
  35. */
  36. public class EditInlineTest extends AbstractAdminAuthenticatedTest
  37. {
  38. // Note: We're not testing basic inline editing since this is already covered by the User Profile tests
  39. @Test
  40. public void testEditButtonTriggersInlineEditing()
  41. {
  42. ProfileUserProfilePage pupp = ProfileUserProfilePage.gotoPage("Admin");
  43. // Clicking edit should perform inline editing.
  44. pupp.edit();
  45. pupp.waitForProfileEditionToLoad();
  46. Assert.assertTrue(new ViewPage().isInlinePage());
  47. }
  48. /* See XE-168 */
  49. @Test
  50. public void testInlineEditCanChangeTitle()
  51. {
  52. String title = RandomStringUtils.randomAlphanumeric(4);
  53. getUtil().gotoPage("EditInlineTest", "testInlineEditCanChangeTitle", "inline", "title=" + title);
  54. ViewPage vp = new InlinePage().clickSaveAndView();
  55. Assert.assertEquals(title, vp.getDocumentTitle());
  56. }
  57. /* See XE-168 */
  58. @Test
  59. public void testInlineEditCanChangeParent()
  60. {
  61. getUtil().gotoPage("EditInlineTest", "testInlineEditCanChangeParent", "inline", "parent=Main.WebHome");
  62. ViewPage vp = new InlinePage().clickSaveAndView();
  63. Assert.assertTrue(vp.hasBreadcrumbContent("Wiki Home", false));
  64. }
  65. /* See XWIKI-2389 */
  66. @Test
  67. public void testInlineEditPreservesTitle()
  68. {
  69. String title = RandomStringUtils.randomAlphanumeric(4);
  70. getUtil().gotoPage("EditInlineTest", "testInlineEditPreservesTitle", "save", "title=" + title);
  71. ViewPage vp = new ViewPage();
  72. Assert.assertEquals(title, vp.getDocumentTitle());
  73. InlinePage ip = vp.editInline();
  74. ViewPage vp2 = ip.clickSaveAndView();
  75. Assert.assertEquals(title, vp2.getDocumentTitle());
  76. }
  77. /* See XWIKI-2389 */
  78. @Test
  79. public void testInlineEditPreservesParent()
  80. {
  81. getUtil().gotoPage("EditInlineTest", "testInlineEditPreservesParent", "save", "parent=Blog.WebHome");
  82. ViewPage vp = new ViewPage();
  83. Assert.assertTrue(vp.hasBreadcrumbContent("The Wiki Blog", false));
  84. InlinePage ip = vp.editInline();
  85. ViewPage vp2 = ip.clickSaveAndView();
  86. Assert.assertTrue(vp2.hasBreadcrumbContent("The Wiki Blog", false));
  87. }
  88. /* See XWIKI-2199 */
  89. @Test
  90. public void testInlineEditPreservesTags()
  91. {
  92. String tag1 = RandomStringUtils.randomAlphanumeric(4);
  93. String tag2 = RandomStringUtils.randomAlphanumeric(4);
  94. getUtil().gotoPage("EditInlineTest", "testInlineEditPreservesTags", "save", "tags=" + tag1 + "|" + tag2);
  95. TaggablePage taggablePage = new TaggablePage();
  96. Assert.assertTrue(taggablePage.hasTag(tag1));
  97. Assert.assertTrue(taggablePage.hasTag(tag2));
  98. taggablePage.editInline().clickSaveAndView();
  99. taggablePage = new TaggablePage();
  100. Assert.assertTrue(taggablePage.hasTag(tag1));
  101. Assert.assertTrue(taggablePage.hasTag(tag2));
  102. }
  103. /**
  104. * Tests that pages can override the default property display mode using $context.setDisplayMode. See XWIKI-2436.
  105. */
  106. @Test
  107. public void testEditModeCanBeSet()
  108. {
  109. String initialContent = null;
  110. try {
  111. ProfileUserProfilePage pupp = ProfileUserProfilePage.gotoPage("Admin");
  112. WikiEditPage wep = pupp.editWiki();
  113. initialContent = wep.getContent();
  114. wep.setContent("{{velocity}}$xcontext.setDisplayMode('edit'){{/velocity}}\n" + initialContent);
  115. wep.clickSaveAndView();
  116. Assert.assertTrue(getDriver().getPageSource().contains("XWiki.XWikiUsers_0_last_name"));
  117. } finally {
  118. if (initialContent != null) {
  119. getUtil().gotoPage("XWiki", "Admin", "save", "content=" + initialContent);
  120. }
  121. }
  122. }
  123. }