multi-downloader-client/tests/MultiDownloaderClientTest.php

60 lines
1.7 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;
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) {
return (new FileRequest($url))
->fileOptions(['name' => 'test' . $i . '.png']);
}, $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 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);
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-11 12:39:51 +00:00
2024-01-12 13:04:17 +00:00
$path = __DIR__ . '/testDownloadTo.zip';
2024-01-11 12:39:51 +00:00
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());
echo $client->htmlForm($this->testFiles());
2024-01-11 13:05:59 +00:00
}
2024-01-11 10:33:29 +00:00
}