コード例 #1
0
<?php

$executeLoader = false;
$app = 'api';
include dirname(__FILE__) . '/../../bootstrap/functional.php';
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->setConfiguration($configuration);
$task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => dirname(__FILE__) . '/fixtures/member_search.yml', 'application' => $app, 'env' => 'test'));
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color()));
Doctrine::getTable('SnsConfig')->set('enable_jsonapi', true);
$key = Doctrine::getTable('Member')->find(1)->getApiKey();
$browser->get('member/search.json', array('apiKey' => $key, 'target' => 'friend', 'target_id' => 1))->with('request')->begin()->isParameter('module', 'member')->isParameter('action', 'search')->end()->with('response')->isStatusCode(200);
$json = $browser->getResponse()->getContent();
$data = json_decode($json, true);
$t = $browser->test();
$t->is($data['status'], 'success', 'status is "success".');
$t->is(count($data['data']), 1, 'returned member count is 1(NOT including blocking_member and prefriend_member).');
$t->is($data['data'][0]['name'], 'Already-friend', 'only including friend member');
コード例 #2
0
$executeLoader = false;
include dirname(__FILE__) . '/../../bootstrap/functional.php';
include dirname(__FILE__) . '/../../bootstrap/database.php';
$numOfTests = 15;
$tester = new opTestFunctional(new opBrowser(), new lime_test($numOfTests, new lime_output_color()));
$t = $tester->test();
Doctrine_Core::getTable('SnsConfig')->set('enable_jsonapi', true);
$apiKeyMember1 = Doctrine_Core::getTable('Member')->find(1)->getApiKey();
if (in_array('opTimelinePlugin', ProjectConfiguration::getActive()->getPlugins())) {
    // opTimelinePlugin breaks standard JSON APIs (activity/*.json)
    $tester->test()->fail('unable to run tests if opTimelinePlugin is installed');
    return;
}
$tester->info('/activity/post.json - single image upload')->postWithFiles('/activity/post.json', array('apiKey' => $apiKeyMember1, 'body' => 'hogehoge'), array('images[0]' => dirname(__FILE__) . '/uploads/dot.gif'))->with('response')->isStatusCode(200);
$response = json_decode($tester->getResponse()->getContent(), true);
$t->is($response['status'], 'success');
$activityImage = Doctrine_Core::getTable('ActivityImage')->findByActivityDataId($response['data']['id']);
$t->is(count($activityImage), 1);
$t->is(count($response['data']['image_uris']), 1);
$t->is($response['data']['image_uris'][0]['small_size'], 'http://localhost/cache/img/gif/w48_h48/' . $activityImage[0]->File->name . '.gif');
$t->is($response['data']['image_uris'][0]['full_size'], 'http://localhost/cache/img/gif/w_h/' . $activityImage[0]->File->name . '.gif');
$tester->info('/activity/post.json - invalid image')->postWithFiles('/activity/post.json', array('apiKey' => $apiKeyMember1, 'body' => 'hogehoge'), array('images[0]' => dirname(__FILE__) . '/uploads/plaintext.txt'))->with('response')->isStatusCode(400);
$tester->info('/activity/post.json - multiple image upload')->postWithFiles('/activity/post.json', array('apiKey' => $apiKeyMember1, 'body' => 'hogehoge'), array('images[0]' => dirname(__FILE__) . '/uploads/dot.gif', 'images[1]' => dirname(__FILE__) . '/uploads/white.jpg'))->with('response')->isStatusCode(200);
$response = json_decode($tester->getResponse()->getContent(), true);
$t->is($response['status'], 'success');
$activityImage = Doctrine_Core::getTable('ActivityImage')->findByActivityDataId($response['data']['id']);
$t->is(count($activityImage), 2);
$t->is(count($response['data']['image_uris']), 2);
$t->is($response['data']['image_uris'][0]['small_size'], 'http://localhost/cache/img/gif/w48_h48/' . $activityImage[0]->File->name . '.gif');
$t->is($response['data']['image_uris'][0]['full_size'], 'http://localhost/cache/img/gif/w_h/' . $activityImage[0]->File->name . '.gif');