multi-downloader-client/tests/MultiDownloaderClientTest.php
Nicolas COMPAIN 24e3d9aa50
All checks were successful
continuous-integration/drone/push Build is passing
add parameter file name to htmlForm() method
2024-01-28 11:25:10 +00:00

65 lines
2.1 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->assertTrue(true);
}
public function testFormDlZipNameSpecified()
{
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
$client->setFiles($this->testFiles());
$output = $client->htmlForm("test123");
$this->assertStringContainsString('action="https://multi-dl.kub.nwb.fr/v2/form/zip/test123.zip"', $output);
}
}