From fe3713d2e5c91e2d07af72b39f321521d3dd470c Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Mon, 3 Dec 2018 01:35:14 +0100 Subject: [PATCH] namespacing: move LinkUtils along \Shaarli\Bookmark classes Signed-off-by: VirtualTam --- application/{ => bookmark}/LinkUtils.php | 4 +- index.php | 2 +- tests/{ => bookmark}/LinkUtilsTest.php | 142 +++++------------------ tests/plugins/PluginMarkdownTest.php | 1 + tests/utils/CurlUtils.php | 94 +++++++++++++++ 5 files changed, 125 insertions(+), 118 deletions(-) rename application/{ => bookmark}/LinkUtils.php (97%) rename tests/{ => bookmark}/LinkUtilsTest.php (76%) create mode 100644 tests/utils/CurlUtils.php diff --git a/application/LinkUtils.php b/application/bookmark/LinkUtils.php similarity index 97% rename from application/LinkUtils.php rename to application/bookmark/LinkUtils.php index b5110edc..de5b61cb 100644 --- a/application/LinkUtils.php +++ b/application/bookmark/LinkUtils.php @@ -7,7 +7,7 @@ use Shaarli\Bookmark\LinkDB; * * @param string $charset to extract from the downloaded page (reference) * @param string $title to extract from the downloaded page (reference) - * @param string $curlGetInfo Optionnaly overrides curl_getinfo function + * @param string $curlGetInfo Optionally overrides curl_getinfo function * * @return Closure */ @@ -198,7 +198,7 @@ function space2nbsp($text) * * @param string $description shaare's description. * @param string $redirector if a redirector is set, use it to gerenate links. - * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. + * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. * @param string $indexUrl URL to Shaarli's index. * @return string formatted description. diff --git a/index.php b/index.php index dbb3c6fc..146b4457 100644 --- a/index.php +++ b/index.php @@ -57,13 +57,13 @@ require_once __DIR__ . '/vendor/autoload.php'; // Shaarli library require_once 'application/ApplicationUtils.php'; +require_once 'application/bookmark/LinkUtils.php'; require_once 'application/config/ConfigPlugin.php'; require_once 'application/feed/Cache.php'; require_once 'application/http/HttpUtils.php'; require_once 'application/http/UrlUtils.php'; require_once 'application/FileUtils.php'; require_once 'application/History.php'; -require_once 'application/LinkUtils.php'; require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/TimeZone.php'; require_once 'application/Utils.php'; diff --git a/tests/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php similarity index 76% rename from tests/LinkUtilsTest.php rename to tests/bookmark/LinkUtilsTest.php index 5407159a..1b8688e6 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php @@ -1,11 +1,15 @@ stuff'. $title .''; + $html = 'stuff' . $title . ''; $this->assertEquals($title, html_extract_title($html)); - $html = ''. $title .'blablaanother'; + $html = '' . $title . 'blablaanother'; $this->assertEquals($title, html_extract_title($html)); } @@ -34,7 +38,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase public function testHeadersExtractExistentCharset() { $charset = 'x-MacCroatian'; - $headers = 'text/html; charset='. $charset; + $headers = 'text/html; charset=' . $charset; $this->assertEquals(strtolower($charset), header_extract_charset($headers)); } @@ -56,7 +60,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase public function testHtmlExtractExistentCharset() { $charset = 'x-MacCroatian'; - $html = 'stuff2'; + $html = 'stuff2'; $this->assertEquals(strtolower($charset), html_extract_charset($html)); } @@ -84,8 +88,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase 'Content-Type: text/html; charset=utf-8', 'Status: 200 OK', 'end' => 'th=device-width">' - .'Refactoring · GitHub' - .'' - .'Refactoring · GitHub' - .'', 'end' => 'th=device-width">' - .'Refactoring · GitHub' - .'' - .'http://hello.there/is=someone#here otherstuff'; + . 'http://hello.there/is=someone#here otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; $expectedText = 'stuff ' - .'http://hello.there/is=someone#here(please) otherstuff'; + . 'http://hello.there/is=someone#here(please) otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; $expectedText = 'stuff ' - .'http://hello.there/is=someone#here(please)&no otherstuff'; + . 'http://hello.there/is=someone#here(please)&no otherstuff'; $processedText = text2clickable($text, ''); $this->assertEquals($expectedText, $processedText); } @@ -242,7 +246,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase { $text = 'stuff http://hello.there/is=someone#here otherstuff'; $redirector = 'http://redirector.to'; - $expectedText = 'stuff http://hello.there/is=someone#here otherstuff'; @@ -257,7 +261,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase { $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; $redirector = 'http://redirector.to'; - $expectedText = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; @@ -270,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase */ public function testSpace2nbsp() { - $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; - $expectedText = '  Are you   thrilled  by flags   ?'. PHP_EOL .' Really?'; + $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?'; + $expectedText = '  Are you   thrilled  by flags   ?' . PHP_EOL . ' Really?'; $processedText = space2nbsp($text); $this->assertEquals($expectedText, $processedText); } @@ -317,105 +321,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase * Util function to build an hashtag link. * * @param string $hashtag Hashtag name. - * @param string $index Index URL. + * @param string $index Index URL. * * @return string HTML hashtag link. */ private function getHashtagLink($hashtag, $index = '') { - $hashtagLink = '#$1'; + $hashtagLink = '#$1'; return str_replace('$1', $hashtag, $hashtagLink); } } - -// old style mock: PHPUnit doesn't allow function mock - -/** - * Returns code 200 or html content type. - * - * @param resource $ch cURL resource - * @param int $type cURL info type - * - * @return int|string 200 or 'text/html' - */ -function ut_curl_getinfo_ok($ch, $type) -{ - switch ($type) { - case CURLINFO_RESPONSE_CODE: - return 200; - case CURLINFO_CONTENT_TYPE: - return 'text/html; charset=utf-8'; - } -} - -/** - * Returns code 200 or html content type without charset. - * - * @param resource $ch cURL resource - * @param int $type cURL info type - * - * @return int|string 200 or 'text/html' - */ -function ut_curl_getinfo_no_charset($ch, $type) -{ - switch ($type) { - case CURLINFO_RESPONSE_CODE: - return 200; - case CURLINFO_CONTENT_TYPE: - return 'text/html'; - } -} - -/** - * Invalid response code. - * - * @param resource $ch cURL resource - * @param int $type cURL info type - * - * @return int|string 404 or 'text/html' - */ -function ut_curl_getinfo_rc_ko($ch, $type) -{ - switch ($type) { - case CURLINFO_RESPONSE_CODE: - return 404; - case CURLINFO_CONTENT_TYPE: - return 'text/html; charset=utf-8'; - } -} - -/** - * Invalid content type. - * - * @param resource $ch cURL resource - * @param int $type cURL info type - * - * @return int|string 200 or 'text/plain' - */ -function ut_curl_getinfo_ct_ko($ch, $type) -{ - switch ($type) { - case CURLINFO_RESPONSE_CODE: - return 200; - case CURLINFO_CONTENT_TYPE: - return 'text/plain'; - } -} - -/** - * Invalid response code and content type. - * - * @param resource $ch cURL resource - * @param int $type cURL info type - * - * @return int|string 404 or 'text/plain' - */ -function ut_curl_getinfo_rs_ct_ko($ch, $type) -{ - switch ($type) { - case CURLINFO_RESPONSE_CODE: - return 404; - case CURLINFO_CONTENT_TYPE: - return 'text/plain'; - } -} diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 44364b05..d6951866 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -5,6 +5,7 @@ use Shaarli\Config\ConfigManager; * PluginMarkdownTest.php */ +require_once 'application/bookmark/LinkUtils.php'; require_once 'application/Utils.php'; require_once 'plugins/markdown/markdown.php'; diff --git a/tests/utils/CurlUtils.php b/tests/utils/CurlUtils.php new file mode 100644 index 00000000..1cc4907e --- /dev/null +++ b/tests/utils/CurlUtils.php @@ -0,0 +1,94 @@ +