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()
|
|
|
|
{
|
|
|
|
return array_map(function ($url) {
|
|
|
|
return new FileRequest($url);
|
|
|
|
}, $this->testFiles);
|
|
|
|
}
|
|
|
|
|
2024-01-11 12:39:51 +00:00
|
|
|
public function testDownloadAsString()
|
2024-01-11 12:23:26 +00:00
|
|
|
{
|
2024-01-12 09:46:25 +00:00
|
|
|
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test' ]);
|
2024-01-11 12:23:26 +00:00
|
|
|
|
2024-01-11 13:20:58 +00:00
|
|
|
$client->setFiles($this->testFiles());
|
|
|
|
|
|
|
|
$response = $client->downloadAsString();
|
2024-01-11 12:23:26 +00:00
|
|
|
|
2024-01-11 12:39:51 +00:00
|
|
|
$md5 = md5($response);
|
|
|
|
|
|
|
|
$this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDownloadTo()
|
|
|
|
{
|
2024-01-12 09:46:25 +00:00
|
|
|
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test' ]);
|
2024-01-11 12:39:51 +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);
|
|
|
|
$this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5);
|
2024-01-11 12:23:26 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 13:05:59 +00:00
|
|
|
public function testForm()
|
|
|
|
{
|
2024-01-12 09:46:25 +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->testFiles());
|
2024-01-11 13:05:59 +00:00
|
|
|
}
|
2024-01-11 10:33:29 +00:00
|
|
|
}
|