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;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class MultiDownloaderClientTest extends TestCase
|
|
|
|
{
|
2024-01-11 13:05:59 +00:00
|
|
|
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()
|
|
|
|
{
|
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');
|
|
|
|
|
|
|
|
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-01-12 13:04:17 +00:00
|
|
|
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $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-01-12 13:04:17 +00:00
|
|
|
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $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());
|
|
|
|
|
2024-01-14 12:13:13 +00:00
|
|
|
echo $client->htmlForm();
|
|
|
|
$this->assertTrue(true);
|
2024-01-11 13:05:59 +00:00
|
|
|
}
|
2024-01-11 10:33:29 +00:00
|
|
|
}
|