Fixed test coverage for user controller.

This commit is contained in:
James Cole
2014-07-04 07:30:12 +02:00
parent abbbba219a
commit f5d3c770b4
2 changed files with 16 additions and 22 deletions

View File

@@ -36,7 +36,7 @@ class UserController extends BaseController
public function register() public function register()
{ {
if (Config::get('auth.allow_register') !== true) { if (Config::get('auth.allow_register') !== true) {
App::abort(404); return View::make('error')->with('message', 'Not possible');
} }
return View::make('user.register'); return View::make('user.register');
} }
@@ -44,7 +44,7 @@ class UserController extends BaseController
public function postRegister() public function postRegister()
{ {
if (Config::get('auth.allow_register') !== true) { if (Config::get('auth.allow_register') !== true) {
App::abort(404); return View::make('error')->with('message', 'Not possible');
} }
$user = $this->user->register(Input::all()); $user = $this->user->register(Input::all());
if ($user) { if ($user) {
@@ -72,18 +72,16 @@ class UserController extends BaseController
public function postRemindme() public function postRemindme()
{ {
$user = $this->user->findByEmail(Input::get('email')); $user = $this->user->findByEmail(Input::get('email'));
if ($user) { if (!$user) {
if (Config::get('auth.verify_reset') === true) { Session::flash('error', 'No good!');
$this->email->sendResetVerification($user); return View::make('user.remindme');
return View::make('user.verification-pending');
}
if (Config::get('auth.verify_reset') === false) {
$this->email->sendPasswordMail($user);
return View::make('user.registered');
}
} }
Session::flash('error', 'No good!'); if (Config::get('auth.verify_reset') === true) {
return View::make('user.remindme'); $this->email->sendResetVerification($user);
return View::make('user.verification-pending');
}
$this->email->sendPasswordMail($user);
return View::make('user.registered');
} }

View File

@@ -57,16 +57,14 @@ class UserControllerTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRegisterNotAllowed() public function testRegisterNotAllowed()
{ {
// no mock for config! :( // no mock for config! :(
Config::set('auth.allow_register', false); Config::set('auth.allow_register', false);
// test // test
$this->call('GET', '/register'); $this->call('GET', '/register');
$this->assertResponseStatus(404); $this->assertResponseStatus(200);
$this->assertViewHas('message','Not possible');
} }
/** /**
@@ -191,12 +189,9 @@ class UserControllerTest extends TestCase
$this->call('POST', '/remindme'); $this->call('POST', '/remindme');
$this->assertResponseOk(); $this->assertResponseOk();
$this->assertSessionHas('error'); $this->assertSessionHas('error','No good!');
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testPostRegisterNotAllowed() public function testPostRegisterNotAllowed()
{ {
// no mock for config! :( // no mock for config! :(
@@ -211,7 +206,8 @@ class UserControllerTest extends TestCase
// test // test
$this->call('POST', '/register', $data); $this->call('POST', '/register', $data);
$this->assertResponseStatus(404); $this->assertResponseStatus(200);
$this->assertViewHas('message','Not possible');
} }