Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Internet dependency from test e_library_managerTest::testDetectionVersionConsistency() #4561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 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 @@ -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;
}

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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