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.

42 lines
1.8 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('2017-06-08T19:32:12+00:00', $data['data']['published']);
  24. $this->assertEquals('vkb', $data['data']['author']['name']);
  25. $this->assertEquals('https://news.ycombinator.com/user?id=vkb', $data['data']['author']['url']);
  26. $this->assertEquals('What are we doing about Facebook, Google, and the closed internet?', $data['data']['name']);
  27. $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/
  28. [2]http://veekaybee.github.io/content-is-dead/
  29. [3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/</p>', $data['data']['content']['html']);
  30. }
  31. }