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.

63 lines
1.9 KiB

  1. <?php
  2. class HelpersTest extends PHPUnit\Framework\TestCase
  3. {
  4. public function testLowercaseHostname()
  5. {
  6. $url = 'http://Example.com/';
  7. $result = p3k\XRay\normalize_url($url);
  8. $this->assertEquals('http://example.com/', $result);
  9. }
  10. public function testAddsSlashToBareDomain()
  11. {
  12. $url = 'http://example.com';
  13. $result = p3k\XRay\normalize_url($url);
  14. $this->assertEquals('http://example.com/', $result);
  15. }
  16. public function testDoesNotModify()
  17. {
  18. $url = 'https://example.com/';
  19. $result = p3k\XRay\normalize_url($url);
  20. $this->assertEquals('https://example.com/', $result);
  21. }
  22. public function testURLEquality()
  23. {
  24. $url1 = 'https://example.com/';
  25. $url2 = 'https://example.com';
  26. $result = p3k\XRay\urls_are_equal($url1, $url2);
  27. $this->assertEquals(true, $result);
  28. }
  29. public function testFindMicroformatsByType()
  30. {
  31. $html = <<<EOF
  32. <div class="h-feed">
  33. <div class="u-author h-card">
  34. <a href="/1" class="u-url p-name">Author</a>
  35. </div>
  36. <div class="h-entry">
  37. <div class="u-author h-card">
  38. <a href="/2" class="u-url p-name">Author</a>
  39. </div>
  40. </div>
  41. <div class="h-card">
  42. <a href="/3" class="u-url p-name">Author</a>
  43. </div>
  44. </div>
  45. <div class="h-card">
  46. <a href="/4" class="u-url p-name">Author</a>
  47. </div>
  48. EOF;
  49. $mf2 = \Mf2\parse($html);
  50. $hcards = \p3k\XRay\Formats\Mf2::findAllMicroformatsByType($mf2, 'h-card');
  51. $this->assertEquals('/1', $hcards[0]['properties']['url'][0]);
  52. $this->assertEquals('/2', $hcards[1]['properties']['url'][0]);
  53. $this->assertEquals('/3', $hcards[2]['properties']['url'][0]);
  54. $this->assertEquals('/4', $hcards[3]['properties']['url'][0]);
  55. }
  56. }