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.

72 lines
5.1 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class HackernewsTest 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 testSubmission() {
  17. $url = 'https://news.ycombinator.com/item?id=14516538';
  18. $response = $this->parse(['url' => $url]);
  19. $body = $response->getContent();
  20. $this->assertEquals(200, $response->getStatusCode());
  21. $data = json_decode($body, true);
  22. $this->assertEquals('entry', $data['data']['type']);
  23. $this->assertEquals('article', $data['data']['post-type']);
  24. $this->assertEquals('2017-06-08T19:32:12+00:00', $data['data']['published']);
  25. $this->assertEquals('vkb', $data['data']['author']['name']);
  26. $this->assertEquals('https://news.ycombinator.com/user?id=vkb', $data['data']['author']['url']);
  27. $this->assertEquals('What are we doing about Facebook, Google, and the closed internet?', $data['data']['name']);
  28. $this->assertEquals('There have been many, many posts about how toxic advertising and Facebook are (I\'ve written many myself[1][2][3]) for our internet ecosystem today.<p>What projects or companies are you working on to combat filter bubbles, walled gardens, emotional manipulation, and the like, and how can the HN community help you in your goals?</p><p>[1]http://veekaybee.github.io/facebook-is-collecting-this/
  29. [2]http://veekaybee.github.io/content-is-dead/
  30. [3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/</p>', $data['data']['content']['html']);
  31. $this->assertEquals('There have been many, many posts about how toxic advertising and Facebook are (I\'ve written many myself[1][2][3]) for our internet ecosystem today.
  32. What projects or companies are you working on to combat filter bubbles, walled gardens, emotional manipulation, and the like, and how can the HN community help you in your goals?
  33. [1]http://veekaybee.github.io/facebook-is-collecting-this/
  34. [2]http://veekaybee.github.io/content-is-dead/
  35. [3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/', $data['data']['content']['text']);
  36. }
  37. public function testComment() {
  38. $url = 'https://news.ycombinator.com/item?id=14516923';
  39. $response = $this->parse(['url' => $url]);
  40. $body = $response->getContent();
  41. $this->assertEquals(200, $response->getStatusCode());
  42. $data = json_decode($body, true);
  43. $this->assertEquals('entry', $data['data']['type']);
  44. $this->assertEquals('reply', $data['data']['post-type']);
  45. $this->assertEquals('2017-06-08T20:23:20+00:00', $data['data']['published']);
  46. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  47. $this->assertEquals('https://news.ycombinator.com/user?id=aaronpk', $data['data']['author']['url']);
  48. $this->assertEquals('https://news.ycombinator.com/item?id=14516538', $data['data']['in-reply-to'][0]);
  49. $this->assertArrayNotHasKey('name', $data['data']);
  50. $this->assertEquals('I am a member of the W3C Social Web Working Group (<a href="https://www.w3.org/wiki/Socialwg">https://www.w3.org/wiki/Socialwg</a>), and have been organizing IndieWebCamp (<a href="https://indieweb.org/">https://indieweb.org/</a>) conferences in this space for the last 7 years. We\'ve been making a lot of progress:<p>* <a href="https://www.w3.org/TR/webmention/">https://www.w3.org/TR/webmention/</a> - cross-site commenting</p><p>* <a href="https://www.w3.org/TR/micropub/">https://www.w3.org/TR/micropub/</a> - API for apps to create posts on various servers</p><p>* <a href="https://www.w3.org/TR/websub/">https://www.w3.org/TR/websub/</a> - realtime subscriptions to feeds</p><p>* More: <a href="https://indieweb.org/specs">https://indieweb.org/specs</a></p><p>We focus on making sure there are a plurality of implementations and approaches rather than trying to build a single software solution to solve everything.</p><p>Try commenting on my copy of this post on my website by sending me a webmention! <a href="https://aaronparecki.com/2017/06/08/9/indieweb">https://aaronparecki.com/2017/06/08/9/indieweb</a></p>', $data['data']['content']['html']);
  51. $this->assertEquals('I am a member of the W3C Social Web Working Group (https://www.w3.org/wiki/Socialwg), and have been organizing IndieWebCamp (https://indieweb.org/) conferences in this space for the last 7 years. We\'ve been making a lot of progress:
  52. * https://www.w3.org/TR/webmention/ - cross-site commenting
  53. * https://www.w3.org/TR/micropub/ - API for apps to create posts on various servers
  54. * https://www.w3.org/TR/websub/ - realtime subscriptions to feeds
  55. * More: https://indieweb.org/specs
  56. We focus on making sure there are a plurality of implementations and approaches rather than trying to build a single software solution to solve everything.
  57. Try commenting on my copy of this post on my website by sending me a webmention! https://aaronparecki.com/2017/06/08/9/indieweb', $data['data']['content']['text']);
  58. }
  59. }