multi-downloader-client/tests/MultiDownloaderClientTest.php
Mathieu e389e72844
Some checks failed
continuous-integration/drone/push Build is failing
FileOptions class
2024-01-12 14:00:06 +00:00

62 lines
1.8 KiB
PHP

<?php
include __DIR__ . '/../vendor/autoload.php';
use Nwb\MultiDownloaderClient\FileRequest;
use Nwb\MultiDownloaderClient\MultiDownloaderClient;
use PHPUnit\Framework\TestCase;
class MultiDownloaderClientTest extends TestCase
{
private $testFiles = [
'https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/portrait.png',
'https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/paysage.png'
];
private function testFiles()
{
return array_map(function ($url, $i) {
$file = new FileRequest($url);
$file->getFileOptions()->name('test' . $i . '.png');
return $file;
}, $this->testFiles, array_keys($this->testFiles));
}
public function testDownloadAsString()
{
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
$client->setFiles($this->testFiles());
$response = $client->downloadAsString();
$md5 = md5($response);
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5);
}
public function testDownloadTo()
{
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
$path = sys_get_temp_dir() . '/testDownloadTo.zip';
$client->setFiles($this->testFiles());
$client->downloadTo($path);
$md5 = md5_file($path);
$this->assertFileExists($path);
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5);
}
public function testForm()
{
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
$client->setFiles($this->testFiles());
echo $client->htmlForm($this->testFiles());
}
}