diff --git a/tests/src/Network/ProbeTest.php b/tests/src/Network/ProbeTest.php new file mode 100644 index 0000000000..2dfc0e2ac8 --- /dev/null +++ b/tests/src/Network/ProbeTest.php @@ -0,0 +1,108 @@ + + +
+Hello World!
+ +'; + + const TEMPLATEBASE = ' + + + +Hello World!
+ +'; + + const EXPECTED = [ + 'https://example.org/path/to/blog/index.php' => [ + 'index.xml' => 'https://example.org/path/to/blog/index.xml', + './index.xml' => 'https://example.org/path/to/blog/index.xml', + '../index.xml' => 'https://example.org/path/to/index.xml', + '/index.xml' => 'https://example.org/index.xml', + '//example.com/index.xml' => 'https://example.com/index.xml', + ], + 'https://example.org/path/to/blog/' => [ + 'index.xml' => 'https://example.org/path/to/blog/index.xml', + './index.xml' => 'https://example.org/path/to/blog/index.xml', + '../index.xml' => 'https://example.org/path/to/index.xml', + '/index.xml' => 'https://example.org/index.xml', + '//example.com/index.xml' => 'https://example.com/index.xml', + ], + 'https://example.org/blog/' => [ + 'index.xml' => 'https://example.org/blog/index.xml', + './index.xml' => 'https://example.org/blog/index.xml', + '../index.xml' => 'https://example.org/index.xml', + '/index.xml' => 'https://example.org/index.xml', + '//example.com/index.xml' => 'https://example.com/index.xml', + ], + 'https://example.org' => [ + 'index.xml' => 'https://example.org/index.xml', + './index.xml' => 'https://example.org/index.xml', + '../index.xml' => 'https://example.org/index.xml', + '/index.xml' => 'https://example.org/index.xml', + '//example.com/index.xml' => 'https://example.com/index.xml', + ], + ]; + + private function replaceMacros($template, $vars) + { + foreach ($vars as $var => $value) { + $template = str_replace('{{' . $var . '}}', $value, $template); + } + + return $template; + } + + /** + * @small + */ + public function testGetFeedLinkNoBase() + { + foreach (self::EXPECTED as $url => $hrefs) { + foreach ($hrefs as $href => $expected) { + $body = $this->replaceMacros(self::TEMPLATENOBASE, ['$link' => $href]); + + $feedLink = Probe::getFeedLink($url, $body); + + $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href); + } + } + } + + /** + * @small + */ + public function testGetFeedLinkBase() + { + foreach (self::EXPECTED as $url => $hrefs) { + foreach ($hrefs as $href => $expected) { + $body = $this->replaceMacros(self::TEMPLATEBASE, ['$url' => $url, '$link' => $href]); + + $feedLink = Probe::getFeedLink('http://example.com', $body); + + $this->assertEquals($expected, $feedLink, 'base url = ' . $url . ' | href = ' . $href); + } + } + } +}