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.

57 lines
1.7 KiB

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