Remove unused tests

This commit is contained in:
James Cole 2023-02-04 17:11:19 +01:00
parent 47a98451a0
commit fd7ba9dd57
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
40 changed files with 2 additions and 5639 deletions

View File

@ -28,7 +28,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
@ -36,7 +36,7 @@
</coverage>
<testsuites>
<testsuite name="Api">
<directory suffix="Test.php">./tests/Api/Models/TransactionCurrency</directory>
<directory suffix="Test.php">./tests</directory>
<!--
<directory suffix="Test.php">./tests/Api</directory>

View File

@ -1,203 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Account;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default asset account test set:
$defaultAssetSet = new FieldSet();
$defaultAssetSet->title = 'default_asset_account';
$defaultAssetSet->addField(Field::createBasic('name', 'uuid'));
$defaultAssetSet->addField(Field::createBasic('type', 'static-asset'));
$defaultAssetSet->addField(Field::createBasic('account_role', 'random-asset-accountRole'));
$configuration->addMandatoryFieldSet($defaultAssetSet);
// expense test set:
$expenseSet = new FieldSet();
$expenseSet->title = 'expense_account';
$expenseSet->addField(Field::createBasic('name', 'uuid'));
// to make sure expense set ignores the opening balance fields:
$field = new Field();
$field->title = 'type';
$field->fieldTitle = 'type';
$field->fieldType = 'static-expense';
$field->ignorableFields = ['opening_balance', 'opening_balance_date', 'virtual_balance', 'order'];
$expenseSet->addField($field);
$configuration->addMandatoryFieldSet($expenseSet);
// liability test set:
$fieldSet = new FieldSet();
$fieldSet->title = 'liabilities_account';
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$fieldSet->addField(Field::createBasic('type', 'static-liabilities'));
$fieldSet->addField(Field::createBasic('liability_type', 'random-liability-type'));
$fieldSet->addField(Field::createBasic('liability_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('interest', 'random-percentage'));
$fieldSet->addField(Field::createBasic('interest_period', 'random-interest-period'));
$field = new Field();
$field->fieldTitle = 'liability_start_date';
$field->fieldType = 'random-past-date';
$field->ignorableFields = ['opening_balance', 'opening_balance_date'];
$field->title = 'liability_start_date';
$fieldSet->addField($field);
$configuration->addMandatoryFieldSet($fieldSet);
// credit card set:
$fieldSet = new FieldSet();
$fieldSet->title = 'cc_account';
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$fieldSet->addField(Field::createBasic('type', 'static-asset'));
$fieldSet->addField(Field::createBasic('account_role', 'static-ccAsset'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'static-monthlyFull'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'random-past-date'));
$configuration->addMandatoryFieldSet($fieldSet);
// optional field sets (for all test configs)
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('iban', 'iban'));
$configuration->addOptionalFieldSet('iban', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('bic', 'bic'));
$configuration->addOptionalFieldSet('bic', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('account_number', 'account_number'));
$configuration->addOptionalFieldSet('account_number', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('opening_balance', 'random-amount'));
$fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
$configuration->addOptionalFieldSet('ob', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('order', 'order'));
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('include_net_worth', 'boolean'));
$configuration->addOptionalFieldSet('include_net_worth', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* storeDataProvider / emptyDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.accounts.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,208 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Account;
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;
use CollectsValues;
/**
* Only create optional sets.
*
* @return array
*/
public function newUpdateDataProvider(): array
{
$configuration = new TestConfiguration();
// optional field sets (for all test configs)
$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('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('iban', 'iban'));
$configuration->addOptionalFieldSet('iban', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('bic', 'bic'));
$configuration->addOptionalFieldSet('bic', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('account_number', 'iban'));
$configuration->addOptionalFieldSet('account_number', $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('include_net_worth', 'boolean'));
$configuration->addOptionalFieldSet('include_net_worth', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('virtual_balance', 'random-amount');
$field->ignorableFields = ['current_balance'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code', 'currency_symbol', 'current_balance'];
$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', 'current_balance'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('account_role', 'random-asset-accountRole'));
$configuration->addOptionalFieldSet('account_role', $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('latitude', 'latitude'));
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('opening_balance', 'random-amount');
$field->ignorableFields = ['current_balance'];
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
$configuration->addOptionalFieldSet('ob', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [7];
$fieldSet->addField(Field::createBasic('account_role', 'static-ccAsset'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'static-monthlyFull'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'random-past-date'));
$configuration->addOptionalFieldSet('cc1', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [13];
$field = new Field();
$field->fieldTitle = 'liability_type';
$field->fieldType = 'random-liability-type';
$field->ignorableFields = ['account_role'];
$field->title = 'liability_type';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('account_role', 'null'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'null'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
$configuration->addOptionalFieldSet('liability-1', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [13];
$fieldSet->addField(Field::createBasic('interest', 'random-percentage'));
$field = new Field();
$field->fieldTitle = 'interest_period';
$field->fieldType = 'random-interest-period';
$field->ignorableFields = ['account_role'];
$field->title = 'interest_period';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('account_role', 'null'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'null'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
$configuration->addOptionalFieldSet('liability-2', $fieldSet);
return $configuration->generateAll();
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @param array $submission
*
* newStoreDataProvider / emptyDataProvider
*
* @dataProvider newUpdateDataProvider
*/
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.accounts.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
}

View File

@ -1,109 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Attachment;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default asset account test set:
$defaultAssetSet = new FieldSet();
$defaultAssetSet->title = 'default_file';
$defaultAssetSet->addField(Field::createBasic('filename', 'uuid'));
$defaultAssetSet->addField(Field::createBasic('attachable_type', 'random-attachment-type'));
$defaultAssetSet->addField(Field::createBasic('attachable_id', 'static-one'));
$configuration->addMandatoryFieldSet($defaultAssetSet);
// optional field sets
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('title', 'uuid'));
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.attachments.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,100 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Attachment;
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;
use 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);
return $configuration->generateAll();
}
}

View File

@ -1,118 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\AvailableBudget;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default asset account test set:
$defaultAssetSet = new FieldSet();
$defaultAssetSet->title = 'default_file';
$defaultAssetSet->addField(Field::createBasic('amount', 'random-amount'));
$defaultAssetSet->addField(Field::createBasic('start', 'random-date-two-year'));
$defaultAssetSet->addField(Field::createBasic('end', 'random-date-one-year'));
$configuration->addMandatoryFieldSet($defaultAssetSet);
// optional field sets
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.available_budgets.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,123 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\AvailableBudget;
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;
use CollectsValues;
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @param array $submission
*
* @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.available_budgets.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];
$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_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('amount', 'random-amount'));
$configuration->addOptionalFieldSet('amount', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
$configuration->addOptionalFieldSet('start', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
$configuration->addOptionalFieldSet('end', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
$configuration->addOptionalFieldSet('both', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,179 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default asset account test set:
$defaultAssetSet = new FieldSet();
$defaultAssetSet->title = 'default_file';
$defaultAssetSet->addField(Field::createBasic('name', 'uuid'));
$defaultAssetSet->addField(Field::createBasic('amount_min', 'random-amount-min'));
$defaultAssetSet->addField(Field::createBasic('amount_max', 'random-amount-max'));
$defaultAssetSet->addField(Field::createBasic('date', 'random-past-date'));
$defaultAssetSet->addField(Field::createBasic('repeat_freq', 'random-bill-repeat-freq'));
$configuration->addMandatoryFieldSet($defaultAssetSet);
// optional field sets
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
$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('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);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.bills.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,164 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
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;
use 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();
}
}

View File

@ -1,131 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Budget;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_budget';
$defaultSet->addField(Field::createBasic('name', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
// optional sets:
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'auto_budget_currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['auto_budget_currency_code'];
$field->title = 'auto_budget_currency_id';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
$configuration->addOptionalFieldSet('auto-id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = new Field();
$field->fieldTitle = 'auto_budget_currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['auto_budget_currency_id'];
$field->title = 'auto_budget_currency_code';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
$configuration->addOptionalFieldSet('auto-code', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.budgets.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,131 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Budget;
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;
use 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.budgets.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('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('order', 'order'));
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = new Field();
$field->fieldTitle = 'auto_budget_currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['auto_budget_currency_code', 'a'];
$field->title = 'auto_budget_currency_id';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
$configuration->addOptionalFieldSet('auto_budget_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = new Field();
$field->fieldTitle = 'auto_budget_currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['auto_budget_currency_id', 'b'];
$field->title = 'auto_budget_currency_code';
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
$configuration->addOptionalFieldSet('auto_budget_code', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = new Field();
$field->fieldTitle = 'auto_budget_type';
$field->fieldType = 'static-auto-none';
$field->ignorableFields = ['auto_budget_currency_code', 'auto_budget_currency_id', 'c', 'auto_budget_period', 'auto_budget_amount'];
$field->expectedReturn = function ($value) {
return null;
};
$field->title = 'auto_budget_type';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('none', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,137 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\BudgetLimit;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_budget_limit';
$defaultSet->addField(Field::createBasic('start', 'random-date-two-year'));
$defaultSet->addField(Field::createBasic('end', 'random-date-one-year'));
$defaultSet->addField(Field::createBasic('amount', 'random-amount'));
$configuration->addMandatoryFieldSet($defaultSet);
// optional tests
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet();
$field = new Field();
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('start', 'random-date-two-year');
$field->ignorableFields = ['spent'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('start', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('end', 'random-date-one-year');
$field->ignorableFields = ['spent'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('end', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('amount', 'random-amount'));
$configuration->addOptionalFieldSet('amount', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.budgets.limits.store', [1]);
$this->assertPOST($address, $submission);
}
}

View File

@ -1,113 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\BudgetLimit;
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;
use 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.budgets.limits.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [1, 1];
$field = new Field();
$field->fieldTitle = 'currency_id';
$field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code', 'currency_name', 'currency_symbol', 'spent'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1, 1];
$field = new Field();
$field->fieldTitle = 'currency_code';
$field->fieldType = 'random-currency-code';
$field->ignorableFields = ['currency_id', 'currency_name', 'currency_symbol', 'spent'];
$field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1, 1];
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
$configuration->addOptionalFieldSet('start', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1, 1];
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
$configuration->addOptionalFieldSet('end', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1, 1];
$fieldSet->addField(Field::createBasic('amount', 'random-amount'));
$configuration->addOptionalFieldSet('amount', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,103 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Category;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_cat';
$defaultSet->addField(Field::createBasic('name', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
// add optional set
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.categories.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,88 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Category;
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;
use 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.categories.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('notes', 'boolean'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,88 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\ObjectGroup;
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;
use 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.object-groups.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('title', 'uuid'));
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('order', 'order'));
$configuration->addOptionalFieldSet('order', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,146 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\PiggyBank;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('name', 'uuid'));
$defaultSet->addField(Field::createBasic('account_id', 'random-piggy-account'));
$defaultSet->addField(Field::createBasic('target_amount', 'random-amount-max'));
$configuration->addMandatoryFieldSet($defaultSet);
// add optional set
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('current_amount', 'random-amount-min'));
$configuration->addOptionalFieldSet('current_amount', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('start_date', 'random-past-date'));
$configuration->addOptionalFieldSet('start_date', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('target_date', 'random-future-date'));
$configuration->addOptionalFieldSet('target_date', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('order', 'order'));
$configuration->addOptionalFieldSet('order', $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'];
$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'];
$field->title = 'object_group_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.piggy_banks.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,146 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\PiggyBank;
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;
use 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.piggy_banks.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];
$field = Field::createBasic('account_id', 'random-piggy-account');
$field->ignorableFields = ['account_name', 'currency_id', 'currency_code'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('account_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('target_amount', 'random-amount-max');
$field->ignorableFields = ['percentage', 'current_amount', 'left_to_save', 'save_per_month'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('target_amount', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('current_amount', 'random-amount-min');
$field->ignorableFields = ['percentage', 'left_to_save', 'save_per_month'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('current_amount', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('start_date', 'random-past-date'));
$configuration->addOptionalFieldSet('start_date', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('target_date', 'random-future-date');
$field->ignorableFields = ['save_per_month'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('target_date', $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('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_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,190 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Recurrence;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_withdrawal';
$defaultSet->addField(Field::createBasic('type', 'static-withdrawal'));
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
$configuration->addMandatoryFieldSet($defaultSet);
$defaultSet = new FieldSet();
$defaultSet->title = 'default_withdrawal_2';
$defaultSet->addField(Field::createBasic('type', 'static-withdrawal'));
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
$defaultSet->addField(Field::createBasic('nr_of_repetitions', 'random-nr-of-reps'));
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
$configuration->addMandatoryFieldSet($defaultSet);
$defaultSet = new FieldSet();
$defaultSet->title = 'default_deposit';
$defaultSet->addField(Field::createBasic('type', 'static-deposit'));
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-revenue-id'));
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-asset-id'));
$configuration->addMandatoryFieldSet($defaultSet);
$defaultSet = new FieldSet();
$defaultSet->title = 'default_transfer';
$defaultSet->addField(Field::createBasic('type', 'static-transfer'));
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('first_date', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repeat_until', 'random-future-date'));
$defaultSet->addField(Field::createBasic('repetitions/0/type', 'static-type-weekly'));
$defaultSet->addField(Field::createBasic('repetitions/0/moment', 'static-one'));
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$defaultSet->addField(Field::createBasic('transactions/0/amount', 'random-amount'));
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-other-asset-id'));
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-asset-id'));
$configuration->addMandatoryFieldSet($defaultSet);
// add optional set
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('description', 'uuid'));
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('apply_rules', 'boolean'));
$configuration->addOptionalFieldSet('apply_rules', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('repetitions/0/skip', 'random-skip'));
$configuration->addOptionalFieldSet('skip', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/foreign_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('transactions/0/foreign_currency_id', 'random-currency-id'));
$configuration->addOptionalFieldSet('foreign1', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/budget_id', 'random-budget-id'));
$configuration->addOptionalFieldSet('budget', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
$configuration->addOptionalFieldSet('category', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
$configuration->addOptionalFieldSet('tags', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/piggy_bank_id', 'random-piggy-id'));
$configuration->addOptionalFieldSet('piggy', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.recurrences.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,176 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Recurrence;
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;
use 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.recurrences.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
// optional fields
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('title', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('description', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('first_date', 'random-past-date');
$field->ignorableFields = ['repetitions'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('first_date', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('apply_rules', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('apply_rules', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('repetitions/0/type', 'static-ndom');
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'moment-ndom'));
$configuration->addOptionalFieldSet('ndom', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('repetitions/0/type', 'static-monthly');
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'moment-monthly'));
$configuration->addOptionalFieldSet('monthly', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('repetitions/0/type', 'static-yearly');
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
$fieldSet->addField($field);
$fieldSet->addField(Field::createBasic('repetitions/0/moment', 'random-past-date'));
$configuration->addOptionalFieldSet('yearly', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('repetitions/0/skip', 'random-skip');
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('skip', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('repetitions/0/weekend', 'weekend');
$field->ignorableFields = ['repetitions/0/description', 'repetitions/0/occurrences'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('weekend', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/foreign_amount', 'random-amount'));
$field = Field::createBasic('transactions/0/foreign_currency_id', 'random-currency-id');
$field->ignorableFields = ['transactions/0/foreign_currency_code', 'transactions/0/foreign_currency_symbol'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('foreign1', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/budget_id', 'random-budget-id');
$field->ignorableFields = ['transactions/0/budget_name'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('budget', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/category_id', 'random-category-id');
$field->ignorableFields = ['transactions/0/category_name'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('category', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
$configuration->addOptionalFieldSet('tags', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/piggy_bank_id', 'random-piggy-id');
$field->ignorableFields = ['transactions/0/piggy_bank_name'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('piggy', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,143 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Rule;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_rule_id';
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('rule_group_id', 'random-rule-group-id'));
$defaultSet->addField(Field::createBasic('trigger', 'random-trigger'));
$defaultSet->addField(Field::createBasic('triggers/0/type', 'random-trigger-type'));
$defaultSet->addField(Field::createBasic('triggers/0/value', 'uuid'));
$defaultSet->addField(Field::createBasic('actions/0/type', 'random-action-type'));
$defaultSet->addField(Field::createBasic('actions/0/value', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
$defaultSet = new FieldSet();
$defaultSet->title = 'default_rule_name';
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('rule_group_title', 'random-rule-group-title'));
$defaultSet->addField(Field::createBasic('trigger', 'random-trigger'));
$defaultSet->addField(Field::createBasic('triggers/0/type', 'random-trigger-type'));
$defaultSet->addField(Field::createBasic('triggers/0/value', 'uuid'));
$defaultSet->addField(Field::createBasic('actions/0/type', 'random-action-type'));
$defaultSet->addField(Field::createBasic('actions/0/value', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
// add optional set
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('order', 'low-order'));
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('strict', 'boolean'));
$configuration->addOptionalFieldSet('strict', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('stop_processing', 'boolean'));
$configuration->addOptionalFieldSet('stop_processing', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('triggers/0/stop_processing', 'boolean'));
$configuration->addOptionalFieldSet('stop_processingX', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('triggers/0/active', 'boolean'));
$configuration->addOptionalFieldSet('activeX', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('actions/0/active', 'boolean'));
$configuration->addOptionalFieldSet('activeXX', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.rules.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,167 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Rule;
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;
use 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.recurrences.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('title', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('description', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('order', 'low-order');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('trigger', 'random-trigger'));
$configuration->addOptionalFieldSet('trigger', $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('strict', 'boolean'));
$configuration->addOptionalFieldSet('strict', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('stop_processing', 'boolean'));
$configuration->addOptionalFieldSet('stop_processing', $fieldSet);
// sub trigger fields
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('triggers/0/type', 'random-trigger-type');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('trigger_type', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('triggers/0/value', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('trigger_value', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('triggers/0/active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('trigger_active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('triggers/0/stop_processing', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('stop_processing', $fieldSet);
// optional action fields
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('actions/0/type', 'random-action-type');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('action_type', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('actions/0/value', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('action_value', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('actions/0/active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('action_active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('actions/0/stop_processing', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('action_stop_processing', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,114 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\RuleGroup;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
// optionals
$fieldSet = new FieldSet();
$field = Field::createBasic('description', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('order', 'low-order');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.rule_groups.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,102 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\RuleGroup;
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;
use 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.rule_groups.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('title', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('description', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('order', 'low-order');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('order', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,115 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Tag;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('tag', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
// optionals
$fieldSet = new FieldSet();
$field = Field::createBasic('date', 'random-past-date');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('date', $fieldSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('description', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$configuration->addOptionalFieldSet('location', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.tags.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,100 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Tag;
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;
use 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.tags.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('tag', 'uuid'));
$configuration->addOptionalFieldSet('tag', $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('description', 'uuid'));
$configuration->addOptionalFieldSet('description', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$configuration->addOptionalFieldSet('location', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,138 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Transaction;
use Carbon\Carbon;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object_withdrawal';
$defaultSet->addField(Field::createBasic('error_if_duplicate_hash', 'boolean'));
$defaultSet->addField(Field::createBasic('transactions/0/type', 'static-withdrawal'));
$field = Field::createBasic('transactions/0/date', 'random-past-date');
$field->expectedReturn = function ($value) {
$date = new Carbon($value, 'Europe/Amsterdam');
return $date->toIso8601String();
};
$defaultSet->addField($field);
$field = Field::createBasic('transactions/0/amount', 'random-amount');
$field->expectedReturn = function ($value) {
return number_format((float)$value, 12);
};
$defaultSet->addField($field);
$defaultSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$defaultSet->addField(Field::createBasic('transactions/0/source_id', 'random-asset-id'));
$defaultSet->addField(Field::createBasic('transactions/0/destination_id', 'random-expense-id'));
$configuration->addMandatoryFieldSet($defaultSet);
// optional fields
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
$configuration->addOptionalFieldSet('category_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/reconciled', 'boolean'));
$configuration->addOptionalFieldSet('reconciled', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/tags', 'random-tags'));
$configuration->addOptionalFieldSet('tags', $fieldSet);
$array = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
foreach ($array as $value) {
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('transactions/0/' . $value, 'uuid'));
$configuration->addOptionalFieldSet($value, $fieldSet);
}
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider emptyDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.transactions.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,172 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\Transaction;
use Carbon\Carbon;
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;
use CollectsValues;
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @dataProvider updateDataProvider
*
* @param array $submission
*/
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.transactions.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('apply_rules', 'boolean'));
$configuration->addOptionalFieldSet('apply_rules', $fieldSet);
// add date
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/date', 'random-past-date');
$field->expectedReturn = function ($value) {
$date = new Carbon($value, 'Europe/Amsterdam');
return $date->toIso8601String();
};
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('date', $fieldSet);
// category
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/category_id', 'random-category-id'));
$configuration->addOptionalFieldSet('category_id', $fieldSet);
// amount
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/amount', 'random-amount');
$field->expectedReturn = function ($value) {
return number_format((float)$value, 12);
};
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('amount', $fieldSet);
// descr
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/description', 'uuid'));
$configuration->addOptionalFieldSet('descr', $fieldSet);
// source
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/source_id', 'random-asset-id');
$field->ignorableFields = ['transactions/0/source_name', 'transactions/0/source_iban'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('src', $fieldSet);
// dest
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/destination_id', 'random-expense-id');
$field->ignorableFields = ['transactions/0/destination_name', 'transactions/0/destination_iban'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('dest', $fieldSet);
// optional fields
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/category_id', 'random-category-id');
$field->ignorableFields = ['transactions/0/category_name'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('category_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/reconciled', 'boolean'));
$configuration->addOptionalFieldSet('reconciled', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('transactions/0/tags', 'random-tags');
$field->expectedReturn = function ($value) {
if (is_array($value)) {
asort($value);
return array_values($value);
}
return $value;
};
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('tags', $fieldSet);
$array = ['notes', 'internal_reference', 'bunq_payment_id', 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id',
'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id'];
foreach ($array as $value) {
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('transactions/0/' . $value, 'uuid'));
$configuration->addOptionalFieldSet($value, $fieldSet);
}
return $configuration->generateAll();
}
}

View File

@ -1,122 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionCurrency;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('code', 'random-new-currency-code'));
$defaultSet->addField(Field::createBasic('name', 'uuid'));
$defaultSet->addField(Field::createBasic('symbol', 'random-new-currency-symbol'));
// 'code' => substr($faker->uuid, 0, 3),
// 'name' => $faker->uuid,
// 'symbol' => $faker->randomAscii . $faker->randomAscii,
$configuration->addMandatoryFieldSet($defaultSet);
// optionals
$fieldSet = new FieldSet();
$field = Field::createBasic('enabled', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('enabled', $fieldSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('default', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('default', $fieldSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('decimal_places', 'currency-dp');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('decimal_places', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.currencies.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,163 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionCurrency;
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;
use 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.currencies.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$configuration->addOptionalFieldSet('name', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$fieldSet->addField(Field::createBasic('symbol', 'random-new-currency-symbol'));
$configuration->addOptionalFieldSet('symbol', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$field = Field::createBasic('enabled', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('enabled', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$field = Field::createBasic('default', 'boolean-true');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('default', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$field = Field::createBasic('decimal_places', 'currency-dp');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('decimal_places', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = ['RMB'];
$fieldSet->addField(Field::createBasic('symbol', 'random-new-currency-code'));
$configuration->addOptionalFieldSet('code', $fieldSet);
return $configuration->generateAll();
}
/**
* @return array
*/
public function updateDataSet(): array
{
$faker = Factory::create();
return [
'name' => [
'id' => 'INR',
'fields' => [
'name' => ['test_value' => $faker->uuid],
],
'extra_ignore' => [],
],
'code' => [
'id' => 'INR',
'fields' => [
'code' => ['test_value' => substr($faker->uuid, 0, 3)],
],
'extra_ignore' => [],
],
'symbol' => [
'id' => 'RUB',
'fields' => [
'description' => ['test_value' => $faker->randomAscii . $faker->randomAscii],
],
'extra_ignore' => [],
],
'decimal_places' => [
'id' => 'ETH',
'fields' => [
'decimal_places' => ['test_value' => $faker->numberBetween(1, 6)],
],
'extra_ignore' => [],
],
'enabled' => [
'id' => 'ETH',
'fields' => [
'enabled' => ['test_value' => $faker->boolean],
],
'extra_ignore' => [],
],
'default' => [
'id' => 'XBT',
'fields' => [
'default' => ['test_value' => $faker->boolean],
],
'extra_ignore' => [],
],
];
}
}

View File

@ -1,111 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionLink;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('link_type_id', 'random-link-type-id'));
$defaultSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
$defaultSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
$configuration->addMandatoryFieldSet($defaultSet);
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object_name';
$defaultSet->addField(Field::createBasic('link_type_name', 'random-link-type-name'));
$defaultSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
$defaultSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
$configuration->addMandatoryFieldSet($defaultSet);
// optionals
$fieldSet = new FieldSet();
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.transaction_links.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,110 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionLink;
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;
use 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.transaction_links.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('link_type_id', 'random-link-type-id');
$field->ignorableFields = ['link_type_name'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('link_type_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('link_type_name', 'random-link-type-name');
$field->ignorableFields = ['link_type_id'];
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('link_type_name', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('inward_id', 'random-low-journal-id'));
$configuration->addOptionalFieldSet('inward_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('outward_id', 'random-high-journal-id'));
$configuration->addOptionalFieldSet('outward_id', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
$configuration->addOptionalFieldSet('notes', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,99 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionLinkType;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('name', 'uuid'));
$defaultSet->addField(Field::createBasic('inward', 'uuid'));
$defaultSet->addField(Field::createBasic('outward', 'uuid'));
$configuration->addMandatoryFieldSet($defaultSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.link_types.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,93 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Models\TransactionLinkType;
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;
use 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.link_types.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [5];
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$configuration->addOptionalFieldSet('name', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [5];
$fieldSet->addField(Field::createBasic('inward', 'uuid'));
$configuration->addOptionalFieldSet('inward', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [5];
$fieldSet->addField(Field::createBasic('outward', 'uuid'));
$configuration->addOptionalFieldSet('outward', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,106 +0,0 @@
<?php
/*
* StoreControllerTest.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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Webhook;
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 StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
use TestHelpers;
use CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @return array
*/
public function storeDataProvider(): array
{
// some test configs:
$configuration = new TestConfiguration();
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('url', 'secure-url'));
$defaultSet->addField(Field::createBasic('trigger', 'webhook-trigger'));
$defaultSet->addField(Field::createBasic('response', 'webhook-response'));
$defaultSet->addField(Field::createBasic('delivery', 'webhook-delivery'));
$configuration->addMandatoryFieldSet($defaultSet);
$fieldSet = new FieldSet();
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
return $configuration->generateAll();
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(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']);
// run account store with a minimal data set:
$address = route('api.v1.webhooks.store');
$this->assertPOST($address, $submission);
}
}

View File

@ -1,114 +0,0 @@
<?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/>.
*/
declare(strict_types=1);
namespace Tests\Api\Webhook;
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;
use 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.webhooks.update', $submission['parameters']);
$this->assertPUT($route, $submission);
}
/**
* @return array
*/
public function updateDataProvider(): array
{
$configuration = new TestConfiguration();
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('title', 'uuid');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('title', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('trigger', 'webhook-trigger');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('trigger', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('response', 'webhook-response');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('response', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('delivery', 'webhook-delivery');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('delivery', $fieldSet);
$fieldSet = new FieldSet();
$fieldSet->parameters = [1];
$field = Field::createBasic('url', 'secure-url');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('url', $fieldSet);
return $configuration->generateAll();
}
}

View File

@ -1,67 +0,0 @@
<?php
/*
* Field.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/>.
*/
declare(strict_types=1);
namespace Tests\Objects;
use Closure;
/**
* Class Field
*/
class Field
{
public ?Closure $expectedReturn;
public string $expectedReturnType;
public string $fieldTitle;
public string $fieldType;
public ?array $ignorableFields;
public string $title;
/**
* Field constructor.
*/
public function __construct()
{
$this->expectedReturnType = 'equal'; // or 'callback'
$this->expectedReturn = null; // or the callback
$this->ignorableFields = []; // something like transactions/0/currency_code
//$optionalField->ignorableFields = ['some_field', 'transactions/0/another_field', 'rules/2/another_one',]; // something like transactions/0/currency_code
}
/**
* @param string $title
* @param string $type
*
* @return static
*/
public static function createBasic(string $title, string $type): self
{
$field = new self();
$field->title = $title;
$field->fieldTitle = $title;
$field->fieldType = $type;
return $field;
}
}

View File

@ -1,58 +0,0 @@
<?php
/*
* FieldSet.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/>.
*/
declare(strict_types=1);
namespace Tests\Objects;
/**
* Class FieldSet
*/
class FieldSet
{
public ?array $fields;
public ?array $parameters;
public string $title;
/**
* FieldSet constructor.
*/
public function __construct()
{
$this->fields = [];
$this->parameters = [];
}
/**
* @param Field $field
* @param string|null $key
*/
public function addField(Field $field, ?string $key = null): void
{
if (null === $key) {
$this->fields[] = $field;
return;
}
$this->fields[$key] = $field;
}
}

View File

@ -1,692 +0,0 @@
<?php
/*
* TestConfiguration.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/>.
*/
declare(strict_types=1);
namespace Tests\Objects;
use Faker\Factory;
use UnexpectedValueException;
/**
* Class TestConfiguration
*/
class TestConfiguration
{
protected const MAX_ITERATIONS = 3;
public const SHOW_DEBUG = false;
public array $ignores;
public array $mandatoryFieldSets;
public array $optionalFieldSets;
public array $parameters;
private array $expected;
private array $submission;
/**
* TestConfiguration constructor.
*/
public function __construct()
{
$this->submission = [];
$this->mandatoryFieldSets = [];
$this->optionalFieldSets = [];
$this->ignores = [];
$this->parameters = [];
$this->expected = [];
}
/**
* @param FieldSet $set
*/
public function addMandatoryFieldSet(FieldSet $set)
{
$this->mandatoryFieldSets[] = $set;
}
public function addOptionalFieldSet(string $key, FieldSet $set)
{
$this->optionalFieldSets[$key] = $set;
}
public function generateAll(): array
{
$this->debugMsg('Now in generateAll()');
// generate submissions
$array = $this->generateSubmissions();
$allParameters = $this->parameters;
$ignored = $this->ignores;
$expectedValue = $this->expected;
$this->debugMsg(sprintf('Now validating %d ignored() values.', count($ignored)));
// update ignored parameters:
$newIgnored = [];
foreach ($ignored as $index => $currentIgnored) {
$this->debugMsg(sprintf(' Value #%d is %s', $index, json_encode($currentIgnored)));
$updated = [];
foreach ($currentIgnored as $key => $value) {
if (!is_array($value)) {
$positions = explode('/', $value);
$count = count($positions);
if (1 === $count) {
$updated[$key] = array_key_exists($key, $updated) ? $updated[$key] : $value;
continue;
}
if (3 === $count) {
$root = $positions[0];
$count = (int)$positions[1];
$final = $positions[2];
$updated[$root][$count][] = $final;
continue;
}
}
if (is_array($value)) {
$updated[$key] = $value;
}
}
$newIgnored[$index] = $updated;
$this->debugMsg(sprintf(' Updated value #%d is %s', $index, json_encode($updated)));
}
// now create a combination for each submission and associated data:
$final = [];
foreach ($array as $index => $submission) {
$final[] = [[
'submission' => $submission,
'expected' => $expectedValue[$index] ?? $submission,
'ignore' => $newIgnored[$index] ?? [],
'parameters' => $allParameters[$index] ?? [],
]];
}
return $final;
}
/**
* @param string $message
*/
private function debugMsg(string $message): void
{
if (true === self::SHOW_DEBUG) {
echo sprintf("%s\n", $message);
}
}
/**
* @return array
*/
private function generateSubmissions(): array
{
$this->debugMsg('Now in generateSubmissions()');
// first generate standard submissions:
$this->submission = [];
// loop each standard submission:
$this->debugMsg(sprintf('There are %d mandatory field sets', count($this->mandatoryFieldSets)));
/** @var FieldSet $set */
foreach ($this->mandatoryFieldSets as $set) {
$this->submission[] = $this->toArray($set);
// expand the standard submission with extra sets from the optional field set.
$setCount = count($this->optionalFieldSets);
$this->debugMsg('Just created a standard set');
if (0 !== $setCount) {
$keys = array_keys($this->optionalFieldSets);
$this->debugMsg(sprintf(' keys to consider are: %s', join(', ', $keys)));
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
for ($i = 1; $i <= $maxCount; $i++) {
$combinationSets = $this->combinationsOf($i, $keys);
$this->debugMsg(sprintf(' will create %d extra sets.', count($combinationSets)));
foreach ($combinationSets as $ii => $combinationSet) {
$this->debugMsg(sprintf('Set %d/%d will consist of:', ($ii + 1), count($combinationSets)));
// the custom set is born!
$customFields = [];
$custom = $this->toArray($set);
$this->debugMsg(' refreshed!');
$this->debugMsg(sprintf(' %s', json_encode($custom)));
foreach ($combinationSet as $combination) {
$this->debugMsg(sprintf(' %s', $combination));
// here we start adding stuff to a copy of the standard submission.
/** @var FieldSet $customSet */
$customSet = $this->optionalFieldSets[$combination] ?? false;
$this->debugMsg(sprintf(' there are %d field(s) in this custom set', count(array_keys($customSet->fields))));
// loop each field in this custom set and add them, nothing more.
/** @var Field $field */
foreach ($customSet->fields as $field) {
$this->debugMsg(sprintf(' added field %s from custom set %s', $field->fieldTitle, $combination));
$custom = $this->parseField($custom, $field);
$customFields[] = $field;
}
}
$this->submission[] = $custom;
// at this point we can update the ignorable fields because we know the position
// of the submission in the array
$index = count($this->submission) - 1;
$this->updateIgnorables($index, $customFields);
$this->updateExpected($index, $customFields);
}
}
}
}
$totalCount = 0;
// no mandatory sets? Loop the optional sets:
if (empty($this->mandatoryFieldSets)) {
// expand the standard submission with extra sets from the optional field set.
$setCount = count($this->optionalFieldSets);
$this->debugMsg(sprintf('there are %d optional field sets', $setCount));
if (0 !== $setCount) {
$keys = array_keys($this->optionalFieldSets);
$this->debugMsg(sprintf(' keys to consider are: %s', join(', ', $keys)));
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
$this->debugMsg(sprintf(' max count is %d', $maxCount));
for ($i = 1; $i <= $maxCount; $i++) {
$combinationSets = $this->combinationsOf($i, $keys);
$this->debugMsg(sprintf(' will create %d extra sets.', count($combinationSets)));
foreach ($combinationSets as $ii => $combinationSet) {
$totalCount++;
$this->debugMsg(sprintf(' Set #%d will consist of:', $totalCount));
// the custom set is born!
$custom = [];
$expectedValue = [];
foreach ($combinationSet as $combination) {
$this->debugMsg(sprintf(' %s', $combination));
// here we start adding stuff to a copy of the standard submission.
/** @var FieldSet $customSet */
$customSet = $this->optionalFieldSets[$combination] ?? false;
$this->debugMsg(sprintf(sprintf(' there are %d field(s) in this custom set', count(array_keys($customSet->fields)))));
// loop each field in this custom set and add them, nothing more.
/** @var Field $field */
foreach ($customSet->fields as $field) {
$this->debugMsg(sprintf(' added field "%s" from custom set "%s"', $field->fieldTitle, $combination));
$custom = $this->parseField($custom, $field);
$expectedValue = $this->parseExpected($expectedValue, $field, $custom);
// for each field, add the ignores to the current index (+1!) of
// ignores.
$count = count($this->submission);
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
$this->debugMsg(sprintf(' This field also has ignore things! %s', json_encode($field->ignorableFields)));
$currentIgnoreSet = $this->ignores[$count] ?? [];
$newIgnoreSet = [];
foreach ($field->ignorableFields as $ignorableField) {
$positions = explode('/', $ignorableField);
$posCount = count($positions);
if (1 === $posCount) {
$newIgnoreSet[] = $ignorableField;
}
if (3 === $posCount) {
$root = $positions[0];
$index = (int)$positions[1];
$final = $positions[2];
$newIgnoreSet[$root] = array_key_exists($root, $newIgnoreSet) ? $newIgnoreSet[$root] : [];
$newIgnoreSet[$root][$index] = array_key_exists($index, $newIgnoreSet[$root]) ? $newIgnoreSet[$root][$index] : [];
$newIgnoreSet[$root][$index][] = $final;
}
}
$this->debugMsg(sprintf(' %s + %s', json_encode($currentIgnoreSet), json_encode($newIgnoreSet)));
$mergedArray = $this->mergeIgnoreArray($currentIgnoreSet, $newIgnoreSet);
//$this->ignores[$count] = $currentIgnoreSet + $newIgnoreSet;
$this->ignores[$count] = $mergedArray;//array_merge_recursive($currentIgnoreSet, $newIgnoreSet);
$this->debugMsg(sprintf(' New set of ignore things (%d) is: %s', $count, json_encode($this->ignores[$count])));
}
$this->expected[$count] = $expectedValue;
}
$count = count($this->submission);
$this->parameters[$count] = $customSet->parameters ?? [];
}
$count = count($this->submission);
$this->submission[] = $custom;
$this->debugMsg(sprintf(' Created set #%d on index %d', $totalCount, $count));
$this->debugMsg(sprintf(' Will submit: %s', json_encode($custom)));
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
}
}
}
}
$this->debugMsg('Done!');
return $this->submission;
}
/**
* @param $left
* @param $right
*
* @return array
*/
private function mergeIgnoreArray($left, $right): array
{
// if both empty just return empty:
if (empty($left) && empty($right)) {
$this->debugMsg('Return empty array');
return [];
}
// if left is empty return right
if (empty($left)) {
$this->debugMsg('Return right');
return $right;
}
// if right is empty return left
if (empty($right)) {
$this->debugMsg('Return left');
return $left;
}
$this->debugMsg('Loop right');
$result = [];
foreach ($right as $key => $value) {
$this->debugMsg(sprintf('Now at right key %s with value %s', json_encode($key), json_encode($value)));
if (is_array($value) && array_key_exists($key, $left)) {
$this->debugMsg(sprintf('Key %s exists in both, go one level deeper.', $key));
$result[$key] = $this->mergeIgnoreArray($right[$key], $left[$key]);
continue;
}
if (is_array($value) && !array_key_exists($key, $left)) {
$this->debugMsg(sprintf('Key %s exists in right only, keep it as it is.', $key));
$result[$key] = $right[$key];
continue;
}
// value is not an array, can be appended to result (ignore the key):
$this->debugMsg(sprintf('Key %s is a string (%s), just append it and return it later.', $key, $value));
$result[] = $value;
}
// loop left:
$this->debugMsg('Loop left');
foreach ($left as $key => $value) {
$this->debugMsg(sprintf('Now at left key %s with value %s', json_encode($key), json_encode($value)));
if (is_array($value) && array_key_exists($key, $right)) {
$this->debugMsg(sprintf('Key %s exists in both, go one level deeper.', $key));
$result[$key] = $this->mergeIgnoreArray($left[$key], $right[$key]);
continue;
}
if (is_array($value) && !array_key_exists($key, $right)) {
$result[$key] = $left[$key];
}
// value is not an array, can be appended to result (ignore the key):
$result[] = $value;
}
//
return $result;
}
/**
* @param FieldSet $set
*
* @return array
*/
private function toArray(FieldSet $set): array
{
$ignore = [];
$result = [];
$expectedValue = [];
/** @var Field $field */
foreach ($set->fields as $field) {
// this is what we will submit:
$result = $this->parseField($result, $field);
$expectedValue = $this->parseExpected($expectedValue, $field, $result);
// this is what we will ignore:
$newIgnore = array_unique($ignore + $field->ignorableFields);
$ignore = $newIgnore;
$this->debugMsg(sprintf('Merged! ignores %s + %s = %s', json_encode($ignore), json_encode($field->ignorableFields), json_encode($newIgnore)));
}
$this->ignores[] = array_values($ignore);
$this->expected[] = $expectedValue;
$this->parameters[] = $set->parameters ?? [];
return $result;
}
/**
* @param array $current
* @param Field $field
*
* @return array
*/
private function parseField(array $current, Field $field): array
{
// fieldTitle indicates the position:
$positions = explode('/', $field->fieldTitle);
$count = count($positions);
if (1 === $count) {
$current[$field->fieldTitle] = $this->generateFieldValue($field->fieldType);
return $current;
}
if (3 === $count) {
$root = $positions[0];
$count = (int)$positions[1];
$final = $positions[2];
$current[$root] = array_key_exists($root, $current) ? $current[$root] : [];
$current[$root][$count] = array_key_exists($count, $current[$root]) ? $current[$root][$count] : [];
$current[$root][$count][$final] = $this->generateFieldValue($field->fieldType);
return $current;
}
throw new UnexpectedValueException(sprintf('Did not expect count %d from fieldTitle "%s".', $count, $field->fieldTitle));
}
/**
* @param string $type
*
* @return mixed
*/
private function generateFieldValue(string $type)
{
$faker = Factory::create();
switch ($type) {
default:
throw new UnexpectedValueException(sprintf('Cannot handle field "%s"', $type));
case 'uuid':
return $faker->uuid;
case 'static-asset':
return 'asset';
case 'static-expense':
return 'expense';
case 'static-liabilities':
return 'liabilities';
case 'static-ccAsset':
return 'ccAsset';
case 'static-monthlyFull':
return 'monthlyFull';
case 'static-one':
return 1;
case 'static-journal-type':
return 'TransactionJournal';
case 'random-liability-type':
return $faker->randomElement(['loan', 'debt', 'mortgage']);
case 'random-journal-id':
return $faker->numberBetween(1, 25);
case 'random-low-journal-id':
return $faker->numberBetween(1, 9);
case 'random-high-journal-id':
return $faker->numberBetween(10, 20);
case 'random-link-type-id':
return $faker->numberBetween(1, 4);
case 'random-link-type-name':
return $faker->randomElement(['Related', 'Refund', 'Paid', 'Reimbursement']);
case 'random-amount':
return number_format($faker->randomFloat(2, 10, 100), 2);
case 'random-percentage':
return $faker->randomFloat(2, 1, 99);
case 'random-interest-period':
return $faker->randomElement(['daily', 'monthly', 'yearly']);
case 'random-bill-repeat-freq':
return $faker->randomElement(['half-year', 'weekly', 'monthly', 'yearly']);
case 'random-past-date':
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
case 'random-future-date':
return $faker->dateTimeBetween('1 years', '3 years')->format('Y-m-d');
case 'random-date-two-year':
return $faker->dateTimeBetween('-2 years', '-1 years')->format('Y-m-d');
case 'random-date-one-year':
return $faker->dateTimeBetween('-1 years', 'now')->format('Y-m-d');
case 'random-asset-accountRole':
return $faker->randomElement(['defaultAsset', 'savingAsset']);
case 'random-transactionType':
return $faker->randomElement(['withdrawal', 'deposit', 'transfer']);
case 'boolean':
return $faker->boolean;
case 'boolean-true':
return true;
case 'iban':
case 'account_number':
return $faker->iban();
case 'bic':
return $faker->swiftBicNumber;
case 'random-currency-id':
return $faker->numberBetween(1, 10);
case 'random-currency-code':
return $faker->randomElement(['EUR', 'USD', 'HUF', 'GBP']);
case 'order':
return $faker->numberBetween(1, 5);
case 'latitude':
return $faker->latitude;
case 'longitude':
return $faker->longitude;
case 'random-zoom_level':
return $faker->numberBetween(1, 12);
case 'null':
return null;
case 'random-attachment-type':
return $faker->randomElement(['Account', 'Budget', 'Bill', 'TransactionJournal', 'PiggyBank', 'Tag',]);
case 'random-amount-min':
return number_format($faker->randomFloat(2, 10, 50), 2);
case 'random-amount-max':
return number_format($faker->randomFloat(2, 50, 100), 2);
case 'random-skip':
return $faker->numberBetween(0, 4);
case 'random-budget-id':
case 'random-category-id':
case 'random-rule-group-id':
case 'random-piggy-id':
case 'low-order':
case 'random-og-id':
return $faker->numberBetween(1, 2);
case 'random-tags':
return $faker->randomElements(['a', 'b', 'c', 'd', 'ef', 'gh', 'sasas', '38sksl'], 5);
case 'random-auto-type':
return $faker->randomElement(['rollover', 'reset']);
case 'random-auto-period':
return $faker->randomElement(['weekly', 'monthly', 'yearly']);
case 'static-auto-none':
return 'none';
case 'random-piggy-account':
return $faker->numberBetween(1, 3);
case 'static-withdrawal':
return 'withdrawal';
case 'static-ndom':
return 'ndom';
case 'moment-ndom':
return sprintf('%d,%d', $faker->numberBetween(1, 4), $faker->numberBetween(1, 7));
case 'static-monthly':
return 'monthly';
case 'moment-monthly':
return $faker->numberBetween(1, 28);
case 'static-yearly':
return 'yearly';
case 'static-deposit':
return 'deposit';
case 'static-transfer':
return 'transfer';
case 'static-type-weekly':
return 'weekly';
case 'random-nr-of-reps':
return $faker->numberBetween(5, 12);
case 'weekend':
return $faker->numberBetween(1, 4);
case 'random-asset-id':
return $faker->randomElement([1, 2, 3]);
case 'random-other-asset-id':
return $faker->randomElement([4, 5, 6]);
case 'random-expense-id':
return $faker->randomElement([8, 11, 12]);
case 'random-revenue-id':
return $faker->randomElement([9, 10]);
case 'random-trigger':
return $faker->randomElement(['store-journal', 'update-journal']);
case 'random-trigger-type':
return $faker->randomElement(['from_account_starts', 'from_account_is', 'description_ends', 'description_is']);
case 'random-action-type':
return $faker->randomElement(['set_category', 'add_tag', 'set_description']);
case 'random-rule-group-title':
return $faker->randomElement(['Rule group 1', 'Rule group 2']);
case 'random-new-currency-code':
return $faker->randomLetter . $faker->randomLetter . $faker->randomLetter;
case 'random-new-currency-symbol':
return $faker->randomAscii . $faker->randomAscii;
case 'currency-dp':
return $faker->numberBetween(0, 11);
case 'secure-url':
return str_replace(['http://'], 'https://', $faker->url);
case 'webhook-trigger':
return $faker->randomElement(['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION']);
case 'webhook-response':
return $faker->randomElement(['RESPONSE_TRANSACTIONS', 'RESPONSE_ACCOUNTS', 'RESPONSE_NONE']);
case 'webhook-delivery':
return $faker->randomElement(['DELIVERY_JSON']);
}
}
/**
* @param array $expected
* @param Field $field
* @param array $result
*
* @return array
*/
private function parseExpected(array $expected, Field $field, array $result): array
{
$this->debugMsg(sprintf(' Now parsing expected return values for field %s', $field->fieldTitle));
// fieldTitle indicates the position:
$positions = explode('/', $field->fieldTitle);
$count = count($positions);
if (1 === $count && null === $field->expectedReturn) {
$expected[$field->fieldTitle] = $result[$field->fieldTitle];
$this->debugMsg(sprintf(' Expected result of field "%s" = "%s"', $field->fieldTitle, $expected[$field->fieldTitle]));
return $expected;
}
if (1 === $count && null !== $field->expectedReturn) {
// call the closure!
$expected[$field->fieldTitle] = ($field->expectedReturn)($result[$field->fieldTitle]);
return $expected;
}
if (3 === $count) {
$root = $positions[0];
$count = (int)$positions[1];
$final = $positions[2];
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
$expected[$root][$count][$final] = null;
$this->debugMsg(sprintf(' Field name is split, so will store the expected return in $expected[%s][%d][%s] = (here)', $root, $count, $final));
if (null === $field->expectedReturn) {
$this->debugMsg(sprintf(' Expected return is NULL, so will use the result for this point: %s', json_encode($result)));
$expected[$root][$count][$final] = $result[$root][$count][$final];
}
if (null !== $field->expectedReturn) {
$this->debugMsg(sprintf(' Expected return is not NULL, so will use a callback for this point: %s', json_encode($result)));
$this->debugMsg(sprintf(' Root : %s', json_encode($result[$root])));
$this->debugMsg(sprintf(' Count : %s', json_encode($result[$root][$count])));
$this->debugMsg(sprintf(' Final : %s', json_encode($result[$root][$count][$final])));
$lastValue = $result[$root][$count][$final];
$expected[$root][$count][$final] = ($field->expectedReturn)($lastValue);
}
return $expected;
}
throw new UnexpectedValueException(sprintf('Did not expect count %d from fieldTitle "%s".', $count, $field->fieldTitle));
}
/**
* @param $k
* @param $xs
*
* @return array|array[]
*/
private function combinationsOf($k, $xs): array
{
if ($k === 0) {
return [[]];
}
if (empty($xs)) {
return [];
}
$x = $xs[0];
$xs1 = array_slice($xs, 1, count($xs) - 1);
$res1 = $this->combinationsOf($k - 1, $xs1);
for ($i = 0; $i < count($res1); $i++) {
array_splice($res1[$i], 0, 0, $x);
}
$res2 = $this->combinationsOf($k, $xs1);
return array_merge($res1, $res2);
}
/**
* @param int $index
* @param array $customFields
*/
public function updateIgnorables(int $index, array $customFields): void
{
if (!empty($customFields)) {
/** @var Field $field */
foreach ($customFields as $field) {
if (0 !== count($field->ignorableFields)) {
$this->ignores[$index] = array_values(array_unique(array_values(array_merge($this->ignores[$index], $field->ignorableFields))));
}
}
}
}
/**
* @param int $index
* @param array $customFields
*/
private function updateExpected(int $index, array $customFields): void
{
$this->debugMsg('Now parsing expected return values for this set.');
if (!empty($customFields)) {
/** @var Field $field */
foreach ($customFields as $field) {
// fieldTitle indicates the position:
$positions = explode('/', $field->fieldTitle);
$count = count($positions);
if (1 === $count) {
if (null === $field->expectedReturn) {
$this->expected[$index][$field->fieldTitle] = $this->submission[$index][$field->fieldTitle];
}
if (null !== $field->expectedReturn) {
$this->expected[$index][$field->fieldTitle] = ($field->expectedReturn)($this->submission[$index][$field->fieldTitle]);
}
}
if (3 === $count) {
$root = $positions[0];
$count = (int)$positions[1];
$final = $positions[2];
$this->expected[$index][$root] = array_key_exists($root, $this->expected[$index]) ? $this->expected[$index][$root] : [];
$this->expected[$index][$root][$count] = array_key_exists($count, $this->expected[$index][$root])
? $this->expected[$index][$root][$count] : [];
$this->expected[$index][$root][$count][$final] = $this->submission[$index][$root][$count][$final];
}
}
}
}
/**
* @param FieldSet $optionalFieldSet
*/
public function setOptionalFieldSet(FieldSet $optionalFieldSet): void
{
$this->optionalFieldSet = $optionalFieldSet;
}
}

View File

@ -1,198 +0,0 @@
<?php
/*
* TestHelpers.php
* Copyright (c) 2020 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/>.
*/
declare(strict_types=1);
namespace Tests\Traits;
use Illuminate\Support\Facades\Log;
/**
* Trait TestHelpers
*/
trait TestHelpers
{
/**
* @param string $route
* @param array $content
*/
protected function assertPOST(string $route, array $content): void
{
Log::debug('Now in assertPOST()');
$submission = $content['submission'];
$expected = $content['expected'];
$ignore = $content['ignore'];
// submit body
$response = $this->post($route, $submission, ['Accept' => 'application/json']);
$responseBody = $response->content();
$responseJson = json_decode($responseBody, true);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
$response->assertHeader('Content-Type', 'application/vnd.api+json');
// get return and compare each field
$responseAttributes = $responseJson['data']['attributes'];
$this->comparePOSTArray($submission, $responseAttributes, $expected, $ignore);
// ignore fields too!
}
/**
* @param array $submission
* @param array $response
* @param array $expected
* @param array $ignore
*/
private function comparePOSTArray(array $submission, array $response, array $expected, array $ignore): void
{
Log::debug('Now in comparePOSTArray()');
Log::debug(sprintf('Submission : %s', json_encode($submission)));
Log::debug(sprintf('Response : %s', json_encode($response)));
Log::debug(sprintf('Expected : %s', json_encode($expected)));
Log::debug(sprintf('Ignore : %s', json_encode($ignore)));
foreach ($response as $key => $value) {
Log::debug(sprintf('Now working on (sub)response key ["%s"]', $key));
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
Log::debug(sprintf('(Sub)response key ["%s"] is an array!', $key));
$this->comparePOSTArray($submission, $value, $expected[$key], $ignore[$key] ?? []);
continue;
}
if (isset($expected[$key])) {
if (in_array($key, $ignore, true)) {
continue;
}
if (!in_array($key, $ignore, true)) {
$message = sprintf(
"Field '%s' with value %s is expected to be %s.\nSubmitted:\n%s\nIgnored: %s\nReturned\n%s",
$key,
var_export($value, true),
var_export($expected[$key], true),
json_encode($submission),
json_encode($ignore),
json_encode($response)
);
$this->assertEquals($value, $expected[$key], $message);
}
}
}
}
/**
* @param string $route
* @param array $content
*/
protected function assertPUT(string $route, array $content): void
{
$submission = $content['submission'];
$ignore = $content['ignore'];
$expected = $content['expected'];
Log::debug('Now in assertPUT()');
// get the original first:
$original = $this->get($route, ['Accept' => 'application/json']);
$originalBody = $original->content();
$originalJson = json_decode($originalBody, true);
$originalAttributes = $originalJson['data']['attributes'];
$status = $original->getStatusCode();
$this->assertEquals($status, 200, sprintf("Response: %s", json_encode($originalBody)));
$response = $this->put($route, $submission, ['Accept' => 'application/json']);
$responseBody = $response->content();
$responseJson = json_decode($responseBody, true);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
$response->assertHeader('Content-Type', 'application/vnd.api+json');
// get return and compare each field
$responseAttributes = $responseJson['data']['attributes'];
$this->comparePUTArray($route, $submission, $responseAttributes, $expected, $ignore, $originalAttributes);
}
/**
* @param string $url
* @param array $submission
* @param array $response
* @param array $expected
* @param array $ignore
* @param array $original
*/
private function comparePUTArray(string $url, array $submission, array $response, array $expected, array $ignore, array $original): void
{
Log::debug('Now in comparePUTArray()');
Log::debug(sprintf('Submission : %s', json_encode($submission)));
Log::debug(sprintf('Response : %s', json_encode($response)));
Log::debug(sprintf('Expected : %s', json_encode($expected)));
Log::debug(sprintf('Ignore : %s', json_encode($ignore)));
Log::debug(sprintf('Original : %s', json_encode($original)));
$extraIgnore = ['created_at', 'updated_at', 'id'];
foreach ($response as $key => $value) {
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
if (in_array($key, $ignore, true)) {
continue;
}
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? [], $original[$key] ?? []);
continue;
}
if (isset($submission[$key])) {
if (in_array($key, $ignore, true)) {
continue;
}
if (!in_array($key, $ignore, true)) {
$message = sprintf(
"Field '%s' with value %s is expected to be %s.\nSubmitted: %s\nIgnored: %s\nExpected: %s\nReturned: %s\nURL: %s",
$key,
var_export($value, true),
var_export($expected[$key], true),
json_encode($submission),
json_encode($ignore),
json_encode($expected),
json_encode($response),
$url
);
$this->assertEquals($value, $expected[$key], $message);
}
}
// if not set, compare to original to see if it's the same:
if (
!isset($submission[$key])
&& isset($response[$key])
&& isset($original[$key])
&& !in_array($key, $ignore, true)
&& !in_array($key, $extraIgnore, true)) {
$message = sprintf(
"Field '%s' was unexpectedly changed from %s to %s.\nSubmitted: %s\nIgnored: %s\nExpected: %s\nReturned: %s\nURL: %s",
$key,
json_encode($original[$key]),
json_encode($response[$key]),
json_encode($submission),
json_encode($ignore),
json_encode($expected),
json_encode($response),
$url
);
$this->assertEquals($response[$key], $original[$key], $message);
}
}
}
}