Skip to content

Commit

Permalink
Added invitation registration test re: Issue #834
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Jun 15, 2011
1 parent ceedf98 commit 0b28709
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 18 deletions.
17 changes: 1 addition & 16 deletions tests/TestOfRegisterController.php
Expand Up @@ -337,19 +337,4 @@ public function testInviteInvalidCode() {
'<p><a href="http://thinkupapp.com">Install ThinkUp on your own '.
'server.</a></p>');
}
}

/**
* Mock Captcha for test use
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class Captcha {
public function generate() {
return '';
}

public function check() {
return true;
}
}
}
77 changes: 77 additions & 0 deletions tests/WebTestOfRegistration.php
@@ -0,0 +1,77 @@
<?php
/**
*
* ThinkUp/tests/WebTestOfRegistration.php
*
* Copyright (c) 2011 Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @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.');
}
}
5 changes: 3 additions & 2 deletions tests/all_integration_tests.php
Expand Up @@ -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 );
Expand Down
9 changes: 9 additions & 0 deletions webapp/_lib/model/class.Captcha.php
Expand Up @@ -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);
Expand All @@ -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"],
Expand Down

0 comments on commit 0b28709

Please sign in to comment.