From f868a8cef63f34cf484b6d8e0fea29d5be91a6ec Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Wed, 2 Jul 2014 09:03:30 +0200
Subject: [PATCH] OO-1068: selenium test, collect a wiki article in a wiki
 learning resource

---
 .../modules/wiki/WikiEditArticleForm.java     |   9 +-
 .../olat/modules/wiki/WikiMainController.java |   1 +
 .../portfolio/FunctionalArtefactTest.java     | 120 ------------------
 .../java/org/olat/selenium/PortfolioTest.java |  86 ++++++++++++-
 .../page/portfolio/ArtefactWizardPage.java    |  23 +++-
 .../org/olat/selenium/page/wiki/WikiPage.java | 106 ++++++++++++++++
 6 files changed, 220 insertions(+), 125 deletions(-)
 create mode 100644 src/test/java/org/olat/selenium/page/wiki/WikiPage.java

diff --git a/src/main/java/org/olat/modules/wiki/WikiEditArticleForm.java b/src/main/java/org/olat/modules/wiki/WikiEditArticleForm.java
index d00b7029e70..34d3ba54d1b 100644
--- a/src/main/java/org/olat/modules/wiki/WikiEditArticleForm.java
+++ b/src/main/java/org/olat/modules/wiki/WikiEditArticleForm.java
@@ -28,10 +28,12 @@ package org.olat.modules.wiki;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.form.flexible.FormItem;
 import org.olat.core.gui.components.form.flexible.FormItemContainer;
+import org.olat.core.gui.components.form.flexible.elements.FormLink;
 import org.olat.core.gui.components.form.flexible.elements.TextElement;
 import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
 import org.olat.core.gui.components.form.flexible.impl.FormEvent;
 import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
+import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit;
 import org.olat.core.gui.components.link.Link;
 import org.olat.core.gui.control.Controller;
 import org.olat.core.gui.control.Event;
@@ -103,6 +105,7 @@ public class WikiEditArticleForm extends FormBasicController {
 	protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
 		
 		wikiContent = uifactory.addTextAreaElement("wikiContentElement", 20, 110, page.getContent() , formLayout);
+		wikiContent.setElementCssClass("o_sel_wiki_content");
 		wikiContent.setLabel(null, null);
 		wikiContent.preventValueTrim(true);//OO-31 prevent trimming, so first line can be with inset (wiki pre-formatted)
 
@@ -111,8 +114,10 @@ public class WikiEditArticleForm extends FormBasicController {
 		// Button layout
 		final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
 		formLayout.add(buttonLayout);
-		uifactory.addFormSubmitButton("save", buttonLayout);
-		uifactory.addFormLink("save.and.close", buttonLayout, Link.BUTTON);
+		FormSubmit submit = uifactory.addFormSubmitButton("save", buttonLayout);
+		submit.setElementCssClass("o_sel_wiki_save");
+		FormLink saveAndClose =uifactory.addFormLink("save.and.close", buttonLayout, Link.BUTTON);
+		saveAndClose.setElementCssClass("o_sel_wiki_save_and_close");
 		if(getIdentity().getKey().equals(Long.valueOf(page.getInitalAuthor())) || securityCallback.mayEditWikiMenu()) {
 			uifactory.addFormLink("delete.page", buttonLayout, Link.BUTTON);
 		}
diff --git a/src/main/java/org/olat/modules/wiki/WikiMainController.java b/src/main/java/org/olat/modules/wiki/WikiMainController.java
index 4e551c0a219..280c4b1abe3 100644
--- a/src/main/java/org/olat/modules/wiki/WikiMainController.java
+++ b/src/main/java/org/olat/modules/wiki/WikiMainController.java
@@ -259,6 +259,7 @@ public class WikiMainController extends BasicController implements CloneableCont
 		
 		createLink = LinkFactory.createLink("navigation.create.article", navigationContent, this);
 		createLink.setIconLeftCSS("o_icon o_icon_create");
+		createLink.setElementCssClass("o_sel_wiki_create_page");
 		createLink.setDomReplacementWrapperRequired(false);
 
 		content.put("navigation", navigationContent);
diff --git a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
index afaae760971..074346565e2 100644
--- a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
+++ b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
@@ -45,7 +45,6 @@ import org.olat.portfolio.FunctionalArtefactTest.Binder.Page.JournalArtefact;
 import org.olat.portfolio.FunctionalArtefactTest.Binder.Page.TextArtefact;
 import org.olat.portfolio.model.artefacts.FileArtefact;
 import org.olat.restapi.support.vo.CourseVO;
-import org.olat.restapi.support.vo.RepositoryEntryVO;
 import org.olat.test.ArquillianDeployments;
 import org.olat.user.restapi.UserVO;
 import org.olat.util.FunctionalCourseUtil;
@@ -464,125 +463,6 @@ public class FunctionalArtefactTest {
 		return(true);
 	}
 
-	@Test
-	@RunAsClient
-	public void checkCollectForumPost() throws IOException, URISyntaxException{
-		/*
-		 * Prepare for verification
-		 */		
-		Object[] retval = prepareVerification(FORUM_BINDER, null,
-				FORUM_PAGE, null,
-				FORUM_STRUCTURE, null,
-				ForumArtefact.class, FORUM_ARTEFACT_TITLE, FORUM_ARTEFACT_DESCRIPTION, FORUM_TAGS, null);
-		
-		Binder binder = (Binder) retval[0];
-		Binder.Page page = (Binder.Page) retval[1];
-		Binder.Page.Structure structure = (Binder.Page.Structure) retval[2];
-		Binder.Page.Artefact artefact = (Binder.Page.Artefact) retval[3];
-		((Binder.Page.ForumArtefact) artefact).postTitle = FORUM_POST_TITLE;
-		((Binder.Page.ForumArtefact) artefact).postContent = FORUM_POST_MESSAGE;
-		
-		/*
-		 * test case
-		 */
-		/* deploy course with REST */
-		CourseVO course = functionalVOUtil.importCourseIncludingForum(deploymentUrl);
-
-		/* login for test setup */
-		Assert.assertTrue(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true));
-
-		/* create binder, page or structure if necessary */
-		Assert.assertTrue(functionalEportfolioUtil.createElements(browser, FORUM_BINDER, FORUM_PAGE, FORUM_STRUCTURE));
-
-		/* post message to forum */
-		Assert.assertTrue(functionalCourseUtil.postForumMessage(browser, course.getRepoEntryKey(), 0, FORUM_POST_TITLE, FORUM_POST_MESSAGE));
-		artefact.businessPath = functionalUtil.currentBusinessPath(browser);
-		
-		/* add artefact */
-		Assert.assertTrue(functionalCourseUtil.addToEportfolio(browser, FORUM_BINDER, FORUM_PAGE, FORUM_STRUCTURE,
-				FORUM_ARTEFACT_TITLE, FORUM_ARTEFACT_DESCRIPTION, FORUM_TAGS,
-				functionalEportfolioUtil));
-		
-		functionalCourseUtil.closeActiveTab(browser);
-		
-		/*
-		 * Test for content and make assumptions if the changes were applied.
-		 * Keep it simple use quick access with business paths.
-		 */
-		binder.ignore = false;
-		
-		page.ignore = false;
-		
-		structure.ignore = false;
-
-		artefact.ignore = false;
-		
-		/* verify */
-		Assert.assertTrue(checkArtefact(artefact));
-		Assert.assertTrue(checkMap(binder));
-		
-		functionalUtil.logout(browser);
-	}
-
-	@Test
-	@RunAsClient
-	public void checkCollectWikiArticle() throws URISyntaxException, IOException{
-		/*
-		 * Prepare for verification
-		 */		
-		Object[] retval = prepareVerification(WIKI_BINDER, null,
-				WIKI_PAGE, null,
-				WIKI_STRUCTURE, null,
-				WikiArtefact.class, WIKI_ARTEFACT_TITLE, WIKI_ARTEFACT_DESCRIPTION, WIKI_TAGS, null);
-		
-		Binder binder = (Binder) retval[0];
-		Binder.Page page = (Binder.Page) retval[1];
-		Binder.Page.Structure structure = (Binder.Page.Structure) retval[2];
-		Binder.Page.Artefact artefact = (Binder.Page.Artefact) retval[3];
-		((Binder.Page.WikiArtefact) artefact).article = WIKI_ARTICLE_CONTENT;
-		
-		/*
-		 * Test case
-		 */
-		/* import wiki via rest */
-		RepositoryEntryVO vo = functionalVOUtil.importWiki(deploymentUrl);
-
-		/* login for test setup */
-		Assert.assertTrue(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true));
-
-		/* create binder, page or structure if necessary */
-		Assert.assertTrue(functionalEportfolioUtil.createElements(browser, WIKI_BINDER, WIKI_PAGE, WIKI_STRUCTURE));
-
-		/* create an article for the wiki */
-		Assert.assertTrue(functionalCourseUtil.createWikiArticle(browser, vo.getKey(), WIKI_ARTICLE_PAGENAME, WIKI_ARTICLE_CONTENT));
-		artefact.businessPath = functionalUtil.currentBusinessPath(browser);
-
-		/* add artefact */
-		Assert.assertTrue(functionalCourseUtil.addToEportfolio(browser, WIKI_BINDER, WIKI_PAGE, WIKI_STRUCTURE,
-				WIKI_ARTEFACT_TITLE, WIKI_ARTEFACT_DESCRIPTION, WIKI_TAGS,
-				functionalEportfolioUtil));
-		
-		functionalCourseUtil.closeActiveTab(browser);
-		
-		/*
-		 * Test for content and make assumptions if the changes were applied.
-		 * Keep it simple use quick access with business paths.
-		 */
-		binder.ignore = false;
-		
-		page.ignore = false;
-		
-		structure.ignore = false;
-
-		artefact.ignore = false;
-		
-		/* verify */
-		Assert.assertTrue(checkArtefact(artefact));
-		Assert.assertTrue(checkMap(binder));
-		
-		functionalUtil.logout(browser);
-	}
-
 	@Test
 	@RunAsClient
 	public void checkCollectBlogPost() throws URISyntaxException, IOException{
diff --git a/src/test/java/org/olat/selenium/PortfolioTest.java b/src/test/java/org/olat/selenium/PortfolioTest.java
index f7ded966101..2dd95c799cf 100644
--- a/src/test/java/org/olat/selenium/PortfolioTest.java
+++ b/src/test/java/org/olat/selenium/PortfolioTest.java
@@ -42,8 +42,10 @@ import org.olat.selenium.page.forum.ForumPage;
 import org.olat.selenium.page.graphene.OOGraphene;
 import org.olat.selenium.page.portfolio.ArtefactWizardPage;
 import org.olat.selenium.page.portfolio.PortfolioPage;
+import org.olat.selenium.page.repository.AuthoringEnvPage;
 import org.olat.selenium.page.repository.AuthoringEnvPage.ResourceType;
 import org.olat.selenium.page.user.UserToolsPage;
+import org.olat.selenium.page.wiki.WikiPage;
 import org.olat.test.ArquillianDeployments;
 import org.olat.test.rest.UserRestClient;
 import org.olat.user.restapi.UserVO;
@@ -80,7 +82,7 @@ public class PortfolioTest {
 	 */
 	@Test
 	@RunAsClient
-	public void collectForumArtfect(@InitialPage LoginPage loginPage)
+	public void collectForumArtefactInCourse(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
@@ -157,5 +159,87 @@ public class PortfolioTest {
 		
 		portfolio.assertArtefact(threadTitle);
 	}
+	
+	/**
+	 * Create a wiki, create a new page.
+	 * Create a map.
+	 * Collect the artefact, bind it to the map.
+	 * Check the map and the artefact.
+	 * 
+	 * @param loginPage
+	 * @throws IOException
+	 * @throws URISyntaxException
+	 */
+	@Test
+	@RunAsClient
+	public void collectWikiArtefactInWikiResource(@InitialPage LoginPage loginPage)
+	throws IOException, URISyntaxException {
+		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
+		loginPage
+			.loginAs(author.getLogin(), author.getPassword())
+			.resume();
+		
+		//open the portfolio
+		PortfolioPage portfolio = userTools
+			.openUserToolsMenu()
+			.openPortfolio();
+				
+		//create a map
+		String mapTitle = "Map-Wiki-" + UUID.randomUUID();
+		String pageTitle = "Page-Wiki-" + UUID.randomUUID();
+		String structureElementTitle = "Struct-Wiki-" + UUID.randomUUID();
+		portfolio
+			.openMyMaps()
+			.createMap(mapTitle, "Hello wiki")
+			.openEditor()
+			.selectMapInEditor(mapTitle)
+			.selectFirstPageInEditor()
+			.setPage(pageTitle, "With a little description about wiki and such tools")
+			.createStructureElement(structureElementTitle, "Structure description");
+
+		//go to authoring
+		AuthoringEnvPage authoringEnv = navBar
+			.assertOnNavigationPage()
+			.openAuthoringEnvironment();
+				
+		String title = "EP-Wiki-" + UUID.randomUUID();
+		//create a wiki and launch it
+		authoringEnv
+			.openCreateDropDown()
+			.clickCreate(ResourceType.wiki)
+			.fillCreateForm(title).assertOnGeneralTab()
+			.clickToolbarBack()
+			.assertOnTitle(title)
+			.launch();
+		
+		//create a page in the wiki
+		String page = "LMS-" + UUID.randomUUID();
+		String content = "Learning Management System";
+		WikiPage wiki = WikiPage.getWiki(browser);
+
+		//create page and add it as artefact to portfolio
+		ArtefactWizardPage artefactWizard = wiki
+				.createPage(page, content)
+				.addAsArtfeact();
+			
+		artefactWizard
+			.next()
+			.tags("Wiki", "Thread", "Miscellanous")
+			.next()
+			.selectMap(mapTitle, pageTitle, structureElementTitle)
+			.finish();
+
+		OOGraphene.closeBlueMessageWindow(browser);
+		
+		//open the portfolio
+		portfolio = userTools
+			.openUserToolsMenu()
+			.openPortfolio()
+			.openMyMaps()
+			.openMap(mapTitle)
+			.selectStructureInTOC(structureElementTitle);
+		
+		portfolio.assertArtefact(page);
+	}
 
 }
diff --git a/src/test/java/org/olat/selenium/page/portfolio/ArtefactWizardPage.java b/src/test/java/org/olat/selenium/page/portfolio/ArtefactWizardPage.java
index 0a694d4b160..e697eed6d0e 100644
--- a/src/test/java/org/olat/selenium/page/portfolio/ArtefactWizardPage.java
+++ b/src/test/java/org/olat/selenium/page/portfolio/ArtefactWizardPage.java
@@ -51,6 +51,10 @@ public class ArtefactWizardPage {
 		return Graphene.createPageFragment(ArtefactWizardPage.class, modal);
 	}
 	
+	/**
+	 * Next
+	 * @return this
+	 */
 	public ArtefactWizardPage next() {
 		WebElement next = browser.findElement(nextBy);
 		Assert.assertTrue(next.isDisplayed());
@@ -61,6 +65,10 @@ public class ArtefactWizardPage {
 		return this;
 	}
 	
+	/**
+	 * Finish the wizard
+	 * @return this
+	 */
 	public ArtefactWizardPage finish() {
 		WebElement finish = browser.findElement(finishBy);
 		Assert.assertTrue(finish.isDisplayed());
@@ -71,6 +79,11 @@ public class ArtefactWizardPage {
 		return this;
 	}
 	
+	/**
+	 * !! Doesn't work
+	 * @param tags
+	 * @return this
+	 */
 	public ArtefactWizardPage tags(String... tags) {
 		By tagBy = By.cssSelector("div.o_sel_artefact_add_wizard div.bootstrap-tagsinput>input");
 		WebElement tagEl = browser.findElement(tagBy);
@@ -82,6 +95,13 @@ public class ArtefactWizardPage {
 		return this;
 	}
 	
+	/**
+	 * Select the map > page > structure by their respective title
+	 * @param mapTitle
+	 * @param pageTitle
+	 * @param structureTitle
+	 * @return this
+	 */
 	public ArtefactWizardPage selectMap(String mapTitle, String pageTitle, String structureTitle) {
 		select(mapTitle, By.cssSelector("a.o_tree_l1"));
 		select(pageTitle, By.cssSelector("a.o_tree_l2"));
@@ -101,5 +121,4 @@ public class ArtefactWizardPage {
 		linkToClick.click();
 		OOGraphene.waitBusy();
 	}
-
-}
+}
\ No newline at end of file
diff --git a/src/test/java/org/olat/selenium/page/wiki/WikiPage.java b/src/test/java/org/olat/selenium/page/wiki/WikiPage.java
new file mode 100644
index 00000000000..1fe6ebfed37
--- /dev/null
+++ b/src/test/java/org/olat/selenium/page/wiki/WikiPage.java
@@ -0,0 +1,106 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.selenium.page.wiki;
+
+import org.jboss.arquillian.drone.api.annotation.Drone;
+import org.jboss.arquillian.graphene.Graphene;
+import org.jcodec.common.Assert;
+import org.olat.selenium.page.graphene.OOGraphene;
+import org.olat.selenium.page.portfolio.ArtefactWizardPage;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+/**
+ * 
+ * Drive the wiki page GUI, editor...
+ * 
+ * Initial date: 02.07.2014<br>
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ *
+ */
+public class WikiPage {
+	
+	@Drone
+	private WebDriver browser;
+	
+	public static WikiPage getWiki(WebDriver browser) {
+		WebElement main = browser.findElement(By.id("o_main"));
+		return Graphene.createPageFragment(WikiPage.class, main);
+	}
+	
+	public WikiPage createPage(String name, String content) {
+		//open the create popover
+		By createBy = By.className("o_sel_wiki_create_page");
+		WebElement createButton = browser.findElement(createBy);
+		createButton.click();
+		
+		//fill the name of the new page
+		By pageNameBy = By.cssSelector("div.o_callout_content form input[type='text']");
+		OOGraphene.waitElement(pageNameBy);
+		WebElement pageNameEl = browser.findElement(pageNameBy);
+		pageNameEl.sendKeys(name);
+		//search for it
+		By searchBy = By.cssSelector("div.popover-content form .o_sel_wiki_search button");
+		WebElement searchButton = browser.findElement(searchBy);
+		searchButton.click();
+		OOGraphene.waitBusy();
+		
+		//not exist -> click the link to create the page
+		By notExistingBy = By.xpath("//div[contains(@class,'o_wikimod-article-box')]//a[@title='" + name + "']");
+		WebElement notExistingLink = browser.findElement(notExistingBy);
+		notExistingLink.click();
+		
+		//fill the form
+		By textBy = By.cssSelector("div.o_wikimod_editform_wrapper form textarea");
+		OOGraphene.waitElement(textBy);
+		WebElement textEl = browser.findElement(textBy);
+		textEl.sendKeys(content);
+		//save the page
+		By saveAndCloseBy = By.className("o_sel_wiki_save_and_close");
+		WebElement saveAndCloseButton = browser.findElement(saveAndCloseBy);
+		saveAndCloseButton.click();
+		OOGraphene.waitBusy();
+		
+		//assert
+		By pageTitleBy = By.className("o_wikimod_heading");
+		WebElement pageTitleEl = browser.findElement(pageTitleBy);
+		Assert.assertTrue(pageTitleEl.getText().contains(name));
+		
+		By contentBy = By.className("o_wikimod-article-box");
+		WebElement contentEl = browser.findElement(contentBy);
+		Assert.assertTrue(contentEl.getText().contains(content));
+		return this;
+	}
+	
+	
+	/**
+	 * Add the current page to my artefacts
+	 * 
+	 */
+	public ArtefactWizardPage addAsArtfeact() {
+		By addAsArtefactBy = By.className("o_eportfolio_add");
+		WebElement addAsArtefactButton = browser.findElement(addAsArtefactBy);
+		addAsArtefactButton.click();
+		OOGraphene.waitBusy();
+		return ArtefactWizardPage.getWizard(browser);
+	}
+
+}
-- 
GitLab