Ich habe den folgenden Test geschrieben:Laravel-Test Confuses POST und GET
/** @test */
public function register_a_new_user_as_a_candidate_with_correct_input()
{
$registrationEmail = '[email protected]';
$this->visit('/')
->click('Register')
->seePageIs('/')
->type($registrationEmail, 'email')
->select('candidate', 'user_type')
->press('Register')
->seePageIs('/')
->see('Registration was successful')
->seeInDatabase('users', ['email' => $registrationEmail, 'userable_type' => App\Candidate::class]);
}
Wenn ich mich manuell Form registrieren durch ich ohne Frage alle Schritte erfolgreich abgeschlossen.
Wenn ich diesen Test ausführen, erhalte ich:
war es ein Fehlschlag:
1) RegistrationTest::register_a_new_user_as_a_candidate_with_correct_input
A request to [http://localhost/register?_token=GNP3xtGrgyKWKfysE6xHd9WYD04FrSbtqb9IWu08&email=dummy%40mail.com&user_type=candidate] failed. Received status code [405].
/home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:196
/home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
/home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:113
/home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:556
/home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:543
/home/vagrant/Code/staffsite/tests/acceptance/RegistrationTest.php:18
Caused by
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /home/vagrant/Code/staffsite/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:218
Ich habe nicht eine Route, die ein Benutzer durch GET registrieren lassen ist. Mein Formular verwendet Ajax, um die Anfrage über POST zu senden, und mein HTML-Formular verwendet den Typ POST.
Ist mein Test falsch? Hier
ist die Form, die ich benutze:
<form type="POST" action="register" class="bootstrap-modal-form">
{{ csrf_field() }}
<div class="modal-body">
<div class="form-group">
<label for="email" class="sr-only">E-Mail Address</label>
<input name="email" type="email" class="form-control" placeholder="Email Address" required autofocus>
</div>
<div class="radio">
<label>
<input name="user_type" type="radio" value="candidate" checked>
I am a candidate looking for work!
</label>
</div>
<div class="radio">
<label>
<input name="user_type" type="radio" value="business">
I am a business interested in hiring candidates.
</label>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Register" class="btn btn-default btn-primary">
<button class="btn modal-default-button" data-dismiss="modal">Back</button>
</div>
</form>
Wie sieht dein '
@Bischof Ich aktualisierte meine Antwort mit dem Formular, das ich benutze. Es ist eine typische Eingabemethode. –