Browse Source

add test for HN comment

pull/49/head
Aaron Parecki 7 years ago
parent
commit
4fab3e9e0a
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 39 additions and 1 deletions
  1. +1
    -1
      lib/XRay/Formats/Hackernews.php
  2. +27
    -0
      tests/HackernewsTest.php
  3. +11
    -0
      tests/data/hacker-news.firebaseio.com/v0_item_14516923.json

+ 1
- 1
lib/XRay/Formats/Hackernews.php View File

@ -67,7 +67,7 @@ class Hackernews extends Format {
if(isset($data['text'])) { if(isset($data['text'])) {
$htmlContent = trim(self::sanitizeHTML($data['text'])); $htmlContent = trim(self::sanitizeHTML($data['text']));
$textContent = str_replace('</p><p>', "</p>\n<p>", $htmlContent);
$textContent = str_replace('<p>', "\n<p>", $htmlContent);
$textContent = strip_tags($textContent); $textContent = strip_tags($textContent);
$entry['content'] = [ $entry['content'] = [
'html' => $htmlContent, 'html' => $htmlContent,

+ 27
- 0
tests/HackernewsTest.php View File

@ -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.<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/ $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/
[2]http://veekaybee.github.io/content-is-dead/ [2]http://veekaybee.github.io/content-is-dead/
[3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/</p>', $data['data']['content']['html']); [3] http://veekaybee.github.io/who-is-doing-this-to-my-internet/</p>', $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 (<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']);
$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']);
}
} }

+ 11
- 0
tests/data/hacker-news.firebaseio.com/v0_item_14516923.json View File

@ -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 (<a href=\"https:&#x2F;&#x2F;www.w3.org&#x2F;wiki&#x2F;Socialwg\" rel=\"nofollow\">https:&#x2F;&#x2F;www.w3.org&#x2F;wiki&#x2F;Socialwg</a>), and have been organizing IndieWebCamp (<a href=\"https:&#x2F;&#x2F;indieweb.org&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;indieweb.org&#x2F;</a>) conferences in this space for the last 7 years. We&#x27;ve been making a lot of progress:<p>* <a href=\"https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;webmention&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;webmention&#x2F;</a> - cross-site commenting<p>* <a href=\"https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;micropub&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;micropub&#x2F;</a> - API for apps to create posts on various servers<p>* <a href=\"https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;websub&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;websub&#x2F;</a> - realtime subscriptions to feeds<p>* More: <a href=\"https:&#x2F;&#x2F;indieweb.org&#x2F;specs\" rel=\"nofollow\">https:&#x2F;&#x2F;indieweb.org&#x2F;specs</a><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>Try commenting on my copy of this post on my website by sending me a webmention! <a href=\"https:&#x2F;&#x2F;aaronparecki.com&#x2F;2017&#x2F;06&#x2F;08&#x2F;9&#x2F;indieweb\" rel=\"nofollow\">https:&#x2F;&#x2F;aaronparecki.com&#x2F;2017&#x2F;06&#x2F;08&#x2F;9&#x2F;indieweb</a>","time":1496953400,"type":"comment"}

Loading…
Cancel
Save