Is this Test Case overkill?
I am new to Unit Testing so I am learning and I'd love to hear your opinion about it.
use Application\Tests\TestCase as TestCase;
class RoutesSubmissionsTest extends TestCase {
public function setUp()
{
parent::setUp();
$this->app['router']->enableFilters();
}
/**
* Tests submissions/welcome route as a Guest.
*
* @return void
*/
public function testRouteToSubmissionsWelcomeAsGuest()
{
$this->route('GET', 'submissions.welcome');
$this->assertRedirectedToRoute('users.login');
}
/**
* Tests submissions/welcome route as an User with GET method.
*
* @return void
*/
public function testRouteToSubmissionsWelcomeAsUserWithGetMethod()
{
$this->authenticateAsUser();
$this->route('GET', 'submissions.welcome');
$this->assertResponseOk();
}
/**
* Tests submissions/welcome route as an User with POST method without CSRF token.
*
* @expectedException Illuminate\Session\TokenMismatchException
* @return void
*/
public function testRouteToSubmissionsWelcomeAsUserWithPostMethodWithoutCSRFToken()
{
$this->authenticateAsUser();
$this->route('POST', 'submissions.welcome');
}
/**
* Tests submissions/welcome route as an User with POST method with CSRF token without AJAX.
*
* @return void
*/
public function testRouteToSubmissionsWelcomeAsUserWithPostMethodWithCSRFTokenWithoutAjax()
{
Session::start();
$this->authenticateAsUser();
$this->route('POST', 'submissions.welcome', [], ['_token' => csrf_token()]);
$this->assertResponseStatus(403);
}
/**
* Tests submissions/welcome route as an User with POST method with CSRF token with AJAX.
*
* @expectedException ErrorException
* @expectedExceptionMessage Undefined index: username
* @return void
*/
public function testRouteToSubmissionsWelcomeAsUserWithPostMethodWithCSRFTokenWithAjax()
{
Session::start();
$this->authenticateAsUser();
$this->route('POST', 'submissions.welcome', [], [], [], ['HTTP_X-CSRF-Token' => csrf_token(), 'HTTP_X-Requested-With' => 'XMLHttpRequest']);
}
/**
* Tests submissions/registration route as a Guest.
*
* @return void
*/
public function testRouteToSubmissionsRegistrationAsGuest()
{
$this->route('GET', 'submissions.registration');
$this->assertRedirectedToRoute('users.login');
}
/**
* Tests submissions/registration route as an User with GET method.
*
* @return void
*/
public function testRouteToSubmissionsRegistrationAsUserWithGetMethod()
{
$this->authenticateAsUser();
$this->route('GET', 'submissions.registration');
$this->assertResponseOk();
}
/**
* Tests submissions/registration route as an User with POST method.
*
* @expectedException Illuminate\Session\TokenMismatchException
* @return void
*/
public function testRouteToSubmissionsRegistrationAsUserWithPostMethodWithoutCSRFToken()
{
$this->authenticateAsUser();
$this->route('POST', 'submissions.registration');
}
/**
* Tests submissions/registration route as an User with POST method with CSRF token without AJAX.
*
* @return void
*/
public function testRouteToSubmissionsRegistrationAsUserWithPostMethodWithCSRFTokenWithoutAjax()
{
Session::start();
$this->authenticateAsUser();
$this->route('POST', 'submissions.registration', [], ['_token' => csrf_token()]);
$this->assertResponseStatus(403);
}
/**
* Tests submissions/registration route as an User with POST method with CSRF token with AJAX.
*
* @expectedException ErrorException
* @expectedExceptionMessage Undefined index: username
* @return void
*/
public function testRouteToSubmissionsRegistrationAsUserWithPostMethodWithCSRFTokenWithAjax()
{
Session::start();
$this->authenticateAsUser();
$this->route('POST', 'submissions.registration', [], [], [], ['HTTP_X-CSRF-Token' => csrf_token(), 'HTTP_X-Requested-With' => 'XMLHttpRequest']);
}
/**
* Authenticates as a User.
*
* @return void
*/
protected function authenticateAsUser()
{
$user = User::where('username', '=', 'n.cognome')->first();
$this->be($user);
}
}