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.

96 lines
4.4 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 testGitHubRepo() {
  49. $url = 'https://github.com/aaronpk/XRay';
  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('repo', $data['data']['type']);
  55. $this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']);
  56. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  57. $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
  58. $this->assertEquals('https://avatars2.githubusercontent.com/u/113001?v=3', $data['data']['author']['photo']);
  59. $this->assertEquals('XRay', $data['data']['name']);
  60. $this->assertEquals('X-Ray returns structured data from any URL', $data['data']['summary']);
  61. }
  62. public function testGitHubIssueComment() {
  63. $url = 'https://github.com/aaronpk/XRay/issues/25#issuecomment-275433926';
  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('entry', $data['data']['type']);
  69. $this->assertEquals('2017-01-26T16:24:37Z', $data['data']['published']);
  70. $this->assertEquals('sebsel', $data['data']['author']['name']);
  71. $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);
  72. $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
  73. $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']);
  74. $this->assertContains('<code class="language-php">', $data['data']['content']['html']);
  75. $this->assertContains('```php', $data['data']['content']['text']);
  76. $this->assertNotContains('name', $data['data']);
  77. }
  78. }