thinhbuzz / laravel-google-captcha

Google captcha for Laravel 5, Laravel 6, Laravel 7, Laravel 8, Laravel 9 and Laravel 10, support multiple captcha on page
MIT License
200 stars 32 forks source link

Passing post tests? #35

Closed stueynet closed 5 years ago

stueynet commented 5 years ago

Read the testing instructions which work well if you are testing forms but what about testing using a simple post request? Thanks in advance for the help!

Eg:

$this->post('/register', [
            'username' => 'TestUser',
            'email' => 'foo@example.com',
            'password' => 'Password123',
            'password_confirmation' => 'Password123',
            'terms' => '1',
        ]);

        $this->assertDatabaseHas('users', [
            'email' => 'foo@example.com',
            'username' => 'TestUser',
        ]);
stueynet commented 5 years ago

Nevermind this worked!

CaptchaFacade::shouldReceive('verify')
                     ->andReturn(true);

        $this->post('/register', [
            'username' => 'TestUser',
            'email' => 'foo@example.com',
            'password' => 'Password123',
            'password_confirmation' => 'Password123',
            'terms' => '1',
            'g-recaptcha-response' => '1',
        ]);

        $this->assertDatabaseHas('users', [
            'email' => 'foo@example.com',
            'username' => 'TestUser',
        ]);