From dc634d357e60c10421471b7865a1ff269e50da71 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Fri, 10 Sep 2021 17:19:30 +0200 Subject: [PATCH] `e_library_managerTest::testDetectionVersionConsistency()`: No Internet Removed Internet dependency for test `e_library_managerTest::testDetectionVersionConsistency()` And now the test is actually useful because it can now detect the version mismatch between the local copy and the CDN link Fixes: https://github.com/e107inc/e107/issues/4560 --- e107_handlers/library_manager.php | 23 +++++++++++++------ .../tests/unit/e_library_managerTest.php | 12 ++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/e107_handlers/library_manager.php b/e107_handlers/library_manager.php index f8a9dc985f..fe602c01c8 100755 --- a/e107_handlers/library_manager.php +++ b/e107_handlers/library_manager.php @@ -154,8 +154,8 @@ public function config() ), // Override library path to CDN. 'library_path' => 'https://cdn.jsdelivr.net/jquery.once', - 'path' => '2.1.2', - 'version' => '2.1.2', + 'path' => '2.2.3', + 'version' => '2.2.3', ); // jQuery Once (local). @@ -238,8 +238,8 @@ public function config() ), // Override library path to CDN. 'library_path' => 'https://cdn.jsdelivr.net/jquery.ui', - 'path' => '1.11.4', - 'version' => '1.11.4', + 'path' => '1.12.1', + 'version' => '1.12.1', ); // jQuery UI (local). @@ -1173,12 +1173,21 @@ class e_library_manager /** @var array list of callbacks to track performance */ private $callbacks = array(); + /** + * @var e_file + */ + private $fileHandler; + /** * Constructor * Use {@link getInstance()}, direct instantiating is not possible for signleton objects. + * + * @param e_file|null $fileHandler */ - public function __construct() + public function __construct($fileHandler = null) { + if ($fileHandler === null) $fileHandler = e107::getFile(); + $this->fileHandler = $fileHandler; } /** @@ -1613,7 +1622,7 @@ private function getLibraries() $directories = array(); // Retrieve list of directories. - $file = e107::getFile(); + $file = $this->fileHandler; $dirs = $file->get_dirs($dir); foreach($dirs as $dirName) @@ -2261,7 +2270,7 @@ private function getVersion($library, $options) // The library will be cached with version number, so this only run once per library. if(strpos($file, 'http') === 0) { - $content = e107::getFile()->getRemoteContent($file); + $content = $this->fileHandler->getRemoteContent($file); $tmpFile = tempnam(sys_get_temp_dir(), 'lib_'); if($tmpFile) diff --git a/e107_tests/tests/unit/e_library_managerTest.php b/e107_tests/tests/unit/e_library_managerTest.php index 892dca198e..db30158ec8 100644 --- a/e107_tests/tests/unit/e_library_managerTest.php +++ b/e107_tests/tests/unit/e_library_managerTest.php @@ -20,7 +20,15 @@ protected function _before() try { - $this->lib = $this->make('e_library_manager'); + $fakeFile = $this->make('e_file', [ + 'getRemoteContent' => function($url) + { + throw new RuntimeException("Test needs rewriting. Blocked Internet fetch of URL: $url"); + }, + ]); + $this->lib = $this->make('e_library_manager', [ + 'fileHandler' => $fakeFile, + ]); } catch(Exception $e) { @@ -72,7 +80,7 @@ function testDetectionVersionConsistency() foreach($this->libraries as $name) { $coded = $this->lib->detect($name); - $detected = $this->lib->detect($name, true); + $detected = $this->lib->detect(str_replace('cdn.', '', $name), true); if(empty($coded['version'])) {