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.3 KiB

  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. }