public function testCaptureFlag()
 {
     $token = $this->doLogin('*****@*****.**', '123456');
     $this->tester->haveHttpHeader('Content-type', 'application/json');
     $this->tester->haveHttpHeader('X-Api-token', $token);
     $region = rand(1, 4);
     $this->tester->sendPOST('/api/capture-flag', json_encode(['regionId' => $region]));
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     $this->tester->haveHttpHeader('Content-type', 'application/json');
     $this->tester->haveHttpHeader('X-Api-token', $token);
     $this->tester->sendGET('/api/player-status');
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     $data = json_decode($this->tester->grabResponse(), true);
     $myTeamId = $data['data']['id'];
     $this->tester->haveHttpHeader('Content-type', 'application/json');
     $this->tester->sendGET('/api/game-status/1');
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     $data = json_decode($this->tester->grabResponse(), true);
     $data = $data['data'];
     $this->assertArrayHasKey('ownerRegion1', $data);
     $this->assertArrayHasKey('ownerRegion2', $data);
     $this->assertArrayHasKey('ownerRegion3', $data);
     $this->assertArrayHasKey('ownerRegion4', $data);
     //        $this->assertEquals($data['ownerRegion' . $region]['id'], $myTeamId);
 }
 private function checkLocationList()
 {
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     $this->tester->seeResponseJsonMatchesJsonPath('$.status');
     $this->tester->seeResponseJsonMatchesJsonPath('$.data');
     $this->tester->seeResponseJsonMatchesJsonPath('$.data[0].lat');
     $this->tester->seeResponseJsonMatchesJsonPath('$.data[0].lng');
     $this->tester->seeResponseJsonMatchesJsonPath('$.data[0].game');
 }
 public function doCheckLogout($token)
 {
     // Do Logout
     $this->tester->haveHttpHeader('Content-type', 'application/json');
     $this->tester->haveHttpHeader('X-Api-Token', $token);
     $this->tester->sendPOST('/api/logout');
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     // Check is logged out
     $this->checkIsLogin($token, false);
 }
 public function createPost(ApiTester $I)
 {
     $I->sendPOST($this->endpoint, ['title' => 'Game of Rings', 'body' => 'By George Tolkien']);
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->seeResponseContainsJson(['title' => 'Game of Rings']);
     $id = $I->grabDataFromJsonResponse('id');
     $I->seeRecord('posts', ['id' => $id, 'title' => 'Game of Rings']);
     $I->sendGET($this->endpoint . "/{$id}");
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->seeResponseContainsJson(['title' => 'Game of Rings']);
 }
 public function updatePost(ApiTester $I)
 {
     $id = $I->haveRecord('posts', $this->getPostAttributes(['title' => 'Game of Thrones']));
     $I->sendPUT($this->endpoint . "/{$id}", ['title' => 'Lord of Thrones']);
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->seeResponseContainsJson(['title' => 'Lord of Thrones']);
     $I->seeRecord('posts', ['title' => 'Lord of Thrones']);
     $I->dontSeeRecord('posts', ['title' => 'Game of Thrones']);
 }
 /**
  * @depends update
  */
 public function delete(ApiTester $I)
 {
     $I->wantTo('Delete a new Contact in com_contacts using DELETE');
     $I->amHttpAuthenticated('admin', 'admin');
     $I->sendDELETE('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}");
     $I->seeResponseCodeIs(200);
     $I->sendGET('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}");
     $I->seeResponseCodeIs(404);
     $I->seeResponseIsJson();
     $I->seeResponseContains('"message":"Item not found with given key.","code":404,"type":"Exception"');
 }
예제 #7
0
 private function checkStatList()
 {
     $this->tester->seeResponseCodeIs(200);
     $this->tester->seeResponseIsJson();
     $data = json_decode($this->tester->grabResponse(), true);
     $this->tester->seeResponseJsonMatchesJsonPath('$.status');
     $this->tester->seeResponseJsonMatchesJsonPath('$.data');
     foreach ($data['data']['stats'] as $item) {
         $this->assertArrayHasKey('team', $item);
         $this->assertArrayHasKey('player', $item);
         $this->assertArrayHasKey('id', $item['player']);
         $this->assertArrayHasKey('alias', $item['player']);
         $this->assertArrayHasKey('level', $item['player']);
         $this->assertArrayHasKey('isLive', $item['player']);
         $this->assertArrayHasKey('isLive', $item);
         $this->assertArrayHasKey('location', $item);
         $this->assertArrayHasKey('player', $item['location']);
         $this->assertArrayHasKey('lat', $item['location']);
         $this->assertArrayHasKey('lng', $item['location']);
         $this->assertArrayHasKey('game', $item['location']);
     }
 }
예제 #8
0
 public function updateDiscussion(ApiTester $I)
 {
     $I->wantTo('update a discussion via API');
     $user = $I->amAuthenticated();
     $discussion = Factory::create('Flarum\\Core\\Models\\Discussion', ['start_user_id' => $user->id]);
     $I->sendPUT($this->endpoint . '/' . $discussion->id, ['discussions' => ['title' => 'foo']]);
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->expect('the discussion title was updated');
     $I->seeResponseContainsJson(['title' => 'foo']);
     $I->expect('the discussion was updated in the database');
     $id = $I->grabDataFromJsonResponse('discussions.id');
     $I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']);
 }
 public function inactiveMemberLogin(ApiTester $I)
 {
     $I->am('an inactive member');
     $I->wantTo('post to the main door endpoint and get an OK back');
     $user = $I->getInactiveKeyholderMember();
     $keyFob = $I->getMemberKeyFob($user->id);
     //Post the keyfob to the endpoint
     $I->sendPOST('/access-control/main-door', ['data' => $keyFob->key_id]);
     //The endpoint always returns 200
     $I->seeResponseCodeIs(200);
     //Make sure a good response is returned
     $I->seeResponseIsJson();
     //Response contains their name
     //$I->seeResponseContains($user->given_name);
     //Make sure the request was allowed
     $I->seeResponseContainsJson(['valid' => '0']);
     //Confirm an access log record was created
     $I->seeInDatabase('access_log', ['user_id' => $user->id, 'key_fob_id' => $keyFob->id, 'response' => 402, 'service' => 'main-door']);
 }
예제 #10
0
<?php

include 'version.php';
$I = new ApiTester($scenario);
$I->wantTo('fetch the version information for the web app');
$I->sendGET('version');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(["api_version" => $api_version, "app_version" => $app_version, "webapp_version" => $webapp_version]);
 function obtainAuthCodeGrant(ApiTester $I)
 {
     $user = factory(App\Models\User::class, 1)->create();
     $user->password = '******';
     $user->save();
     $I->amLoggedAs($user);
     $client = factory(App\Models\OAuthClient::class, 1)->create();
     $grant = \App\Models\OAuthGrant::find('authorization_code');
     $client->oauth_grants()->attach($grant);
     $scope = \App\Models\OAuthScope::find('user_read');
     $client->oauth_scopes()->attach($scope);
     $endpoint = factory(App\Models\OAuthClientEndpoint::class, 1)->make();
     $endpoint->oauth_client()->associate($client);
     $endpoint->save();
     $I->wantTo('Perform a full 3rd party authorisation flow and get an access token');
     $I->amOnPage('authorize?client_id=' . $client->id . '&redirect_uri=' . $endpoint->redirect_uri . '&response_type=code&scope=user_read');
     $I->click('approve');
     $I->seeInCurrentUrl('code=');
     $url = Request::fullUrl();
     $parts = parse_url($url);
     parse_str($parts['query'], $query);
     $code = $query['code'];
     $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
     $I->sendPOST('oauth/access_token', ['grant_type' => 'authorization_code', 'client_id' => $client->id, 'client_secret' => $client->secret, 'redirect_uri' => $endpoint->redirect_uri, 'code' => $code]);
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->seeResponseMatchesJsonType(['access_token' => 'string']);
 }
예제 #12
0
 /**
  * @param \ApiTester $I
  */
 public function missingRateError(ApiTester $I)
 {
     $I->wantTo('Error while saving: missing rate.');
     $I->sendPost('http://currencyfairtest.com/api/messages', ["userId" => "100", "currencyFrom" => "EUR", "amountSell" => "999.0000", "timePlaced" => "31-AUG-15 22:00:00"]);
     $I->seeResponseCodeIs(400);
     $I->seeResponseIsJson();
     $I->seeResponseContains('ERROR');
     $I->seeResponseContains('rate');
     $I->seeResponseContains('The rate field is required.');
 }
예제 #13
0
 public function serversRespondsWitJson(ApiTester $I)
 {
     $I->sendGET($this->endpoint . SOURCE);
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
 }