i have written following test :
/** @test */ public function register_a_new_user_as_a_candidate_with_correct_input() { $registrationemail = 'dummy@mail.com'; $this->visit('/') ->click('register') ->seepageis('/') ->type($registrationemail, 'email') ->select('candidate', 'user_type') ->press('register') ->seepageis('/') ->see('registration successful') ->seeindatabase('users', ['email' => $registrationemail, 'userable_type' => app\candidate::class]); }
when manually register myself through form complete steps no issue.
when run test :
there 1 failure:
1) registrationtest::register_a_new_user_as_a_candidate_with_correct_input request [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 symfony\component\httpkernel\exception\methodnotallowedhttpexception in /home/vagrant/code/staffsite/vendor/laravel/framework/src/illuminate/routing/routecollection.php:218
i don't have route let's user register through get. form uses ajax send request on post , html form uses type post.
is test incorrect?
here form using :
<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> candidate looking work! </label> </div> <div class="radio"> <label> <input name="user_type" type="radio" value="business"> 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>
i suspect problem form defined type="post"
, while the correct declaration method="post"
. change to:
<form method="post" action="register" class="bootstrap-modal-form">
without method
, form submitted get
. doesn't cover stated fact works in browser. perhaps there caching going on?
Comments
Post a Comment