From 0650e640c5ffe2e8cde746d294eeaedac006d17c Mon Sep 17 00:00:00 2001
From: Dirk Furrer <none@none>
Date: Fri, 20 Mar 2015 11:15:21 +0100
Subject: [PATCH] OO-1472: selenium tests to test the multi enrollment
 functionality

---
 .../org/olat/selenium/BusinessGroupTest.java  | 107 +++++++++++++++++-
 .../course/EnrollmentConfigurationPage.java   |  31 ++++-
 .../selenium/page/course/EnrollmentPage.java  |  20 ++++
 3 files changed, 153 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/olat/selenium/BusinessGroupTest.java b/src/test/java/org/olat/selenium/BusinessGroupTest.java
index 08a43673455..0bc2a063384 100644
--- a/src/test/java/org/olat/selenium/BusinessGroupTest.java
+++ b/src/test/java/org/olat/selenium/BusinessGroupTest.java
@@ -22,6 +22,8 @@ package org.olat.selenium;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
 import org.jboss.arquillian.container.test.api.Deployment;
@@ -557,7 +559,110 @@ public class BusinessGroupTest {
 		Assert.assertEquals(1, participants);
 		Assert.assertEquals(2, waitingList);
 	}
-	
+	/**
+	 * An author create a course, with an enrollment course element. It
+	 * configure it and create 3 groups and set the maximum enrollment counter to 2<br>
+	 * 
+	 * One user goes to the course and enrolls in 2 of the groups. It shouldent be possible
+	 * enroll in the third<br>
+	 * 
+	 * @param authorLoginPage
+	 * @param ryomouBrowser
+	 * @throws IOException
+	 * @throws URISyntaxException
+	 */
+
+	@Test
+	@RunAsClient
+	public void enrolmentWithMultiEnrollment(@InitialPage LoginPage authorLoginPage,
+			@Drone @User WebDriver ryomouBrowser)
+	throws IOException, URISyntaxException {
+		
+		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
+		authorLoginPage.loginAs(author.getLogin(), author.getPassword());
+		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
+		
+		//create a course
+		String courseTitle = "Enrolment-3-" + UUID.randomUUID();
+		navBar
+			.openAuthoringEnvironment()
+			.createCourse(courseTitle)
+			.clickToolbarBack();
+
+		//create a course element of type Enrolment
+		String enNodeTitle = "Enrolment-3";
+		CourseEditorPageFragment courseEditor = CoursePageFragment.getCourse(browser)
+			.edit();
+		courseEditor
+			.createNode("en")
+			.nodeTitle(enNodeTitle);
+		//configure enrolment with a group that we create
+		List<String> groups = new ArrayList<String>();
+		groups.add("Enrolment group - 3 " + UUID.randomUUID());
+		groups.add("Enrolment group - 3 " + UUID.randomUUID());
+		groups.add("Enrolment group - 3 " + UUID.randomUUID());
+		
+		EnrollmentConfigurationPage enrolmentConfig = new EnrollmentConfigurationPage(browser);
+		enrolmentConfig
+			.selectConfiguration()
+			.createBusinessGroup(groups.get(0), "-", 4, false, false)
+			.createBusinessGroup(groups.get(1), "-", 4, false, false)
+			.createBusinessGroup(groups.get(2), "-", 4, false, false)
+			.selectMultipleEnrollments(browser, 2);
+		//publish the course
+		courseEditor
+			.publish()
+			.quickPublish(Access.users);
+		courseEditor.clickToolbarBack();
+		
+
+		for(String groupName:groups){
+				navBar
+					.openGroups(browser)
+					.selectGroup(groupName)
+					.openAdministration()
+					.openAdminMembers()
+					.setVisibility(true, true, false)
+					.openMembers();
+		}
+				
+		//Ryomou open the course
+		Enrollment ryomouEnrollment = new Enrollment(ryomou, ryomouBrowser);
+				
+		WebDriver driver = ryomouEnrollment.getDriver();
+		LoginPage.getLoginPage(driver, deploymentUrl)
+			.loginAs(ryomouEnrollment.getUser())
+			.resume();
+		
+		NavigationPage participantNavBar = new NavigationPage(driver);
+		participantNavBar
+			.openMyCourses()
+			.openSearch()
+			.extendedSearch(courseTitle)
+			.select(courseTitle)
+			.start();
+		
+		OOGraphene.waitBusy(ryomouBrowser);
+		
+		//go to the enrollment
+		CoursePageFragment participantCourse = new CoursePageFragment(driver);
+		participantCourse
+			.clickTree()
+			.selectWithTitle(enNodeTitle);
+		
+		EnrollmentPage enrollmentPage = new EnrollmentPage(driver);
+		enrollmentPage
+			.assertOnEnrolmentPage();
+		ryomouEnrollment.setEnrollmentPage(enrollmentPage);
+		
+		ryomouEnrollment.getEnrollmentPage().multiEnroll(2);
+		
+		//wait
+		OOGraphene.waitBusy(driver);
+		//assert that that no more enrollment is allowed
+		ryomouEnrollment.getEnrollmentPage().assertNoEnrollmentAllowed(driver);
+		
+	}
 	/**
 	 * An author create a course and a business group in the members
 	 * management. It has max. participants set to 1 and no waiting list.
diff --git a/src/test/java/org/olat/selenium/page/course/EnrollmentConfigurationPage.java b/src/test/java/org/olat/selenium/page/course/EnrollmentConfigurationPage.java
index 688f0b18017..74cd9c18341 100644
--- a/src/test/java/org/olat/selenium/page/course/EnrollmentConfigurationPage.java
+++ b/src/test/java/org/olat/selenium/page/course/EnrollmentConfigurationPage.java
@@ -54,7 +54,7 @@ public class EnrollmentConfigurationPage {
 	}
 	
 	public EnrollmentConfigurationPage selectBusinessGroups() {
-		By createGroupBy = By.cssSelector("a.o_sel_course_en_choose_group");
+		By createGroupBy = By.cssSelector("a.o_form_groupchooser");
 		browser.findElement(createGroupBy).click();
 		OOGraphene.waitBusy(browser);
 		
@@ -77,7 +77,11 @@ public class EnrollmentConfigurationPage {
 	 */
 	public EnrollmentConfigurationPage createBusinessGroup(String name, String description,
 			int maxParticipants, boolean waitingList, boolean auto) {
-		By createGroupBy = By.cssSelector("a.o_sel_course_en_create_group");
+		By chooseGroupBy = By.cssSelector("a.o_form_groupchooser");
+		browser.findElement(chooseGroupBy).click();
+		OOGraphene.waitBusy(browser);
+		
+		By createGroupBy = By.cssSelector("div.o_button_group_right a");
 		browser.findElement(createGroupBy).click();
 		OOGraphene.waitBusy(browser);
 		
@@ -100,12 +104,31 @@ public class EnrollmentConfigurationPage {
 			OOGraphene.waitBusy(browser);
 		}
 		
-		//save
+		//save the group
 		By submitBy = By.cssSelector(".o_sel_group_edit_group_form button.btn-primary");
 		WebElement submitButton = browser.findElement(submitBy);
 		submitButton.click();
 		OOGraphene.waitBusy(browser);
-				
+		// save group selection
+		By saveBy = By.cssSelector(".o_sel_group_selection_groups button.btn-primary");
+		WebElement saveButton = browser.findElement(saveBy);
+		saveButton.click();
+		OOGraphene.waitBusy(browser);
+		return this;
+	}
+	
+	public EnrollmentConfigurationPage selectMultipleEnrollments(WebDriver browser, int maxEnrollmentCount){
+		By multiEnroll = By.name("allowMultipleEnroll");
+		browser.findElement(multiEnroll).click();
+		OOGraphene.waitBusy(browser);
+		By maxCountBy = By.cssSelector(".o_sel_enroll_max input[type='text']");
+		WebElement maxCountBox = browser.findElement(maxCountBy);
+		maxCountBox.clear();
+		maxCountBox.sendKeys(Integer.toString(maxEnrollmentCount));
+		OOGraphene.waitBusy(browser);
+		By saveBy = By.tagName("button");
+		browser.findElement(saveBy).click();
+		OOGraphene.waitBusy(browser);
 		return this;
 	}
 	
diff --git a/src/test/java/org/olat/selenium/page/course/EnrollmentPage.java b/src/test/java/org/olat/selenium/page/course/EnrollmentPage.java
index a2d7def9a40..fa5baa3a3ac 100644
--- a/src/test/java/org/olat/selenium/page/course/EnrollmentPage.java
+++ b/src/test/java/org/olat/selenium/page/course/EnrollmentPage.java
@@ -54,6 +54,12 @@ public class EnrollmentPage {
 		return this;
 	}
 	
+	public EnrollmentPage assertNoEnrollmentAllowed(WebDriver browser){
+		By enrollBy = By.xpath("//div[contains(@class,'o_table_wrapper')]//table//tr//td//a[contains(@href,'cmd.enroll.in.group')]");
+		List<WebElement> pageEls = browser.findElements(enrollBy);
+		Assert.assertTrue(pageEls.isEmpty());
+		return this;
+	}
 	/**
 	 * Enroll without wait busy to make them very quick.
 	 * 
@@ -68,6 +74,20 @@ public class EnrollmentPage {
 		return this;
 	}
 	
+	/**
+	 * Enroll to multiple groups
+	 * 
+	 * @return
+	 */
+	public EnrollmentPage multiEnroll(int enrollCount) {
+		for(int i = 1;i<=enrollCount; i++){
+			WebElement selectLink = browser.findElement(By.xpath("//div[contains(@class,'o_table_wrapper')]//table//tr["+i+"]//td//a[contains(@href,'cmd.enroll.in.group')]"));
+			OOGraphene.waitBusy(browser);
+			selectLink.click();
+		}
+		return this;
+	}
+	
 	/**
 	 * Check if the enrollment return an error message or if the cancel
 	 * link appears.
-- 
GitLab