/**
* @covers FOF30\Download\Download::importFromUrl
*
* @dataProvider FOF30\Tests\Download\DownloadDataprovider::getTestImportFromUrl
*
* @param array $config
* @param array $params
* @param array $test
*/
public function testImportFromUrl(array $config, array $params, array $test)
{
// Set up the FakeCurl simulator
FakeCurl::setUp($config);
// Get the download class
$download = new Download(static::$container);
$download->setAdapter('curl');
// Initialise
$loopAllowed = $test['loop'];
// Get the output file name
$platformDirs = static::$container->platform->getPlatformBaseDirs();
$tmpDir = $platformDirs['tmp'];
$localFilename = $tmpDir . '/test.dat';
// Set up the download parameters
$params['localFilename'] = $localFilename;
#$params['maxExecTime'] = $test['loop'] ? 10000 : 0;
$params['maxExecTime'] = 0;
if (isset($test['localfile'])) {
if (empty($test['localfile'])) {
unset($params['localFilename']);
} else {
$params['localFilename'] = $test['localfile'];
}
}
// Remove the local filename if it's still there
@unlink($localFilename);
do {
$ret = $download->importFromURL($params);
if ($loopAllowed) {
$loopAllowed = !($ret['frag'] == -1 || $ret['error']);
}
$params = array_merge($params, $ret);
if (isset($params['localFilename']) && !empty($params['localFilename'])) {
$localFilename = $params['localFilename'];
}
} while ($loopAllowed);
foreach ($test['expect'] as $k => $v) {
// Validate expected parameters
$this->assertEquals($v, $ret[$k], $test['message'] . " (returned {$k} does not match)");
}
// Check the return size
if (!$test['expect']['error']) {
$fileSize = @filesize($localFilename);
$this->assertEquals($test['retSize'], $fileSize, $test['message'] . " (size doesn't match {$test['retSize']})");
}
// Remove the local filename if it's still there
@unlink($localFilename);
}