multi-downloader-client/tests/MultiDownloaderClientTest.php
2024-03-18 13:15:48 +00:00

73 lines
2.5 KiB
PHP

<?php
include __DIR__ . '/../vendor/autoload.php';
use Nwb\MultiDownloaderClient\FileRequest;
use Nwb\MultiDownloaderClient\MultiDownloaderClient;
use Nwb\MultiDownloaderClient\Watermark;
use Nwb\MultiDownloaderClient\WatermarkOption;
use PHPUnit\Framework\TestCase;
class MultiDownloaderClientTest extends TestCase
{
private $testFiles = [
'https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/source1.jpg',
'https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/Source_portrait_sans_orientation.jpg'
];
private function testFiles()
{
return array_map(function ($url, $i) {
$file = new FileRequest($url);
$file->getFileOptions()->name('test' . $i . '.png');
$watermark = new Watermark([
new WatermarkOption('https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/watermarks/watermark.png', 100, 100)
]);
$file->getImageEditOptions()->addWatermark($watermark);
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('65b11e1e8b2283f769006cec577ee8e0', $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('65b11e1e8b2283f769006cec577ee8e0', $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);
}
}