Skip to content

Firefly III: a personal finances manager

Finished testing user controller

James Cole516fe54bf05c
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index b09900b06a..d46ef4e671 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -75,9 +75,11 @@ class UserController extends BaseController
if ($user) {
if (Config::get('auth.verify_reset') === true) {
$this->email->sendResetVerification($user);
+ 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!');
diff --git a/app/tests/controllers/UserControllerTest.php b/app/tests/controllers/UserControllerTest.php
index da9b128e2a..b07585323c 100644
--- a/app/tests/controllers/UserControllerTest.php
+++ b/app/tests/controllers/UserControllerTest.php
@@ -94,6 +94,35 @@ class UserControllerTest extends TestCase
}
+ public function mock($class)
+ {
+ $mock = Mockery::mock($class);
+
+ $this->app->instance($class, $mock);
+
+ return $mock;
+ }
+
+ /**
+ * Register and verify FAILED:
+ */
+ public function testPostRegisterAllowedFailed()
+ {
+ // no mock for config! :(
+ Config::set('auth.verify_mail', true);
+ Config::set('auth.allow_register', true);
+
+ // mock repository:
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $email = $this->mock('Firefly\Helper\Email\EmailHelper');
+ $repository->shouldReceive('register')->once()->andReturn(null);
+ // test
+ $crawler = $this->client->request('POST', '/register');
+ $this->assertTrue($this->client->getResponse()->isOk());
+ $this->assertCount(1, $crawler->filter('h1:contains("Register")'));
+
+ }
+
/**
* Register and NO verify:
*/
@@ -116,17 +145,59 @@ class UserControllerTest extends TestCase
// test
$crawler = $this->client->request('POST', '/register', $data);
$this->assertTrue($this->client->getResponse()->isOk());
- $this->assertCount(1, $crawler->filter('h1:contains("Registered!")'));
+ $this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
}
- public function mock($class)
+ public function testLogout()
{
- $mock = Mockery::mock($class);
- $this->app->instance($class, $mock);
+ Auth::shouldReceive('logout');
- return $mock;
+ $this->call('GET', '/logout');
+
+ }
+
+ public function testRemindme()
+ {
+
+ $this->call('GET', '/remindme');
+ $this->assertResponseOk();
+ }
+
+ public function testPostRemindmeWithVerification()
+ {
+ Config::set('auth.verify_reset', true);
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $email = $this->mock('Firefly\Helper\Email\EmailHelper');
+ $repository->shouldReceive('findByEmail')->once()->andReturn(new User);
+ $email->shouldReceive('sendResetVerification')->once()->andReturn(true);
+
+ $this->call('POST', '/remindme');
+ $this->assertResponseOk();
+
+ }
+
+ public function testPostRemindmeWithoutVerification()
+ {
+ Config::set('auth.verify_reset', false);
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $email = $this->mock('Firefly\Helper\Email\EmailHelper');
+ $repository->shouldReceive('findByEmail')->once()->andReturn(new User);
+ $email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
+
+ $this->call('POST', '/remindme');
+ $this->assertResponseOk();
+ }
+
+ public function testPostRemindmeFails()
+ {
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $repository->shouldReceive('findByEmail')->once()->andReturn(null);
+
+ $this->call('POST', '/remindme');
+ $this->assertResponseOk();
+ $this->assertSessionHas('error');
}
/**
@@ -150,6 +221,62 @@ class UserControllerTest extends TestCase
}
+ public function testVerification()
+ {
+
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $email = $this->mock('Firefly\Helper\Email\EmailHelper');
+
+ $repository->shouldReceive('findByVerification')->once()->andReturn(new User);
+ $email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
+
+ // test
+ $crawler = $this->client->request('GET', '/verify/blabla');
+ $this->assertTrue($this->client->getResponse()->isOk());
+ $this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
+
+ }
+
+ public function testVerificationFails()
+ {
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $repository->shouldReceive('findByVerification')->once()->andReturn(null);
+
+ // test
+ $crawler = $this->client->request('GET', '/verify/blabla');
+ $this->assertTrue($this->client->getResponse()->isOk());
+ $this->assertCount(1, $crawler->filter('h1:contains("Error")'));
+ $this->assertViewHas('message');
+ }
+
+ public function testReset()
+ {
+
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $email = $this->mock('Firefly\Helper\Email\EmailHelper');
+
+ $repository->shouldReceive('findByReset')->once()->andReturn(new User);
+ $email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
+
+ // test
+ $crawler = $this->client->request('GET', '/reset/blabla');
+ $this->assertTrue($this->client->getResponse()->isOk());
+ $this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
+
+ }
+
+ public function testResetFails()
+ {
+ $repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
+ $repository->shouldReceive('findByReset')->once()->andReturn(null);
+
+ // test
+ $crawler = $this->client->request('GET', '/reset/blabla');
+ $this->assertTrue($this->client->getResponse()->isOk());
+ $this->assertCount(1, $crawler->filter('h1:contains("Error")'));
+ $this->assertViewHas('message');
+ }
+
public function tearDown()
{
Mockery::close();
diff --git a/app/views/user/registered.blade.php b/app/views/user/registered.blade.php
index b60f786c96..3724140e4e 100644
--- a/app/views/user/registered.blade.php
+++ b/app/views/user/registered.blade.php
@@ -3,7 +3,7 @@
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<h1>Firefly<br/>
- <small>Registered!</small>
+ <small>Password sent!</small>
</h1>
</div>
</div>