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 25a8b68 commit c5da7e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
27 changes: 18 additions & 9 deletions e107_handlers/library_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -929,9 +929,9 @@ public function config()
),
'variants' => array(),
// Override library path to CDN.
'library_path' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0',
'library_path' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2',
'path' => '',
'version' => '5.14.0',
'version' => '5.15.2',
);

// Font-Awesome (local).
Expand Down Expand Up @@ -1094,12 +1094,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 @@ -1534,7 +1543,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 @@ -2182,7 +2191,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 c5da7e7

Please sign in to comment.