Skip to content

Commit

Permalink
Add error log check to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Dec 1, 2018
1 parent 39e94b2 commit 441a624
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/testRoutesLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function testThatUnknownRouteDoesNothing() {
unset( self::$wp->query_vars['a0_action'] );
self::$wp->query_vars['pagename'] = uniqid();
$this->assertFalse( self::$routes->custom_requests( self::$wp ) );

$this->assertEmpty( self::$error_log->get() );
}

/**
Expand All @@ -118,6 +120,8 @@ public function testThatLoginRouteIsForbiddenByDefault() {

$this->assertEquals( 403, $output->status );
$this->assertEquals( 'Forbidden', $output->error );

$this->assertEmpty( self::$error_log->get() );
}

/**
Expand All @@ -132,19 +136,26 @@ public function testThatLoginRouteIsUnauthorizedIfWrongIp() {

$this->assertEquals( 401, $output->status );
$this->assertEquals( 'Unauthorized', $output->error );

$this->assertEmpty( self::$error_log->get() );
}

/**
* If there is no token, the route should fail with an error.
*/
public function testThatLoginRouteIsUnauthorizedIfNoToken() {
$expected_msg =
self::$opts->set( 'migration_ws', 1 );
self::$wp->query_vars['a0_action'] = 'migration-ws-login';

$output = json_decode( self::$routes->custom_requests( self::$wp ) );

$this->assertEquals( 401, $output->status );
$this->assertEquals( 'Unauthorized: missing authorization header', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -159,6 +170,10 @@ public function testThatLoginRouteIsUnauthorizedIfBadToken() {

$this->assertEquals( 400, $output->status );
$this->assertEquals( 'Key may not be empty', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -177,6 +192,10 @@ public function testThatLoginRouteIsUnauthorizedIfWrongJti() {

$this->assertEquals( 401, $output->status );
$this->assertEquals( 'Invalid token ID', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -196,6 +215,10 @@ public function testThatLoginRouteIsBadRequestIfNoUsername() {

$this->assertEquals( 400, $output->status );
$this->assertEquals( 'Username is required', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -216,6 +239,10 @@ public function testThatLoginRouteIsBadRequestIfNoPassword() {

$this->assertEquals( 400, $output->status );
$this->assertEquals( 'Password is required', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -238,6 +265,10 @@ public function testThatLoginRouteIsUnauthorizedIfNotAuthenticated() {

$this->assertEquals( 401, $output->status );
$this->assertEquals( 'Invalid Credentials', $output->error );

$log = self::$error_log->get();
$this->assertCount( 1, $log );
$this->assertEquals( $output->error, $log[0]['message'] );
}

/**
Expand All @@ -263,5 +294,7 @@ public function testThatLoginRouteReturnsUserIfSuccessful() {
$this->assertEquals( $user->user_email, $output->data->user_email );
$this->assertEquals( $user->display_name, $output->data->display_name );
$this->assertObjectNotHasAttribute( 'user_pass', $output->data );

$this->assertEmpty( self::$error_log->get() );
}
}

0 comments on commit 441a624

Please # to comment.