/tests/unit/suites/libraries/joomla/github/activity/JGithubPackageActivityEventsTest.php

https://github.com/pjwiseman/joomla-cms · PHP · 349 lines · 195 code · 49 blank · 105 comment · 0 complexity · fbf26a3972e8f8dc133dc873382e0f8e MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Github
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. /**
  10. * Test class for JGithubEvents.
  11. *
  12. * @package Joomla.UnitTest
  13. * @subpackage Github
  14. * @since 12.3
  15. */
  16. class JGithubPackageActivityEventsTest extends PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @var JRegistry Options for the GitHub object.
  20. * @since 11.4
  21. */
  22. protected $options;
  23. /**
  24. * @var JGithubHttp Mock client object.
  25. * @since 11.4
  26. */
  27. protected $client;
  28. /**
  29. * @var JGithubPackageActivityEvents Object under test.
  30. * @since 11.4
  31. */
  32. protected $object;
  33. /**
  34. * @var string
  35. * @since 11.4
  36. */
  37. protected $response = '[
  38. {
  39. "type": "Event",
  40. "public": true,
  41. "payload": {
  42. },
  43. "repo": {
  44. "id": 3,
  45. "name": "octocat/Hello-World",
  46. "url": "https://api.github.com/repos/octocat/Hello-World"
  47. },
  48. "actor": {
  49. "login": "octocat",
  50. "id": 1,
  51. "avatar_url": "https://github.com/images/error/octocat_happy.gif",
  52. "gravatar_id": "somehexcode",
  53. "url": "https://api.github.com/users/octocat"
  54. },
  55. "org": {
  56. "login": "octocat",
  57. "id": 1,
  58. "avatar_url": "https://github.com/images/error/octocat_happy.gif",
  59. "gravatar_id": "somehexcode",
  60. "url": "https://api.github.com/users/octocat"
  61. },
  62. "created_at": "2011-09-06T17:26:27Z",
  63. "id": "12345"
  64. }
  65. ]';
  66. /**
  67. * @var string
  68. * @since 11.4
  69. */
  70. protected $owner = 'joomla';
  71. /**
  72. * @var string
  73. * @since 11.4
  74. */
  75. protected $repo = 'joomla-platform';
  76. /**
  77. * Sets up the fixture, for example, opens a network connection.
  78. * This method is called before a test is executed.
  79. *
  80. * @since 12.4
  81. * @return void
  82. */
  83. protected function setUp()
  84. {
  85. parent::setUp();
  86. $this->options = new JRegistry;
  87. $this->client = $this->getMock('JGithubHttp', array('get', 'post', 'delete', 'patch', 'put'));
  88. $this->object = new JGithubPackageActivityEvents($this->options, $this->client);
  89. }
  90. /**
  91. * Tests the getPublic method
  92. *
  93. * @since 12.4
  94. * @return void
  95. */
  96. public function testGetPublic()
  97. {
  98. $returnData = new JHttpResponse;
  99. $returnData->code = 200;
  100. $returnData->body = $this->response;
  101. $this->client->expects($this->once())
  102. ->method('get')
  103. ->with('/events', 0, 0)
  104. ->will($this->returnValue($returnData));
  105. $this->assertThat(
  106. $this->object->getPublic(),
  107. $this->equalTo(json_decode($returnData->body))
  108. );
  109. }
  110. /**
  111. * Tests the getRepository method
  112. *
  113. * @since 12.4
  114. * @return void
  115. */
  116. public function testGetRepository()
  117. {
  118. $returnData = new JHttpResponse;
  119. $returnData->code = 200;
  120. $returnData->body = $this->response;
  121. $path = '/repos/' . $this->owner . '/' . $this->repo . '/events';
  122. $this->client->expects($this->once())
  123. ->method('get')
  124. ->with($path, 0, 0)
  125. ->will($this->returnValue($returnData));
  126. $this->assertThat(
  127. $this->object->getRepository($this->owner, $this->repo),
  128. $this->equalTo(json_decode($returnData->body))
  129. );
  130. }
  131. /**
  132. * Tests the getIssue method
  133. *
  134. * @since 12.4
  135. * @return void
  136. */
  137. public function testGetIssue()
  138. {
  139. $returnData = new JHttpResponse;
  140. $returnData->code = 200;
  141. $returnData->body = $this->response;
  142. $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events';
  143. $this->client->expects($this->once())
  144. ->method('get')
  145. ->with($path, 0, 0)
  146. ->will($this->returnValue($returnData));
  147. $this->assertThat(
  148. $this->object->getIssue($this->owner, $this->repo),
  149. $this->equalTo(json_decode($returnData->body))
  150. );
  151. }
  152. /**
  153. * Tests the getNetwork method
  154. *
  155. * @since 12.4
  156. * @return void
  157. */
  158. public function testGetNetwork()
  159. {
  160. $returnData = new JHttpResponse;
  161. $returnData->code = 200;
  162. $returnData->body = $this->response;
  163. $path = '/networks/' . $this->owner . '/' . $this->repo . '/events';
  164. $this->client->expects($this->once())
  165. ->method('get')
  166. ->with($path, 0, 0)
  167. ->will($this->returnValue($returnData));
  168. $this->assertThat(
  169. $this->object->getNetwork($this->owner, $this->repo),
  170. $this->equalTo(json_decode($returnData->body))
  171. );
  172. }
  173. /**
  174. * Tests the getOrg method
  175. *
  176. * @since 12.4
  177. * @return void
  178. */
  179. public function testGetOrg()
  180. {
  181. $returnData = new JHttpResponse;
  182. $returnData->code = 200;
  183. $returnData->body = $this->response;
  184. $path = '/orgs/' . $this->owner . '/events';
  185. $this->client->expects($this->once())
  186. ->method('get')
  187. ->with($path, 0, 0)
  188. ->will($this->returnValue($returnData));
  189. $this->assertThat(
  190. $this->object->getOrg($this->owner, $this->repo),
  191. $this->equalTo(json_decode($returnData->body))
  192. );
  193. }
  194. /**
  195. * Tests the getUser method
  196. *
  197. * @since 12.4
  198. * @return void
  199. */
  200. public function testGetUser()
  201. {
  202. $returnData = new JHttpResponse;
  203. $returnData->code = 200;
  204. $returnData->body = $this->response;
  205. $path = '/users/' . $this->owner . '/received_events';
  206. $this->client->expects($this->once())
  207. ->method('get')
  208. ->with($path, 0, 0)
  209. ->will($this->returnValue($returnData));
  210. $this->assertThat(
  211. $this->object->getUser($this->owner),
  212. $this->equalTo(json_decode($returnData->body))
  213. );
  214. }
  215. /**
  216. * Tests the getUserPublic method
  217. *
  218. * @since 12.4
  219. * @return void
  220. */
  221. public function testGetUserPublic()
  222. {
  223. $returnData = new JHttpResponse;
  224. $returnData->code = 200;
  225. $returnData->body = $this->response;
  226. $path = '/users/' . $this->owner . '/received_events/public';
  227. $this->client->expects($this->once())
  228. ->method('get')
  229. ->with($path, 0, 0)
  230. ->will($this->returnValue($returnData));
  231. $this->assertThat(
  232. $this->object->getUserPublic($this->owner),
  233. $this->equalTo(json_decode($returnData->body))
  234. );
  235. }
  236. /**
  237. * Tests the getByUser method
  238. *
  239. * @since 12.4
  240. * @return void
  241. */
  242. public function testGetByUser()
  243. {
  244. $returnData = new JHttpResponse;
  245. $returnData->code = 200;
  246. $returnData->body = $this->response;
  247. $path = '/users/' . $this->owner . '/events';
  248. $this->client->expects($this->once())
  249. ->method('get')
  250. ->with($path, 0, 0)
  251. ->will($this->returnValue($returnData));
  252. $this->assertThat(
  253. $this->object->getByUser($this->owner),
  254. $this->equalTo(json_decode($returnData->body))
  255. );
  256. }
  257. /**
  258. * Tests the getByUserPublic method
  259. *
  260. * @since 12.4
  261. * @return void
  262. */
  263. public function testGetByUserPublic()
  264. {
  265. $returnData = new JHttpResponse;
  266. $returnData->code = 200;
  267. $returnData->body = $this->response;
  268. $path = '/users/' . $this->owner . '/events/public';
  269. $this->client->expects($this->once())
  270. ->method('get')
  271. ->with($path, 0, 0)
  272. ->will($this->returnValue($returnData));
  273. $this->assertThat(
  274. $this->object->getByUserPublic($this->owner),
  275. $this->equalTo(json_decode($returnData->body))
  276. );
  277. }
  278. /**
  279. * Tests the getUserOrg method
  280. *
  281. * @since 12.4
  282. * @return void
  283. */
  284. public function testGetUserOrg()
  285. {
  286. $returnData = new JHttpResponse;
  287. $returnData->code = 200;
  288. $returnData->body = $this->response;
  289. $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo;
  290. $this->client->expects($this->once())
  291. ->method('get')
  292. ->with($path, 0, 0)
  293. ->will($this->returnValue($returnData));
  294. $this->assertThat(
  295. $this->object->getUserOrg($this->owner, $this->repo),
  296. $this->equalTo(json_decode($returnData->body))
  297. );
  298. }
  299. }