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.

109 lines
4.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\HTTPTest(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('entry', $data['data']['type']);
  24. $this->assertEquals('2017-04-10T17:44:57Z', $data['data']['published']);
  25. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  26. $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
  27. $this->assertEquals('https://avatars2.githubusercontent.com/u/113001?v=3', $data['data']['author']['photo']);
  28. $this->assertEquals('#1690 fixes bookmark Microformats markup', $data['data']['name']);
  29. $this->assertContains('<h2>Here\'s what I fixed or added:</h2>', $data['data']['content']['html']);
  30. $this->assertContains('## Here\'s what I fixed or added:', $data['data']['content']['text']);
  31. }
  32. public function testGitHubIssue() {
  33. $url = 'https://github.com/aaronpk/XRay/issues/25';
  34. $response = $this->parse(['url' => $url]);
  35. $body = $response->getContent();
  36. $this->assertEquals(200, $response->getStatusCode());
  37. $data = json_decode($body, true);
  38. $this->assertEquals('entry', $data['data']['type']);
  39. $this->assertEquals('2017-01-26T14:13:42Z', $data['data']['published']);
  40. $this->assertEquals('sebsel', $data['data']['author']['name']);
  41. $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
  42. $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);
  43. $this->assertEquals('#25 Post type discovery', $data['data']['name']);
  44. $this->assertContains('<blockquote>', $data['data']['content']['html']);
  45. $this->assertContains('<a href="https://www.w3.org/TR/post-type-discovery/">', $data['data']['content']['html']);
  46. $this->assertContains('> sebsel', $data['data']['content']['text']);
  47. }
  48. public function testGitHubIssueWithCategory() {
  49. $url = 'https://github.com/aaronpk/XRay/issues/20';
  50. $response = $this->parse(['url' => $url]);
  51. $body = $response->getContent();
  52. $this->assertEquals(200, $response->getStatusCode());
  53. $data = json_decode($body, true);
  54. $this->assertEquals('entry', $data['data']['type']);
  55. $this->assertContains('silo', $data['data']['category']);
  56. }
  57. public function testGitHubRepo() {
  58. $url = 'https://github.com/aaronpk/XRay';
  59. $response = $this->parse(['url' => $url]);
  60. $body = $response->getContent();
  61. $this->assertEquals(200, $response->getStatusCode());
  62. $data = json_decode($body, true);
  63. $this->assertEquals('repo', $data['data']['type']);
  64. $this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']);
  65. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  66. $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
  67. $this->assertEquals('https://avatars2.githubusercontent.com/u/113001?v=3', $data['data']['author']['photo']);
  68. $this->assertEquals('XRay', $data['data']['name']);
  69. $this->assertEquals('X-Ray returns structured data from any URL', $data['data']['summary']);
  70. }
  71. public function testGitHubIssueComment() {
  72. $url = 'https://github.com/aaronpk/XRay/issues/25#issuecomment-275433926';
  73. $response = $this->parse(['url' => $url]);
  74. $body = $response->getContent();
  75. $this->assertEquals(200, $response->getStatusCode());
  76. $data = json_decode($body, true);
  77. $this->assertEquals('entry', $data['data']['type']);
  78. $this->assertEquals('2017-01-26T16:24:37Z', $data['data']['published']);
  79. $this->assertEquals('sebsel', $data['data']['author']['name']);
  80. $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);
  81. $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
  82. $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']);
  83. $this->assertContains('<code class="language-php">', $data['data']['content']['html']);
  84. $this->assertContains('```php', $data['data']['content']['text']);
  85. $this->assertNotContains('name', $data['data']);
  86. $this->assertContains('https://github.com/aaronpk/XRay/issues/25', $data['data']['in-reply-to']);
  87. }
  88. }