SignupTest.php 1.86 KB
<?php

namespace FootyRoom\Tests;

class SignupTest extends TestCase
{
    use SetsUpFixtures;

    public function testGuestCanViewSignupPage()
    {
        $response = $this->call('GET', '/signup');
        $this->assertEquals(200, $response->status());
    }

    public function testLoggedInUserShouldNotViewSignupPage()
    {
        $user = factory('FootyRoom\User\User')->make();
        $response = $this->actingAs($user)->call('GET', '/signup');
        $this->assertEquals(302, $response->status());
        $response->assertLocation('http://'.app('FootyRoom\Config')->get('domain'));
    }

    public function testCheckUsernameExistShowCorrectResponse()
    {
        $response = $this->call('GET', '/signup/check-username?username=chandu');
        $this->assertEquals(200, $response->status());
        $this->assertEquals('taken', $response->original);

        $response = $this->call('GET', '/signup/check-username?username=asf');
        $this->assertEquals(200, $response->status());
        $this->assertEquals('available', $response->original);
    }

    public function testSignupWithInvalidCaptchaShouldShowCorrectMessage()
    {
        $response = $this->call('POST', '/signup', [
            'username' => 'asdf',
            'password' => 'asdf',
            'email' => 'asdf@gmail.com',
        ]);

        $this->assertEquals(400, $response->status());
        $this->assertEquals('You have not passed the CAPTCHA test, please try again.', $response->original['server'][0]);

        $response = $this->call('POST', '/signup', [
            'username' => 'asdf',
            'password' => 'asdf',
            'email' => 'asdf@gmail.com',
            'gRecaptchaResponse' => '',
        ]);

        $this->assertEquals(400, $response->status());
        $this->assertEquals('You have not passed the CAPTCHA test, please try again.', $response->original['server'][0]);
    }
}