vm's avatar
Level 2

Test Failing but app working in Form Validation

Laracasts\Validation\FormValidationException: Validation failed

Scenario Steps: 9. I click "Sign Up" THIS IS RED 8. I fill field "Password Confirmation:","demo" 7. I fill field "Password:","demo" 6. I fill field "Email:","john@example.com" 5. I fill field "Username:","JohnDoe" 4. I see current url equals "/register" 3. I click "Sign Up!"

when i do a dd like

public function store() { dd(Input::all()); $this->registrationForm->validate(Input::all());

    extract(Input::only('username', 'email', 'password'));

    $user = $this->execute(

        new RegisterUserCommand($username, $email, $password)
    );

    Auth::login($user);

    return Redirect::home();
}

I get

Functional Tests (1) ---------------------------------------------------------------------------------------- Trying to sign up for a account (SignUpCept) array(5) { '_token' => string(40) "gjzeNsyqpRBYcNZUQBj2xmu7Tf5oFeRsx5fru10Y" 'username' => string(7) "JohnDoe" 'email' => string(16) "john@example.com" 'password' => string(4) "demo" 'password_confirmation' => string(0) "" WHY?????????????? }

0 likes
5 replies
kreitje's avatar

Is your label for the correct input? Maybe you left it as password instead of password_confirmation assuming you copy + pasted. Is your spelling correct? Do you have a colon after "Password Confirmation"?

vm's avatar
Level 2

Here is the cept file

$I = new FunctionalTester($scenario); $I->am('a guest'); $I->wantTo('sign up for account'); $I->amOnPage('/'); $I->click('Sign Up!'); $I->seeCurrentUrlEquals('/register'); $I->fillField('Username:', 'JohnDoe'); $I->fillField('Email:', 'john@example.com'); $I->fillField('Password:', 'demo'); $I->fillField('Password Confirmation:', 'demo'); $I->click('Sign Up');

$I->seeCurrentUrlEquals(''); $I->see('Welcome to !');

$I->seeRecord('users',[

'username' => 'JohnDoe',
'email' => 'john@example.com'

]);

$I->assertTrue(Auth::check());

and form is

{{ Form::open(['route' => 'register_path']) }}

{{Form::label('username', 'Username:')}} {{Form::text('username', null, ['class' => 'form-control'])}} {{Form::label('email', 'Email:')}} {{Form::text('email', null, ['class' => 'form-control'])}} {{Form::label('password', 'Password:')}} {{Form::text('password', null, ['class' => 'form-control'])}} {{Form::label('password', 'Password Confirmation:')}} {{Form::text('password_confirmation', null, ['class' => 'form-control'])}} {{Form::submit('Sign Up', ['class' => 'btn btn-signUp'])}}
 {{Form::close()}}

I don't see any discrepancies as you suggested as potential cause. Thank you for responding.

kreitje's avatar
kreitje
Best Answer
Level 9
{{Form::label('password', 'Password Confirmation:')}}

Change that to the following:

{{Form::label('password_confirmation', 'Password Confirmation:')}}
2 likes
Devon's avatar

Good eye, @kreitje! Pretty sure kreitje's last response will solve the problem.

@vichu, for future reference, please put you code in code blocks... Laracasts makes use of GitHub-flavored markdown. Therefore, using 3 backticks (or backwards single quotes) will work...

For example:
```
// Your code
```
Will generate:

// Your code

It's also worth noting:

  • 2 spaces and a line break = new line.
  • 2 line breaks = new paragraph.

Proper formatting will result in much faster responses since things are easier to read. :)

Please or to participate in this conversation.