| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2014-08-21 07:21:56 +02:00
										 |  |  | use League\FactoryMuffin\Facade as f; | 
					
						
							| 
									
										
										
										
											2014-08-28 07:53:54 +02:00
										 |  |  | use Mockery as m; | 
					
						
							| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class ProfileControllerTest | 
					
						
							| 
									
										
										
										
											2014-08-10 18:22:42 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.TooManyMethods) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.CamelCasePropertyName) | 
					
						
							| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | class ProfileControllerTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     protected $_user; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::setUp(); | 
					
						
							|  |  |  |         Artisan::call('migrate'); | 
					
						
							|  |  |  |         Artisan::call('db:seed'); | 
					
						
							|  |  |  |         $this->_user = m::mock('User', 'Eloquent'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function tearDown() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m::close(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testChangePassword() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($this->_user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action('GET', 'ProfileController@changePassword'); | 
					
						
							|  |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testIndex() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($this->_user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action('GET', 'ProfileController@index'); | 
					
						
							|  |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testPostChangePasswordDifferentNew() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = f::create('User'); | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action( | 
					
						
							|  |  |  |             'POST', 'ProfileController@postChangePassword', | 
					
						
							|  |  |  |             ['old' => 'sander', 'new1' => 'sander1', 'new2' => 'sander2'] | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testPostChangePasswordOK() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = f::create('User'); | 
					
						
							| 
									
										
										
										
											2014-08-21 15:16:12 +02:00
										 |  |  |         $user->password = 'sander'; | 
					
						
							|  |  |  |         $user->save(); | 
					
						
							| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action( | 
					
						
							|  |  |  |             'POST', 'ProfileController@postChangePassword', | 
					
						
							|  |  |  |             ['old' => 'sander', 'new1' => 'sander2', 'new2' => 'sander2'] | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2014-08-21 15:16:12 +02:00
										 |  |  |         $this->assertSessionHas('success'); | 
					
						
							| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  |         $this->assertResponseStatus(302); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testPostChangePasswordNoCurrent() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($this->_user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($this->_user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('password')->andReturn('Blablabla'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-10 11:30:14 +02:00
										 |  |  |         $this->action('POST', 'ProfileController@postChangePassword', ['old' => '']); | 
					
						
							| 
									
										
										
										
											2014-08-09 13:40:13 +02:00
										 |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testPostChangePasswordNoMatchNew() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = f::create('User'); | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action( | 
					
						
							|  |  |  |             'POST', 'ProfileController@postChangePassword', ['old' => 'sander', 'new1' => 'sander', 'new2' => 'sander'] | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testPostChangePasswordSame() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = f::create('User'); | 
					
						
							|  |  |  |         // for binding
 | 
					
						
							|  |  |  |         Auth::shouldReceive('user')->andReturn($user); | 
					
						
							|  |  |  |         Auth::shouldReceive('check')->andReturn(true); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($user->id); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn($user->email); | 
					
						
							|  |  |  |         $this->_user->shouldReceive('getAttribute')->with('password')->andReturn($user->password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->action('POST', 'ProfileController@postChangePassword', ['old' => 'sander']); | 
					
						
							|  |  |  |         $this->assertResponseOk(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  |