diff --git a/tests/Fileshare/FileshareFilesActionTest.php b/tests/Fileshare/FileshareFilesActionTest.php new file mode 100644 index 00000000..94bfe41d --- /dev/null +++ b/tests/Fileshare/FileshareFilesActionTest.php @@ -0,0 +1,25 @@ +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'); + } +} diff --git a/tests/FileshareTestCase.php b/tests/FileshareTestCase.php index 52fa62f5..f29d48c0 100644 --- a/tests/FileshareTestCase.php +++ b/tests/FileshareTestCase.php @@ -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 + */ + 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 $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); + } }