Also covered ProfileController.

This commit is contained in:
James Cole committed 2014-07-03 09:16:17 +02:00
1 parent 516fe54bf0
commit 924ec29eaf
6 files changed
+184 -24

No files matched your search

@@ -0,0 +1,141 @@
<?php
class ProfileControllerTest extends TestCase
{
public function testIndex()
{
// mock:
View::shouldReceive('make')->with('profile.index');
// call
$this->call('GET', '/profile');
// test
$this->assertResponseOk();
}
public function testChangePassword()
{
// mock:
View::shouldReceive('make')->with('profile.change-password');
// call
$this->call('GET', '/profile/change-password');
// test
$this->assertResponseOk();
}
public function testOldNoMatch()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(false);
$data = [
'old' => 'lala',
'new1' => 'a',
'new2' => 'a',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'Invalid current password!');
}
public function testNewEmpty()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
$data = [
'old' => 'lala',
'new1' => '',
'new2' => '',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'Do fill in a password!');
}
public function testOldSame()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$data = [
'old' => 'a',
'new1' => 'a',
'new2' => 'a',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'The idea is to change your password.');
}
public function testNewNoMatch()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$data = [
'old' => 'b',
'new1' => 'c',
'new2' => 'd',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'New passwords do not match!');
}
public function testPostChangePassword()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$repository->shouldReceive('updatePassword')->once()->andReturn(true);
$data = [
'old' => 'b',
'new1' => 'c',
'new2' => 'c',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertRedirectedToRoute('profile');
$this->assertSessionHas('success', 'Password changed!');
}
}
+1 -7
View File
@@ -17,6 +17,7 @@ class UserControllerTest extends TestCase
$this->call('GET', '/login');
// test
$this->assertResponseOk();
}
public function testPostLogin()
@@ -94,14 +95,7 @@ class UserControllerTest extends TestCase
}
public function mock($class)
{
$mock = Mockery::mock($class);
$this->app->instance($class, $mock);
return $mock;
}
/**
* Register and verify FAILED: