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.

67 lines
2.4 KiB

  1. <?php
  2. class LibraryTest extends PHPUnit_Framework_TestCase {
  3. public function testInputIsParsedMf2Array() {
  4. $html = '<div class="h-entry"><p class="p-content p-name">Hello World</p><img src="/photo.jpg"></p></div>';
  5. $mf2 = Mf2\parse($html, 'http://example.com/entry');
  6. $xray = new p3k\XRay();
  7. $data = $xray->process('http://example.com/entry', $mf2);
  8. $this->assertEquals('Hello World', $data['data']['content']['text']);
  9. $this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
  10. }
  11. public function testInputIsParsedMf2JSON() {
  12. $html = '<div class="h-entry"><p class="p-content p-name">Hello World</p><img src="/photo.jpg"></p></div>';
  13. $mf2 = Mf2\parse($html, 'http://example.com/entry');
  14. $xray = new p3k\XRay();
  15. $data = $xray->process('http://example.com/entry', json_encode($mf2));
  16. $this->assertEquals('Hello World', $data['data']['content']['text']);
  17. $this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
  18. }
  19. public function testInputIsParsedMf2HCard() {
  20. $url = 'https://waterpigs.co.uk/';
  21. $html = '<a class="h-card" href="https://waterpigs.co.uk/">Barnaby Walters</a>';
  22. $mf2 = Mf2\parse($html, $url);
  23. $xray = new p3k\XRay();
  24. $data = $xray->process($url, $mf2);
  25. $this->assertEquals('card', $data['data']['type']);
  26. $this->assertEquals('Barnaby Walters', $data['data']['name']);
  27. }
  28. public function testNoHEntryMarkupMF2JSON() {
  29. $url = 'http://example.com/';
  30. $html = '<p><a href="http://target.example.com/">Target</a></p>';
  31. $mf2 = Mf2\parse($html, $url);
  32. $xray = new p3k\XRay();
  33. $data = $xray->process($url, $mf2);
  34. $this->assertEquals('unknown', $data['data']['type']);
  35. }
  36. public function testNoHEntryMarkup() {
  37. $url = 'http://example.com/';
  38. $html = '<p><a href="http://target.example.com/">Target</a></p>';
  39. $xray = new p3k\XRay();
  40. $data = $xray->parse($url, $html);
  41. $this->assertEquals('unknown', $data['data']['type']);
  42. }
  43. public function testNoHEntryMarkupWithTarget() {
  44. $url = 'http://example.com/';
  45. $html = '<p><a href="http://target.example.com/">Target</a></p>';
  46. $xray = new p3k\XRay();
  47. $data = $xray->parse($url, $html, ['target' => 'http://target.example.com/']);
  48. $this->assertEquals('unknown', $data['data']['type']);
  49. $this->assertArrayNotHasKey('error', $data);
  50. $this->assertArrayNotHasKey('html', $data);
  51. }
  52. }