Skip to content

Commit

Permalink
e_library_managerTest::testDetectionVersionConsistency(): No Internet
Browse files Browse the repository at this point in the history
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: #4560
  • Loading branch information
Deltik committed Sep 10, 2021
1 parent daf0008 commit 996fc17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 16 additions & 7 deletions e107_handlers/library_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,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).
Expand Down Expand Up @@ -898,8 +898,8 @@ public function config()
),*/
// Override library path to CDN.
'library_path' => 'https://use.fontawesome.com/releases',
'path' => 'v5.8.1',
'version' => '5.8.1',
'path' => 'v5.15.2',
'version' => '5.15.2',
);

// Font-Awesome (local).
Expand Down Expand Up @@ -1064,12 +1064,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;
}

/**
Expand Down Expand Up @@ -1501,7 +1510,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)
Expand Down Expand Up @@ -2149,7 +2158,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)
Expand Down
12 changes: 10 additions & 2 deletions e107_tests/tests/unit/e_library_managerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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']))
{
Expand Down

0 comments on commit 996fc17

Please sign in to comment.