Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #705 from delving/12.09-registration-test
Browse files Browse the repository at this point in the history
12.09 registration test
  • Loading branch information
geralddejong committed Oct 3, 2012
2 parents 21db371 + 8f10135 commit d603726
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
5 changes: 3 additions & 2 deletions app/controllers/Registration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ trait Registration extends ApplicationController { this: BoundController =>
}

def captchaConstraint(implicit configuration: DomainConfiguration) = Constraint[RegistrationInfo]("registration.invalidCode") {
case r if Cache.get(r.randomId) == Some(r.code) => Valid
case r if Cache.get(r.randomId) == Some(r.code) || Play.isTest => Valid
case e => Invalid(ValidationError(Messages("registration.invalidCode")))
}

Expand Down Expand Up @@ -111,7 +111,7 @@ trait Registration extends ApplicationController { this: BoundController =>
}

def register() = ApplicationAction {
Action {
Action(parse.urlFormEncoded) {
implicit request =>
registrationForm.bindFromRequest.fold(
formWithErrors => {
Expand All @@ -124,6 +124,7 @@ trait Registration extends ApplicationController { this: BoundController =>
},
registration => {
val r = registration

Cache.set(r.randomId, null)

val activationToken = registrationServiceLocator.byDomain.registerUser(
Expand Down
5 changes: 0 additions & 5 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ object Build extends sbt.Build {
val appDependencies = Seq(
"org.apache.amber" % "oauth2-authzserver" % "0.2-SNAPSHOT",
"org.apache.amber" % "oauth2-client" % "0.2-SNAPSHOT",
"net.liftweb" %% "lift-json-ext" % "2.4-M4",
"org.seleniumhq.selenium" % "selenium-firefox-driver" % "2.25.0" % "test",
"org.seleniumhq.selenium" % "selenium-htmlunit-driver" % "2.25.0" % "test",
"org.fluentlenium" % "fluentlenium-core" % "0.7.2" % "test",
"net.sourceforge.htmlunit" % "htmlunit" % "2.10" % "test",
"eu.delving" %% "themes" % "1.0-SNAPSHOT" changing()
)

Expand Down
68 changes: 68 additions & 0 deletions test/RegistrationSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import core.HubServices
import play.api.i18n.{Messages, Lang}
import play.api.test._
import play.api.test.Helpers._
import util.DomainConfigurationHandler

/**
* Testing the registration work-flow
*
* TODO check that a user can't be created twice
* TODO check that password recovery works
* TODO check other things along the way
*
* @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
*/
class RegistrationSpec extends Specs2TestContext {

"The Registration" should {

"work" in {

running(TestServer(3333, FakeApplication(path = applicationPath)), classOf[FirefoxHtmlUnitDriver]) {
browser =>
registerAlice(browser)
activateAlice(browser)
loginAlice(browser)
}
}
}

def registerAlice(browser: TestBrowser) = {
browser.goTo("http://delving.localhost:3333/registration")

browser.fill("#firstName").`with`("Alice")
browser.fill("#lastName").`with`("Smith")
browser.fill("#email").`with`("alice@smith.com")
browser.fill("#userName").`with`("alice")
browser.fill("#password1").`with`("alice")
browser.fill("#password2").`with`("alice")
browser.fill("#code").`with`("test")

browser.$("#submit").click()
browser.url must equalTo("http://delving.localhost:3333/")

val msg = Messages("ui.message.registration.success", "alice@smith.com")(Lang("en"))
browser.$(".alert-success").first.getText must equalTo(msg)

}

def activateAlice(browser: TestBrowser) = {
browser.goTo("http://delving.localhost:3333/registration/activate/TESTACTIVATION")
browser.url must equalTo("http://delving.localhost:3333/")
val msg = Messages("ui.message.activation.success")(Lang("en"))
browser.$(".alert-success").first.getText must equalTo(msg)

implicit val configuration = DomainConfigurationHandler.getByOrgId("delving")
HubServices.registrationServiceLocator.byDomain.isAccountActive("alice@smith.com") must beTrue
}

def loginAlice(browser: TestBrowser) = {
browser.goTo("http://delving.localhost:3333/login")
browser.fill("#userName").`with`("alice")
browser.fill("#password").`with`("alice")
browser.$("#signin").click()
browser.url must equalTo("http://delving.localhost:3333/")
}

}
7 changes: 5 additions & 2 deletions web-core/app/core/SystemField.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package core

/**
* The system fields used by the CultureHub
* The system fields used by the CultureHub.
*
* Don't touch this class unless there has been a consensus amongst the core developers.
*
* @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
*/
Expand All @@ -15,13 +17,14 @@ case class SystemField(name: String) {

object SystemField {

val values = List(TITLE, DESCRIPTION, PROVIDER, OWNER, THUMBNAIL, LANDING_PAGE, DEEP_ZOOM_URL, SPEC, COLLECTION)
val values = List(TITLE, DESCRIPTION, PROVIDER, OWNER, THUMBNAIL, IMAGE_URL, LANDING_PAGE, DEEP_ZOOM_URL, SPEC, COLLECTION)

def valueOf(name: String) = values.find(v => v.name.toUpperCase == name.toUpperCase.replaceAll("_", "")).getOrElse(throw new IllegalArgumentException("Invalid SystemField " + name))

object TITLE extends SystemField("title")
object DESCRIPTION extends SystemField("description")
object THUMBNAIL extends SystemField("thumbnail")
object IMAGE_URL extends SystemField("imageUrl")

object CREATOR extends SystemField("creator")
object LANDING_PAGE extends SystemField("landingPage")
Expand Down
9 changes: 6 additions & 3 deletions web-core/app/core/services/MemoryServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import core._
import scala.collection.mutable.HashMap
import extensions.MissingLibs
import eu.delving.definitions.OrganizationEntry
import play.api.Play
import play.api.Play.current


/**
Expand All @@ -30,14 +32,15 @@ class MemoryServices(val users: HashMap[String, MemoryUser] = new HashMap[String

def registerUser(userName: String, node: String, firstName: String, lastName: String, email: String, password: String): Option[String] = {
if (users.contains(userName)) return None
val newUser = MemoryUser(userName, firstName, lastName, email, password, models.UserProfile())
val newUser = MemoryUser(userName, firstName, lastName, email, password, models.UserProfile(), false, if (Play.isTest) "TESTACTIVATION" else MissingLibs.UUID)
users += (userName -> newUser)
Some(newUser.activationToken)
}

def activateUser(activationToken: String) = {
users.values.find(_.activationToken == activationToken).map {
u => Some(RegisteredUser(u.userName, u.firstName, u.lastName, u.email))
users.values.find(_.activationToken == activationToken).map { u =>
users.put(u.userName, u.copy(isActive = true))
Some(RegisteredUser(u.userName, u.firstName, u.lastName, u.email))
}.getOrElse(None)
}

Expand Down
6 changes: 5 additions & 1 deletion web-core/test/TestContext.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import com.gargoylesoftware.htmlunit.BrowserVersion
import core.HubServices
import core.indexing.IndexingService
import core.services.AggregatingOrganizationCollectionLookupService
import java.io.File
import models.HubMongoContext._
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.specs2.mutable.Specification
import play.api.mvc.{AsyncResult, Result}
import play.api.test._
Expand Down Expand Up @@ -88,4 +90,6 @@ trait Specs2TestContext extends Specification with TestContext {

args(sequential = true)

}
}

class FirefoxHtmlUnitDriver extends HtmlUnitDriver(BrowserVersion.FIREFOX_3_6)

0 comments on commit d603726

Please sign in to comment.