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']);
 }
예제 #3
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']);
 }
예제 #5
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('create a new device');
$user = $I->haveAnAccount();
$I->amHttpAuthenticated($user['email'], $user['password']);
$I->sendPOST('devices', ['mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel']);
$I->seeResponseCodeIs(422);
$I->seeResponseIsJson();
$I->sendPOST('devices', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel']);
$I->seeResponseCodeIs(201);
$I->seeHttpHeader('Location', 'http://localhost/api/v1/devices/1');
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.123', 'name' => 'Manuel', 'on_home_page' => 'auto', 'group' => null]]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->seeRecord('devices', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'public' => 'auto', 'group' => null]);
<?php

$I = new ApiTester($scenario);
$I->wantTo('create a request on a asset via POST');
$I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8');
//no whitespaces in content hash!
$I->haveHttpHeader('X-Hash', '9fdcd3d292ce958b3d14c803aba077c965e54ebb1b991fee0d01038c9e8951c5');
$I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6');
$I->sendPOST('asset/4b674c6d9e9ff/request', '{"Request_date":"2014-02-14","Request_desc":"blob","Request_contact_name":"Nicola Keller","Request_note":"somenotes","Request_st_id":"1","VisiTpID":"4"}');
$I->seeResponseCodeIs(201);
$I->seeResponseIsJson();
//we don't test request_id response because its everytime different (PHP's uniqid())
$I->seeResponseContainsJson(array("error" => false));
$I->seeResponseContainsJson(array("message" => "Request added"));
$I->seeInDatabase('request', array("AssetID" => "4b674c6d9e9ff", "Request_contact_name" => "Nicola Keller"));
예제 #7
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('update a device');
$user = $I->haveAnAccount();
$I->amHttpAuthenticated($user['email'], $user['password']);
$created_at = \Carbon\Carbon::now()->subHour();
$updated_at = \Carbon\Carbon::now()->subHour();
$I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One', 'created_at' => $created_at, 'updated_at' => $updated_at]);
$I->sendPATCH('devices/1', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['ip' => '192.168.1.102', 'name' => 'Updated Awesome Pi One', 'on_home_page' => 'auto', 'group' => null]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->canSeeRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One', 'public' => 'auto', 'group' => null]);
$updatedDevice = $I->grabRecord('devices', ['ip' => '192.168.1.102']);
$I->cantSeeRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One']);
$updated_created_at_timestamp = $I->carbonize($updatedDevice->created_at);
$updated_updated_at_timestamp = $I->carbonize($updatedDevice->updated_at);
$I->assertTrue($updated_created_at_timestamp->eq($created_at), 'Updated created_at timestamp is equal to the initial created_at timestamp');
$I->assertTrue($updated_updated_at_timestamp->gt($updated_at), 'Updated updated_at timestamp is greater than the initial updated_at timestamp');
$I->assertTrue($updated_updated_at_timestamp->gt($created_at), 'Updated updated_at timestamp is greater than the initial created_at timestamp');
$I->sendPATCH('devices/100', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']);
$I->seeResponseCodeIs(404);
$I->seeResponseIsJson();
<?php

$I = new ApiTester($scenario);
$I->wantTo('Test the database/export endpoint via GET');
$I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6');
$I->haveHttpHeader('X-Hash', 'e651e0f6450f89d82ab0a34c1d421097a635897f5e719179e49263ff145e6ed9');
$I->sendGET('database/export');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array('assets' => array(0 => array('AssetID' => '4b67517f4462a', 'GenericAssetID' => '12636', 'UMDNS' => '12636', 'AssetFullName' => 'Dash', 'ManufacturerID' => '4c44276c3c2c0', 'Model' => '4000 ', 'SerialNumber' => 'SD008484463GA', 'InternalIventoryNumber' => '01382928', 'LocationID' => '4b6b4f5120321', 'ResponsiblePers' => NULL, 'AssetStatusID' => '1', 'AssetUtilizationID' => '1', 'PurchaseDate' => NULL, 'InstallationDate' => NULL, 'Lifetime' => '10', 'PurchasePrice' => '131174', 'CurrentValue' => '104939', 'WarrantyContractID' => '1', 'AgentID' => '4c90677ca7db7', 'WarrantyContractExp' => NULL, 'WarrantyContractNotes' => NULL, 'EmployeeID' => '4cb6b8bbb9df6', 'SupplierID' => '4b595a7124c8b', 'DonorID' => '4c9066fc81b53', 'Notes' => NULL, 'Picture' => 'gen_images/12636.jpg', 'lastmodified' => '2010-02-05 01:47:18', 'by_user' => 'demo', 'URL_Manual' => NULL, 'MetrologyDocument' => NULL, 'MetrologyDate' => NULL, 'Metrology' => '0'))));
$I->seeResponseContainsJson(array('location' => array(0 => array('LocationID' => '4b6b4f5120321', 'FacilityID' => '11', 'DeptID' => '2', 'Roomnb' => '', 'Floor' => '', 'Building' => '', 'NotetoTech' => '-'))));
$I->seeResponseContainsJson(array('facilities' => array(0 => array('FacilityID' => '11', 'DistrictID' => '10001', 'FacilityName' => 'Central Hosptial'))));
$I->seeResponseContainsJson(array('facilities' => array(0 => array('FacilityID' => '11', 'DistrictID' => '10001', 'FacilityName' => 'Central Hosptial'))));
$I->seeResponseContainsJson(array('contacttype' => array(0 => array('ContactTypeID' => '1', 'ContactTypeName' => 'Manufacturer'))));
$I->seeResponseContainsJson(array('contact' => array(0 => array('ContactID' => '4ac3718e8d251', 'ContactTypeID' => '3', 'ContactName' => 'Nespecificat', 'ContactPersonName' => NULL, 'ContactTitle' => NULL, 'Address' => NULL, 'City' => NULL, 'PostalCode' => NULL, 'CountryID' => '99999', 'PhoneNumber' => NULL, 'FaxNumber' => NULL, 'Website' => '', 'Services' => NULL))));
$I->seeResponseContainsJson(array('donors' => array(0 => array('DonorID' => '0', 'ContactID' => '4ac3718e8d251'))));
$I->seeResponseContainsJson(array('agents' => array(0 => array('AgentID' => '0', 'ContactID' => '4ac3718e8d251'))));
$I->seeResponseContainsJson(array('suppliers' => array(0 => array('SupplierID' => '4b59581a8bb8f', 'ContactID' => '4b59581a8abf1'))));
$I->seeResponseContainsJson(array('manufactures' => array(0 => array('ManufacturerID' => '4b0be58d2806b', 'ContactID' => '4b0be58d2612c'))));
$I->seeResponseContainsJson(array('consumables' => array(0 => array('ConsumableID' => '1', 'Name' => 'Sensor debit', 'ManufacturerID' => '4c62506a58149', 'PartNumber' => '121', 'PackageQty' => '1', 'SupplierID' => '4c36d8223e3cf', 'UnitPrice' => '1', 'Notes' => '1', 'lastmodified' => '2012-01-17 14:15:11', 'by_user' => 'demo', 'TypeCons' => NULL))));
$I->seeResponseContainsJson(array('consumables_linked' => array(0 => array('Consumable_linkedID' => '1', 'ConsumableID' => '1', 'AssetID' => '4f154ff62df0e', 'AnnualConsumption' => '100', 'Notes' => 'Order 2 month before'))));
$I->seeResponseContainsJson(array('employees' => array(0 => array('EmployeeID' => '0', 'LoginID' => '3', 'FirstName' => 'admin', 'LastName' => 'admin', 'Position' => NULL, 'TechnicianYN' => '1', 'LocationID' => '4b0be83d5d1d7', 'WorkPhone' => NULL, 'HandPhone' => NULL, 'Email' => NULL, 'Fax' => NULL, 'Accesslevel' => ' AND (facilities.FacilityID=12)'))));
$I->seeResponseContainsJson(array('department' => array(3 => array('DeptID' => '4', 'DepartmentDesc' => 'Allergology'))));
$I->seeResponseContainsJson(array('essential_equipment' => array(0 => array('EssentialEquipmentID' => '1', 'FacilityID' => '11', 'GenericAssetID' => '10134', 'MinimalQuantity' => '2', 'Notes' => NULL))));
$I->seeResponseContainsJson(array('assetgenericname' => array(0 => array('GenericAssetID' => '10134', 'GenericAssetCode' => '10134', 'GenericAssetName' => 'Anaesthesia Units', 'AssetCategoryID' => '5', 'GenericPicture' => 'gen_images/10134.jpg'))));
$I->seeResponseContainsJson(array('assetutilization' => array(0 => array('AssetUtilizationID' => '1', 'AssetUtilizationDesc' => 'Normal'))));
$I->seeResponseContainsJson(array('assetstatus' => array(0 => array('AssetStatusID' => '1', 'AssetStatusDesc' => 'Fully functional'))));
$I->seeResponseContainsJson(array('assetcategory' => array(0 => array('AssetCategoryID' => '1', 'AssetCategoryNr' => '1', 'AssetCategoryName' => 'Dental'))));
$I->seeResponseContainsJson(array('intervention' => array(0 => array('IntervID' => '532c5b53aab95', 'Date' => '2014-03-21', 'EmployeeID' => '4d64045c4a525', 'AssetStatusID' => '1', 'AssetID_Visit' => '4b67517f4462a', 'Request_id' => '52fddba460044', 'FaildPart' => 'Cable', 'FailurCategID' => '2', 'FailureCauseID' => '0', 'Interv_desc' => 'Description Intervention', 'Interv_desc_eg' => '', 'Comments' => 'Comments', 'RespEng' => '4c8fcac9f06fa', 'TotalWork' => '0', 'TotalCosts' => '0', 'lastmodified' => '2014-03-21 16:59:22', 'by_user' => 'demo'))));
$I->seeResponseContainsJson(array('request' => array(0 => array('Request_id' => '52fddba460044', 'Request_date' => '2014-02-14', 'Request_desc' => 'Repair', 'Request_desc_eg' => 'Repair', 'AssetID' => '4b67517f4462a', 'Request_st_id' => '1', 'Request_contact_name' => 'Agata Correia', 'Request_note' => 'Notes', 'lastmodified' => '2014-02-14 10:02:53', 'by_user' => 'demo', 'VisiTpID' => '1'))));
$I->seeResponseContainsJson(array('request_st' => array(0 => array('Request_st_id' => '1', 'Request_st_desc' => 'Open'))));
예제 #9
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Test the cart behaviour with items');
$I->amGoingTo('confirm the cart is empty');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
/**
 * @var array $item1
 * @var array $item2
 * @var int   $item_id
 */
require "_AddItems.php";
$I->amGoingTo('Verify order');
$I->sendGET('cart');
$I->expectTo('see items in order');
$I->seeCodeAndJson(200, ['items' => [$item1, $item2]]);
$I->expectTo('see correct total');
$I->seeResponseContainsJson(['total' => floatify($item1['final_price'] + $item2['final_price'])]);
$I->amGoingTo('delete an item');
$I->sendDELETE('cart/item/' . $item_id);
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [$item2], 'total' => floatify($item2['final_price'])]);
$I->amGoingTo('clear the cart');
$I->sendDELETE('cart');
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
예제 #10
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Get a specific note');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendGET('/notes/6');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['id' => 6, 'content' => 'tyutyu', 'deadline' => '2016-01-07 10:28:42', 'completed' => 1]);
<?php

$I = new ApiTester($scenario);
$I->wantTo('poke with optional configuration parameters');
$I->sendPOST('devices/poke', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'public' => 'false', 'group' => 'strebl']);
$I->seeResponseCodeIs(200);
$I->seeHttpHeader('Location', 'http://localhost/api/v1/devices/1');
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.123', 'name' => 'Manuel', 'on_home_page' => 'false', 'group' => 'strebl']]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->seeRecord('devices', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'public' => 'false', 'group' => 'strebl']);
$I->seeRecord('pokes', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC']);
<?php

$I = new ApiTester($scenario);
$I->wantTo('check login via POST with wrong credentials');
$I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8');
$I->haveHttpHeader('Accept', 'application/json;charset=utf-8');
$I->sendPOST('login', json_encode(array('username' => 'demo', 'password' => 'somewrongpassword1234')));
$I->seeResponseCodeIs(401);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array('error' => true, 'message' => "Login failed. Incorrect credentials"));
예제 #13
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Get all users');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendGET('/users');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([['id' => 1, 'name' => 'BluePrint'], ['id' => 2, 'name' => 'Howken']]);
<?php

/** @var AcceptanceTester $I */
$I = new ApiTester($scenario);
$I->wantTo('get list of frameworks');
$I->sendGET('/api/frameworks');
$I->seeResponseCodeIs(200);
$I->dontSeeResponseCodeIs(500);
$I->canSeeHttpHeader('Content-Type', 'application/json');
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['name' => 'Phalcon', 'version' => '2.0.8']);
$I->seeResponseMatchesJsonType(['name' => 'string', 'version' => 'string:regex(~\\d\\.\\d\\.\\d~)']);
예제 #15
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('get a single device');
$piOne = $I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piTwo = $I->haveRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Awesome Pi Two', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$I->sendGET('devices/1');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.101', 'name' => 'Awesome Pi One', 'on_home_page' => 'auto', 'group' => null]]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.102', 'name' => 'Awesome Pi Two', 'on_home_page' => 'auto', 'group' => null]]);
$I->sendGET('devices/100');
$I->seeResponseCodeIs(404);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['errors' => ['title' => 'Did not find the device you are looking for!', 'status' => 404]]);
예제 #16
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('get the list of categories');
$I->sendGET('category');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([["id" => "6", "title" => "Objects", "makerid" => "1", "approved" => "1", "color" => "e91e63"]]);
예제 #17
0
<?php

Yii::$app->redis->executeCommand('FLUSHDB');
use Codeception\Util\Debug;
$model = new \app\models\Message();
$model->author_email = '*****@*****.**';
$model->author_name = 'test';
$model->message = str_repeat('A', 140);
$model->save();
$I = new ApiTester($scenario);
$I->wantTo('Excluir uma mensagem');
$I->sendDELETE('messages', ['' => $model->id]);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([]);
예제 #18
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Get all non-deleted notes');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendGET('/notes');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([['id' => 8, 'user' => 'Howken', 'project' => 'KulGrej', 'content' => 'rtyrty', 'completed' => 1, 'created' => '2016-01-05 10:28:03', 'deadline' => '2016-01-08 10:28:03'], ['id' => 2, 'user' => 'BluePrint', 'project' => 'Fiskpinne', 'content' => 'qweqwea', 'completed' => 1, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-05 10:28:42'], ['id' => 3, 'user' => 'BluePrint', 'project' => 'KulGrej', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', 'completed' => 1, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-05 10:28:42'], ['id' => 4, 'user' => 'BluePrint', 'project' => 'Fiskpinne', 'content' => '123123', 'completed' => 0, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-08 10:28:42'], ['id' => 5, 'user' => 'Howken', 'project' => 'Birdie', 'content' => 'jkljkl', 'completed' => 0, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-05 10:28:42'], ['id' => 6, 'user' => 'Howken', 'project' => 'Fiskpinne', 'content' => 'tyutyu', 'completed' => 1, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-07 10:28:42'], ['id' => 7, 'user' => 'Howken', 'project' => 'KulGrej', 'content' => 'bnmbnm', 'completed' => 0, 'created' => '2016-01-05 10:28:42', 'deadline' => '2016-01-05 10:28:42'], ['id' => 1, 'user' => 'BluePrint', 'project' => 'Birdie', 'content' => 'Martin', 'completed' => 0, 'created' => '2016-01-05 10:30:41', 'deadline' => '2016-01-14 10:29:38']]);
예제 #19
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('fetch the details for the given item id');
$I->sendGET('items/1');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([["id" => "1", "makerid" => "1", "title" => "Matt Lee", "description" => "Matt Lee", "uri" => "http://creativecommons.org", "approved" => "1", "category" => "1", "name" => "Creative Commons"]]);
<?php

$I = new ApiTester($scenario);
$I->wantTo('adicionar um novo pedido');
$I->amHttpAuthenticated('phptesting', '123');
$I->sendPOST('/pedido', ['produtoid' => 1, 'produtonome' => 'Firefox', 'produtoestoque' => 10, 'produtovalor' => 49.9]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['status' => 'sucesso', 'message' => 'Sucesso']);
예제 #21
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('fetch the details for the given maker id');
$I->sendGET('makers/1');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([["id" => "1", "name" => "Creative Commons", "uri" => "http://creativecommons.org"]]);
예제 #22
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('list all devices');
$I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Public Pi', 'public' => 'true', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piOne = $I->grabRecord('devices', ['ip' => '192.168.1.101']);
$piTwo = $I->haveRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Private Pi', 'public' => 'false', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piTwo = $I->grabRecord('devices', ['ip' => '192.168.1.102']);
$piThree = $I->haveRecord('devices', ['ip' => '192.168.1.103', 'mac' => 'AA:11:BB:22:CC:33', 'name' => 'Auto Pi without group', 'public' => 'auto', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piThree = $I->grabRecord('devices', ['ip' => '192.168.1.103']);
$piFour = $I->haveRecord('devices', ['ip' => '192.168.1.104', 'mac' => 'DD:44:EE:55:FF:66', 'name' => 'Auto Pi with group', 'public' => 'auto', 'group' => 'my-group', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piFour = $I->grabRecord('devices', ['ip' => '192.168.1.104']);
$I->sendGET('devices');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.101', 'name' => 'Public Pi', 'on_home_page' => 'true', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piOne->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piOne->updated_at)->toIso8601String()]]);
$I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.102', 'name' => 'Private Pi', 'on_home_page' => 'false', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.103', 'name' => 'Auto Pi without group', 'on_home_page' => 'auto', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.104', 'name' => 'Auto Pi with group', 'on_home_page' => 'auto', 'group' => 'my-group', 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->sendGET('devices/@my-group');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['name' => 'Auto Pi with group']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Auto Pi without group']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Private Pi']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Public Pi']]);
예제 #23
0
<?php

$request_body = ['gm_id' => '1Z3967', 'token' => 'Works for me'];
$response_body = ['work_phone' => '517-555-4356'];
$I = new ApiTester($scenario);
$I->wantTo('update device token for a user');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPOST('/device_token.php', $request_body);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson($response_body);
예제 #24
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Get all projects');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendGET('/projects');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([['id' => 1, 'name' => 'Birdie'], ['id' => 2, 'name' => 'Fiskpinne'], ['id' => 3, 'name' => 'KulGrej']]);
예제 #25
0
<?php

$scenario->group('rels');
$I = new ApiTester($scenario);
$I->wantTo('load the initial rels');
$I->sendGET('/rels');
$I->grabDataFromResponseByJsonPath('$');
$I->seeResponseContainsJson(['loadList' => '/list/elements', 'addToList' => '/list/elements', 'removeFromList' => '/list/elements']);
<?php

$I = new ApiTester($scenario);
$I->wantTo('create new intervention via POST');
$I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8');
//no whitespaces in content hash!
$I->haveHttpHeader('X-Hash', '34756c567620857fac3539130db7c4e7d52162c7c349baeb82f635cf7003716a');
$I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6');
//no whitespaces in json
$I->sendPOST('asset/4b6342489a963/532c5ad50d547/intervention', '{"Date":"2014-01-01","EmployeeID":"4d64045c4a525","AssetStatusID":1,"FaildPart":"Cable","FailurCategID":2,"FailureCauseID":1,"Interv_desc":"cables fixed","Comments":"repeat","RespEng":"4c8fcac9f06fa","TotalWork":1,"TotalCosts":2}');
$I->seeResponseCodeIs(201);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array("error" => false));
$I->seeResponseContainsJson(array("message" => "Intervention added"));
$I->seeInDatabase('intervention', array('AssetID_Visit' => '4b6342489a963', "Request_id" => '532c5ad50d547', "EmployeeID" => "4d64045c4a525"));
예제 #27
0
$hash = hash('sha256', $data);
$I->haveHttpHeader('Content-Type', 'application/octet-stream');
$I->haveHttpHeader('x-amz-archive-description', 'test123');
$I->haveHttpHeader('x-amz-sha256-tree-hash', $treeHash);
$I->haveHttpHeader('x-amz-content-sha256', $hash);
$I->sendPOST('/-/vaults/testvault/archives', $data);
$I->seeResponseCodeIs(201);
$I->seeResponseEquals('');
$archiveID = $I->grabHttpHeader('x-amz-archive-id');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPOST('/-/vaults/testvault/jobs', ['Type' => 'archive-retrieval', 'ArchiveId' => $archiveID]);
$I->seeResponseCodeIs(202);
$jobID = $I->grabHttpHeader('x-amz-job-id');
$I->sendGET("/-/vaults/testvault/jobs/{$jobID}");
$I->seeResponseCodeIs(200);
$I->seeResponseContainsJson(['StatusCode' => 'InProgress']);
$I->sendPOST("/-/vaults/testvault/jobs/{$jobID}/force-complete", []);
$I->seeResponseCodeIs(200);
$I->sendGET("/-/vaults/testvault/jobs/{$jobID}");
$I->seeResponseCodeIs(200);
$I->seeResponseContainsJson(['StatusCode' => 'Succeeded']);
$I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output");
$I->seeResponseCodeIs(200);
$this->assertTrue($I->grabResponse() === $data);
$I->haveHttpHeader('Range', 'bytes=0-1');
$I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output");
$I->seeResponseCodeIs(206);
$this->assertTrue($I->grabResponse() === 'AB');
$I->haveHttpHeader('Range', 'bytes=2-3');
$I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output");
$I->seeResponseCodeIs(206);
<?php

//has to be called first (thus 1LoginCept.php) because of the private keys after sql file import.
$I = new ApiTester($scenario);
$I->wantTo('login via POST');
$I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8');
$I->haveHttpHeader('Accept', 'application/json;charset=utf-8');
$I->sendPOST('login', json_encode(array('username' => 'demo', 'password' => 'demo')));
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array("error" => false, "login_id" => 123, "username" => "demo", "group_id" => 3, "locale" => "en", "public_key" => "248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6", "access_level" => " AND (facilities.FacilityID = 11 OR facilities.FacilityID = 14 OR facilities.FacilityID = 13 OR facilities.FacilityID = 17 OR facilities.FacilityID = 16 OR facilities.FacilityID = 15 OR facilities.FacilityID = 12)"));
예제 #29
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]);
예제 #30
0
 */
require "_AddItems.php";
$calculate_discount = function ($discount, ...$items) {
    $mult = 1 - $discount;
    return array_reduce($items, function ($total, $item) use($mult) {
        return floatify($total + floatify($item['final_price'] * $mult));
    }, 0);
};
$I->amGoingTo('use an invalid coupon code');
$I->sendPOST('cart/coupon', ['code' => 'XXX']);
$I->seeResponseCodeIs(HTTP_NOT_FOUND);
$set_coupon = function ($coupon) use($I, $item1, $item2, $calculate_discount) {
    $I->sendPOST('cart/coupon', ['code' => $coupon['code']]);
    $I->seeCodeAndJson(HTTP_OK, $coupon);
    $I->sendGET('cart');
    $I->seeResponseContainsJson(['total' => $calculate_discount($coupon['discount'], $item1, $item2)]);
};
$I->amGoingTo('use a valid coupon code');
$set_coupon($coupons[0]);
$I->amGoingTo('change the coupon');
$set_coupon($coupons[1]);
$I->amGoingTo('add a new item to see the price discount');
$item3 = $gen_item();
$I->sendPUT('cart', $item3);
$item3['final_price'] = $item3['price'] * $item3['qty'];
$I->sendGET('cart');
$I->seeResponseContainsJson(['total' => $calculate_discount($coupons[1]['discount'], $item1, $item2, $item3)]);
$I->amGoingTo('remove the wrong coupon');
$I->sendDELETE('cart/coupon?code=' . $coupons[0]['code']);
$I->seeResponseCodeIs(HTTP_CONFLICT);
$I->amGoingTo('remove a weird coupon');