From: Hypolite Petovan Date: Thu, 21 May 2020 04:24:46 +0000 (-0400) Subject: Add tests for Network\Probe::getFeedLink X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=782218f781343969b797ec00b7e5f397cb6a10ed;p=friendica.git Add tests for Network\Probe::getFeedLink --- 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 @@ + + + + Example Blog + + + + +

Hello World!

+ +'; + + const TEMPLATEBASE = ' + + + + Example Blog + + + + + +

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); + } + } + } +}