adrema/tests/Fileshare/FileshareStoreActionTest.php

84 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2024-06-27 00:19:12 +02:00
<?php
namespace Tests\Fileshare;
2024-07-13 22:30:34 +02:00
use App\Fileshare\ConnectionTypes\NextcloudConnection;
2024-06-27 00:19:12 +02:00
use App\Fileshare\ConnectionTypes\OwncloudConnection;
2024-06-27 17:41:54 +02:00
use App\Fileshare\Models\Fileshare;
2024-06-27 00:19:12 +02:00
use Tests\FileshareTestCase;
2024-06-27 12:48:20 +02:00
class FileshareStoreActionTest extends FileshareTestCase
2024-06-27 00:19:12 +02:00
{
public function testItStoresAConnection(): void
{
2024-07-13 22:30:34 +02:00
$this->withoutExceptionHandling()->login()->loginNami()->withUser('badenpowell', 'secret');
2024-06-27 00:19:12 +02:00
$this->post(route('fileshare.store'), [
'name' => 'Lala',
'type' => OwncloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'secret',
'base_url' => env('TEST_OWNCLOUD_DOMAIN'),
]
])->assertOk();
2024-06-27 17:41:54 +02:00
$connection = Fileshare::firstOrFail();
2024-06-27 00:19:12 +02:00
$this->assertEquals('badenpowell', $connection->type->user);
$this->assertEquals('secret', $connection->type->password);
$this->assertEquals(env('TEST_OWNCLOUD_DOMAIN'), $connection->type->baseUrl);
$this->assertEquals('Lala', $connection->name);
}
public function testItChecksConnection(): void
{
$this->withExceptionHandling()->login()->loginNami();
$this->postJson(route('fileshare.store'), [
'name' => 'Lala',
'type' => OwncloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'secret',
'base_url' => env('TEST_OWNCLOUD_DOMAIN'),
]
])->assertJsonValidationErrors(['type' => 'Verbindung fehlgeschlagen']);
}
public function testItNeedsName(): void
{
$this->withExceptionHandling()->login()->loginNami();
$this->postJson(route('fileshare.store'), [
'name' => '',
'type' => OwncloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'secret',
'base_url' => env('TEST_OWNCLOUD_DOMAIN'),
]
])->assertJsonValidationErrors(['name' => 'Name ist erforderlich.']);
}
2024-07-13 22:30:34 +02:00
public function testItStoresNextcloudConnection(): void
{
$this->withoutExceptionHandling()->login()->loginNami()->withUser('badenpowell', 'uaLeitu3eecoweePhaeGei3Oa');
$this->post(route('fileshare.store'), [
'name' => 'Lala',
'type' => NextcloudConnection::class,
'config' => [
'user' => 'badenpowell',
'password' => 'uaLeitu3eecoweePhaeGei3Oa',
'base_url' => env('TEST_NEXTCLOUD_DOMAIN'),
]
])->assertOk();
$connection = Fileshare::firstOrFail();
$this->assertEquals('badenpowell', $connection->type->user);
$this->assertEquals('uaLeitu3eecoweePhaeGei3Oa', $connection->type->password);
$this->assertEquals(env('TEST_NEXTCLOUD_DOMAIN'), $connection->type->baseUrl);
$this->assertEquals('Lala', $connection->name);
}
2024-06-27 00:19:12 +02:00
}