3 namespace Friendica\Test\src\Network;
5 use Friendica\Network\Probe;
6 use PHPUnit\Framework\TestCase;
8 class ProbeTest extends TestCase
10 const TEMPLATENOBASE = '
14 <title>Example Blog</title>
15 <link href="{{$link}}" rel="alternate" type="application/rss+xml" title="Example Blog" />
16 <link href="{{$link}}" rel="feed" type="application/rss+xml" title="Example Blog" />
23 const TEMPLATEBASE = '
27 <title>Example Blog</title>
28 <link href="{{$link}}" rel="alternate" type="application/rss+xml" title="Example Blog" />
29 <link href="{{$link}}" rel="feed" type="application/rss+xml" title="Example Blog" />
30 <base href="{{$url}}">
38 'https://example.org/path/to/blog/index.php' => [
39 'index.xml' => 'https://example.org/path/to/blog/index.xml',
40 './index.xml' => 'https://example.org/path/to/blog/index.xml',
41 '../index.xml' => 'https://example.org/path/to/index.xml',
42 '/index.xml' => 'https://example.org/index.xml',
43 '//example.com/index.xml' => 'https://example.com/index.xml',
45 'https://example.org/path/to/blog/' => [
46 'index.xml' => 'https://example.org/path/to/blog/index.xml',
47 './index.xml' => 'https://example.org/path/to/blog/index.xml',
48 '../index.xml' => 'https://example.org/path/to/index.xml',
49 '/index.xml' => 'https://example.org/index.xml',
50 '//example.com/index.xml' => 'https://example.com/index.xml',
52 'https://example.org/blog/' => [
53 'index.xml' => 'https://example.org/blog/index.xml',
54 './index.xml' => 'https://example.org/blog/index.xml',
55 '../index.xml' => 'https://example.org/index.xml',
56 '/index.xml' => 'https://example.org/index.xml',
57 '//example.com/index.xml' => 'https://example.com/index.xml',
59 'https://example.org' => [
60 'index.xml' => 'https://example.org/index.xml',
61 './index.xml' => 'https://example.org/index.xml',
62 '../index.xml' => 'https://example.org/index.xml',
63 '/index.xml' => 'https://example.org/index.xml',
64 '//example.com/index.xml' => 'https://example.com/index.xml',
68 private function replaceMacros($template, $vars)
70 foreach ($vars as $var => $value) {
71 $template = str_replace('{{' . $var . '}}', $value, $template);
80 public function testGetFeedLinkNoBase()
82 foreach (self::EXPECTED as $url => $hrefs) {
83 foreach ($hrefs as $href => $expected) {
84 $body = $this->replaceMacros(self::TEMPLATENOBASE, ['$link' => $href]);
86 $feedLink = Probe::getFeedLink($url, $body);
88 $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href);
96 public function testGetFeedLinkBase()
98 foreach (self::EXPECTED as $url => $hrefs) {
99 foreach ($hrefs as $href => $expected) {
100 $body = $this->replaceMacros(self::TEMPLATEBASE, ['$url' => $url, '$link' => $href]);
102 $feedLink = Probe::getFeedLink('http://example.com', $body);
104 $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href);