2024-06-30 23:36:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Fileshare;
|
|
|
|
|
|
|
|
use App\Fileshare\ConnectionTypes\OwncloudConnection;
|
|
|
|
use App\Fileshare\Data\FileshareResourceData;
|
|
|
|
use App\Fileshare\Models\Fileshare;
|
|
|
|
use App\Form\Actions\ExportSyncAction;
|
|
|
|
use App\Form\Data\ExportData;
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use App\Form\Models\Participant;
|
|
|
|
use App\Group;
|
|
|
|
use Tests\FileshareTestCase;
|
|
|
|
use Tests\Lib\CreatesFormFields;
|
|
|
|
|
|
|
|
class ExportSyncActionTest extends FileshareTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use CreatesFormFields;
|
|
|
|
|
|
|
|
public function testItDoesntUploadFileWhenNoExportGiven(): void
|
|
|
|
{
|
|
|
|
$form = Form::factory()->fields([
|
|
|
|
$this->textField('vorname'),
|
|
|
|
$this->textField('nachname'),
|
|
|
|
])->create();
|
|
|
|
|
|
|
|
ExportSyncAction::run($form);
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItUploadsRootFile(): void
|
|
|
|
{
|
2024-07-14 00:37:38 +02:00
|
|
|
$this->withoutExceptionHandling()->withUser('badenpowell', 'zai8hie3oozaiX5queey0Xa9a')->withDirs('badenpowell', ['/abc']);
|
2024-06-30 23:36:44 +02:00
|
|
|
$connection = Fileshare::factory()
|
2024-07-14 00:37:38 +02:00
|
|
|
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'zai8hie3oozaiX5queey0Xa9a', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
|
2024-06-30 23:36:44 +02:00
|
|
|
->create();
|
|
|
|
$form = Form::factory()->name('Formular')->fields([
|
|
|
|
$this->textField('vorname'),
|
|
|
|
$this->textField('nachname'),
|
|
|
|
])->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => $connection->id, 'resource' => '/abc'])]))->create();
|
|
|
|
Participant::factory()->for($form)->data(['firstname' => 'AAA', 'lastname' => 'BBB'])->create();
|
|
|
|
|
|
|
|
ExportSyncAction::run($form);
|
|
|
|
|
|
|
|
$this->assertEquals(['abc/Anmeldungen Formular.xlsx'], $connection->type->getFilesystem()->files('/abc'));
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItUploadsGroupFile(): void
|
|
|
|
{
|
2024-07-14 00:37:38 +02:00
|
|
|
$this->withoutExceptionHandling()->withUser('badenpowell', 'Aejahpoopood1Keetaaghoe0Z')->withDirs('badenpowell', ['/abc', '/stamm']);
|
2024-06-30 23:36:44 +02:00
|
|
|
$connection = Fileshare::factory()
|
2024-07-14 00:37:38 +02:00
|
|
|
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'Aejahpoopood1Keetaaghoe0Z', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
|
2024-06-30 23:36:44 +02:00
|
|
|
->create();
|
|
|
|
$group = Group::factory()->create(['fileshare' => FileshareResourceData::from(['connection_id' => $connection->id, 'resource' => '/stamm'])]);
|
|
|
|
$form = Form::factory()->name('Formular')->fields([
|
|
|
|
$this->textField('vorname')->name('Vorname'),
|
|
|
|
$this->textField('nachname')->name('Nachname'),
|
|
|
|
$this->groupField('stamm')->name('Stamm'),
|
|
|
|
])->export(ExportData::from(['to_group_field' => 'stamm', 'group_by' => 'vorname', 'root' => FileshareResourceData::from(['connection_id' => $connection->id, 'resource' => '/abc'])]))->create();
|
|
|
|
Participant::factory()->for($form)->data(['vorname' => 'AAA', 'nachname' => 'BBB', 'stamm' => $group->id])->create();
|
|
|
|
Participant::factory()->for($form)->data(['vorname' => 'CCC', 'nachname' => 'DDD', 'stamm' => null])->create();
|
|
|
|
|
|
|
|
ExportSyncAction::run($form);
|
|
|
|
|
|
|
|
$this->assertEquals(['stamm/Anmeldungen Formular.xlsx'], $connection->type->getFilesystem()->files('/stamm'));
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
}
|