Skip to content

Commit

Permalink
Merge 2c0e278 into 9246bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
PSkierniewski committed Nov 1, 2015
2 parents 9246bcc + 2c0e278 commit a8bb072
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/AccountApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function update($id)
$this->userRepo->update($user, $input);
return Response::json(['success' => true]);
} catch (ValidationException $e) {
return Response::json(['success' => false, 'errors' => $e->getErrors()]);
// @TODO Use response code from ValidationException class
return Response::json(['success' => false, 'errors' => $e->getErrors()], 400);
}
}

Expand Down
29 changes: 16 additions & 13 deletions resources/views/account/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,27 @@
$.ajax({
url: "/<?php echo $lang->code;?>/api/v1/account/ <?php echo $user->id;?>",
data: $('#edit-account-form').serializeObject(),
type: 'PUT'
}).done(function (result) {
Loading.stop();
if(result.success){
type: 'PUT',
success: function (xhr) {
Loading.stop();
// set success message
setGlobalMessage('success', "@lang('common.changesSavedMessage')");
hideMessages();
clearFormValidationErrors();
} else {
// clear previous errors
clearFormValidationErrors();
$.each(result.errors, function (index, error) {
// set form errors
setFormValidationErrors(index, error);
});
},
error: function(xhr, status, error){
Loading.stop();
if(typeof xhr.responseJSON !== 'undefined'){
// clear previous errors
clearFormValidationErrors();
$.each(xhr.responseJSON.errors, function (index, error) {
// set form errors
setFormValidationErrors(index, error);
});
}
}
})
});
});
})
});
</script>
@stop
79 changes: 79 additions & 0 deletions tests/functional/AccountCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php namespace platform;

use DateTime;

class AccountCest
{

public function _before(FunctionalTester $I)
{
$I->haveRecord(
'Users',
[
'firstName' => 'Johny',
'lastName' => 'Doe',
'email' => 'john@doe.com',
'password' => bcrypt('test123'),
'createdAt' => new DateTime(),
'updatedAt' => new DateTime(),
]
);
}

public function _after(FunctionalTester $I)
{
}

// tests
public function canAccessUserAccount(FunctionalTester $I)
{
$I->wantTo('can access user account');
$I->login('john@doe.com', 'test123');
$I->click('Edit Account', '.user-nav');
$I->canSeeInCurrentUrl('/en/account/edit');
$I->click('My Account', '.nav');
$I->canSeeInCurrentUrl('/en/account');
}

public function canChangeFirstNameAndLastName(FunctionalTester $I)
{
$I->wantTo('change user first name & last name');
$I->login('john@doe.com', 'test123');
$I->click('Edit Account', '.user-nav');
$I->canSee('Change password');
$token = $I->grabValueFrom("input[name='_token']");
$loggedUser = $I->grabRecord('Users', ['email' => 'john@doe.com']);
$I->sendAjaxRequest('PUT', '/en/api/v1/account/' . $loggedUser->id, ['firstName' => 'xxx', 'lastName' => 'yyy', '_token' => $token]);
$I->seeResponseCodeIs(200);
$I->amOnPage('/en');
$I->see('xxx yyy');
}

public function canChangePassword(FunctionalTester $I)
{
$I->wantTo('change user password');
$I->login('john@doe.com', 'test123');
$I->click('Edit Account', '.user-nav');
$I->canSee('Change password');
$token = $I->grabValueFrom("input[name='_token']");
$loggedUser = $I->grabRecord('Users', ['email' => 'john@doe.com']);
$I->sendAjaxRequest('PUT', '/en/api/v1/account/' . $loggedUser->id, ['password' => 'test124', 'password_confirmation' => 'test124', '_token' => $token]);
$I->seeResponseCodeIs(200);
$I->logout();
$I->login('john@doe.com', 'test124');
}

public function canNotChangePasswordWithoutConfirmation(FunctionalTester $I)
{
$I->wantTo('change user password');
$I->login('john@doe.com', 'test123');
$I->click('Edit Account', '.user-nav');
$I->canSee('Change password');
$token = $I->grabValueFrom("input[name='_token']");
$loggedUser = $I->grabRecord('Users', ['email' => 'john@doe.com']);
$I->sendAjaxRequest('PUT', '/en/api/v1/account/' . $loggedUser->id, ['password' => 'test124', '_token' => $token]);
$I->seeResponseCodeIs(400);
}

}

29 changes: 29 additions & 0 deletions tests/functional/HomePageCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php namespace platform;

use DateTime;

class HomePageCest
{

public function _before(FunctionalTester $I)
{
}

public function _after(FunctionalTester $I)
{
}

// tests
public function canViewHomePage(FunctionalTester $I)
{
$I->wantTo('can view home page');
$I->amOnPage('/en');
$I->seeResponseCodeIs(200);
$I->canSee('GZERO CMS!');
$I->seeLink('Get started today', 'http://localhost/en/register');
$I->seeLink('Login', 'http://localhost/en/login');
$I->seeLink('Register', 'http://localhost/en/register');
}

}

0 comments on commit a8bb072

Please sign in to comment.