Guest User

Untitled

a guest
Sep 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.04 KB | None | 0 0
  1. <?php
  2. $app = 'api';
  3.  
  4. include_once dirname(__FILE__) . '/../../bootstrap/unit.php';
  5. include_once dirname(__FILE__) . '/../../bootstrap/database.php';
  6.  
  7. $configuration = ProjectConfiguration::getApplicationConfiguration('api', 'prod', isset($debug) ? $debug : true);
  8. sfContext::createInstance($configuration);
  9.  
  10. $numOfTest = 42;
  11.  
  12. $t = new lime_test($numOfTest, new lime_output_color());
  13. $browser = new opBrowser();
  14.  
  15. /************************
  16. * Test apiKey Response (5)
  17. ************************/
  18.  
  19. Doctrine::getTable('SnsConfig')->set('enable_jsonapi', false);
  20. $member1ApiKey = Doctrine::getTable('Member')->find(1)->getApiKey();
  21.  
  22. $browser->get('/activity/search.json');
  23. $t->is($browser->getResponse()->getStatusCode(), 404, '[apiKey] JSON API is not enabled.');
  24.  
  25. Doctrine::getTable('SnsConfig')->set('enable_jsonapi', true);
  26.  
  27. $browser->get('/activity/search.json');
  28. $t->is($browser->getResponse()->getStatusCode(), 401, '[apiKey] apiKey not specified');
  29.  
  30. $browser->get('/activity/search.json', array('apiKey' => ''));
  31. $t->is($browser->getResponse()->getStatusCode(), 401, '[apiKey] empty apiKey');
  32.  
  33. $browser->get('/activity/search.json', array('apiKey' => 'aaaaaaaaaa'));
  34. $t->is($browser->getResponse()->getStatusCode(), 401, '[apiKey] invalid apiKey');
  35.  
  36. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey));
  37. $t->is($browser->getResponse()->getStatusCode(), 200, '[apiKey] valid apiKey');
  38.  
  39. /****************************
  40. * Test activity/search.json (10)
  41. ***************************/
  42.  
  43. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey));
  44. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] valid request');
  45.  
  46. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'target' => 'hoge'));
  47. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/search.json] invalid parameter');
  48.  
  49. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'target' => 'friend'));
  50. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] target => friend is valid parameter.');
  51. echo $browser->getResponse()->getContent();
  52. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'target' => 'community'));
  53. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/search.json] target => community parameter requires target_id parameter.');
  54.  
  55. $browser->get('/activity/seaech.json', array('apiKey' => $member1ApiKey, 'target' => 'community', 'target_id' => '1'));
  56. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] target => community is valid parameter.');
  57.  
  58. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'activity_id' => ''));
  59. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/search.json] activiy_id parameter is not set.');
  60.  
  61. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'activity_id' => 'hogefuga'));
  62. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/search.json] activity_id => hogefuga is invalid parameter');
  63.  
  64. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'activity_id' => '1'));
  65. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] activity_id => 1 is valid parameter');
  66.  
  67. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'member_id' => ''));
  68. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] member_id parameter is valid parameter.');
  69. echo $browser->getResponse()->getContent();
  70. $browser->get('/activity/search.json', array('apiKey' => $member1ApiKey, 'max_id' => '', 'since_id' => ''));
  71. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/search.json] max_id and since_id parameter is valid parameter.');
  72.  
  73.  
  74. /*************************
  75. * Test activity/post.json (7)
  76. *************************/
  77.  
  78. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey));
  79. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/post.json] body parameter is required.');
  80.  
  81. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => 'hogefuga'));
  82. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/post.json] body => hogefuga parameter should be posted.');
  83.  
  84. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => ' '));
  85. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/post.json] body => (space) parameter should be rejected.');
  86.  
  87. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => '\t'));
  88. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/post.json] body => (tabs) parameter should be rejected.');
  89.  
  90. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => 'hogefuga', 'target' => 'hoge'));
  91. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/post.json] target parameter (except: \'community\') should not be set.');
  92.  
  93. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => 'hogefuga', 'target' => 'community'));
  94. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/post.json] target_id parameter is required.');
  95.  
  96. $browser->get('/activity/post.json', array('apiKey' => $member1ApiKey, 'body' => 'hogefuga', 'target_id' => 'community', 'target_id' => '1'));
  97. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/post.json] target => community and target_id => 1 parameter should be posted.');
  98.  
  99.  
  100. /*******************************
  101. * Test activity/delete.json (4)
  102. *******************************/
  103.  
  104. $browser->get('/activity/delete.json', array('apiKey' => $member1ApiKey));
  105. $t->is($browser->getResponse()->getStatusCode(), 400, '[activity/delete.json] activity_id parameter is required.');
  106.  
  107. $browser->get('/activity/delete.json', array('apiKey' => $member1ApiKey, 'activity_id' => 1));
  108. $t->is($browser->getResponse()->getStatusCode(), 200, '[activity/delete.json] activity_id => 1 is valid parameter.');
  109.  
  110. $browser->get('/activity/delete.json', array('apiKey' => $member1ApiKey, 'id' => 2));
  111. $t->is($browser->getResponse()->getStatusCode(), 404, '[activity/delete.json] id => 2 parameter is invalid parameter (not found).');
  112.  
  113. $browser->get('/activity/delete.json', array('apiKey' => $member1ApiKey, 'activity_id' => 3));
  114. $t->is($browser->getResponse()->getStatusCode(), 403, '[activity/delete.json] id => 3 activity data is not allowed to delete.');
  115.  
  116.  
  117. /********************************
  118. * test member/search.json (5)
  119. ********************************/
  120.  
  121. $browser->get('/member/search.json', array('apiKey' => $member1ApiKey, 'target' => 'friend'));
  122. $t->is($browser->getResponse()->getStatusCode(), 400, '[member/search.json] target => friend parameter is invalid.');
  123.  
  124. $browser->get('/member/search.json', array('apiKey' => $member1ApiKey, 'target' => 'friend', 'target_id' => 1));
  125. $t->is($browser->getResponse()->getStatusCode(), 200, '[member/search.json] target => friend and target_id parameter is valid.');
  126.  
  127. $browser->get('/member/search.json', array('apiKey' => $member1ApiKey, 'target' =>'community'));
  128. $t->is($browser->getResponse()->getStatusCode(), 400, '[member/search.json] target => community parameter is invalid.');
  129.  
  130. $browser->get('/member/search.json', array('apiKey' => $member1ApiKey, 'target' =>'community', 'target_id' => 1));
  131. $t->is($browser->getResponse()->getStatusCode(), 200, '[member/search.json] target => community and target_id parameter is valid.');
  132.  
  133. $browser->get('/member/search.json', array('apiKey' => $member1ApiKey, 'keyword' => 'dummy'));
  134. $t->is($browser->getResponse()->getStatusCode(), 200, '[member/search.json] target => dummy parameter id valid.');
  135.  
  136.  
  137. /*******************************
  138. * test community/search.json (9)
  139. *******************************/
  140.  
  141. $browser->get('/community/search.json', array('apiKey' => $member1ApiKey, 'keyword' => 'dummy'));
  142. $t->is($browser->getResponse()->getStatusCode(), 200, '[community/search.json] keyword => dummy parameter is valid.');
  143.  
  144. $browser->get('/community/member.json', array('apiKey' => $member1ApiKey,));
  145. $t->is($browser->getResponse()->getStatusCode(), 400, '[community/member.json] community_id parameter is required.');
  146.  
  147. $browser->get('/community/member.json', array('apiKey' => $member1ApiKey, 'community_id' => '1'));
  148. $t->is($browser->getResponse()->getStatusCode(), 200, '[community/member.json] community_id => 1 parameter is valid.');
  149.  
  150. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey,));
  151. $t->is($browser->getResponse()->getStatusCode(), 400, '[community/join.json] community_id parameter is required.');
  152.  
  153. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey, 'community_id' => 10000));
  154. $t->is($browser->getResponse()->getStatusCode(), 404, '[community/join.json] community_id => 10000 does not exist.');
  155.  
  156. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey, 'community_id' => 1));
  157. $t->is($browser->getResponse()->getStatusCode(), 400, '[community/join.json] community_id => 1 is already joined.');
  158.  
  159. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey, 'community_id' => 2));
  160. $t->is($browser->getResponse()->getStatusCode(), 200, '[community/join.json] community_id => 2 parameter is valid.');
  161.  
  162. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey, 'community_id' => 2, 'leave' => 'true'));
  163. $t->is($browser->getResponse()->getStatusCode(), 200, '[community/join.json] community_id => 2 and leave => true parameter is valid.');
  164. echo $browser->getResponse()->getContent();
  165. $browser->get('/community/join.json', array('apiKey' => $member1ApiKey, 'community_id' => 1, 'leave' => 'true'));
  166. $t->is($browser->getResponse()->getStatusCode(), 400, '[community/join.json] This member cannot leave this community (community_id => 1)');
  167.  
  168.  
  169. /*******************************
  170. * test push/count.json (1)
  171. ******************************/
  172.  
  173. $browser->get('/push/count.json', array('apiKey' => $member1ApiKey));
  174. $t->is($browser->getResponse()->getStatusCode(), 200, '[push/count.json] valid.');
  175.  
  176. /*******************************
  177. * test push/search.json (1)
  178. ******************************/
  179.  
  180. $browser->get('/push/search.json', array('apiKey' => $member1ApiKey));
  181. $t->is($browser->getResponse()->getStatusCode(), 200, '[push/search.json] valid.');
Add Comment
Please, Sign In to add comment