Add tests
This commit is contained in:
parent
f04cf7a1b2
commit
0ad6b40393
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fileshare;
|
||||
|
||||
use App\Fileshare\ConnectionTypes\OwncloudConnection;
|
||||
use App\Fileshare\Models\Fileshare;
|
||||
use Tests\FileshareTestCase;
|
||||
|
||||
class FileshareFilesActionTest extends FileshareTestCase
|
||||
{
|
||||
public function testItGetsFilesForAConnection(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami()->withOwncloudUser('badenpowell', 'secret')
|
||||
->withDirs('badenpowell', ['/pictures', '/lala']);
|
||||
|
||||
$connection = Fileshare::factory()
|
||||
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'secret', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
|
||||
->create();
|
||||
|
||||
$this->postJson(route('fileshare.files', ['fileshare' => $connection]), [
|
||||
'parent' => null,
|
||||
])->assertJsonPath('data.0.name', 'pictures')
|
||||
->assertJsonPath('data.1.name', 'lala');
|
||||
}
|
||||
}
|
|
@ -2,9 +2,14 @@
|
|||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\WebDAV\WebDAVAdapter;
|
||||
use Sabre\DAV\Client;
|
||||
|
||||
abstract class FileshareTestCase extends TestCase
|
||||
{
|
||||
|
@ -13,6 +18,11 @@ abstract class FileshareTestCase extends TestCase
|
|||
protected string $adminUser = 'admin';
|
||||
protected string $adminPassword = 'admin';
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $passwords = [];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -27,6 +37,7 @@ abstract class FileshareTestCase extends TestCase
|
|||
|
||||
public function withOwncloudUser(string $username, string $password): self
|
||||
{
|
||||
$this->passwords[$username] = $password;
|
||||
$this->http()->asForm()->post('/ocs/v1.php/cloud/users?format=json', ['password' => $password, 'userid' => $username]);
|
||||
|
||||
return $this;
|
||||
|
@ -36,4 +47,34 @@ abstract class FileshareTestCase extends TestCase
|
|||
{
|
||||
return Http::withOptions(['base_uri' => env('TEST_OWNCLOUD_DOMAIN')])->withBasicAuth($this->adminUser, $this->adminPassword)->acceptJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $dirs
|
||||
*/
|
||||
protected function withDirs(string $username, array $dirs): self
|
||||
{
|
||||
$adapter = $this->adapter($username);
|
||||
|
||||
foreach ($adapter->directories() as $directory) {
|
||||
$adapter->deleteDirectory($directory);
|
||||
}
|
||||
dd($adapter->directories());
|
||||
|
||||
$adapter->makeDirectory('lala');
|
||||
$adapter->makeDirectory('aa/zz');
|
||||
$adapter->makeDirectory('aa/zz');
|
||||
dd($adapter->directories());
|
||||
// dd(array_map(fn ($d) => str_replace('remote.php/dav/files/' . $username, '', $d), $adapter->directories()));
|
||||
}
|
||||
|
||||
private function adapter(string $username): FilesystemAdapter
|
||||
{
|
||||
$adapter = new WebDAVAdapter(new Client([
|
||||
'baseUri' => env('TEST_OWNCLOUD_DOMAIN') . '/remote.php/dav/files/' . $username,
|
||||
'userName' => $username,
|
||||
'password' => $this->passwords[$username],
|
||||
]), '/remote.php/dav/files/' . $username);
|
||||
|
||||
return new FilesystemAdapter(new Filesystem($adapter), $adapter);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue