<?php

use Codeception\Module\ApiHelper;
$I = new ApiGuy($scenario);
$I->wantTo('TEST Orders');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$data = array();
//get token
$I->sendGET('Tokens?email=' . ApiHelper::$testUser['email'] . '&hash=' . md5(ApiHelper::$testUser['pass']), array());
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":1,"data":{"signature":"');
$token = json_decode($I->grabResponse(), true);
$days2 = strtotime('next tuesday');
//'collection_local_date' => date("Y-m-d",$days2),
for ($i = 0; $i < 100; $i++) {
    foreach (ApiHelper::$testOrdersData as $providerID => $providerDataset) {
        codecept_debug('[_Debug data] ' . $providerID . ' test');
        foreach ($providerDataset as $datasetName => $datasetData) {
            codecept_debug('[_Debug data] ' . $datasetName . ' test');
            $datasetData['client_ID'] = $token['data']['client_ID'];
            $datasetData['signature'] = $token['data']['signature'];
            $I->sendGET('Prices/' . $providerID, $datasetData);
            $I->seeResponseIsJson();
            //echo '!NULL';
            $I->seeResponseContains('{"result":1,"data":');
            $priceData = json_decode($I->grabResponse(), true);
        }
    }
}
示例#2
0
<?php

$I = new ApiGuy($scenario);
$I->wantTo('create a user via API');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('users', array('username' => '*****@*****.**', 'Password' => ''));
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('{"message":"Password","success":0}');
?>

?>

示例#3
0
<?php

/**
 * Copyright (c) 2014 Ebizu Sdn. Bhd.
 * 
 * @author Budi Irawan <*****@*****.**>
 */
$I = new ApiGuy($scenario);
$I->wantTo('login as user');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('users/login', ['email' => '*****@*****.**', 'password' => 'halimi']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->amGoingTo('login using wrong username or password');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('users/login', ['email' => '*****@*****.**', 'password' => 'halimi']);
$I->seeResponseIsJson();
$I->seeResponseContains('404');
<?php

$I = new ApiGuy($scenario);
$I->wantTo('TEST TNT Provider');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$pass = '******';
$hash = md5($pass);
//get token
$data = array();
$I->sendGET('Tokens?email=aydar@creativestripe.ru&hash=' . $hash, $data);
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":1,"data":{"signature":"');
$response = json_decode($I->grabResponse(), true);
$responseToken = $response;
//get prices
$data = array('client_ID' => $response['data']['client_ID'], 'signature' => $response['data']['signature'], 'type' => 'd', 'quantity' => 3, 'sender_locality' => 'Kazan', 'sender_country_code' => 'RU', 'sender_locality_translated' => 'Казань', 'sender_postal_code' => '420001', 'receiver_locality' => 'Moscow', 'receiver_country_code' => 'RU', 'receiver_locality_translated' => 'Москва', 'receiver_postal_code' => '101000');
$I->sendGET('Prices/1', $data);
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":1,"data":');
$days2 = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 4, date("Y"));
$days10 = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 12, date("Y"));
$days2timefrom = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 4, date("Y"));
$days10timefrom = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 12, date("Y"));
$days2timeto = mktime(date("H") + 1, date("i"), date("s"), date("m"), date("d") + 4, date("Y"));
$days10timeto = mktime(date("H") + 1, date("i"), date("s"), date("m"), date("d") + 12, date("Y"));
$requiredParams = array('client_ID' => $response['data']['client_ID'], 'signature' => $response['data']['signature'], 'type' => 'd', 'quantity' => 3, 'sender_locality' => 'Kazan', 'sender_country_code' => 'RU', 'sender_locality_translated' => 'Казань', 'sender_postal_code' => '420001', 'receiver_locality' => 'Moscow', 'receiver_country_code' => 'RU', 'receiver_locality_translated' => 'Москва', 'receiver_postal_code' => '101000', 'receiver_phone' => '+79510665133', 'sender_full_name' => 'Aydar Akhmeyzyanov', 'sender_type' => 'c', 'sender_company' => 'creativestripe', 'receiver_full_name' => 'Vadim Perov', 'receiver_type' => 'p', 'collection_local_date' => date("Y-m-d", $days2), 'delivery_timezone' => '4', 'sender_street' => 'chetaeva', 'sender_housenumber' => '1', 'sender_roomnumber' => '2', 'receiver_street' => 'chetaeva', 'receiver_housenumber' => '3', 'receiver_roomnumber' => '5', 'sender_significantinformation' => 'wtf???', 'invoice_contents' => 'wtf???', 'invoice_price' => '200', 'extra_insurance' => '100');
$response2 = json_decode($I->grabResponse(), true);
$requiredParams['provider_price_data'] = json_encode($response2['data']['0']);
$data = $requiredParams;
$I->sendPOST('Ship?action=create', $data);
$I->seeResponseIsJson();
<?php

$I = new ApiGuy($scenario);
$I->wantTo('TEST Terminals response');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$data = array();
$I->sendGET('Datasets/Terminals/Pickup/RU/Kazan?locality_translated=Казань&weight=10&length=100&width=100&height=100&provider_ID=2', $data);
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":1,"data":[{"ID');
$PickupTerminal = json_decode($I->grabResponse(), true);
$datasetData['sender_terminal_ID'] = json_encode($PickupTerminal['data'][0]['ID']);
codecept_debug('[_Debug data] ' . $datasetData['sender_terminal_ID'] . ' test');
示例#6
0
<?php

$I = new ApiGuy($scenario);
$I->wantTo('create a user via API');
$I->haveHttpHeader('Content-Type', 'application/json');
include "constant.php";
$I->sendPOST('/auth/registration', array('username' => $user_name, 'email' => $email, 'password' => $pass, 'password_confirmation' => $pass));
$I->seeResponseContains("data", "errors");
$I->seeResponseIsJson();
$I->seeResponseCodeIs(200);
示例#7
0
$nonexistingPage = $lastPage + 1;
$firstCategorySlug = Fixtures::get('data:categories[0]:slug');
$urls = array(\BlogFeedPage::$url, \AuthorFeedPage::route(1), \CategoryFeedPage::route($firstCategorySlug));
foreach ($urls as $url) {
    $I->amOnPage($url . '?format=json');
    $I->seeResponseIsJson();
    $I->amOnPage($url . '?format=json&page=' . $lastPage);
    $I->seeResponseIsJson();
    $I->amOnPage($url . '?format=json&page=' . $nonexistingPage);
    $I->seeResponseCodeIs(404);
    /** @todo wouldn't it be cooler to return the last page on -1, penultimate page
     * on -2 and so on? */
    $I->amOnPage($url . '?format=json&page=-1');
    $I->seeResponseCodeIs(400);
    $I->amOnPage($url . '?format=xml');
    $I->seeResponseContains('<posts>');
    $I->assertNotEmpty($xml->posts);
    $I->amOnPage($url . '?format=xml&page=' . $lastPage);
    $response = $I->grabResponse();
    $xml = new \SimpleXMLElement($response);
    $I->assertNotEmpty($xml->posts);
    $I->amOnPage($url . '?format=xml&page=' . $nonexistingPage);
    $I->seeResponseCodeIs(404);
    $I->amOnPage($url . '?format=xml&page=-1');
    $I->seeResponseCodeIs(400);
    $I->amOnPage($url . '?format=rss');
    $response = $I->grabResponse();
    $rss = new \SimpleXMLElement($response);
    $I->assertNotEmpty($rss->channel);
    $I->assertNotEmpty($rss->channel->children());
    $I->amOnPage($url . '?format=rss&page=' . $lastPage);