You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.9 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class GitHubTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testGitHubPull() {
  17. // Original URL: https://github.com/idno/Known/pull/1690
  18. $url = 'https://github.com/idno/Known/pull/1690';
  19. $response = $this->parse(['url' => $url]);
  20. $body = $response->getContent();
  21. $this->assertEquals(200, $response->getStatusCode());
  22. $data = json_decode($body, true);
  23. $this->assertEquals(200, $data['code']);
  24. $this->assertEquals('github', $data['source-format']);
  25. $this->assertEquals('entry', $data['data']['type']);
  26. $this->assertEquals('reply', $data['data']['post-type']);
  27. $this->assertEquals('https://github.com/idno/Known', $data['data']['in-reply-to'][0]);
  28. $this->assertEquals('2017-04-10T17:44:57Z', $data['data']['published']);
  29. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  30. $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
  31. $this->assertEquals('https://avatars2.githubusercontent.com/u/113001?v=3', $data['data']['author']['photo']);
  32. $this->assertEquals('#1690 fixes bookmark Microformats markup', $data['data']['name']);
  33. $this->assertContains('<h2>Here\'s what I fixed or added:</h2>', $data['data']['content']['html']);
  34. $this->assertContains('## Here\'s what I fixed or added:', $data['data']['content']['text']);
  35. }
  36. public function testGitHubIssue() {
  37. $url = 'https://github.com/aaronpk/XRay/issues/25';
  38. $response = $this->parse(['url' => $url]);
  39. $body = $response->getContent();
  40. $this->assertEquals(200, $response->getStatusCode());
  41. $data = json_decode($body, true);
  42. $this->assertEquals(200, $data['code']);
  43. $this->assertEquals('github', $data['source-format']);
  44. $this->assertEquals('entry', $data['data']['type']);
  45. $this->assertEquals('reply', $data['data']['post-type']);
  46. $this->assertEquals('https://github.com/aaronpk/XRay/issues', $data['data']['in-reply-to'][0]);
  47. $this->assertEquals('2017-01-26T14:13:42Z', $data['data']['published']);
  48. $this->assertEquals('sebsel', $data['data']['author']['name']);
  49. $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
  50. $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);
  51. $this->assertEquals('#25 Post type discovery', $data['data']['name']);
  52. $this->assertContains('<blockquote>', $data['data']['content']['html']);
  53. $this->assertContains('<a href="https://www.w3.org/TR/post-type-discovery/">', $data['data']['content']['html']);
  54. $this->assertContains('> sebsel', $data['data']['content']['text']);
  55. }
  56. public function testGitHubIssueWithCategory() {
  57. $url = 'https://github.com/aaronpk/XRay/issues/20';
  58. $response = $this->parse(['url' => $url]);
  59. $body = $response->getContent();
  60. $this->assertEquals(200, $response->getStatusCode());
  61. $data = json_decode($body, true);
  62. $this->assertEquals(200, $data['code']);
  63. $this->assertEquals('github', $data['source-format']);
  64. $this->assertEquals('entry', $data['data']['type']);
  65. $this->assertContains('silo', $data['data']['category']);
  66. }
  67. public function testGitHubRepo() {
  68. $url = 'https://github.com/aaronpk/XRay';
  69. $response = $this->parse(['url' => $url]);
  70. $body = $response->getContent();
  71. $this->assertEquals(200, $response->getStatusCode());
  72. $data = json_decode($body, true);
  73. $this->assertEquals(200, $data['code']);
  74. $this->assertEquals('github', $data['source-format']);
  75. $this->assertEquals('repo', $data['data']['type']);
  76. $this->assertArrayNotHasKey('post-type', $data['data']);
  77. $this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']);
  78. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  79. $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
  80. $this->assertEquals('https://avatars2.githubusercontent.com/u/113001?v=3', $data['data']['author']['photo']);
  81. $this->assertEquals('XRay', $data['data']['name']);
  82. $this->assertEquals('X-Ray returns structured data from any URL', $data['data']['summary']);
  83. }
  84. public function testGitHubIssueComment() {
  85. $url = 'https://github.com/aaronpk/XRay/issues/25#issuecomment-275433926';
  86. $response = $this->parse(['url' => $url]);
  87. $body = $response->getContent();
  88. $this->assertEquals(200, $response->getStatusCode());
  89. $data = json_decode($body, true);
  90. $this->assertEquals(200, $data['code']);
  91. $this->assertEquals('github', $data['source-format']);
  92. $this->assertEquals('entry', $data['data']['type']);
  93. $this->assertEquals('reply', $data['data']['post-type']);
  94. $this->assertEquals('https://github.com/aaronpk/XRay/issues/25', $data['data']['in-reply-to'][0]);
  95. $this->assertEquals('2017-01-26T16:24:37Z', $data['data']['published']);
  96. $this->assertEquals('sebsel', $data['data']['author']['name']);
  97. $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);
  98. $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
  99. $this->assertContains('<p>Well it\'s just that php-comments does more than XRay does currently. But that\'s no good reason.</p>', $data['data']['content']['html']);
  100. $this->assertContains('<code class="language-php">', $data['data']['content']['html']);
  101. $this->assertContains('```php', $data['data']['content']['text']);
  102. $this->assertNotContains('name', $data['data']);
  103. $this->assertContains('https://github.com/aaronpk/XRay/issues/25', $data['data']['in-reply-to']);
  104. }
  105. }