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.

139 lines
6.4 KiB

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