From 0b28709b145c51cdf80fc6870f2ffc82a3488578 Mon Sep 17 00:00:00 2001 From: Gina Trapani Date: Tue, 14 Jun 2011 18:27:47 -0700 Subject: [PATCH] Added invitation registration test re: Issue #834 --- tests/TestOfRegisterController.php | 17 +------ tests/WebTestOfRegistration.php | 77 +++++++++++++++++++++++++++++ tests/all_integration_tests.php | 5 +- webapp/_lib/model/class.Captcha.php | 9 ++++ 4 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 tests/WebTestOfRegistration.php diff --git a/tests/TestOfRegisterController.php b/tests/TestOfRegisterController.php index 7e06d5708d..da46653b6c 100644 --- a/tests/TestOfRegisterController.php +++ b/tests/TestOfRegisterController.php @@ -337,19 +337,4 @@ public function testInviteInvalidCode() { '

Install ThinkUp on your own '. 'server.

'); } -} - -/** - * Mock Captcha for test use - * @author Gina Trapani - * - */ -class Captcha { - public function generate() { - return ''; - } - - public function check() { - return true; - } -} +} \ No newline at end of file diff --git a/tests/WebTestOfRegistration.php b/tests/WebTestOfRegistration.php new file mode 100644 index 0000000000..f4e9be58ef --- /dev/null +++ b/tests/WebTestOfRegistration.php @@ -0,0 +1,77 @@ +. + * + * + * @author Gina Trapani + * @license http://www.gnu.org/licenses/gpl.html + * @copyright 2011 Gina Trapani + */ +require_once dirname(__FILE__).'/init.tests.php'; +require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php'; +require_once THINKUP_ROOT_PATH.'webapp/config.inc.php'; +require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/web_tester.php'; + +class WebTestOfRegistration extends ThinkUpWebTestCase { + + public function setUp() { + parent::setUp(); + $this->builders = self::buildData(); + } + + public function tearDown() { + $this->builders = null; + $test_email = THINKUP_WEBAPP_PATH . '_lib/view/compiled_view' . Mailer::EMAIL; + if (file_exists($test_email)) { + unlink($test_email); + } + + parent::tearDown(); + } + + public function testRegistrationClosedByDefault() { + $this->get($this->url.'/session/register.php'); + $this->assertText('Sorry, registration is closed on this ThinkUp installation.'); + } + + public function testInvalidInvitationCode() { + $this->get($this->url.'/session/register.php?code=invalidcode'); + $this->assertText('Sorry, registration is closed on this ThinkUp installation.'); + } + + public function testValidInvitationCode() { + $invite_dao = new InviteMySQLDAO(); + $invite_dao->addInviteCode('aabbddcc'); + $this->get($this->url.'/session/register.php?code=aabbddcc'); + $this->assertNoText('Sorry, registration is closed on this ThinkUp installation.'); + + $this->setFieldById('full_name', 'Test User'); + $this->setFieldById('email', 'TestUser@example.com'); + $this->setFieldById('pass1', 'p4sswd'); + $this->setFieldById('pass2', 'p4sswd'); + $this->setFieldById('captcha', '123456'); + $this->clickSubmitById('login-save'); + + $this->assertNoText('Sorry, registration is closed on this ThinkUp installation.'); + // $this->showSource(); + $this->assertText('Success! Check your email for an activation link.'); + } +} \ No newline at end of file diff --git a/tests/all_integration_tests.php b/tests/all_integration_tests.php index 2d8292481f..0e10bce8f3 100644 --- a/tests/all_integration_tests.php +++ b/tests/all_integration_tests.php @@ -33,14 +33,15 @@ /* INTEGRATION TESTS */ $web_tests = new TestSuite('Integration tests'); $web_tests->add(new WebTestOfApplicationSettings()); +$web_tests->add(new WebTestOfCaptchaImage()); $web_tests->add(new WebTestOfChangePassword()); $web_tests->add(new WebTestOfCrawlerRun()); $web_tests->add(new WebTestOfDashboard()); $web_tests->add(new WebTestOfDeleteInstance()); $web_tests->add(new WebTestOfLogin()); -$web_tests->add(new WebTestOfCaptchaImage()); -$web_tests->add(new WebTestOfTwitterDashboard()); $web_tests->add(new WebTestOfPostDetailPage()); +$web_tests->add(new WebTestOfRegistration()); +$web_tests->add(new WebTestOfTwitterDashboard()); $tr = new TextReporter(); $web_tests->run( $tr ); diff --git a/webapp/_lib/model/class.Captcha.php b/webapp/_lib/model/class.Captcha.php index e01b3759b1..5fc8e064db 100644 --- a/webapp/_lib/model/class.Captcha.php +++ b/webapp/_lib/model/class.Captcha.php @@ -50,6 +50,10 @@ public function __construct() { } } public function generate() { + //if in test mode, return empty string + if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { + return ''; + } switch ($this->type) { case 1: $code = recaptcha_get_html($this->pubkey, $this->msg); @@ -67,6 +71,11 @@ public function generate() { } } public function check() { + //if in test mode, assume check is good + if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { + return true; + } + switch ($this->type) { case 1: $resp = recaptcha_check_answer($this->prikey, $_SERVER["REMOTE_ADDR"],