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.

56 lines
2.9 KiB

6 years ago
  1. <?php
  2. use Telegraph\FindLinks;
  3. class FindLinksTest extends PHPUnit_Framework_TestCase {
  4. public function testFindLinksInText() {
  5. $links = FindLinks::inText('Hello world http://example.com/');
  6. $this->assertContains('http://example.com/', $links);
  7. }
  8. public function testFindLinksInHTML() {
  9. $links = FindLinks::inHTML('<a href="http://example.com/">Hello</a>');
  10. $this->assertContains('http://example.com/', $links);
  11. }
  12. public function testFindLinksInJSONArray() {
  13. $links = FindLinks::all([
  14. 'link' => 'http://example.com/',
  15. 'nested' => [
  16. 'foo' => 'http://example.net/',
  17. 'html' => 'This is some html with a <a href="http://example.html/">link</a>',
  18. 'photo' => [
  19. 'http://example.com/img.jpg'
  20. ],
  21. 'bar' => [
  22. 'baz' => [
  23. 'http://example.org/'
  24. ]
  25. ],
  26. [[['http://example.io/']]]
  27. ]
  28. ]);
  29. $this->assertContains('http://example.com/', $links);
  30. $this->assertContains('http://example.com/img.jpg', $links);
  31. $this->assertContains('http://example.net/', $links);
  32. $this->assertContains('http://example.org/', $links);
  33. $this->assertContains('http://example.io/', $links);
  34. $this->assertContains('http://example.html/', $links);
  35. }
  36. public function testFindLinksInXRayResult() {
  37. $data = json_decode('
  38. {"data":{"type":"entry","published":"2018-06-19T14:32:44-07:00","url":"https://aaronparecki.com/2018/06/19/12/indiewebsummit","category":["indieweb"],"syndication":["https://twitter.com/aaronpk/status/1009187255204732928"],"content":{"text":"I\'m excited to announce that @namedotcom is our newest sponsor of @IndieWebSummit and they\'ll be joining us next week! It\'s not too late to register! \ud83d\udd1c https://2018.indieweb.org","html":"I\'m excited to announce that <a href=\"https://twitter.com/namedotcom\">@namedotcom</a> is our newest sponsor of <a href=\"https://twitter.com/IndieWebSummit\">@IndieWebSummit</a> and they\'ll be joining us next week! It\'s not too late to register! <a href=\"https://aaronparecki.com/emoji/%F0%9F%94%9C\">\ud83d\udd1c</a> <a href=\"https://2018.indieweb.org\">https://2018.indieweb.org</a>"},"author":{"type":"card","name":"Aaron Parecki","url":"https://aaronparecki.com/","photo":"https://aaronparecki.com/images/profile.jpg"}},"url":"https://aaronparecki.com/2018/06/19/12/indiewebsummit","code":200}
  39. ', true);
  40. unset($data['data']['author']);
  41. $links = FindLinks::all($data['data']);
  42. $this->assertContains('https://aaronparecki.com/2018/06/19/12/indiewebsummit', $links);
  43. $this->assertContains('https://twitter.com/aaronpk/status/1009187255204732928', $links);
  44. $this->assertContains('https://2018.indieweb.org', $links);
  45. $this->assertContains('https://twitter.com/namedotcom', $links);
  46. $this->assertContains('https://twitter.com/IndieWebSummit', $links);
  47. $this->assertContains('https://aaronparecki.com/emoji/%F0%9F%94%9C', $links);
  48. }
  49. }