diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index f38c81fa..23518374 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -33,7 +33,7 @@ class UserController extends Controller
public function postEditUser(Request $request)
{
$rules = [
- 'email' => ['required', 'email', 'exists:users,email,account_id,'.Auth::user()->account_id],
+ 'email' => ['required', 'email', 'unique:users,email,' . Auth::user()->id . ',id,account_id,' . Auth::user()->account_id],
'new_password' => ['min:5', 'confirmed', 'required_with:password'],
'password' => 'passcheck',
'first_name' => ['required'],
@@ -44,7 +44,7 @@ class UserController extends Controller
'email.email' => 'Please enter a valid E-mail address.',
'email.required' => 'E-mail address is required.',
'password.passcheck' => 'This password is incorrect.',
- 'email.exists' => 'This E-mail has is already in use.',
+ 'email.unique' => 'This E-mail is already in use.',
'first_name.required' => 'Please enter your first name.',
];
@@ -65,6 +65,7 @@ class UserController extends Controller
$user->first_name = $request->get('first_name');
$user->last_name = $request->get('last_name');
+ $user->email = $request->get('email');
$user->save();
diff --git a/resources/views/ManageUser/Modals/EditUser.blade.php b/resources/views/ManageUser/Modals/EditUser.blade.php
index 32c3ccb7..4d626db4 100644
--- a/resources/views/ManageUser/Modals/EditUser.blade.php
+++ b/resources/views/ManageUser/Modals/EditUser.blade.php
@@ -1,89 +1,90 @@
- {!! Form::model($user, array('url' => route('postEditUser'), 'class' => 'ajax closeModalAfter')) !!}
-
-
-
-
- @if(!Auth::user()->first_name)
-
-
- Welcome to {{config('attendize.app_name')}}!
-
- Before you continue please update your account with your name and a new password.
+ {!! Form::model($user, array('url' => route('postEditUser'), 'class' => 'ajax closeModalAfter')) !!}
+ {!! Form::password('meaningless_password') !!}
+
+
+
- @endif
-
-
-
- {!! Form::label('first_name', 'First Name', array('class'=>'control-label required')) !!}
- {!! Form::text('first_name', Input::old('first_name'),
- array(
- 'class'=>'form-control'
- )) !!}
+
+ @if(!Auth::user()->first_name)
+
+
+ Welcome to {{config('attendize.app_name')}}!
+
+ Before you continue please update your account with your name and a new password.
+
+ @endif
+
+
+
+ {!! Form::label('first_name', 'First Name', array('class'=>'control-label required')) !!}
+ {!! Form::text('first_name', Input::old('first_name'),
+ array(
+ 'class'=>'form-control'
+ )) !!}
+
+
+
+
+ {!! Form::label('last_name', 'Last Name', array('class'=>'control-label required')) !!}
+ {!! Form::text('last_name', Input::old('last_name'),
+ array(
+ 'class'=>'form-control'
+ )) !!}
+
-
-
-
-
-
- {!! Form::label('email', 'Email', array('class'=>'control-label required')) !!}
- {!! Form::text('email', Input::old('email'),
- array(
- 'class'=>'form-control '
- )) !!}
-
-
-
-
-
+
+
-
- {!! Form::label('password', 'Old Password', array('class'=>'control-label')) !!}
- {!! Form::password('password',
- array(
- 'class'=>'form-control'
- )) !!}
-
-
- {!! Form::label('new_password', 'New Password', array('class'=>'control-label')) !!}
- {!! Form::password('new_password',
- array(
- 'class'=>'form-control'
- )) !!}
-
-
+
+ Change Password
+
+
+
-
- Change Password
-
-
-
- {!! Form::close() !!}
-
+ {!! Form::close() !!}
diff --git a/tests/UserLoginTest.php b/tests/UserLoginTest.php
new file mode 100644
index 00000000..23c8f965
--- /dev/null
+++ b/tests/UserLoginTest.php
@@ -0,0 +1,53 @@
+visit(route('login'))
+ ->type($this->test_user_email, 'email')
+ ->type($this->test_user_password, 'password')
+ ->press('Login')
+ ->seePageIs(route('showCreateOrganiser', ['first_run' => '1']));
+ }
+
+ /**
+ * Test login page is unsuccessful with wrong password
+ *
+ * @return void
+ */
+ public function test_login_is_unsuccessful_with_wrong_password()
+ {
+ $this->visit(route('login'))
+ ->type($this->test_user_email, 'email')
+ ->type('incorrect_password', 'password')
+ ->press('Login')
+ ->seePageIs(route('login'))
+ ->see('Your username/password combination was incorrect');
+ }
+
+ /**
+ * Test login page is unsuccessful with wrong email address
+ *
+ * @return void
+ */
+ public function test_login_is_unsuccessful_with_wrong_email_address()
+ {
+ $this->visit(route('login'))
+ ->type('other@email.com', 'email')
+ ->type($this->test_user_password, 'password')
+ ->press('Login')
+ ->seePageIs(route('login'))
+ ->see('Your username/password combination was incorrect');
+ }
+}
diff --git a/tests/UserSignUpTest.php b/tests/UserSignUpTest.php
new file mode 100644
index 00000000..019ecab1
--- /dev/null
+++ b/tests/UserSignUpTest.php
@@ -0,0 +1,80 @@
+visit(route('showSignup'))
+ ->type($this->faker->firstName, 'first_name')
+ ->type($this->faker->lastName, 'last_name')
+ ->type($this->faker->email, 'email')
+ ->type('password', 'password')
+ ->type('password', 'password_confirmation');
+
+ // Add checkbox submission for attendize (dev/cloud) only
+ if (Utils::isAttendize()) {
+ $this->check('terms_agreed');
+ }
+
+ $this->press('Sign Up')
+ ->seePageIs(route('login'));
+
+ // TODO: Test User Details are correct
+ }
+
+ /**
+ * Test sign up page is unsuccessful
+ *
+ * @return void
+ */
+ public function test_signup_is_unsuccessful_because_of_no_values()
+ {
+ $this->visit(route('showSignup'))
+ ->press('Sign Up')
+ ->seePageIs(route('showSignup'));
+ }
+
+ /**
+ * Test sign up page is unsuccessful
+ *
+ * @return void
+ */
+ public function test_signup_is_unsuccessful_because_of_invalid_email()
+ {
+ $this->visit(route('showSignup'))
+ ->type($this->faker->firstName, 'first_name')
+ ->type($this->faker->lastName, 'last_name')
+ ->type('test@test', 'email')
+ ->type('password', 'password')
+ ->type('password', 'password_confirmation')
+ ->press('Sign Up')
+ ->seePageIs(route('showSignup'));
+ }
+
+ /**
+ * Test sign up page is unsuccessful
+ *
+ * @return void
+ */
+ public function test_signup_is_unsuccessful_because_of_unmatched_password()
+ {
+ $this->visit(route('showSignup'))
+ ->type($this->faker->firstName, 'first_name')
+ ->type($this->faker->lastName, 'last_name')
+ ->type($this->faker->email, 'email')
+ ->type('password', 'password')
+ ->type('incorrect_matching', 'password_confirmation')
+ ->press('Sign Up')
+ ->seePageIs(route('showSignup'));
+ }
+}
diff --git a/tests/UserTest.php b/tests/UserTest.php
index b629a8dd..bcd1492a 100644
--- a/tests/UserTest.php
+++ b/tests/UserTest.php
@@ -7,37 +7,39 @@ use App\Attendize\Utils;
class UserTest extends TestCase
{
-
/**
- * Test sign up page is successful
+ * Test user edit page is successful
*
* @return void
*/
- public function testSignup()
+ public function test_edit_user_is_successful()
{
- $this->visit(route('showSignup'))
- ->type('Joe', 'first_name')
- ->type('Blogs', 'last_name')
- ->type($this->faker->email, 'email')
- ->type('password', 'password')
- ->type('password', 'password_confirmation');
+ $this->actingAs($this->test_user);
- // Add checkbox submission for attendize (dev/cloud) only
- if (Utils::isAttendize()) {
- $this->check('terms_agreed');
- }
+ $organiser = factory(App\Models\Organiser::class)->create(['account_id' => 1]);
- $this->press('Sign Up')
- ->seePageIs(route('login'));
+ $server = array('HTTP_X-Requested-With' => 'XMLHttpRequest');
+
+ $firstName = $this->faker->firstName;
+ $lastName = $this->faker->lastName;
+ $email = 'new@email.com.au';
+ $post = array(
+ 'first_name' => $firstName,
+ 'last_name' => $lastName,
+ 'email' => $email,
+ );
+
+ $this->call('post', route('postEditUser'), $post, $server);
+
+ $this->seeJson([
+ 'status' => 'success',
+ 'message' => 'Successfully Edited User',
+ ]);
+
+ $user = App\Models\User::find($this->test_user->id);
+
+ $this->assertEquals($firstName, $user->first_name);
+ $this->assertEquals($lastName, $user->last_name);
+ $this->assertEquals($email, $user->email);
}
-
- public function testLogin()
- {
- $this->visit(route('login'))
- ->type($this->test_user_email, 'email')
- ->type($this->test_user_password, 'password')
- ->press('Login')
- ->seePageIs(route('showCreateOrganiser', ['first_run' => '1']));
- }
-
}