firefly-iii/tests/Api/Models/Bill/UpdateControllerTest.php
2021-03-21 08:13:19 +01:00

166 lines
6.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\Bill;
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.bills.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration;
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$configuration->addOptionalFieldSet('name', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('amount_min', 'random-amount-min'));
$configuration->addOptionalFieldSet('amount_min', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('amount_max', 'random-amount-max'));
$configuration->addOptionalFieldSet('amount_max', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('date', 'random-past-date'));
$configuration->addOptionalFieldSet('date', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('repeat_freq', 'random-bill-repeat-freq'));
$configuration->addOptionalFieldSet('repeat_freq', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('skip', 'random-skip'));
$configuration->addOptionalFieldSet('skip', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('order', 'order'));
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$field = new Field;
$field->fieldTitle = 'object_group_id';
$field->fieldType = 'random-og-id';
$field->ignorableFields = ['object_group_title', 'object_group_order'];
$field->title = 'object_group_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$field = new Field;
$field->fieldTitle = 'object_group_title';
$field->fieldType = 'uuid';
$field->ignorableFields = ['object_group_id', 'object_group_order'];
$field->title = 'object_group_title';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
// optional field sets
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$field = new Field;
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code', 'currency_symbol'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet;
$fieldSet->parameters = [1];
$field = new Field;
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id', 'currency_symbol'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
return $configuration->generateAll();
}
}