multi-downloader-client/tests/MultiDownloaderClientTest.php

73 lines
2.5 KiB
PHP
Raw Normal View History

2024-01-11 10:33:29 +00:00
<?php
include __DIR__ . '/../vendor/autoload.php';
2024-01-11 12:23:26 +00:00
use Nwb\MultiDownloaderClient\FileRequest;
2024-01-11 10:33:29 +00:00
use Nwb\MultiDownloaderClient\MultiDownloaderClient;
2024-03-18 12:38:14 +00:00
use Nwb\MultiDownloaderClient\Watermark;
2024-03-18 13:15:48 +00:00
use Nwb\MultiDownloaderClient\WatermarkOption;
2024-01-11 10:33:29 +00:00
use PHPUnit\Framework\TestCase;
class MultiDownloaderClientTest extends TestCase
{
2024-01-11 13:05:59 +00:00
private $testFiles = [
2024-03-18 12:38:14 +00:00
'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'
2024-01-11 13:05:59 +00:00
];
private function testFiles()
{
2024-01-12 13:04:17 +00:00
return array_map(function ($url, $i) {
2024-01-12 14:00:06 +00:00
$file = new FileRequest($url);
$file->getFileOptions()->name('test' . $i . '.png');
2024-03-18 13:15:48 +00:00
$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)
]);
2024-03-18 12:38:14 +00:00
2024-03-18 13:15:48 +00:00
$file->getImageEditOptions()->addWatermark($watermark);
2024-03-18 12:38:14 +00:00
2024-01-12 14:00:06 +00:00
return $file;
2024-01-12 13:04:17 +00:00
}, $this->testFiles, array_keys($this->testFiles));
2024-01-11 13:05:59 +00:00
}
2024-01-11 12:39:51 +00:00
public function testDownloadAsString()
2024-01-11 12:23:26 +00:00
{
2024-01-12 12:26:11 +00:00
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
2024-01-11 13:20:58 +00:00
$client->setFiles($this->testFiles());
$response = $client->downloadAsString();
2024-01-11 12:39:51 +00:00
$md5 = md5($response);
2024-03-18 12:38:14 +00:00
$this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5);
2024-01-11 12:39:51 +00:00
}
public function testDownloadTo()
{
2024-01-12 12:26:11 +00:00
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
2024-01-12 14:00:06 +00:00
$path = sys_get_temp_dir() . '/testDownloadTo.zip';
2024-01-11 13:20:58 +00:00
$client->setFiles($this->testFiles());
$client->downloadTo($path);
2024-01-11 12:39:51 +00:00
$md5 = md5_file($path);
$this->assertFileExists($path);
2024-03-18 12:38:14 +00:00
$this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5);
2024-01-11 12:23:26 +00:00
}
2024-01-11 13:05:59 +00:00
public function testForm()
{
2024-01-12 12:26:11 +00:00
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
2024-01-11 13:20:58 +00:00
$client->setFiles($this->testFiles());
// echo $client->htmlForm();
$this->assertTrue(true);
2024-01-11 13:05:59 +00:00
}
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);
}
2024-01-11 10:33:29 +00:00
}