From 4fab3e9e0aa6d84859e636f385cafff27386d9d1 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 9 Jun 2017 07:33:01 -0700 Subject: [PATCH] add test for HN comment --- lib/XRay/Formats/Hackernews.php | 2 +- tests/HackernewsTest.php | 27 +++++++++++++++++++ .../v0_item_14516923.json | 11 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/data/hacker-news.firebaseio.com/v0_item_14516923.json diff --git a/lib/XRay/Formats/Hackernews.php b/lib/XRay/Formats/Hackernews.php index 780683d..a359aff 100644 --- a/lib/XRay/Formats/Hackernews.php +++ b/lib/XRay/Formats/Hackernews.php @@ -67,7 +67,7 @@ class Hackernews extends Format { if(isset($data['text'])) { $htmlContent = trim(self::sanitizeHTML($data['text'])); - $textContent = str_replace('

', "

\n

", $htmlContent); + $textContent = str_replace('

', "\n

", $htmlContent); $textContent = strip_tags($textContent); $entry['content'] = [ 'html' => $htmlContent, diff --git a/tests/HackernewsTest.php b/tests/HackernewsTest.php index 71cd9d4..e414f92 100644 --- a/tests/HackernewsTest.php +++ b/tests/HackernewsTest.php @@ -34,8 +34,35 @@ class HackernewsTest extends PHPUnit_Framework_TestCase { $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.

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?

[1]http://veekaybee.github.io/facebook-is-collecting-this/ [2]http://veekaybee.github.io/content-is-dead/ [3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/

', $data['data']['content']['html']); + $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. +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? +[1]http://veekaybee.github.io/facebook-is-collecting-this/ +[2]http://veekaybee.github.io/content-is-dead/ +[3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/', $data['data']['content']['text']); } + public function testComment() { + $url = 'https://news.ycombinator.com/item?id=14516923'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('entry', $data['data']['type']); + $this->assertEquals('2017-06-08T20:23:20+00:00', $data['data']['published']); + $this->assertEquals('aaronpk', $data['data']['author']['name']); + $this->assertEquals('https://news.ycombinator.com/user?id=aaronpk', $data['data']['author']['url']); + $this->assertArrayNotHasKey('name', $data['data']); + $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:

* https://www.w3.org/TR/webmention/ - cross-site commenting

* https://www.w3.org/TR/micropub/ - API for apps to create posts on various servers

* https://www.w3.org/TR/websub/ - realtime subscriptions to feeds

* More: https://indieweb.org/specs

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.

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']['html']); + $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: +* https://www.w3.org/TR/webmention/ - cross-site commenting +* https://www.w3.org/TR/micropub/ - API for apps to create posts on various servers +* https://www.w3.org/TR/websub/ - realtime subscriptions to feeds +* More: https://indieweb.org/specs +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. +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']); + } } diff --git a/tests/data/hacker-news.firebaseio.com/v0_item_14516923.json b/tests/data/hacker-news.firebaseio.com/v0_item_14516923.json new file mode 100644 index 0000000..21c8119 --- /dev/null +++ b/tests/data/hacker-news.firebaseio.com/v0_item_14516923.json @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Fri, 09 Jun 2017 14:30:19 GMT +Content-Type: application/json; charset=utf-8 +Content-Length: 1701 +Connection: keep-alive +Access-Control-Allow-Origin: * +Cache-Control: no-cache +Strict-Transport-Security: max-age=31556926; includeSubDomains; preload + +{"by":"aaronpk","id":14516923,"kids":[14517124,14517655,14516983,14518902,14518663],"parent":14516538,"text":"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:

* https://www.w3.org/TR/webmention/ - cross-site commenting

* https://www.w3.org/TR/micropub/ - API for apps to create posts on various servers

* https://www.w3.org/TR/websub/ - realtime subscriptions to feeds

* More: https://indieweb.org/specs

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.

Try commenting on my copy of this post on my website by sending me a webmention! https://aaronparecki.com/2017/06/08/9/indieweb","time":1496953400,"type":"comment"} \ No newline at end of file