From 13ca1666e0310655d4987687841f798b2c047ff3 Mon Sep 17 00:00:00 2001 From: Jim Cummins Date: Sun, 8 Dec 2013 23:23:35 -0600 Subject: [PATCH] Add UserController Valid Guest Registration test --- app/config/testing/mail.php | 108 +++++++++++++++++++++++++++++ app/controllers/UserController.php | 46 ++++++------ app/tests/UserControllerTest.php | 21 ++++++ 3 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 app/config/testing/mail.php diff --git a/app/config/testing/mail.php b/app/config/testing/mail.php new file mode 100644 index 00000000..9b0b4ca3 --- /dev/null +++ b/app/config/testing/mail.php @@ -0,0 +1,108 @@ + 'smtp', + + /* + |-------------------------------------------------------------------------- + | SMTP Host Address + |-------------------------------------------------------------------------- + | + | Here you may provide the host address of the SMTP server used by your + | applications. A default option is provided that is compatible with + | the Postmark mail service, which will provide reliable delivery. + | + */ + + 'host' => 'smtp.mailgun.org', + + /* + |-------------------------------------------------------------------------- + | SMTP Host Port + |-------------------------------------------------------------------------- + | + | This is the SMTP port used by your application to delivery e-mails to + | users of your application. Like the host we have set this value to + | stay compatible with the Postmark e-mail application by default. + | + */ + + 'port' => 587, + + /* + |-------------------------------------------------------------------------- + | Global "From" Address + |-------------------------------------------------------------------------- + | + | You may wish for all e-mails sent by your application to be sent from + | the same address. Here, you may specify a name and address that is + | used globally for all e-mails that are sent by your application. + | + */ + + 'from' => array('address' => null, 'name' => null), + + /* + |-------------------------------------------------------------------------- + | E-Mail Encryption Protocol + |-------------------------------------------------------------------------- + | + | Here you may specify the encryption protocol that should be used when + | the application send e-mail messages. A sensible default using the + | transport layer security protocol should provide great security. + | + */ + + 'encryption' => 'tls', + + /* + |-------------------------------------------------------------------------- + | SMTP Server Username + |-------------------------------------------------------------------------- + | + | If your SMTP server requires a username for authentication, you should + | set it here. This will get used to authenticate with your server on + | connection. You may also set the "password" value below this one. + | + */ + + 'username' => null, + + /* + |-------------------------------------------------------------------------- + | SMTP Server Password + |-------------------------------------------------------------------------- + | + | Here you may set the password required by your SMTP server to send out + | messages from your application. This will be given to the server on + | connection so that the application will be able to send messages. + | + */ + + 'password' => null, + + /* + |-------------------------------------------------------------------------- + | Pretend to email + |-------------------------------------------------------------------------- + | + | In testing, we don't actually want to send emails. Instead, just pretend. + | + */ + + 'pretend' => true, + +); diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 035bc09c..3a669a86 100755 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -87,14 +87,14 @@ public function store() if( $result['success'] ) { Event::fire('user.signup', array( - 'email' => $result['mailData']['email'], - 'userId' => $result['mailData']['userId'], - 'activationCode' => $result['mailData']['activationCode'] - )); + 'email' => $result['mailData']['email'], + 'userId' => $result['mailData']['userId'], + 'activationCode' => $result['mailData']['activationCode'] + )); // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { Session::flash('error', $result['message']); @@ -232,11 +232,11 @@ public function activate($id, $code) { // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { Session::flash('error', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } } @@ -252,14 +252,14 @@ public function resend() if( $result['success'] ) { Event::fire('user.resend', array( - 'email' => $result['mailData']['email'], - 'userId' => $result['mailData']['userId'], - 'activationCode' => $result['mailData']['activationCode'] - )); + 'email' => $result['mailData']['email'], + 'userId' => $result['mailData']['userId'], + 'activationCode' => $result['mailData']['activationCode'] + )); // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { @@ -282,14 +282,14 @@ public function forgot() if( $result['success'] ) { Event::fire('user.forgot', array( - 'email' => $result['mailData']['email'], - 'userId' => $result['mailData']['userId'], - 'resetCode' => $result['mailData']['resetCode'] - )); + 'email' => $result['mailData']['email'], + 'userId' => $result['mailData']['userId'], + 'resetCode' => $result['mailData']['resetCode'] + )); // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { @@ -320,17 +320,17 @@ public function reset($id, $code) if( $result['success'] ) { Event::fire('user.newpassword', array( - 'email' => $result['mailData']['email'], - 'newPassword' => $result['mailData']['newPassword'] - )); + 'email' => $result['mailData']['email'], + 'newPassword' => $result['mailData']['newPassword'] + )); // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { Session::flash('error', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } } @@ -358,7 +358,7 @@ public function change($id) { // Success! Session::flash('success', $result['message']); - return Redirect::to('/'); + return Redirect::route('home'); } else { diff --git a/app/tests/UserControllerTest.php b/app/tests/UserControllerTest.php index 5316c1bb..8b9d025c 100644 --- a/app/tests/UserControllerTest.php +++ b/app/tests/UserControllerTest.php @@ -304,4 +304,25 @@ public function testUserControllerStoreInvalidBlankInputAsAdmin() $this->assertSessionHasErrors(); } + public function testUserControllerStoreValidAsGuest() + { + $this->beGuest(); + Input::replace($input = array( + 'IgnoreCSRFTokenError' => true, + 'email' => 'test@test.com', + 'password' => 'testtest', + 'password_confirmation' => 'testtest' + )); + + $userSignupEventFired = false; + Event::listen('user.signup', function() use (&$userSignupEventFired) { + $userSignupEventFired = true; + }); + + $this->call('post', URL::action('UserController@store'), $input); + + $this->assertTrue($userSignupEventFired, 'The user.signup event never fired during UserController@store'); + $this->assertRedirectedToRoute('home'); + } + } \ No newline at end of file