mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 03:39:00 +00:00
164 lines
5.1 KiB
PHP
164 lines
5.1 KiB
PHP
<?php
|
|
/*
|
|
* UpdateControllerTest.php
|
|
* Copyright (c) 2021 james@firefly-iii.org
|
|
*
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace Tests\Api\Models\Attachment;
|
|
|
|
|
|
use Faker\Factory;
|
|
use Laravel\Passport\Passport;
|
|
use Log;
|
|
use Tests\Objects\Field;
|
|
use Tests\Objects\FieldSet;
|
|
use Tests\Objects\TestConfiguration;
|
|
use Tests\TestCase;
|
|
use Tests\Traits\CollectsValues;
|
|
use Tests\Traits\TestHelpers;
|
|
|
|
/**
|
|
* Class UpdateControllerTest
|
|
*/
|
|
class UpdateControllerTest extends TestCase
|
|
{
|
|
use TestHelpers, CollectsValues;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Passport::actingAs($this->user());
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
|
}
|
|
|
|
|
|
/**
|
|
* @dataProvider updateDataProvider
|
|
*/
|
|
public function testUpdate(array $submission): void
|
|
{
|
|
if ([] === $submission) {
|
|
$this->markTestSkipped('Empty provider.');
|
|
}
|
|
Log::debug('testStoreUpdated()');
|
|
Log::debug('submission :', $submission['submission']);
|
|
Log::debug('expected :', $submission['expected']);
|
|
Log::debug('ignore :', $submission['ignore']);
|
|
Log::debug('parameters :', $submission['parameters']);
|
|
|
|
$route = route('api.v1.attachments.update', $submission['parameters']);
|
|
$this->assertPUT($route, $submission);
|
|
}
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function updateDataProvider(): array
|
|
{
|
|
$configuration = new TestConfiguration;
|
|
|
|
// optional field sets (for all test configs)
|
|
$fieldSet = new FieldSet;
|
|
$fieldSet->parameters = [1];
|
|
$fieldSet->addField(Field::createBasic('filename', 'uuid'));
|
|
$configuration->addOptionalFieldSet('filename', $fieldSet);
|
|
|
|
$fieldSet = new FieldSet;
|
|
$fieldSet->parameters = [1];
|
|
$fieldSet->addField(Field::createBasic('title', 'uuid'));
|
|
$configuration->addOptionalFieldSet('title', $fieldSet);
|
|
|
|
$fieldSet = new FieldSet;
|
|
$fieldSet->parameters = [1];
|
|
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
|
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
|
|
|
$fieldSet = new FieldSet;
|
|
$fieldSet->parameters = [1];
|
|
$fieldSet->addField(Field::createBasic('attachable_type', 'static-journal-type'));
|
|
$fieldSet->addField(Field::createBasic('attachable_id', 'random-journal-id'));
|
|
$configuration->addOptionalFieldSet('attachable_type', $fieldSet);
|
|
|
|
// generate submissions
|
|
$array = $configuration->generateSubmissions();
|
|
$expected = $configuration->generateExpected($array);
|
|
$parameters = $configuration->parameters;
|
|
$ignored = $configuration->ignores;
|
|
|
|
// now create a combination for each submission and associated data:
|
|
$final = [];
|
|
foreach ($array as $index => $submission) {
|
|
$final[] = [[
|
|
'submission' => $submission,
|
|
'expected' => $expected[$index],
|
|
'ignore' => $ignored[$index] ?? [],
|
|
'parameters' => $parameters[$index],
|
|
]];
|
|
}
|
|
|
|
return $final;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function updateDataSet(): array
|
|
{
|
|
$faker = Factory::create();
|
|
$set = [
|
|
'filename' => [
|
|
'id' => 1,
|
|
'fields' => [
|
|
'filename' => ['test_value' => $faker->text(64)],
|
|
],
|
|
'extra_ignore' => [],
|
|
],
|
|
'title' => [
|
|
'id' => 1,
|
|
'fields' => [
|
|
'title' => ['test_value' => $faker->uuid],
|
|
],
|
|
'extra_ignore' => [],
|
|
],
|
|
'notes' => [
|
|
'id' => 1,
|
|
'fields' => [
|
|
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
|
],
|
|
'extra_ignore' => [],
|
|
],
|
|
'model' => [
|
|
'id' => 1,
|
|
'fields' => [
|
|
'attachable_type' => ['test_value' => 'TransactionJournal'],
|
|
'attachable_id' => ['test_value' => (string)2],
|
|
],
|
|
'extra_ignore' => [],
|
|
],
|
|
];
|
|
|
|
return $set;
|
|
}
|
|
|
|
|
|
} |