/** * @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"'); }
public function successfullMemberLogin(ApiTester $I) { $I->am('an active member'); $I->wantTo('post to the main door endpoint and get an OK back'); $user = $I->getActiveKeyholderMember(); $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' => '1']); $I->dontSeeHttpHeader('Set-Cookie'); $I->dontSeeHttpHeader('Built-By'); //Confirm an access log record was created $I->seeInDatabase('access_log', ['user_id' => $user->id, 'key_fob_id' => $keyFob->id, 'response' => 200, 'service' => 'main-door']); }
public function variantsProbabilityInvalid(ApiTester $I) { $I->createAndLoginUser(); $I->createProjectAndSetHeader(); # invalid variants_probability $data = $I->getTableShortData(); $data['variants_probability'] = 'invalid'; $I->sendPOST('api/v1/admin/tables', $data); $I->seeResponseCodeIs(422); $I->seeResponseContains('variants_probability'); # more than 100 $data['variants_probability'] = 'percent'; $data['variants'][0]['probability'] = 30; $data['variants'][0]['title'] = 'Variant 1'; $data['variants'][1] = ['title' => 'Variant 2', 'default_title' => 'Variant 2', 'default_description' => 'Description Variant 2', 'default_decision' => 'Decline', 'probability' => 71, 'rules' => $I->getVariantRules()]; $I->sendPOST('api/v1/admin/tables', $data); $I->seeResponseCodeIs(422); $I->seeResponseContains('variants_probability'); # less than 100 $data['variants'][0]['probability'] = 28; $I->sendPOST('api/v1/admin/tables', $data); $I->seeResponseCodeIs(422); $I->seeResponseContains('variants_probability'); }
<?php $I = new ApiTester($scenario); $I->wantTo('get new pid for a user'); $I->haveHttpHeader("HTTP_Content-Type", "application/json"); $I->haveHttpHeader("Content-Type", "application/json"); $I->sendPOST('http://localhost/api/v1/action/GetPid.php', json_encode(array('action' => 'GetPid'))); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains("pid");
<?php $I = new ApiTester($scenario); $I->wantTo('Get list of hotels'); $I->sendPOST('/hotels-api/detail/1', []); $I->seeResponseContains('{"id":"2","title":"Vip","price":"180","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/rooms\\/images\\/source\\/vip_ton.jpg","count":"2","available_rooms":"2"},{"id":"3","title":"Standart","price":"100","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/rooms\\/images\\/source\\/standart_ton.jpg","count":"6","available_rooms":"6"},{"id":"4","title":"Family","price":"200","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/rooms\\/images\\/source\\/family_ton.jpg","count":"4","available_rooms":"4"}');
public function consumers(ApiTester $I) { $faker = $I->getFaker(); $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->createConsumer(); $I->sendPOST('api/v1/projects/consumers', ['description' => $faker->text('20'), 'scope' => ['decisions_view', 'decisions_make']]); $consumer = json_decode($I->grabResponse())->data[0]; $I->assertConsumers('$.data[*]', 201); $text = $faker->text('20'); $I->sendPUT('api/v1/projects/consumers', ['description' => $text, 'scope' => ['decisions_view', 'decisions_make'], 'client_id' => $consumer->client_id]); $I->seeResponseContains($text); $I->assertConsumers(); $I->sendDELETE('api/v1/projects/consumers', ['client_id' => $consumer->client_id]); $I->cantSeeResponseContains($consumer->client_id); $I->assertConsumers(); }
<?php $I = new ApiTester($scenario); $I->wantTo('check teams resource'); $I->sendGET('/players/33?expand=teams'); $I->seeResponseCodeIs(401); $token = $I->login('q@q.q', 'q'); // show list of user's teams $I->haveHttpHeader('Authorization', "Bearer {$token}"); $I->sendGET('/players/33?expand=teams'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('teams'); $I->seeResponseContains('"sport":"football"'); $I->seeResponseContains('"name":"FridayPlay"'); $I->seeResponseContains('"is_capitan":"1"'); $teams = $I->grabDataFromResponseByJsonPath('$.teams')[0]; \PHPUnit_Framework_Assert::assertEquals(1, count($teams)); \PHPUnit_Framework_Assert::assertEquals(2, count($teams[0]['players'])); // new team creation $I->sendPOST('/teams', ['name' => "QA", 'sport' => "voleyball"]); $I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('"sport":"voleyball"'); $I->seeResponseContains('"name":"QA"'); $I->seeResponseContains('"is_capitan":"1"'); $players = $I->grabDataFromResponseByJsonPath('$.players')[0]; \PHPUnit_Framework_Assert::assertEquals(1, count($players)); $teamId = $I->grabDataFromResponseByJsonPath('$.id')[0]; $I->sendGET('/players/33?expand=teams'); $I->seeResponseCodeIs(200);
<?php $I = new ApiTester($scenario); $I->wantTo('check games resource'); $I->sendGET('/teams/26?expand=games'); $I->seeResponseCodeIs(401); $token = $I->login('q@q.q', 'q'); // show list of games for team $I->haveHttpHeader('Authorization', "Bearer {$token}"); $I->sendGET('/teams/26?expand=games'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('games'); $games = $I->grabDataFromResponseByJsonPath('$.games')[0]; \PHPUnit_Framework_Assert::assertEquals(2, count($games)); $I->seeResponseContains('training'); $I->seeResponseContains('evening game'); // check for empty list for team with no games $I->sendGET('/teams/27?expand=games'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('games'); $games = $I->grabDataFromResponseByJsonPath('$.games')[0]; \PHPUnit_Framework_Assert::assertEquals(0, count($games)); // create game $I->sendPOST('/games', ['team_id' => 26, 'datetime' => date("Y-m-d H:i:s"), 'location' => "home", 'title' => "important game"]); $I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('important game'); $I->seeResponseContains('home'); $gameId = $I->grabDataFromResponseByJsonPath('$.id')[0];
<?php $I = new ApiTester($scenario); $I->wantTo('check player login'); $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->sendPOST('/auth/login', ['email' => 'q@q.q', 'password' => 'q']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('token'); $I->sendPOST('/auth/login', ['email' => 'q@q.q', 'password' => 'wrong_password']); $I->seeResponseCodeIs(401); $I->seeResponseIsJson(); $I->seeResponseContains('Incorrect username or password.');
<?php $user_data = ['name' => 'Player 1', 'email' => '*****@*****.**', 'password' => 'test', 'password_repeat' => 'test']; $I = new ApiTester($scenario); $I->wantTo('check players resource'); // creating new player $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->sendPOST('/players', $user_data); $I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('token'); // already existing player $user_data['email'] = 'q@q.q'; $I->sendPOST('/players', $user_data); $I->seeResponseCodeIs(422); $I->seeResponseIsJson(); $I->seeResponseContains('Email \\"q@q.q\\" has already been taken.'); // check that all other routes are disabled // index $I->sendGET('/players'); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.'); // update $I->sendPUT('/players/33', ['name' => 'updated_name']); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.'); // update $I->sendDELETE('/players/33'); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.');
<?php $I = new ApiTester($scenario); $I->am('Saman IT employee!'); $I->wantTo('test GetProductInfo method on this webservice'); $I->haveHttpHeader('Content-Type', 'text/xml'); $I->sendPOST('/webservice.php', '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <GetProductInfo xmlns="http://example.com/nikapps/samanussd/soap/samansoapserver"> <productCode>123213</productCode> <languageCode>Fa</languageCode> </GetProductInfo> </Body> </Envelope>'); $I->seeResponseIsXml(); $I->seeResponseContains('<Result>1;1000;Ok!</Result>');
<?php $I = new ApiTester($scenario); $I->am('Saman IT employee!'); $I->wantTo('test CallSaleProvider method on this webservice'); $I->haveHttpHeader('Content-Type', 'text/xml'); $I->sendPOST('/webservice.php', '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <CallSaleProvider xmlns="http://example.com/nikapps/samanussd/soap/samansoapserver"> <productCode>12345*4444*123</productCode> <Amount>4444</Amount> <CellNumber>09123456789</CellNumber> <SEPId>4324642342342</SEPId> <languageCode>Fa</languageCode> </CallSaleProvider> </Body> </Envelope>'); $I->seeResponseIsXml(); $I->seeResponseContains('<Result>1;p-123-123</Result>');
<?php $I = new ApiTester($scenario); $I->wantTo('Get list of hotels'); $I->sendPOST('/hotels-api/rooms/2', []); $I->seeResponseContains('{"id":"2","title":"Vip","price":"180","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/rooms\\/images\\/source\\/vip_ton.jpg","count":"2"}');
<?php $I = new ApiTester($scenario); $I->am('Saman IT employee!'); $I->wantTo('test CheckStatus method on this webservice'); $I->haveHttpHeader('Content-Type', 'text/xml'); $I->sendPOST('/webservice.php', '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <CheckStatus xmlns="http://example.com/nikapps/samanussd/soap/samansoapserver"> <ProviderID>p-123-123</ProviderID> </CheckStatus> </Body> </Envelope>'); $I->seeResponseIsXml(); $I->seeResponseContains('<Result>1;1</Result>');
<?php $I = new ApiTester($scenario); $I->wantTo('Get list of hotels'); $I->sendPOST('/hotels-api', []); $I->seeResponseContains('{"id":"1","title":"Tonyresort","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/hotels\\/images\\/source\\/download(6).jpg","country":"Lithuania","city":"Vilnius"},{"id":"3","title":"Kaunas","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/hotels\\/images\\/source\\/36207618.jpg","country":"Lithuania","city":"Kaunas"},{"id":"4","title":"Gaia Village","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/hotels\\/images\\/source\\/211050_xl.jpg","country":null,"city":null},{"id":"5","title":"Europa Royale","image":"http:\\/\\/andriuss.ktu.ongr.rocks\\/src\\/Frontend\\/Files\\/hotels\\/images\\/source\\/big_4ac32e645761a.jpg","country":null,"city":null}');
<?php $I = new ApiTester($scenario); $I->wantTo('get new pid for a user'); $I->haveHttpHeader("Content-Type", "application/json"); $I->sendGET('http://localhost/api/v1/action/GetPid.php'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains("action");
public function accessForCheck(ApiTester $I) { $first_user = $I->createUser(true, '', false); $second_user = $I->createUser(true); $I->loginUser($first_user); $I->createProjectAndSetHeader(); $consumer = $I->createConsumer(); $table = $I->createTable(); $table_id = $table->_id; $data = ['borrowers_phone_verification' => 'Positive', 'contact_person_phone_verification' => 'Positive', 'internal_credit_history' => 'Positive', 'employment' => true, 'property' => true, 'matching_rules_type' => 'decision']; $I->sendPOST("api/v1/tables/{$table_id}/decisions", $data); $I->canSeeResponseCodeIs(403); $I->seeResponseContains("Project owner is not activated, try again later"); $I->sendPOST('api/v1/projects/users', ['user_id' => $second_user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'decisions_make']]); $I->loginUser($second_user); $I->sendPOST("api/v1/tables/{$table_id}/decisions", $data); $I->canSeeResponseCodeIs(403); $I->seeResponseContains("Project owner is not activated, try again later"); $I->loginConsumer($consumer); $I->sendPOST("api/v1/tables/{$table_id}/decisions", $data); $I->canSeeResponseCodeIs(403); $I->seeResponseContains("Project owner is not activated, try again later"); $I->logout(); $I->loginClient($I->getCurrentClient()); $I->sendPOST('api/v1/users/verify/email', ['token' => $first_user->sandbox->token_email->token]); $I->seeResponseCodeIs(200); $I->loginUser($first_user); $I->makeDecision($table_id); $I->loginConsumer($consumer); $I->makeDecision($table_id); $I->loginUser($second_user); $I->makeDecision($table_id); }
/** * @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.'); }
<?php $I = new ApiTester($scenario); $I->wantTo('check teams search by name and player mail'); $I->sendGET('/teams/search?name=test&email='); $I->seeResponseCodeIs(401); $token = $I->login('q@q.q', 'q'); // search by team name $I->haveHttpHeader('Authorization', "Bearer {$token}"); $I->sendGET('/teams/search?name=play&email='); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('"name":"FridayPlay"'); $I->seeResponseContains('"name":"MondayPlay"'); $teams = $I->grabDataFromResponseByJsonPath('$')[0]; \PHPUnit_Framework_Assert::assertEquals(2, count($teams)); // search by email $I->sendGET('/teams/search?name=&email=w@w.w'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('"name":"FridayPlay"'); $teams = $I->grabDataFromResponseByJsonPath('$')[0]; \PHPUnit_Framework_Assert::assertEquals(1, count($teams)); // no team parameters $I->sendGET('/teams/search?name=&email=wrong@mail.com'); $I->seeResponseCodeIs(404); $I->seeResponseIsJson(); $I->seeResponseContains('"No teams found for passed name and mail"'); // bad request with empty parameters $I->sendGET('/teams/search?name=&email='); $I->seeResponseCodeIs(400);