Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.
 
 
 
 
 
 

109 lines
3.3 KiB

  1. <?php
  2. namespace Friendica\Test\src\Network;
  3. use Friendica\Network\Probe;
  4. use PHPUnit\Framework\TestCase;
  5. class ProbeTest extends TestCase
  6. {
  7. const TEMPLATENOBASE = '
  8. <!DOCTYPE html>
  9. <html lang="en-us">
  10. <head>
  11. <title>Example Blog</title>
  12. <link href="{{$link}}" rel="alternate" type="application/rss+xml" title="Example Blog" />
  13. <link href="{{$link}}" rel="feed" type="application/rss+xml" title="Example Blog" />
  14. </head>
  15. <body>
  16. <p>Hello World!</p>
  17. </body>
  18. </html>';
  19. const TEMPLATEBASE = '
  20. <!DOCTYPE html>
  21. <html lang="en-us">
  22. <head>
  23. <title>Example Blog</title>
  24. <link href="{{$link}}" rel="alternate" type="application/rss+xml" title="Example Blog" />
  25. <link href="{{$link}}" rel="feed" type="application/rss+xml" title="Example Blog" />
  26. <base href="{{$url}}">
  27. </head>
  28. <body>
  29. <p>Hello World!</p>
  30. </body>
  31. </html>';
  32. const EXPECTED = [
  33. 'https://example.org/path/to/blog/index.php' => [
  34. 'index.xml' => 'https://example.org/path/to/blog/index.xml',
  35. './index.xml' => 'https://example.org/path/to/blog/index.xml',
  36. '../index.xml' => 'https://example.org/path/to/index.xml',
  37. '/index.xml' => 'https://example.org/index.xml',
  38. '//example.com/index.xml' => 'https://example.com/index.xml',
  39. ],
  40. 'https://example.org/path/to/blog/' => [
  41. 'index.xml' => 'https://example.org/path/to/blog/index.xml',
  42. './index.xml' => 'https://example.org/path/to/blog/index.xml',
  43. '../index.xml' => 'https://example.org/path/to/index.xml',
  44. '/index.xml' => 'https://example.org/index.xml',
  45. '//example.com/index.xml' => 'https://example.com/index.xml',
  46. ],
  47. 'https://example.org/blog/' => [
  48. 'index.xml' => 'https://example.org/blog/index.xml',
  49. './index.xml' => 'https://example.org/blog/index.xml',
  50. '../index.xml' => 'https://example.org/index.xml',
  51. '/index.xml' => 'https://example.org/index.xml',
  52. '//example.com/index.xml' => 'https://example.com/index.xml',
  53. ],
  54. 'https://example.org' => [
  55. 'index.xml' => 'https://example.org/index.xml',
  56. './index.xml' => 'https://example.org/index.xml',
  57. '../index.xml' => 'https://example.org/index.xml',
  58. '/index.xml' => 'https://example.org/index.xml',
  59. '//example.com/index.xml' => 'https://example.com/index.xml',
  60. ],
  61. ];
  62. private function replaceMacros($template, $vars)
  63. {
  64. foreach ($vars as $var => $value) {
  65. $template = str_replace('{{' . $var . '}}', $value, $template);
  66. }
  67. return $template;
  68. }
  69. /**
  70. * @small
  71. */
  72. public function testGetFeedLinkNoBase()
  73. {
  74. foreach (self::EXPECTED as $url => $hrefs) {
  75. foreach ($hrefs as $href => $expected) {
  76. $body = $this->replaceMacros(self::TEMPLATENOBASE, ['$link' => $href]);
  77. $feedLink = Probe::getFeedLink($url, $body);
  78. $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href);
  79. }
  80. }
  81. }
  82. /**
  83. * @small
  84. */
  85. public function testGetFeedLinkBase()
  86. {
  87. foreach (self::EXPECTED as $url => $hrefs) {
  88. foreach ($hrefs as $href => $expected) {
  89. $body = $this->replaceMacros(self::TEMPLATEBASE, ['$url' => $url, '$link' => $href]);
  90. $feedLink = Probe::getFeedLink('http://example.com', $body);
  91. $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href);
  92. }
  93. }
  94. }
  95. }