Skip to content

Firefly III: a personal finances manager

Remove old tests. To be reinstated later.

James Cole76cfdef27d33
diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.php
deleted file mode 100644
index 0ab7d59e47..0000000000
--- a/tests/Api/V1/Controllers/AccountControllerTest.php
+++ /dev/null
@@ -1,512 +0,0 @@
-<?php
-/**
- * AccountControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Exception;
-use FireflyIII\Models\Account;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Transformers\AccountTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AccountControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Opening balance without date.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreInvalidBalance(): void
- {
-
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $data = [
- 'name' => 'Some new asset account #' . $this->randomInt(),
- 'type' => 'asset',
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '123.45',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'opening_balance_date' => ['The opening balance date field is required when opening balance is present.'],
- ],
- ]
- );
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- */
- public function testShow(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(AccountTransformer::class);
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- [
- 'id' => 1,
- 'attributes' => [
- 'name' => 'Account',
- ],
- ]);
- $transformer->shouldReceive('setCurrentScope')->atLeast()->once();
- $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
-
-
- // getAccountType
-
- $account = $this->getRandomAsset();
- $response = $this->get(route('api.v1.accounts.show', [$account->id]));
- $response->assertStatus(200);
- }
-
- /**
- * Send correct data. Should call account repository store method.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreLiability(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = $this->mock(AccountTransformer::class);
- $account = $this->getRandomAsset();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // data to submit
- $data = [
- 'name' => 'Some new liability account #' . $this->randomInt(),
- 'type' => 'liability',
- 'liability_amount' => '10000',
- 'liability_start_date' => '2016-01-01',
- 'liability_type' => 'mortgage',
- 'active' => true,
- 'interest' => '1',
- 'interest_period' => 'daily',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- }
-
- /**
- * CC type present when account is a credit card.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreNoCreditCardData(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $this->mock(AccountTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
-
- // data to submit
- $data = [
- 'name' => 'Some new asset account #' . $this->randomInt(),
- 'type' => 'asset',
- 'account_role' => 'ccAsset',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'credit_card_type' => ['The credit card type field is required when account role is ccAsset.'],
- 'monthly_payment_date' => ['The monthly payment date field is required when account role is ccAsset.'],
-
- ],
- ]
- );
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * No currency information (is allowed).
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreNoCurrencyInfo(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(AccountTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn(new Account);
-
- // data to submit
- $data = [
- 'name' => 'Some new asset account #' . $this->randomInt(),
- 'type' => 'asset',
- 'account_role' => 'defaultAsset',
- 'include_net_worth' => false,
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Name already in use.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreNotUnique(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
-
- $account = $this->getRandomAsset();
- // data to submit
- $data = [
- 'name' => $account->name,
- 'currency_id' => 1,
- 'type' => 'asset',
- 'active' => 1,
- 'include_net_worth' => 1,
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'name' => ['This account name is already in use.'],
- ],
- ]
- );
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Send correct data. Should call account repository store method.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreValid(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(AccountTransformer::class);
- $account = $this->getRandomAsset();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // data to submit
- $data = [
- 'name' => 'Some new asset account #' . $this->randomInt(),
- 'type' => 'asset',
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Send correct data. Should call account repository store method.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- * @throws Exception
- */
- public function testStoreWithCurrencyCode(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(AccountTransformer::class);
- $account = $this->getRandomAsset();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- $repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // data to submit
- $data = [
- 'name' => 'Some new asset account #' . $this->randomInt(),
- 'currency_code' => 'EUR',
- 'type' => 'asset',
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update first asset account we find. Name can be the same as it was.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testUpdate(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(AccountTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- $repository->shouldReceive('update')->atLeast()->once();
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- $account = $this->getRandomAsset();
- // data to submit
- $data = [
- 'active' => true,
- 'include_net_worth' => true,
- 'name' => $account->name,
- 'type' => 'asset',
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update first asset account we find. Name can be the same as it was.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testUpdateCurrencyCode(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = $this->mock(AccountTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- $repository->shouldReceive('update')->atLeast()->once();
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- $account = $this->getRandomAsset();
- // data to submit
- $data = [
- 'name' => $account->name,
- 'type' => 'asset',
- 'currency_code' => 'EUR',
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update a liability
- *
- * @covers \FireflyIII\Api\V1\Controllers\AccountController
- * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testUpdateLiability(): void
- {
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = $this->mock(AccountTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- $repository->shouldReceive('update')->atLeast()->once();
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- $account = $this->getRandomAsset();
- // data to submit
- $data = [
- 'active' => true,
- 'include_net_worth' => true,
- 'name' => $account->name,
- 'type' => 'liability',
- 'liability_type' => 'loan',
- 'liability_amount' => '100',
- 'interest' => '1',
- 'interest_period' => 'yearly',
- 'liability_start_date' => '2019-01-01',
- 'account_role' => 'defaultAsset',
- ];
-
- // test API
- $response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/AttachmentControllerTest.php b/tests/Api/V1/Controllers/AttachmentControllerTest.php
deleted file mode 100644
index 54ecf385e0..0000000000
--- a/tests/Api/V1/Controllers/AttachmentControllerTest.php
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-/**
- * AttachmentControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Exception;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Transformers\AttachmentTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class AttachmentControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AttachmentControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test show attachment.
- * @covers \FireflyIII\Api\V1\Controllers\AttachmentController
- */
- public function testShow(): void
- {
- $transformer = $this->mock(AttachmentTransformer::class);
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- [
- 'id' => 1,
- 'attributes' => [
- 'file' => 'Test.pdf',
- ],
- ]);
- $transformer->shouldReceive('setCurrentScope')->atLeast()->once();
- $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
-
- $attachment = $this->user()->attachments()->inRandomOrder()->first();
-
- // test API
- $response = $this->get(route('api.v1.attachments.show', [$attachment->id]));
- $response->assertStatus(200);
- }
-
- /**
- * Store a new attachment.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AttachmentController
- * @throws Exception
- */
- public function testStore(): void
- {
- /** @var Attachment $attachment */
- $attachment = $this->user()->attachments()->first();
-
- // mock stuff:
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transformer = $this->mock(AttachmentTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $journal = $this->getRandomWithdrawal();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($attachment);
- $repository->shouldReceive('getNoteText')->andReturn('Hi There');
- $journalRepos->shouldReceive('setUser')->once();
-
- $journalRepos->shouldReceive('findNull')->once()->andReturn($journal);
-
- // data to submit
- $data = [
- 'filename' => 'Some new att',
- 'description' => sprintf('Attempt #%d', $this->randomInt()),
- 'attachable_type' => 'TransactionJournal',
- 'attachable_id' => $journal->id,
- ];
-
-
- // test API
- $response = $this->post(route('api.v1.attachments.store'), $data, ['accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- }
-
- /**
- * Update an attachment.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AttachmentController
- * @throws Exception
- */
- public function testUpdate(): void
- {
- // mock repositories
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $transformer = $this->mock(AttachmentTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- /** @var Attachment $attachment */
- $attachment = $this->user()->attachments()->first();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('update')->once()->andReturn($attachment);
- $repository->shouldReceive('getNoteText')->andReturn('Hi There');
- // data to submit
- $data = [
- 'filename' => $attachment->filename,
- 'description' => sprintf('Attempt #%d', $this->randomInt()),
- 'attachable_type' => 'TransactionJournal',
- 'attachable_id' => 1,
- ];
-
- // test API
- $response = $this->put(route('api.v1.attachments.update', [$attachment->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
-
- }
-}
diff --git a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php
deleted file mode 100644
index df350ba1ce..0000000000
--- a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php
+++ /dev/null
@@ -1,239 +0,0 @@
-<?php
-/**
- * AvailableBudgetControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Amount;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Models\AvailableBudget;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Transformers\AvailableBudgetTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class AvailableBudgetControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AvailableBudgetControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Store new available budget.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
- */
- public function testStore(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
- $transformer = $this->mock(AvailableBudgetTransformer::class);
- $factory = $this->mock(TransactionCurrencyFactory::class);
- $availableBudget = new AvailableBudget;
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $factory->shouldReceive('find')->withArgs([2, ''])->once()->andReturn(TransactionCurrency::find(2));
-
- // mock calls:
- $abRepository->shouldReceive('setUser')->atLeast()->once();
- $abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
-
- // data to submit
- $data = [
- 'currency_id' => '2',
- 'amount' => '100',
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- ];
-
-
- // test API
- $response = $this->post(route('api.v1.available_budgets.store'), $data);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'available_budgets', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Store new available budget without a valid currency.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
- */
- public function testStoreNoCurrencyAtAll(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock stuff:
- $transformer = $this->mock(AvailableBudgetTransformer::class);
- $factory = $this->mock(TransactionCurrencyFactory::class);
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
- $availableBudget = new AvailableBudget;
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $factory->shouldReceive('find')->withArgs([0, ''])->once()->andReturnNull();
-
- Amount::shouldReceive('getDefaultCurrency')->once()->andReturn(TransactionCurrency::find(5));
-
- // mock calls:
- $abRepository->shouldReceive('setUser')->atLeast()->once();
- $abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
-
- // data to submit
- $data = [
- 'amount' => '100',
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- ];
-
-
- // test API
- $response = $this->post(route('api.v1.available_budgets.store'), $data);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Store new available budget without a valid currency.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
- */
- public function testStoreNoCurrencyId(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- /** @var AvailableBudget $availableBudget */
- $availableBudget = $this->user()->availableBudgets()->first();
-
- // mock stuff:
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
- $transformer = $this->mock(AvailableBudgetTransformer::class);
- $factory = $this->mock(TransactionCurrencyFactory::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $factory->shouldReceive('find')->withArgs([0, 'EUR'])->once()->andReturnNull();
- Amount::shouldReceive('getDefaultCurrency')->once()->andReturn(TransactionCurrency::find(5));
-
- // mock calls:
- $abRepository->shouldReceive('setUser')->once();
- $abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
-
- // data to submit
- $data = [
- 'currency_code' => 'EUR',
- 'amount' => '100',
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- ];
-
-
- // test API
- $response = $this->post(route('api.v1.available_budgets.store'), $data);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'available_budgets', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update available budget.
- *
- * @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
- *
- */
- public function testUpdate(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock repositories
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
- $currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(AvailableBudgetTransformer::class);
- $factory = $this->mock(TransactionCurrencyFactory::class);
- $euro = $this->getEuro();
- // mock facades:
- Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $factory->shouldReceive('find')->withArgs([1, ''])->once()->andReturnNull();
-
- /** @var AvailableBudget $availableBudget */
- $availableBudget = $this->user()->availableBudgets()->first();
-
- // mock calls:
- $abRepository->shouldReceive('setUser');
- $abRepository->shouldReceive('updateAvailableBudget')->once()->andReturn($availableBudget);
- $currencyRepository->shouldReceive('findNull')->andReturn($this->getEuro());
-
- // data to submit
- $data = [
- 'currency_id' => '1',
- 'amount' => '100',
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- ];
-
- // test API
- $response = $this->put(route('api.v1.available_budgets.update', $availableBudget->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'available_budgets', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/BillControllerTest.php b/tests/Api/V1/Controllers/BillControllerTest.php
deleted file mode 100644
index b2f8085951..0000000000
--- a/tests/Api/V1/Controllers/BillControllerTest.php
+++ /dev/null
@@ -1,192 +0,0 @@
-<?php
-/**
- * BillControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use Exception;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Transformers\BillTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BillControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BillControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- }
-
- /**
- * Store with minimum amount more than maximum amount
- *
- * @covers \FireflyIII\Api\V1\Controllers\BillController
- * @throws Exception
- */
- public function testStoreMinOverMax(): void
- {
- // create stuff
- $bill = $this->user()->bills()->first();
- $repository = $this->mock(BillRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->andReturn($bill);
-
- // data to submit:
- $data = [
- 'name' => 'New bill #' . $this->randomInt(),
- 'match' => 'some,words,' . $this->randomInt(),
- 'amount_min' => '66.34',
- 'amount_max' => '45.67',
- 'date' => '2018-01-01',
- 'currency_id' => 1,
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'automatch' => 1,
- 'active' => 1,
-
- ];
-
- // test API
- $response = $this->post(route('api.v1.bills.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'amount_min' => ['The minimum amount cannot be larger than the maximum amount.'],
- ],
- ]
- );
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Store a valid bill
- *
- * @covers \FireflyIII\Api\V1\Controllers\BillController
- * @throws Exception
- */
- public function testStoreValid(): void
- {
- // create stuff
- $bill = $this->user()->bills()->first();
- $repository = $this->mock(BillRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->andReturn($bill);
-
- // data to submit:
- $data = [
- 'name' => 'New bill #' . $this->randomInt(),
- 'match' => 'some,words,' . $this->randomInt(),
- 'amount_min' => '12.34',
- 'amount_max' => '45.67',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'automatch' => 1,
- 'active' => 1,
- 'currency_id' => 1,
-
- ];
-
- // test API
- $response = $this->post(route('api.v1.bills.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'bills', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-
- /**
- * Update a valid bill.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BillController
- * @throws Exception
- */
- public function testUpdateValid(): void
- {
- // create stuff
- $bill = $this->user()->bills()->first();
- $repository = $this->mock(BillRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('update')->andReturn($bill);
- // data to submit:
- $data = [
- 'name' => 'New bill #' . $this->randomInt(),
- 'match' => 'some,words,' . $this->randomInt(),
- 'amount_min' => '12.34',
- 'amount_max' => '45.67',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'automatch' => 1,
- 'active' => 1,
- 'currency_id' => 1,
- ];
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // test API
- $response = $this->put(route('api.v1.bills.update', [$bill->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'bills', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-}
diff --git a/tests/Api/V1/Controllers/BudgetControllerTest.php b/tests/Api/V1/Controllers/BudgetControllerTest.php
deleted file mode 100644
index 4335d8880f..0000000000
--- a/tests/Api/V1/Controllers/BudgetControllerTest.php
+++ /dev/null
@@ -1,179 +0,0 @@
-<?php
-/**
- * BudgetControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Transformers\BudgetLimitTransformer;
-use FireflyIII\Transformers\BudgetTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class BudgetControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Store a new budget.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetController
- */
- public function testStore(): void
- {
- /** @var Budget $budget */
- $budget = new Budget;
-
- // mock stuff:
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $transformer = $this->mock(BudgetTransformer::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $blRepository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($budget);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // data to submit
- $data = [
- 'name' => 'Some budget',
- ];
-
- // test API
- $response = $this->post(route('api.v1.budgets.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'budgets', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Store new budget limit.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetController
- */
- public function testStoreBudgetLimit(): void
- {
- $budget = $this->user()->budgets()->first();
- $budgetLimit = new BudgetLimit;
- $data
- = [
- 'budget_id' => $budget->id,
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'amount' => 1,
- ];
- // mock stuff:
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
- $transformer = $this->mock(BudgetLimitTransformer::class);
-
- $blRepository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
- $blRepository->shouldReceive('setUser')->atLeast()->once();
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit);
-
- // call API
- $response = $this->post(route('api.v1.budgets.store_budget_limit', [$budget->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertSee('budget_limits');
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update a budget.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetController
- */
- public function testUpdate(): void
- {
- // mock repositories
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $transformer = $this->mock(BudgetTransformer::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
- /** @var Budget $budget */
- $budget = $this->user()->budgets()->first();
-
- // mock calls:
- $repository->shouldReceive('setUser');
- $blRepository->shouldReceive('setUser');
- $repository->shouldReceive('update')->once()->andReturn(new Budget);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // data to submit
- $data = [
- 'name' => 'Some new budget',
- 'active' => '1',
- ];
-
- // test API
- $response = $this->put(route('api.v1.budgets.update', $budget->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'budgets', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-}
diff --git a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php
deleted file mode 100644
index c8a7ff5d6c..0000000000
--- a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php
+++ /dev/null
@@ -1,179 +0,0 @@
-<?php
-/**
- * BudgetLimitControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Transformers\BudgetLimitTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class BudgetLimitControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetLimitControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Store new budget limit.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
- */
- public function testStore(): void
- {
- $budget = $this->user()->budgets()->first();
- $transformer = $this->mock(BudgetLimitTransformer::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $budgetLimit = BudgetLimit::create(
- [
- 'budget_id' => $budget->id,
- 'start_date' => '2018-01-01',
- 'end_date' => '2018-01-31',
- 'amount' => 1,
- ]
- );
- $data
- = [
- 'budget_id' => $budget->id,
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'amount' => 1,
- ];
- // mock stuff:
- $repository->shouldReceive('findNull')->andReturn($budget)->once();
- $blRepository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $blRepository->shouldReceive('setUser')->once();
-
- // call API
- $response = $this->post(route('api.v1.budget_limits.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Store new budget limit, but give error
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
- */
- public function testStoreBadBudget(): void
- {
- $data
- = [
- 'budget_id' => '1',
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'amount' => 1,
- ];
- // mock stuff:
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $transformer = $this->mock(BudgetLimitTransformer::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
-
- // call API
- Log::warning('The following error is part of a test.');
- $response = $this->post(route('api.v1.budget_limits.store'), $data);
- $response->assertStatus(500);
- $response->assertSee('Unknown budget.');
- }
-
- /**
- * Test update of budget limit.
- *
- * @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
- */
- public function testUpdate(): void
- {
- $transformer = $this->mock(BudgetLimitTransformer::class);
- $blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
- $budget = $this->user()->budgets()->first();
- $budgetLimit = BudgetLimit::create(
- [
- 'budget_id' => $budget->id,
- 'start_date' => '2018-01-01',
- 'end_date' => '2018-01-31',
- 'amount' => 1,
- ]
- );
- $data
- = [
- 'budget_id' => $budget->id,
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'amount' => 2,
- ];
- // mock stuff:
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $blRepository->shouldReceive('updateBudgetLimit')->andReturn($budgetLimit)->once();
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $blRepository->shouldReceive('setUser')->once();
-
- // call API
- $response = $this->put(route('api.v1.budget_limits.update', [$budgetLimit->id]), $data);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- }
-}
diff --git a/tests/Api/V1/Controllers/CategoryControllerTest.php b/tests/Api/V1/Controllers/CategoryControllerTest.php
deleted file mode 100644
index 7fb1fdb3ce..0000000000
--- a/tests/Api/V1/Controllers/CategoryControllerTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * CategoryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-
-use FireflyIII\Models\Category;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Transformers\CategoryTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class CategoryControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Store a new category.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CategoryController
- */
- public function testStore(): void
- {
- /** @var Category $category */
- $category = $this->user()->categories()->first();
-
- // mock stuff:
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $transformer = $this->mock(CategoryTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->once()->andReturn($category);
-
- // data to submit
- $data = [
- 'name' => 'Some category',
- 'active' => '1',
- ];
-
- // test API
- $response = $this->post(route('api.v1.categories.store'), $data);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'categories', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update a category.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CategoryController
- */
- public function testUpdate(): void
- {
- // mock repositories
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $transformer = $this->mock(CategoryTransformer::class);
- /** @var Category $category */
- $category = $this->user()->categories()->first();
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('update')->once()->andReturn($category);
-
- // data to submit
- $data = [
- 'name' => 'Some new category',
- 'active' => '1',
- ];
-
- // test API
- $response = $this->put(route('api.v1.categories.update', $category->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'categories', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-}
diff --git a/tests/Api/V1/Controllers/Chart/AccountControllerTest.php b/tests/Api/V1/Controllers/Chart/AccountControllerTest.php
deleted file mode 100644
index a550734cda..0000000000
--- a/tests/Api/V1/Controllers/Chart/AccountControllerTest.php
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-/**
- * AccountControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers\Chart;
-
-
-use Amount;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Laravel\Passport\Passport;
-use Log;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class AccountControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\AccountController
- * @covers \FireflyIII\Api\V1\Requests\DateRequest
- */
- public function testOverview(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
- // mock calls
- $repository->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->atLeast()->once()->andReturn(new Collection([$asset]));
- $repository->shouldReceive('getAccountsById')->withArgs([[$asset->id]])->atLeast()->once()->andReturn(new Collection([$asset]));
- $repository->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // mock Steam:
- Steam::shouldReceive('balanceInRange')->atLeast()->once()->andReturn(['2019-01-01' => '-123',]);
-
- // mock Preferences:
- $preference = new Preference;
- $preference->data = [$asset->id];
- Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$asset->id]])->andReturn($preference);
-
- // mock Amount
- Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
-
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(route('api.v1.chart.account.overview') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\AccountController
- * @covers \FireflyIII\Api\V1\Requests\DateRequest
- */
- public function testRevenueOverview(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $revenue = $this->getRandomRevenue();
- $euro = $this->getEuro();
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])
- ->atLeast()->once()->andReturn(new Collection([$revenue]));
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()->withArgs([1])->andReturn($euro);
-
- // mock Steam, first start and then end.
- $startBalances = [
- $revenue->id => [
- 1 => '10',
- ],
- ];
- $endBalances = [
- $revenue->id => [
- 1 => '20',
- ],
- ];
-
- Steam::shouldReceive('balancesPerCurrencyByAccounts')->times(2)
- ->andReturn($startBalances, $endBalances);
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(route('api.v1.chart.account.revenue') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\AccountController
- */
- public function testExpenseOverview(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock repositories
- $repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $expense = $this->getRandomExpense();
- $euro = $this->getEuro();
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])
- ->atLeast()->once()->andReturn(new Collection([$expense]));
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()->withArgs([1])->andReturn($euro);
-
- // mock Steam, first start and then end.
- $startBalances = [
- $expense->id => [
- 1 => '-10',
- ],
- ];
- $endBalances = [
- $expense->id => [
- 1 => '-20',
- ],
- ];
-
- Steam::shouldReceive('balancesPerCurrencyByAccounts')->times(2)
- ->andReturn($startBalances, $endBalances);
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(route('api.v1.chart.account.expense') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/Chart/AvailableBudgetControllerTest.php b/tests/Api/V1/Controllers/Chart/AvailableBudgetControllerTest.php
deleted file mode 100644
index 980b2cf6fe..0000000000
--- a/tests/Api/V1/Controllers/Chart/AvailableBudgetControllerTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * AvailableBudgetControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers\Chart;
-
-
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use Illuminate\Support\Collection;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AvailableBudgetControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AvailableBudgetControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\AvailableBudgetController
- */
- public function testOverview(): void
- {
- $availableBudget = $this->user()->availableBudgets()->first();
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
-
- // get data:
- $budget = $this->getBudget();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $opsRepository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- $opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
- [
- [
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'currency_symbol' => 'x',
- 'currency_decimal_places' => 2,
- 'amount' => 321.21,
- ],
- ]
- );
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(
- route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
- . http_build_query($parameters), ['Accept' => 'application/json']
- );
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\AvailableBudgetController
- */
- public function testOverviewNothingLeft(): void
- {
- $availableBudget = $this->user()->availableBudgets()->first();
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- // get data:
- $budget = $this->getBudget();
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $opsRepository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- $opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
- [
- [
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'currency_symbol' => 'x',
- 'currency_decimal_places' => 2,
- 'amount' => -3321.21,
- ],
- ]
- );
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(
- route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
- . http_build_query($parameters), ['Accept' => 'application/json']
- );
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php b/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php
deleted file mode 100644
index 10d8571354..0000000000
--- a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * CategoryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers\Chart;
-
-
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class CategoryControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\Chart\CategoryController
- */
- public function testOverview(): void
- {
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $noCatRepos =$this->mock(NoCategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $noCatRepos->shouldReceive('setUser')->atLeast()->once();
- $opsRepos->shouldReceive('setUser')->atLeast()->once();
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
- //$opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
-
- $noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
- //$noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
-
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
- $response = $this->get(route('api.v1.chart.category.overview') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Api/V1/Controllers/CurrencyControllerTest.php b/tests/Api/V1/Controllers/CurrencyControllerTest.php
deleted file mode 100644
index d740dfa36c..0000000000
--- a/tests/Api/V1/Controllers/CurrencyControllerTest.php
+++ /dev/null
@@ -1,242 +0,0 @@
-<?php
-/**
- * CurrencyControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\CurrencyTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Preferences;
-use Tests\TestCase;
-use Amount;
-/**
- * Class CurrencyControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CurrencyControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- }
-
- /**
- * Store new currency.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CurrencyController
- */
- public function testStore(): void
- {
-
- $currency = $this->getEuro();
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(CurrencyTransformer::class);
- $this->mock(UserRepositoryInterface::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock facades.
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
- Preferences::shouldReceive('mark');
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->andReturn($currency);
-
- // data to submit:
- $data = [
- 'name' => 'New currency',
- 'code' => 'ABC',
- 'symbol' => 'A',
- 'decimal_places' => 2,
- 'default' => '0',
- 'enabled' => '1',
- ];
-
- // test API
- $response = $this->post(route('api.v1.currencies.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'currencies', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Store new currency and make it default.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CurrencyController
- */
- public function testStoreWithDefault(): void
- {
- $currency = $this->getEuro();
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(CurrencyTransformer::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
-
- // mock facades.
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $preference = new Preference;
- $preference->data = 'EUR';
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->andReturn($currency);
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->once();
- Preferences::shouldReceive('mark')->once();
- //Preferences::shouldReceive('lastActivity')->once();
- //Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
-
- // data to submit:
- $data = [
- 'name' => 'New currency',
- 'code' => 'ABC',
- 'symbol' => 'A',
- 'decimal_places' => 2,
- 'default' => '1',
- 'enabled' => '1',
- ];
-
- // test API
- $response = $this->post(route('api.v1.currencies.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'currencies', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update currency.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CurrencyController
- */
- public function testUpdate(): void
- {
- $currency = $this->getEuro();
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(CurrencyTransformer::class);
- $this->mock(UserRepositoryInterface::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- Preferences::shouldReceive('mark');
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('update')->andReturn($currency);
-
- // data to submit:
- $data = [
- 'name' => 'Updated currency',
- 'code' => 'ABC',
- 'symbol' => '$E',
- 'decimal_places' => '2',
- 'default' => '0',
- 'enabled' => '1',
- ];
-
- // test API
- $response = $this->put(route('api.v1.currencies.update', [$currency->code]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'currencies', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Update currency and make default.
- *
- * @covers \FireflyIII\Api\V1\Controllers\CurrencyController
- */
- public function testUpdateWithDefault(): void
- {
- $currency = $this->getEuro();
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(CurrencyTransformer::class);
- $this->mock(UserRepositoryInterface::class);
- $preference = new Preference;
- $preference->data = 'EUR';
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('update')->andReturn($currency);
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->once();
- Preferences::shouldReceive('mark')->once();
- //Preferences::shouldReceive('lastActivity')->once();
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
- //Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
-
- // data to submit:
- $data = [
- 'name' => 'Updated currency',
- 'code' => 'ABC',
- 'symbol' => '$E',
- 'decimal_places' => '2',
- 'default' => '1',
- 'enabled' => '1',
- ];
-
- // test API
- $response = $this->put(route('api.v1.currencies.update', [$currency->code]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'currencies', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-}
diff --git a/tests/Api/V1/Controllers/LinkTypeControllerTest.php b/tests/Api/V1/Controllers/LinkTypeControllerTest.php
deleted file mode 100644
index 6ff67aa458..0000000000
--- a/tests/Api/V1/Controllers/LinkTypeControllerTest.php
+++ /dev/null
@@ -1,263 +0,0 @@
-<?php
-/**
- * LinkTypeControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Exception;
-use FireflyIII\Models\LinkType;
-use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\LinkTypeTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class LinkTypeControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class LinkTypeControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
- * @throws Exception
- */
- public function testStore(): void
- {
- $linkType = LinkType::first();
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(LinkTypeTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->once()->andReturn($linkType);
- $userRepository->shouldReceive('hasRole')->once()->andReturn(true);
-
-
- // data to submit
- $data = [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ];
-
- // test API
- $response = $this->post(route('api.v1.link_types.store'), $data);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
- * @throws Exception
- */
- public function testStoreNotOwner(): void
- {
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $userRepository->shouldReceive('hasRole')->once()->andReturn(false);
-
-
- // data to submit
- $data = [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->post(route('api.v1.link_types.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200005');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
- * @throws Exception
- */
- public function testUpdate(): void
- {
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(LinkTypeTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $userRepository->shouldReceive('hasRole')->once()->andReturn(true);
-
- // create editable link type:
- $linkType = LinkType::create(
- [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ]
- );
-
- // mock calls:
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('update')->once()->andReturn($linkType);
-
- // data to submit
- $data = [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ];
-
- // test API
- $response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
- * @throws Exception
- */
- public function testUpdateNotEditable(): void
- {
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
-
- // create editable link type:
- $linkType = LinkType::create(
- [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => false,
-
- ]
- );
-
- // mock calls:
- $repository->shouldReceive('setUser');
-
- // data to submit
- $data = [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200020');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
- * @throws Exception
- */
- public function testUpdateNotOwner(): void
- {
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
-
- $userRepository->shouldReceive('hasRole')->once()->andReturn(false);
-
- // create editable link type:
- $linkType = LinkType::create(
- [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ]
- );
-
- // mock calls:
- $repository->shouldReceive('setUser');
-
- // data to submit
- $data = [
- 'name' => 'random' . $this->randomInt(),
- 'outward' => 'outward' . $this->randomInt(),
- 'inward' => 'inward ' . $this->randomInt(),
- 'editable' => true,
-
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200005');
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/PiggyBankControllerTest.php b/tests/Api/V1/Controllers/PiggyBankControllerTest.php
deleted file mode 100644
index 0e031c972e..0000000000
--- a/tests/Api/V1/Controllers/PiggyBankControllerTest.php
+++ /dev/null
@@ -1,229 +0,0 @@
-<?php
-/**
- * PiggyBankControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Exception;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Transformers\PiggyBankTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- *
- * Class PiggyBankControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankControllerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
- * @throws Exception
- */
- public function testStore(): void
- {
- // create stuff
- $piggy = $this->user()->piggyBanks()->first();
-
- // mock stuff:
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $transformer = $this->mock(PiggyBankTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('store')->once()->andReturn($piggy);
-
- $data = [
- 'name' => 'New piggy #' . $this->randomInt(),
- 'account_id' => 1,
- 'target_amount' => '100',
- ];
-
- // test API
- $response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'piggy_banks', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
- * @throws Exception
- */
- public function testStoreThrowError(): void
- {
- // mock stuff:
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('store')->once()->andThrow(new FireflyException('400005'));
-
-
- $data = [
- 'name' => 'New piggy #' . $this->randomInt(),
- 'account_id' => 1,
- 'target_amount' => '100',
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertHeader('Content-Type', 'application/json');
- $response->assertSee('400005');
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
- * @throws Exception
- */
- public function testUpdate(): void
- {
- // create stuff
- $piggy = $this->user()->piggyBanks()->first();
-
- // mock stuff:
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(PiggyBankTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- // mock calls:
- $repository->shouldReceive('setUser');
-
- $repository->shouldReceive('update')->once()->andReturn($piggy);
-
- $repository->shouldReceive('getCurrentAmount')->andReturn('12');
- $repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12');
-
- //$accountRepos->shouldReceive('setUser');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- $currencyRepos->shouldReceive('setUser');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro());
-
- $data = [
- 'name' => 'new pigy bank ' . $this->randomInt(),
- 'account_id' => 1,
- 'target_amount' => '100',
- ];
-
- // test API
- $response = $this->put(route('api.v1.piggy_banks.update', [$piggy->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'piggy_banks', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
- * @throws Exception
- */
- public function testUpdateWithAmount(): void
- {
- // create stuff
- $piggy = $this->getRandomPiggyBank();
-
- // mock stuff:
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $transformer = $this->mock(PiggyBankTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- // mock calls:
- $repository->shouldReceive('setUser');
-
- $repository->shouldReceive('update')->once()->andReturn($piggy);
- $repository->shouldReceive('setCurrentAmount')->once();
- $repository->shouldReceive('getCurrentAmount')->andReturn('0');
- $repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12');
-
- //$accountRepos->shouldReceive('setUser');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- $currencyRepos->shouldReceive('setUser');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro());
-
- $data = [
- 'name' => 'new pigy bank ' . $this->randomInt(),
- 'account_id' => 1,
- 'current_amount' => '5',
- 'target_amount' => '100',
- ];
-
- // test API
- $response = $this->put(route('api.v1.piggy_banks.update', [$piggy->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertJson(['data' => ['type' => 'piggy_banks', 'links' => true],]);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/PreferencesControllerTest.php b/tests/Api/V1/Controllers/PreferencesControllerTest.php
deleted file mode 100644
index a6273e1562..0000000000
--- a/tests/Api/V1/Controllers/PreferencesControllerTest.php
+++ /dev/null
@@ -1,203 +0,0 @@
-<?php
-/**
- * PreferencesControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Transformers\PreferenceTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class PreferencesControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PreferencesControllerTest extends TestCase
-{
-
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PreferenceController
- */
- public function testUpdateArray(): void
- {
- $transformer = $this->mock(PreferenceTransformer::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls to preferences facade.
- $pref = new Preference;
- $pref->data = [1, 2, 3];
-
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($pref);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', ['4', '5', '6']])->atLeast()->once()->andReturn($pref);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- ///** @var Preference $preference */
- //$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]);
- $data = ['data' => '4,5,6'];
- $response = $this->put(route('api.v1.preferences.update', ['frontPageAccounts']), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PreferenceController
- */
- public function testUpdateBoolean(): void
- {
- $transformer = $this->mock(PreferenceTransformer::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls to preferences facade.
- $pref = new Preference;
- $pref->data = false;
- $countable = new Preference;
- $countable->data = [1];
-
- $saved = new Preference;
- $saved->user_id = $this->user()->id;
- $saved->name = 'customFiscalYear';
- $saved->data = false;
- $saved->save();
-
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['customFiscalYear', '1'])->atLeast()->once()->andReturn($pref);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- /** @var Preference $preference */
- $data = ['data' => '1'];
- $response = $this->put(route('api.v1.preferences.update', ['customFiscalYear']), $data, ['Accept' => 'application/json']);
-
- $response->assertStatus(200);
-
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PreferenceController
- */
- public function testUpdateDefault(): void
- {
- $transformer = $this->mock(PreferenceTransformer::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to preferences facade.
- $pref = new Preference;
- $pref->data = 'EUR';
- $countable = new Preference;
- $countable->data = [1];
-
- $saved = new Preference;
- $saved->user_id = $this->user()->id;
- $saved->name = 'customFiscalYear';
- $saved->data = false;
- $saved->save();
-
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
-
- $data = ['data' => 'EUR'];
- $response = $this->put(route('api.v1.preferences.update', ['currencyPreference']), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\PreferenceController
- */
- public function testUpdateInteger(): void
- {
- $transformer = $this->mock(PreferenceTransformer::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to preferences facade.
- $pref = new Preference;
- $pref->data = 'EUR';
- $countable = new Preference;
- $countable->data = [1];
-
- $saved = new Preference;
- $saved->user_id = $this->user()->id;
- $saved->name = 'listPageSize';
- $saved->data = 200;
- $saved->save();
-
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['listPageSize', '434'])->atLeast()->once()->andReturn($pref);
-
- $data = ['data' => '434'];
- $response = $this->put(route('api.v1.preferences.update', ['listPageSize']), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
-}
diff --git a/tests/Api/V1/Controllers/RecurrenceControllerTest.php b/tests/Api/V1/Controllers/RecurrenceControllerTest.php
deleted file mode 100644
index b9c3fbce0c..0000000000
--- a/tests/Api/V1/Controllers/RecurrenceControllerTest.php
+++ /dev/null
@@ -1,1466 +0,0 @@
-<?php
-/**
- * RecurrenceControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use Carbon\Carbon;
-use FireflyIII\Models\Recurrence;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Transformers\RecurrenceTransformer;
-use FireflyIII\Validation\AccountValidator;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class RecurrenceControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveClassLength)
- */
-class RecurrenceControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreAssetId(): void
- {
- // get a recurrence:
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source name field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreAssetName(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, 'Checking Account', null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_name' => 'Checking Account',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Submit a deposit. Since most validators have been tested in other methods, dont bother too much.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreDeposit(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Some expense account', null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'deposit',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description deposit',
- 'source_name' => 'Some expense account',
- 'destination_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Add a recurring with correct reference to a destination (expense).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreDestinationId(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
- $expenseAccount = $this->getRandomExpense();
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$expenseAccount->id, null, null])->andReturn(true);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- 'destination_id' => $expenseAccount->id,
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Add a recurring with correct reference to a destination (expense).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreDestinationName(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $expenseAccount = $this->getRandomExpense();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, $expenseAccount->name, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- 'destination_name' => $expenseAccount->name,
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Includes both repetition count and an end date.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailBothRepetitions(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $repeatUntil = new Carbon;
- $repeatUntil->addMonth();
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'repeat_until' => $repeatUntil->format('Y-m-d'),
- 'nr_of_repetitions' => 10,
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repeat_until' => [
- 'Require either a number of repetitions, or an end date (repeat_until). Not both.',
- ],
- 'nr_of_repetitions' => [
- 'Require either a number of repetitions, or an end date (repeat_until). Not both.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit foreign amount but no currency information.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailForeignCurrency(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Checking Account', null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'foreign_amount' => '100',
- 'description' => 'Test description',
- 'source_name' => 'Checking Account',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions.0.foreign_amount' => [
- 'The content of this field is invalid without currency information.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidDaily(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '1',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Add a recurring but refer to an asset as destination.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidDestinationId(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $assetAccount = $this->getRandomAsset();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$assetAccount->id, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$assetAccount->id, null, null])->andReturn(false);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => $assetAccount->id,
- 'destination_id' => $assetAccount->id,
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions.0.destination_id' => [
- null,
- ],
- 'transactions.0.destination_name' => [
- null,
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidMonthly(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'monthly',
- 'moment' => '32',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidNdom(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'ndom',
- 'moment' => '9,9',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidNdomCount(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'ndom',
- 'moment' => '9',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidNdomHigh(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'ndom',
- 'moment' => '4,9',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit the minimum amount to store a recurring transaction (using source ID field).
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailInvalidWeekly(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'weekly',
- 'moment' => '8',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions.0.moment' => [
- 'Invalid repetition moment for this type of repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit without a source account.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailNoAsset(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, null, null])->andReturn(false);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '0',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions.0.source_id' => [
- null,
- ],
- 'transactions.0.source_name' => [
- null,
- ],
- ],
- ]
- );
- $response->assertStatus(422);
-
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit with an expense account.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailNotAsset(): void
- {
- // expense account:
- $expenseAccount = $this->getRandomExpense();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$expenseAccount->id, null, null])->andReturn(false);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => $expenseAccount->id,
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions.0.source_id' => [
- null,
- ],
- 'transactions.0.source_name' => [
- null,
- ],
- ],
- ]
- );
- $response->assertStatus(422);
-
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit with an invalid asset account name.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailNotAssetName(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, 'Fake name', null])->andReturn(false);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_name' => 'Fake name',
- 'source_id' => '0',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions.0.source_id' => [
- null,
- ],
- 'transactions.0.source_name' => [
- null,
- ],
- ],
- ]
- );
- $response->assertStatus(422);
-
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Dont include enough repetitions.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailRepetitions(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null, null])->andReturn(true);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description',
- 'source_id' => '1',
- ],
- ],
- 'repetitions' => [],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'repetitions' => [
- 'Need at least one repetition.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Dont include enough repetitions.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreFailTransactions(): void
- {
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(AccountValidator::class);
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'withdrawal',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertExactJson(
- [
- 'message' => 'The given data was invalid.',
- 'errors' => [
- 'transactions' => [
- 'Need at least one transaction.',
- ],
- ],
- ]
- );
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * Submit a transfer. Since most validators have been tested in other methods, dont bother too much.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testStoreTransfer(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- $assetAccount = $this->getRandomAsset();
- $otherAssetAccount = $this->getRandomAsset($assetAccount->id);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$assetAccount->id, null, null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$otherAssetAccount->id, null, null])->andReturn(true);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('store')->once()->andReturn($recurrence);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'transfer',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description transfer',
- 'source_id' => $assetAccount->id,
- 'destination_id' => $otherAssetAccount->id,
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * Just a basic test because the store() tests cover everything.
- *
- * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
- * @covers \FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest
- * @covers \FireflyIII\Api\V1\Requests\Request
- */
- public function testUpdate(): void
- {
- /** @var Recurrence $recurrence */
- $recurrence = $this->user()->recurrences()->first();
-
- // mock stuff:
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- // mock calls to validator:
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Some expense account', null])->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([1, null, null])->andReturn(true);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('update')->once()->andReturn($recurrence);
-
- // data to submit
- $firstDate = new Carbon;
- $firstDate->addDays(2);
- $data = [
- 'type' => 'deposit',
- 'title' => 'Hello',
- 'first_date' => $firstDate->format('Y-m-d'),
- 'apply_rules' => 1,
- 'active' => 1,
- 'transactions' => [
- [
- 'amount' => '100',
- 'currency_id' => '1',
- 'description' => 'Test description deposit',
- 'source_name' => 'Some expense account',
- 'destination_id' => '1',
- ],
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => '0',
- 'weekend' => '1',
-
- ],
- ],
- ];
-
- // test API
- $response = $this->put(route('api.v1.recurrences.update', [$recurrence->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
-
-}
diff --git a/tests/Api/V1/Controllers/RuleControllerTest.php b/tests/Api/V1/Controllers/RuleControllerTest.php
deleted file mode 100644
index 633894eaa6..0000000000
--- a/tests/Api/V1/Controllers/RuleControllerTest.php
+++ /dev/null
@@ -1,404 +0,0 @@
-<?php
-/**
- * RuleControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Rule;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use FireflyIII\TransactionRules\TransactionMatcher;
-use FireflyIII\Transformers\RuleTransformer;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class RuleControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RuleControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleStoreRequest
- */
- public function testStore(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $ruleRepos->shouldReceive('setUser')->once();
- $rule = $this->user()->rules()->first();
- $data = [
- 'title' => 'Store new rule',
- 'rule_group_id' => 1,
- 'trigger' => 'store-journal',
- 'strict' => 1,
- 'stop_processing' => 1,
- 'active' => 1,
- 'triggers' => [
- [
- 'type' => 'description_is',
- 'value' => 'Hello',
- 'stop_processing' => 1,
- ],
- ],
- 'actions' => [
- [
- 'type' => 'add_tag',
- 'value' => 'A',
- 'stop_processing' => 1,
- ],
- ],
- ];
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('store')->once()->andReturn($rule);
-
- // test API
- $response = $this->post(route('api.v1.rules.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleStoreRequest
- */
- public function testStoreNoActions(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(RuleTransformer::class);
- Preferences::shouldReceive('mark');
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
- $data = [
- 'title' => 'Store new rule',
- 'rule_group_id' => 1,
- 'trigger' => 'store-journal',
- 'strict' => 1,
- 'stop_processing' => 1,
- 'active' => 1,
- 'triggers' => [
- [
- 'type' => 'description_is',
- 'value' => 'Hello',
- 'stop_processing' => 1,
- ],
- ],
- 'actions' => [
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.rules.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'title' => [
- 'Rule must have at least one action.',
- ],
- ],
- 'message' => 'The given data was invalid.',
- ]);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleStoreRequest
- */
- public function testStoreNoTriggers(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(RuleTransformer::class);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
- $data = [
- 'title' => 'Store new rule',
- 'rule_group_id' => 1,
- 'trigger' => 'store-journal',
- 'strict' => 1,
- 'stop_processing' => 1,
- 'active' => 1,
- 'triggers' => [
- ],
- 'actions' => [
- [
- 'type' => 'add_tag',
- 'value' => 'A',
- 'stop_processing' => 1,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.rules.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'title' => [
- 'Rule must have at least one trigger.',
- ],
- ],
- 'message' => 'The given data was invalid.',
- ]);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleTestRequest
- */
- public function testTestRule(): void
- {
- $rule = $this->user()->rules()->first();
-
- // mock used classes.
- $repository = $this->mock(AccountRepositoryInterface::class);
- $matcher = $this->mock(TransactionMatcher::class);
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
-
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
-
- $repository->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
-
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($asset);
- $repository->shouldReceive('findNull')->withArgs([2])->andReturn($expense);
- $repository->shouldReceive('findNull')->withArgs([3])->andReturn(null);
-
- $matcher->shouldReceive('setRule')->once();
- $matcher->shouldReceive('setEndDate')->once();
- $matcher->shouldReceive('setStartDate')->once();
- $matcher->shouldReceive('setSearchLimit')->once();
- $matcher->shouldReceive('setTriggeredLimit')->once();
- $matcher->shouldReceive('setAccounts')->once();
- $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([[1]]);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 50;
-
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
-
- $response = $this->get(route('api.v1.rules.test', [$rule->id]) . '?accounts=1,2,3');
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleTriggerRequest
- */
- public function testTriggerRule(): void
- {
- $rule = $this->user()->rules()->first();
- $repository = $this->mock(AccountRepositoryInterface::class);
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- Preferences::shouldReceive('mark');
-
- // new mocks for ruleEngine
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
-
- $collector->shouldReceive('setAccounts')->atLeast()->once();
- $collector->shouldReceive('setRange')->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
-
-
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
-
- $repository->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($asset);
- $repository->shouldReceive('findNull')->withArgs([2])->andReturn($expense);
- $repository->shouldReceive('findNull')->withArgs([3])->andReturn(null);
-
- $response = $this->post(route('api.v1.rules.trigger', [$rule->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
- $response->assertStatus(204);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- */
- public function testMoveRuleDown(): void
- {
- /** @var Rule $rule */
- $rule = $this->user()->rules()->first();
-
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('find')->once()->andReturn($rule);
- $ruleRepos->shouldReceive('moveDown')->once();
-
- // test API
- $response = $this->post(route('api.v1.rules.down', [$rule->id]), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- */
- public function testMoveRuleUp(): void
- {
- /** @var Rule $rule */
- $rule = $this->user()->rules()->first();
-
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('find')->once()->andReturn($rule);
- $ruleRepos->shouldReceive('moveUp')->once();
-
- // test API
- $response = $this->post(route('api.v1.rules.up', [$rule->id]), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleController
- * @covers \FireflyIII\Api\V1\Requests\RuleUpdateRequest
- */
- public function testUpdate(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleRepos->shouldReceive('setUser')->once();
-
- /** @var Rule $rule */
- $rule = $this->user()->rules()->first();
- $data = [
- 'title' => 'Store new rule',
- 'rule_group_id' => 1,
- 'trigger' => 'store-journal',
- 'strict' => 1,
- 'stop_processing' => 1,
- 'active' => 1,
- 'triggers' => [
- [
- 'type' => 'description_is',
- 'value' => 'Hello',
- 'stop_processing' => 1,
- ],
- ],
- 'actions' => [
- [
- 'type' => 'add_tag',
- 'value' => 'A',
- 'stop_processing' => 1,
- ],
- ],
- ];
-
- $ruleRepos->shouldReceive('update')->once()->andReturn($rule);
-
- // test API
- $response = $this->put(route('api.v1.rules.update', [$rule->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
-}
diff --git a/tests/Api/V1/Controllers/RuleGroupControllerTest.php b/tests/Api/V1/Controllers/RuleGroupControllerTest.php
deleted file mode 100644
index f45c787f88..0000000000
--- a/tests/Api/V1/Controllers/RuleGroupControllerTest.php
+++ /dev/null
@@ -1,324 +0,0 @@
-<?php
-/**
- * RuleGroupControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
-use FireflyIII\Jobs\Job;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use FireflyIII\TransactionRules\TransactionMatcher;
-use FireflyIII\Transformers\RuleGroupTransformer;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use Illuminate\Support\Collection;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Preferences;
-use Queue;
-use Tests\TestCase;
-
-/**
- *
- * Class RuleGroupControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RuleGroupControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- * @covers \FireflyIII\Api\V1\Requests\RuleGroupRequest
- */
- public function testStore(): void
- {
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleGroupTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $ruleGroup = $this->user()->ruleGroups()->first();
- $data = [
- 'title' => 'Store new rule group ' . $this->randomInt(),
- 'active' => 1,
- 'description' => 'Hello',
- ];
-
- $ruleGroupRepos->shouldReceive('store')->once()->andReturn($ruleGroup);
-
-
-
- // test API
- $response = $this->post(route('api.v1.rule_groups.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- * @covers \FireflyIII\Api\V1\Requests\RuleGroupTestRequest
- */
- public function testTestGroupBasic(): void
- {
- $group = $this->user()->ruleGroups()->first();
- $rule = $this->user()->rules()->first();
-
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
- $matcher = $this->mock(TransactionMatcher::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
-
-
- // mock calls
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
-
-
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('setUser')->once();
-
- $ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection([$rule]));
-
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($asset);
- $repository->shouldReceive('findNull')->withArgs([2])->andReturn($expense);
- $repository->shouldReceive('findNull')->withArgs([3])->andReturn(null);
-
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $matcher->shouldReceive('setRule')->once();
- $matcher->shouldReceive('setEndDate')->once();
- $matcher->shouldReceive('setStartDate')->once();
- $matcher->shouldReceive('setSearchLimit')->once();
- $matcher->shouldReceive('setTriggeredLimit')->once();
- $matcher->shouldReceive('setAccounts')->once();
- $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 50;
-
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
-
- // call API
- $response = $this->get(route('api.v1.rule_groups.test', [$group->id]) . '?accounts=1,2,3');
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- * @covers \FireflyIII\Api\V1\Requests\RuleGroupTestRequest
- */
- public function testTestGroupEmpty(): void
- {
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection);
-
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 50;
-
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- // call API
- $group = $this->user()->ruleGroups()->first();
- Log::warning('The following error is part of a test.');
- $response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200023');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- * @covers \FireflyIII\Api\V1\Requests\RuleGroupTriggerRequest
- */
- public function testTrigger(): void
- {
- $group = $this->user()->ruleGroups()->first();
- $rule = $this->user()->rules()->first();
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
-
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
- $matcher = $this->mock(TransactionMatcher::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
-
-
- // new mocks for ruleEngine
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
-
- $collector->shouldReceive('setAccounts')->atLeast()->once();
- $collector->shouldReceive('setRange')->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
-
-
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection([$rule]));
-
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($asset);
- $repository->shouldReceive('findNull')->withArgs([2])->andReturn($expense);
- $repository->shouldReceive('findNull')->withArgs([3])->andReturn(null);
- $repository->shouldReceive('isAsset')->withArgs([1])->andReturn(true);
- $repository->shouldReceive('isAsset')->withArgs([2])->andReturn(false);
-
-
-
- $response = $this->post(route('api.v1.rule_groups.trigger', [$group->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
- $response->assertStatus(204);
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- * @covers \FireflyIII\Api\V1\Requests\RuleGroupRequest
- */
- public function testUpdate(): void
- {
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleGroupTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $ruleGroup = $this->user()->ruleGroups()->first();
- $data = [
- 'title' => 'Store new rule ' . $this->randomInt(),
- 'active' => 1,
- 'description' => 'Hello',
- ];
-
- $ruleGroupRepos->shouldReceive('update')->once()->andReturn($ruleGroup);
-
- // test API
- $response = $this->put(route('api.v1.rule_groups.update', [$ruleGroup->id]), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
-
- }
-
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- */
- public function testMoveRuleGroupDown(): void
- {
- /** @var RuleGroup $group */
- $group = $this->user()->ruleGroups()->first();
-
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleGroupTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('find')->once()->andReturn($group);
- $ruleGroupRepos->shouldReceive('moveDown')->once();
-
- // test API
- $response = $this->post(route('api.v1.rule_groups.down', [$group->id]), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
- */
- public function testMoveRuleGroupUp(): void
- {
- /** @var RuleGroup $group */
- $group = $this->user()->ruleGroups()->first();
-
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RuleGroupTransformer::class);
-
- // mock calls to transformer:
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $accountRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('setUser')->once();
- $ruleGroupRepos->shouldReceive('find')->once()->andReturn($group);
- $ruleGroupRepos->shouldReceive('moveUp')->once();
-
- // test API
- $response = $this->post(route('api.v1.rule_groups.up', [$group->id]), ['Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Api/V1/Controllers/SummaryControllerTest.php b/tests/Api/V1/Controllers/SummaryControllerTest.php
deleted file mode 100644
index d43c7e9560..0000000000
--- a/tests/Api/V1/Controllers/SummaryControllerTest.php
+++ /dev/null
@@ -1,280 +0,0 @@
-<?php
-/**
- * SummaryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Report\NetWorthInterface;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class SummaryControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class SummaryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Also includes NULL currencies for better coverage.
- *
- * @covers \FireflyIII\Api\V1\Controllers\SummaryController
- */
- public function testBasicInTheFuture(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $netWorth = $this->mock(NetWorthInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon();
- $date->addWeek();
-
- // data
- $euro = $this->getEuro();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $account = $this->getRandomAsset();
- $journals = [
- [
- 'amount' => '10',
- 'currency_id' => 1,
- ],
- [
- 'amount' => '10',
- 'currency_id' => 2,
- ],
-
- ];
- $netWorthData = [
- [
- 'currency' => $euro,
- 'balance' => '232',
- ],
- [
- 'currency' => $euro,
- 'balance' => '0',
- ],
- ];
-
- // mock calls.
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $netWorth->shouldReceive('setUser')->atLeast()->once();
- $opsRepos->shouldReceive('setUser')->atLeast()->once();
- $abRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock collector calls:
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
-
- // used to get balance information (deposits)
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->atLeast()->once()->andReturnSelf();
-
- // same, but for withdrawals
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->atLeast()->once()->andReturnSelf();
-
- // system always returns one basic transaction (see above)
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($journals);
-
- // currency repos does some basic collecting
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($euro);
- $currencyRepos->shouldReceive('findNull')->withArgs([2])->atLeast()->once()->andReturn(null);
-
- // bill repository return value
- $billRepos->shouldReceive('getBillsPaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
- $billRepos->shouldReceive('getBillsUnpaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
-
- // budget repos
- $abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
- $budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
-
- // new stuff
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
-
-
- //$opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
-// [
-// [
-// 'currency_id' => 3,
-// 'currency_code' => 'EUR',
-// 'currency_symbol' => 'x',
-// 'currency_decimal_places' => 2,
-// 'amount' => 321.21,
-// ],
-// [
-// 'currency_id' => 1,
-// 'currency_code' => 'EUR',
-// 'currency_symbol' => 'x',
-// 'currency_decimal_places' => 2,
-// 'amount' => 321.21,
-// ],
-//
-// ]
-// );
-
- // account repos:
- $accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
-
- // net worth calculator
- $netWorth->shouldReceive('getNetWorthByCurrency')->atLeast()->once()->andReturn($netWorthData);
-
- $parameters = [
- 'start' => $date->format('Y-m-d'),
- 'end' => $date->addWeek()->format('Y-m-d'),
- ];
-
- // TODO AFTER 4.8,0: check if JSON is correct
- $response = $this->get(route('api.v1.summary.basic') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
- //$response->assertSee('hi there');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\SummaryController
- */
- public function testBasicInThePast(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $netWorth = $this->mock(NetWorthInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
- // data
- $euro = $this->getEuro();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $account = $this->getRandomAsset();
- $journals = [
- [
- 'amount' => '10',
- 'currency_id' => 1,
- ],
- ];
- $netWorthData = [
- [
- 'currency' => $euro,
- 'balance' => '232',
- ],
- ];
-
- // mock calls.
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $netWorth->shouldReceive('setUser')->atLeast()->once();
- $abRepos->shouldReceive('setUser')->atLeast()->once();
- $opsRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock collector calls:
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
-
- // used to get balance information (deposits)
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->atLeast()->once()->andReturnSelf();
-
- // same, but for withdrawals
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->atLeast()->once()->andReturnSelf();
-
- // system always returns one basic transaction (see above)
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($journals);
-
- // currency repos does some basic collecting
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($euro);
-
- // bill repository return value
- $billRepos->shouldReceive('getBillsPaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123']);
- $billRepos->shouldReceive('getBillsUnpaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123']);
-
- // budget repos
- $abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123']);
- $budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
-
- // new stuff
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
-
-// $opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
-// [
-// [
-// 'currency_id' => 1,
-// 'currency_code' => 'EUR',
-// 'currency_symbol' => 'x',
-// 'currency_decimal_places' => 2,
-// 'amount' => 321.21,
-// ],
-// ]
-// );
-
- // account repos:
- $accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
-
- // net worth calculator
- $netWorth->shouldReceive('getNetWorthByCurrency')->atLeast()->once()->andReturn($netWorthData);
-
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-31',
- ];
-
- $response = $this->get(route('api.v1.summary.basic') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
- // TODO AFTER 4.8,0: check if JSON is correct
- }
-}
diff --git a/tests/Api/V1/Controllers/TagControllerTest.php b/tests/Api/V1/Controllers/TagControllerTest.php
deleted file mode 100644
index ac3e424873..0000000000
--- a/tests/Api/V1/Controllers/TagControllerTest.php
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-/**
- * TagControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-use FireflyIII\Repositories\Tag\TagRepositoryInterface;
-use FireflyIII\Transformers\TagTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TagControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TagControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Create Tag over API.
- *
- * @covers \FireflyIII\Api\V1\Controllers\TagController
- * @covers \FireflyIII\Api\V1\Requests\TagStoreRequest
- */
- public function testStore(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->user()->tags()->inRandomOrder()->first();
- $data = ['tag' => 'Some tag' . $this->randomInt(),];
- $transformer = $this->mock(TagTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- $tagRepos->shouldReceive('setUser')->times(1);
- $tagRepos->shouldReceive('store')->times(1)->andReturn($tag);
-
- // call API
- $response = $this->post(route('api.v1.tags.store'), $data);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TagController
- */
- public function testCloud(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tags = $this->user()->tags()->inRandomOrder()->limit(3)->get();
-
- $tagRepos->shouldReceive('setUser')->times(1);
- $tagRepos->shouldReceive('get')->atLeast()->once()->andReturn($tags);
- $tagRepos->shouldReceive('earnedInPeriod')->times(3)->andReturn('0');
- $tagRepos->shouldReceive('spentInPeriod')->times(3)->andReturn('-10', '-20', '-30');
-
- // call API
- $parameters = [
- 'start' => '2019-01-01',
- 'end' => '2019-01-05',
- ];
- $response = $this->get(route('api.v1.tag-cloud.cloud') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- $response->assertJson(
- [
- 'tags' => [
- [
- 'size' => 10,
- 'relative' => 0.3333,
- ],
- [
- 'size' => 20,
- 'relative' => 0.6667,
- ],
- [
- 'size' => 30,
- 'relative' => 1,
- ],
- ],
- ]);
- }
-
- /**
- * Update Tag over API.
- *
- * @covers \FireflyIII\Api\V1\Controllers\TagController
- * @covers \FireflyIII\Api\V1\Requests\TagUpdateRequest
- */
- public function testUpdate(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->user()->tags()->inRandomOrder()->first();
- $data = ['tag' => 'Some tag' . $this->randomInt(),];
- $transformer = $this->mock(TagTransformer::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- $tagRepos->shouldReceive('setUser')->times(2);
- $tagRepos->shouldReceive('update')->times(1)->andReturn($tag);
- $tagRepos->shouldReceive('findByTag')->times(1)->andReturnNull();
- $tagRepos->shouldReceive('findNull')->times(1)->andReturn($tag);
-
- // call API
- $response = $this->put(route('api.v1.tags.update', [$tag->id]), $data);
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php
deleted file mode 100644
index b3f802b8ff..0000000000
--- a/tests/Api/V1/Controllers/TransactionControllerTest.php
+++ /dev/null
@@ -1,916 +0,0 @@
-<?php
-/**
- * TransactionControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use Exception;
-use FireflyIII\Events\StoredTransactionGroup;
-use FireflyIII\Events\UpdatedTransactionGroup;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use FireflyIII\Validation\AccountValidator;
-use Illuminate\Support\Collection;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Submit empty description.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailDescription(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'transactions' => [
- [
- 'description' => '',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.description' => ['The description field is required.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Fail the valid destination information test.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailDestination(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- /** fail destination */
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false)
- ->andSet('destError', 'Some error');
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Fails anyway',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.destination_id' => ['Some error'],
- 'transactions.0.destination_name' => ['Some error'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Submit foreign currency info, but no foreign currency amount.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailForeignCurrencyAmount(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Test',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'foreign_currency_code' => 'USD',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.foreign_amount' => ['The content of this field is invalid without foreign amount information.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Submit foreign currency, but no foreign currency info.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailForeignCurrencyInfo(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Test',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'foreign_amount' => '11',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.foreign_amount' => ['The content of this field is invalid without currency information.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Fail the valid source information test.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailSource(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- /** source info returns FALSE **/
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false)
- ->andSet('sourceError', 'Some error');
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Some withdrawal ',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.source_id' => ['Some error'],
- 'transactions.0.source_name' => ['Some error'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Submit multiple transactions but no group title.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailStoreGroupTitle(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'group_title' => ['A group title is mandatory when there is more than one transaction.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Submit multiple transactions but no group title.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailStoreNoTransactions(): void
- {
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
- $data = [
- 'transactions' => [
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.description' => ['Need at least one transaction.', 'The description field is required.'],
- 'transactions.0.type' => ['Invalid transaction type.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Try to submit different transaction types for a withdrawal.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailTypes(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'group_title' => 'Hi there',
- 'transactions' => [
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'deposit',
- 'amount' => '10',
- 'destination_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.source_id' => ['All accounts in this field must be equal.'],
- 'transactions.0.type' => ['All splits must be of the same type.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Try to submit different transaction types for a deposit.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailTypesDeposit(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'group_title' => 'Hi there',
- 'transactions' => [
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'deposit',
- 'amount' => '10',
- 'destination_id' => $source->id,
- ],
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
-
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.destination_id' => ['All accounts in this field must be equal.'],
- 'transactions.0.type' => ['All splits must be of the same type.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Try to submit different transaction types for a transfer.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreFailTypesTransfer(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
- $dest = $this->getRandomAsset($source->id);
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['transfer'])->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'group_title' => 'Hi there',
- 'transactions' => [
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'transfer',
- 'amount' => '10',
- 'destination_id' => $source->id,
- 'source_id' => $dest->id,
- ],
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'deposit',
- 'amount' => '10',
- 'destination_id' => $dest->id,
- 'source_id' => $source->id,
- ],
-
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.destination_id' => ['All accounts in this field must be equal.'],
- 'transactions.0.source_id' => ['All accounts in this field must be equal.'],
- 'transactions.0.type' => ['All splits must be of the same type.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- }
-
- /**
- * Submit the minimum amount of data required to create a single, unsplit withdrawal.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testStoreOK(): void
- {
- // mock data:
- $source = $this->getRandomAsset();
- $group = $this->getRandomWithdrawalGroup();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
- $validator = $this->mock(AccountValidator::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // transformer is called:
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 1]);
- $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
-
- // collector is called:
- $collector->shouldReceive('setTransactionGroup')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAPIInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection([[]]));
-
- // expect to store the group:
- $repository->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- // expect the event:
- try {
- $this->expectsEvents(StoredTransactionGroup::class);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
-
-
- $data = [
- 'transactions' => [
- [
- 'description' => 'Some description',
- 'date' => '2018-01-01',
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'source_id' => $source->id,
- ],
- ],
- ];
-
- // test API
- $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertExactJson(
- [
- 'data' => [
- 'attributes' => [],
- 'id' => '1',
- 'links' => [
- 'self' => 'http://localhost/api/v1/transactions/1',
- ],
- 'type' => 'transactions',
- ],
- ]
- );
- }
-
- /**
- * Submit a bad journal ID during update.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testUpdateFailBadJournal(): void
- {
- // mock data:
- $group = $this->getRandomWithdrawalGroup();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- $validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
- //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
- //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
-
- $data = [
- 'group_title' => 'Empty',
- 'transactions' => [
- [
- 'order' => 0,
- 'transaction_journal_id' => -1,
- 'reconciled' => 'false',
- 'tags' => [],
- 'interest_date' => '2019-01-01',
- 'description' => 'Some new description',
- ],
- [
- 'order' => 0,
- 'transaction_journal_id' => -1,
- 'reconciled' => 'false',
- 'tags' => [],
- 'interest_date' => '2019-01-01',
- 'description' => 'Some new description',
- ],
- ],
- ];
-
- // test API
- $response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],
- 'transactions.1.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
-
- }
-
- /**
- * Update transaction but fail to submit equal transaction types.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testUpdateFailTypes(): void
- {
- // mock data:
- $group = $this->getRandomWithdrawalGroup();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
- //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
- //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- $data = [
- 'group_title' => 'Empty',
- 'transactions' => [
- [
- 'transaction_journal_id' => 0,
- 'order' => 0,
- 'reconciled' => 'false',
- 'tags' => [],
- 'interest_date' => '2019-01-01',
- 'type' => 'withdrawal',
- 'description' => 'Some new description',
- ],
- [
- 'transaction_journal_id' => 0,
- 'order' => 0,
- 'reconciled' => 'false',
- 'tags' => [],
- 'interest_date' => '2019-01-01',
- 'type' => 'deposit',
- 'description' => 'Some new description',
- ],
- ],
- ];
-
- // test API
- $response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
-
- $response->assertExactJson(
- [
- 'errors' => [
- 'transactions.0.type' => ['All splits must be of the same type.'],
- ],
- 'message' => 'The given data was invalid.',
- ]
- );
- $response->assertStatus(422);
- }
-
- /**
- * Submit the minimum amount of data to update a single withdrawal.
- *
- * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest
- * @covers \FireflyIII\Api\V1\Controllers\TransactionController
- */
- public function testUpdateOK(): void
- {
- // mock data:
- $group = $this->getRandomWithdrawalGroup();
-
- // mock repository
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
- $validator = $this->mock(AccountValidator::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- $validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
- //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
- //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);
-
- // some mock calls:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $repository->shouldReceive('setUser')->atLeast()->once();
- $apiRepos->shouldReceive('setUser')->atLeast()->once();
-
- // call stuff:
- $repository->shouldReceive('update')->atLeast()->once()->andReturn($group);
-
-
- // transformer is called:
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 1]);
- $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
-
- // collector is called:
- $collector->shouldReceive('setTransactionGroup')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAPIInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection([[]]));
-
- $data = [
- 'group_title' => 'Empty',
- 'transactions' => [
- [
- 'order' => 0,
- 'reconciled' => 'false',
- 'tags' => [],
- 'interest_date' => '2019-01-01',
- 'description' => 'Some new description',
- ],
- ],
- ];
-
- // expect the event:
- try {
- $this->expectsEvents(UpdatedTransactionGroup::class);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
-
- // test API
- $response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);
-
- $response->assertExactJson(
- [
- 'data' => [
- 'attributes' => [],
- 'id' => '1',
- 'links' => [
- 'self' => 'http://localhost/api/v1/transactions/1',
- ],
- 'type' => 'transactions',
- ],
- ]
- );
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php b/tests/Api/V1/Controllers/TransactionLinkControllerTest.php
deleted file mode 100644
index e2bb253410..0000000000
--- a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php
+++ /dev/null
@@ -1,430 +0,0 @@
-<?php
-/**
- * TransactionLinkControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use Carbon\Carbon;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournalLink;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
-use FireflyIII\Transformers\TransactionLinkTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class TransactionLinkControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionLinkControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStore(): void
- {
- $journalLink = TransactionJournalLink::first();
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transformer = $this->mock(TransactionLinkTransformer::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
- $journalRepos->shouldReceive('findNull')->andReturn($journal)->atLeast()->once();
- $repository->shouldReceive('storeLink')->once()->andReturn($journalLink);
- $repository->shouldReceive('findLink')->once()->andReturn(false);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->post(route('api.v1.transaction_links.store'), $data);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * In this particular test the journal link request will fail.
- *
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStoreExistingLink(): void
- {
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
-
- $journalRepos->shouldReceive('findNull')->andReturn($journal);
- $repository->shouldReceive('findLink')->once()->andReturn(true);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertSee('Already have a link between inward and outward.');
-
-
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * In this particular test the TransactionLinkRequest will report the failure.
- *
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStoreInvalidInward(): void
- {
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn(null);
- $journalRepos->shouldReceive('findNull')->once()->withArgs([2])->andReturn(null);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
- $response->assertSee('Invalid inward ID.'); // the creation moment.
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * In this particular test the TransactionLinkRequest will report the failure.
- *
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStoreInvalidOutward(): void
- {
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn($journal);
- $journalRepos->shouldReceive('findNull')->once()->withArgs([2])->andReturn(null);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
- $response->assertSee('Invalid outward ID.');
- $response->assertStatus(422);
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStoreNoJournal(): void
- {
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->twice()->withArgs([1])->andReturn($journal, null);
- $journalRepos->shouldReceive('findNull')->twice()->withArgs([2])->andReturn($journal, null);
- $repository->shouldReceive('findLink')->once()->andReturn(false);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200024'); // the creation moment.
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testStoreWithNull(): void
- {
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock stuff:
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->andReturn(null);
-
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertSee('Invalid inward ID.'); // error message
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testUpdate(): void
- {
- // mock repositories
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transformer = $this->mock(TransactionLinkTransformer::class);
-
- $journalLink = TransactionJournalLink::first();
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
- $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->andReturn($journal);
- $repository->shouldReceive('updateLink')->once()->andReturn($journalLink);
- $repository->shouldReceive('findLink')->once()->andReturn(false);
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(200);
- $response->assertHeader('Content-Type', 'application/vnd.api+json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testUpdateNoJournal(): void
- {
- // mock repositories
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- $journalLink = TransactionJournalLink::first();
- $journal = $this->user()->transactionJournals()->find(1);
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->twice()->withArgs([1])->andReturn($journal, null);
- $journalRepos->shouldReceive('findNull')->twice()->withArgs([2])->andReturn($journal, null);
- $repository->shouldReceive('findLink')->once()->andReturn(false);
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- Log::warning('The following error is part of a test.');
- $response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(500);
- $response->assertSee('200024'); // the creation moment.
- $response->assertHeader('Content-Type', 'application/json');
- }
-
- /**
- * @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
- * @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
- */
- public function testUpdateWithNull(): void
- {
- // mock repositories
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- $journalLink = TransactionJournalLink::first();
- $transaction = Transaction::first();
- $transaction->date = new Carbon;
- $transaction->transaction_type_type = 'Withdrawal';
-
-
- // mock calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- $journalRepos->shouldReceive('findNull')->andReturn(null);
-
- // data to submit
- $data = [
- 'link_type_id' => '1',
- 'inward_id' => '1',
- 'outward_id' => '2',
- 'notes' => 'Some notes',
- ];
-
- // test API
- $response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);
- $response->assertStatus(422);
- $response->assertSee('Invalid inward ID.'); // the creation moment.
- $response->assertHeader('Content-Type', 'application/json');
- }
-}
diff --git a/tests/Api/V1/Controllers/UserControllerTest.php b/tests/Api/V1/Controllers/UserControllerTest.php
deleted file mode 100644
index 0c090772eb..0000000000
--- a/tests/Api/V1/Controllers/UserControllerTest.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * UserControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\V1\Controllers;
-
-
-use Faker\Factory;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\UserTransformer;
-use Laravel\Passport\Passport;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class UserControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UserControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Passport::actingAs($this->user());
- $this->mockDefaultConfiguration();
-
- }
-
- /**
- * Store new user.
- *
- * @covers \FireflyIII\Api\V1\Controllers\UserController
- * @covers \FireflyIII\Api\V1\Requests\UserStoreRequest
- */
- public function testStoreBasic(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // random user
- $faker = Factory::create();
- $data = ['email' => $faker->email,];
-
- // test API
- $response = $this->post(route('api.v1.users.store'), $data, ['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json']);
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/BasicTest.php b/tests/Feature/BasicTest.php
deleted file mode 100644
index 1e4558f7fe..0000000000
--- a/tests/Feature/BasicTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * BasicTest.php
- * Copyright (c) 2020 [email protected]
- *
- * 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\Feature;
-
-
-use Tests\TestCase;
-
-/**
- * Class BasicTest
- */
-class BasicTest extends TestCase
-{
- /**
- * A basic test example.
- *
- * @return void
- */
- public function testBasicTest(): void
- {
- self::assertTrue(true);
- }
-
- /**
- *
- */
- public function testDatabase(): void
- {
- $this->assertDatabaseHas(
- 'users', [
- 'email' => 'james@firefly',
- ]
- );
- }
-}
diff --git a/tests/Feature/Console/Commands/DecryptDatabaseTest.php b/tests/Feature/Console/Commands/DecryptDatabaseTest.php
deleted file mode 100644
index 6f5ebc89b4..0000000000
--- a/tests/Feature/Console/Commands/DecryptDatabaseTest.php
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-/**
- * DecryptDatabaseTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands;
-
-
-use Crypt;
-use FireflyConfig;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\Configuration;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class DecryptDatabaseTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DecryptDatabaseTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\DecryptDatabase
- */
- public function testHandle(): void
- {
- // create encrypted account:
- $name = 'Encrypted name';
- $iban = 'HR1723600001101234565';
- $account = Account::create(
- [
- 'user_id' => 1,
- 'account_type_id' => 1,
- 'name' => Crypt::encrypt($name),
- 'iban' => Crypt::encrypt($iban),
- ]);
-
-
- FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn(null);
- FireflyConfig::shouldReceive('set')->withArgs([Mockery::any(), true])->atLeast()->once();
-
- $this->artisan('firefly-iii:decrypt-all')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
-
- $this->assertCount(1, Account::where('id', $account->id)->where('name', $name)->get());
- $this->assertCount(1, Account::where('id', $account->id)->where('iban', $iban)->get());
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\DecryptDatabase
- */
- public function testHandleDecrypted(): void
- {
- // create encrypted account:
- $name = 'Encrypted name';
- $iban = 'HR1723600001101234565';
- $encryptedName = Crypt::encrypt($name);
- $encryptedIban = Crypt::encrypt($iban);
- $account = Account::create(
- [
- 'user_id' => 1,
- 'account_type_id' => 1,
- 'name' => $encryptedName,
- 'iban' => $encryptedIban,
- ]);
-
- // pretend its not yet decrypted.
- $true = new Configuration;
- $true->data = true;
-
- FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn($true);
-
- $this->artisan('firefly-iii:decrypt-all')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
-
- $this->assertCount(1, Account::where('id', $account->id)->where('name', $encryptedName)->get());
- $this->assertCount(1, Account::where('id', $account->id)->where('iban', $encryptedIban)->get());
- }
-
- /**
- * Try to decrypt data that isn't actually encrypted.
- *
- * @covers \FireflyIII\Console\Commands\DecryptDatabase
- */
- public function testHandleNotEncrypted(): void
- {
- // create encrypted account:
- $name = 'Encrypted name';
- $iban = 'HR1723600001101234565';
- $account = Account::create(
- [
- 'user_id' => 1,
- 'account_type_id' => 1,
- 'name' => $name,
- 'iban' => $iban,
- ]);
-
- // pretend its not yet decrypted.
- $true = new Configuration;
- $true->data = true;
-
- FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn($true);
-
- $this->artisan('firefly-iii:decrypt-all')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
-
- $this->assertCount(1, Account::where('id', $account->id)->where('name', $name)->get());
- $this->assertCount(1, Account::where('id', $account->id)->where('iban', $iban)->get());
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Integrity/ReportEmptyObjectsTest.php b/tests/Feature/Console/Commands/Integrity/ReportEmptyObjectsTest.php
deleted file mode 100644
index 908e3ff3b4..0000000000
--- a/tests/Feature/Console/Commands/Integrity/ReportEmptyObjectsTest.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-/**
- * ReportEmptyObjectsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Integrity;
-
-
-use FireflyIII\Models\Account;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\Category;
-use FireflyIII\Models\Tag;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ReportEmptyObjectsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ReportEmptyObjectsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Run basic test routine.
- *
- * @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
- */
- public function testHandleBudget(): void
- {
- $user = $this->user();
- $budget = Budget::create(
- [
- 'user_id' => $user->id,
- 'name' => 'Some budget',
- ]);
- $budgetLine = sprintf('User #%d (%s) has budget #%d ("%s") which has no transaction journals.',
- $user->id, $user->email, $budget->id, $budget->name);
- $budgetLimitLine = sprintf('User #%d (%s) has budget #%d ("%s") which has no budget limits.',
- $user->id, $user->email, $budget->id, $budget->name);
-
- $this->artisan('firefly-iii:report-empty-objects')
- ->expectsOutput($budgetLine)
- ->expectsOutput($budgetLimitLine)
- ->assertExitCode(0);
- $budget->forceDelete();
-
- // this method changes no objects so there is nothing to verify.
- }
-
- /**
- * Run basic test routine.
- *
- * @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
- */
- public function testHandleCategory(): void
- {
- $user = $this->user();
- $category = Category::create(
- [
- 'user_id' => $user->id,
- 'name' => 'Some category',
- ]);
- $categoryLine = sprintf('User #%d (%s) has category #%d ("%s") which has no transaction journals.',
- $user->id, $user->email, $category->id, $category->name);
-
- $this->artisan('firefly-iii:report-empty-objects')
- ->expectsOutput($categoryLine)
- ->assertExitCode(0);
- $category->forceDelete();
-
- // this method changes no objects so there is nothing to verify.
- }
-
- /**
- * Run basic test routine.
- *
- * @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
- */
- public function testHandleTag(): void
- {
- $user = $this->user();
- $tag = Tag::create(
- [
- 'user_id' => $user->id,
- 'tag' => 'Some tag',
- 'tagMode' => 'nothing',
- ]);
- $tagLine = sprintf('User #%d (%s) has tag #%d ("%s") which has no transaction journals.',
- $user->id, $user->email, $tag->id, $tag->tag);
-
- $this->artisan('firefly-iii:report-empty-objects')
- ->expectsOutput($tagLine)
- ->assertExitCode(0);
- $tag->forceDelete();
-
- // this method changes no objects so there is nothing to verify.
- }
-
- /**
- * Run basic test routine.
- *
- * @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
- */
- public function testHandleAccount(): void
- {
- $user = $this->user();
- $account = Account::create(
- [
- 'user_id' => $user->id,
- 'name' => 'Some account',
- 'account_type_id' => 1,
- ]);
- $tagLine = sprintf('User #%d (%s) has account #%d ("%s") which has no transactions.',
- $user->id, $user->email, $account->id, $account->name);
-
- $this->artisan('firefly-iii:report-empty-objects')
- ->expectsOutput($tagLine)
- ->assertExitCode(0);
- $account->forceDelete();
-
- // this method changes no objects so there is nothing to verify.
- }
-
-
-}
diff --git a/tests/Feature/Console/Commands/Integrity/ReportSumTest.php b/tests/Feature/Console/Commands/Integrity/ReportSumTest.php
deleted file mode 100644
index 1291f03d03..0000000000
--- a/tests/Feature/Console/Commands/Integrity/ReportSumTest.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-/**
- * ReportSumTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Integrity;
-
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ReportSumTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ReportSumTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Integrity\ReportSum
- */
- public function testHandle(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
-
- $this->artisan('firefly-iii:report-sum')
- ->expectsOutput(sprintf('Amount integrity OK for user #%d', $this->user()->id))
- ->assertExitCode(0);
-
- // this method changes no objects so there is nothing to verify.
- }
-
- /**
- * Create transaction to make balance uneven.
- * @covers \FireflyIII\Console\Commands\Integrity\ReportSum
- */
- public function testHandleUneven(): void
- {
- $transaction = Transaction::create(
- [
- 'transaction_journal_id' => $this->getRandomWithdrawal()->id,
- 'user_id' => 1,
- 'account_id' => $this->getRandomAsset()->id,
- 'amount' => 10,
- ]
- );
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
-
- $this->artisan('firefly-iii:report-sum')
- ->expectsOutput(sprintf('Error: Transactions for user #%d (%s) are off by %s!', $this->user()->id, $this->user()->email, '10.0'))
- ->assertExitCode(0);
- $transaction->forceDelete();
-
- // this method changes no objects so there is nothing to verify.
- }
-}
diff --git a/tests/Feature/Console/Commands/Tools/ApplyRulesTest.php b/tests/Feature/Console/Commands/Tools/ApplyRulesTest.php
deleted file mode 100644
index 9f6a86ad73..0000000000
--- a/tests/Feature/Console/Commands/Tools/ApplyRulesTest.php
+++ /dev/null
@@ -1,459 +0,0 @@
-<?php
-/**
- * ApplyRulesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Tools;
-
-
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class ApplyRulesTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ApplyRulesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic call with everything perfect (and ALL rules).
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandle(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // data
- $asset = $this->getRandomAsset();
- $journal = $this->getRandomWithdrawal();
- $group = $this->user()->ruleGroups()->first();
- $rule = $this->user()->rules()->first();
- $groups = new Collection([$group]);
- $rules = new Collection([$rule]);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
- $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
-
- $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
- $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
-
-
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->times(3);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=1',
- '--all_rules',
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
-
- // this method changes no objects so there is nothing to verify.
- }
-
- /**
- * Basic call with everything perfect (and ALL rules), but no rules will be selected.
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandEmpty(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // data
- $asset = $this->getRandomAsset();
- $journal = $this->getRandomWithdrawal();
- $group = $this->user()->ruleGroups()->first();
- $groups = new Collection([$group]);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
- $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
-
- $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
- $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn(new Collection);
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=1',
- '--all_rules',
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('No rules or rule groups have been included.')
- ->assertExitCode(1);
- }
-
-
- /**
- * Basic call with everything perfect (and ALL rules) and dates.
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandleDate(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // data
- $asset = $this->getRandomAsset();
- $group = $this->user()->ruleGroups()->first();
- $rule = $this->user()->rules()->first();
- $groups = new Collection([$group]);
- $rules = new Collection([$rule]);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
-
- $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
- $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
-
-
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->times(3);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=1',
- '--all_rules',
- '--start_date=2019-01-31',
- '--end_date=2019-01-01',
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
- }
-
- /**
- * Will submit some rules to apply.
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandleRules(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // data
- $asset = $this->getRandomAsset();
- $journal = $this->getRandomWithdrawal();
- $group = $this->user()->ruleGroups()->first();
- $groups = new Collection([$group]);
- $activeRule = $this->user()->rules()->where('active', 1)->inRandomOrder()->first();
- $inactiveRule = $this->user()->rules()->where('active', 0)->inRandomOrder()->first();
- $rules = new Collection([$activeRule]);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
- $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
-
- $ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeRule->id])->andReturn($activeRule);
- $ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveRule->id])->andReturn($inactiveRule);
-
- $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
- $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
-
-
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->times(3);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=1',
- sprintf('--rules=%d,%d', $activeRule->id, $inactiveRule->id),
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
- }
-
- /**
- * Basic call with two rule groups. One active, one inactive.
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandleRuleGroups(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $activeGroup = $this->user()->ruleGroups()->where('active', 1)->inRandomOrder()->first();
- $inactiveGroup = $this->user()->ruleGroups()->where('active', 0)->inRandomOrder()->first();
-
- // data
- $asset = $this->getRandomAsset();
- $journal = $this->getRandomWithdrawal();
- $rule = $this->user()->rules()->first();
- $groups = new Collection([$activeGroup]);
- $rules = new Collection([$rule]);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
- $journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
-
- $ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
- $ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
- $ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeGroup->id])->andReturn($activeGroup);
- $ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveGroup->id])->andReturn($inactiveGroup);
-
- $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->times(3);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=1',
- sprintf('--rule_groups=%d,%d', $activeGroup->id, $inactiveGroup->id),
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Will ignore inactive rule group #%d ("%s")', $inactiveGroup->id, $inactiveGroup->title))
- // one rule out of 2 groups:
- ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
- ->expectsOutput('Done!')
- ->assertExitCode(0);
- }
-
- /**
- * Basic call but no accounts submitted.
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandleNoAccounts(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(GroupCollectorInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(RuleEngine::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
-
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=',
- '--all_rules',
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('Please use the --accounts option to indicate the accounts to apply rules to.')
- ->assertExitCode(1);
- }
-
- /**
- * Basic call but only one expense account submitted
- *
- * @covers \FireflyIII\Console\Commands\Tools\ApplyRules
- */
- public function testHandleExpenseAccounts(): void
- {
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(RuleEngine::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(GroupCollectorInterface::class);
-
- // data
- $expense = $this->getRandomExpense();
-
- // expected calls:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
- $ruleRepos->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$expense->id])->andReturn($expense);
-
-
- $parameters = [
- '--user=1',
- '--token=token',
- '--accounts=' . $expense->id,
- '--all_rules',
- ];
-
- // mock Preferences Facade:
- $pref = new Preference;
- $pref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
-
- $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
- ->expectsOutput('Please make sure all accounts in --accounts are asset accounts or liabilities.')
- ->assertExitCode(1);
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/AccountCurrenciesTest.php b/tests/Feature/Console/Commands/Upgrade/AccountCurrenciesTest.php
deleted file mode 100644
index c37e7e93de..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/AccountCurrenciesTest.php
+++ /dev/null
@@ -1,358 +0,0 @@
-<?php
-/**
- * AccountCurrenciesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class AccountCurrenciesTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountCurrenciesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Perfect run without opening balance.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandle(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'EUR';
- $account = $this->getRandomAsset();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput('All accounts are OK.')
- ->assertExitCode(0);
-
- // nothing changed, so nothing to verify.
- }
-
- /**
- * Perfect run without opening balance.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleNotNull(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'EUR';
- $account = $this->getRandomAsset();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journal = $this->getRandomWithdrawal();
-
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- // account reports USD
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('2');
- // journal is EUR.
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name))
- ->assertExitCode(0);
-
- // check if currency has been changed for the journal + transactions.
- $this->assertCount(1, TransactionJournal::where('id', $journal->id)->where('transaction_currency_id', 2)->get());
- $this->assertCount(2, Transaction::where('transaction_journal_id', $journal->id)->where('transaction_currency_id', 2)->get());
- }
-
- /**
- * Perfect run with opening balance.
- *
- * TODO this method crashes some times but not sure why.
- * 2019-07-27 should be fixed.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleOpeningBalance(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'EUR';
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journal = $this->getRandomWithdrawal();
- $euro = $this->getEuro();
- $journal->transaction_currency_id = $euro->id;
- $journal->save();
- $journal->refresh();
-
- $account = $this->getRandomAsset();
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput('All accounts are OK.')
- ->assertExitCode(0);
-
- // nothing changed, dont check output.
- }
-
- /**
- * Perfect run with opening balance with different currencies
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleDifferent(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'USD';
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $journal = $this->getRandomWithdrawal();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $journal->transaction_currency_id = $euro->id;
- $journal->save();
-
- // delete meta data of account just in case:
- AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('0');
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput(sprintf('Account #%d ("%s") now has a currency setting (#%d).', $account->id, $account->name, $euro->id))
- ->assertExitCode(0);
-
- // verify account meta data change.
- $this->assertCount(1,
- AccountMeta::where('account_id', $account->id)
- ->where('name', 'currency_id')
- ->where('data', $euro->id)->get());
- }
-
- /**
- * No known currency preferences.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleZeroPreference(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'EUR';
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('0');
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput(sprintf('Account #%d ("%s") now has a currency setting (%s).',
- $account->id, $account->name, $euro->code
- ))
- ->expectsOutput('Corrected 1 account(s).')
- ->assertExitCode(0);
-
- $this->assertCount(1, AccountMeta::where('account_id', $account->id)
- ->where('name', 'currency_id')
- ->where('data', $euro->id)->get());
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleNoPreference(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = false;
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $account = $this->getRandomAsset();
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
- $accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput('All accounts are OK.')
- ->assertExitCode(0);
- // nothing changed, so nothing to verify.
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleInvalidPreference(): void
- {
- $false = new Configuration;
- $false->data = false;
- $pref = new Preference;
- $pref->data = 'ABC';
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $account = $this->getRandomAsset();
-
- // mock calls
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
- $userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput('User has a preference for "ABC", but this currency does not exist.')
- ->assertExitCode(0);
-
- // nothing changed, so nothing to verify.
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
- */
- public function testHandleAlreadyExecuted(): void
- {
- $true = new Configuration;
- $true->data = true;
- $pref = new Preference;
- $pref->data = 'EUR';
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
-
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($true);
- FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
-
- // check preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
-
- $this->artisan('firefly-iii:account-currencies')
- ->expectsOutput('This command has already been executed.')
- ->assertExitCode(0);
- // nothing changed, so nothing to verify.
- }
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/BackToJournalsTest.php b/tests/Feature/Console/Commands/Upgrade/BackToJournalsTest.php
deleted file mode 100644
index c4aac07d1b..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/BackToJournalsTest.php
+++ /dev/null
@@ -1,253 +0,0 @@
-<?php
-/**
- * BackToJournalsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\Category;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Transaction;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BackToJournalsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BackToJournalsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Perfect run. Will report on nothing.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
- */
- public function testHandle(): void
- {
- // verify preference:
- $false = new Configuration;
- $false->data = false;
- $true = new Configuration;
- $true->data = true;
- FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
-
- // set new preference after running:
- FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
-
- $this->artisan('firefly-iii:back-to-journals')
- ->expectsOutput('Check 0 transaction journal(s) for budget info.')
- ->expectsOutput('Check 0 transaction journal(s) for category info.')
- ->assertExitCode(0);
-
- }
-
- /**
- * Transaction has a budget, journal doesn't.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
- */
- public function testHandleBudget(): void
- {
- $journal = $this->getRandomWithdrawal();
- /** @var Transaction $transaction */
- $transaction = $journal->transactions()->first();
- /** @var Budget $budget */
- $budget = $this->user()->budgets()->first();
- $transaction->budgets()->sync([$budget->id]);
- $journal->budgets()->sync([]);
- $journal->save();
- $transaction->save();
-
-
- // verify preference:
- $false = new Configuration;
- $false->data = false;
- $true = new Configuration;
- $true->data = true;
- FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
-
- // set new preference after running:
- FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
-
- $this->artisan('firefly-iii:back-to-journals')
- ->expectsOutput('Check 1 transaction journal(s) for budget info.')
- ->expectsOutput('Check 0 transaction journal(s) for category info.')
- ->assertExitCode(0);
-
- // transaction should have no budget:
- $this->assertEquals(0, $transaction->budgets()->count());
- // journal should have one.
- $this->assertEquals(1, $journal->budgets()->count());
- // should be $budget:
- $this->assertEquals($budget->id, $journal->budgets()->first()->id);
- }
-
- /**
- * Transaction has a category, journal doesn't.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
- */
- public function testHandleCategory(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $journal = $this->getRandomWithdrawal();
- /** @var Transaction $transaction */
- $transaction = $journal->transactions()->first();
- /** @var Category $category */
- $category = $this->user()->categories()->first();
- $transaction->categories()->sync([$category->id]);
- $journal->categories()->sync([]);
- $journal->save();
- $transaction->save();
-
- // verify preference:
- $false = new Configuration;
- $false->data = false;
- $true = new Configuration;
- $true->data = true;
-
- FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
-
- // set new preference after running:
- FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
-
- $this->artisan('firefly-iii:back-to-journals')
- ->expectsOutput('Check 0 transaction journal(s) for budget info.')
- ->expectsOutput('Check 1 transaction journal(s) for category info.')
- ->assertExitCode(0);
-
- // transaction should have no category:
- $this->assertEquals(0, $transaction->categories()->count());
- // journal should have one.
- $this->assertEquals(1, $journal->categories()->count());
- // should be $category:
- $this->assertEquals($category->id, $journal->categories()->first()->id);
- }
-
- /**
- * Transaction has a budget, journal has another
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
- */
- public function testHandleDifferentBudget(): void
- {
- $journal = $this->getRandomWithdrawal();
- /** @var Transaction $transaction */
- $transaction = $journal->transactions()->first();
- /** @var Budget $budget */
- $budget = $this->user()->budgets()->first();
- $otherBudget = $this->user()->budgets()->where('id', '!=', $budget->id)->first();
- $transaction->budgets()->sync([$budget->id]);
- $journal->budgets()->sync([$otherBudget->id]);
- $journal->save();
- $transaction->save();
-
-
- // verify preference:
- $false = new Configuration;
- $false->data = false;
- $true = new Configuration;
- $true->data = true;
- FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
-
- // set new preference after running:
- FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
-
- $this->artisan('firefly-iii:back-to-journals')
- ->expectsOutput('Check 1 transaction journal(s) for budget info.')
- ->expectsOutput('Check 0 transaction journal(s) for category info.')
- ->assertExitCode(0);
-
- // transaction should have no budget:
- $this->assertEquals(0, $transaction->budgets()->count());
- // journal should have one.
- $this->assertEquals(1, $journal->budgets()->count());
- // should be $budget:
- $this->assertEquals($budget->id, $journal->budgets()->first()->id);
-
- }
-
-
- /**
- * Transaction has a category, journal has another
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
- */
- public function testHandleDifferentCategory(): void
- {
- $journal = $this->getRandomWithdrawal();
- /** @var Transaction $transaction */
- $transaction = $journal->transactions()->first();
- /** @var Category $category */
- $category = $this->user()->categories()->first();
- $otherCategory = $this->user()->categories()->where('id', '!=', $category->id)->first();
- $transaction->categories()->sync([$category->id]);
- $journal->categories()->sync([$otherCategory->id]);
- $journal->save();
- $transaction->save();
-
- // verify preference:
- $false = new Configuration;
- $false->data = false;
- $true = new Configuration;
- $true->data = true;
- FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
-
- // set new preference after running:
- FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
-
- $this->artisan('firefly-iii:back-to-journals')
- ->expectsOutput('Check 0 transaction journal(s) for budget info.')
- ->expectsOutput('Check 1 transaction journal(s) for category info.')
- ->assertExitCode(0);
-
- // transaction should have no category:
- $this->assertEquals(0, $transaction->categories()->count());
- // journal should have one.
- $this->assertEquals(1, $journal->categories()->count());
- // should be $category:
- $this->assertEquals($category->id, $journal->categories()->first()->id);
-
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php b/tests/Feature/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php
deleted file mode 100644
index 04155169c0..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-/**
- * BudgetLimitCurrencyTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use Amount;
-use FireflyConfig;
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Models\Configuration;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BudgetLimitCurrencyTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetLimitCurrencyTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\BudgetLimitCurrency
- */
- public function testHandle(): void
- {
- BudgetLimit::whereNull('transaction_currency_id')->forceDelete();
-
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);
-
- $this->artisan('firefly-iii:bl-currency')
- ->expectsOutput('All budget limits are correct.')
- ->assertExitCode(0);
- }
-
- /**
- * Create a bad budget limit.
- * @covers \FireflyIII\Console\Commands\Upgrade\BudgetLimitCurrency
- */
- public function testHandleBadLimit(): void
- {
- $false = new Configuration;
- $false->data = false;
- $budget = $this->user()->budgets()->first();
- $limit = BudgetLimit::create(
- [
- 'budget_id' => $budget->id,
- 'amount' => '10',
- 'start_date' => '2019-01-01',
- 'end_date' => '2019-01-31',
- ]);
-
- FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);
-
- $currency = $this->getEuro();
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
-
- $this->artisan('firefly-iii:bl-currency')
- ->expectsOutput(
- sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).',
- $limit->id, $budget->name, 'Euro'
- )
- )
- ->assertExitCode(0);
-
- // assume currency is filled in.
- $this->assertCount(1, BudgetLimit::where('id', $limit->id)->where('transaction_currency_id', 1)->get());
- }
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/CCLiabilitiesTest.php b/tests/Feature/Console/Commands/Upgrade/CCLiabilitiesTest.php
deleted file mode 100644
index 3aa4005662..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/CCLiabilitiesTest.php
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-/**
- * CCLiabilitiesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Configuration;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class CCLiabilitiesTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CCLiabilitiesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
- */
- public function testHandle(): void
- {
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
-
-
- $this->artisan('firefly-iii:cc-liabilities')
- ->expectsOutput('No incorrectly stored credit card liabilities.')
- ->assertExitCode(0);
-
- // nothing changed, so nothing to verify.
- }
-
- /**
- * Add type to make the script run.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
- */
- public function testHandleEmpty(): void
- {
- $type = AccountType::create(
- [
- 'type' => AccountType::CREDITCARD,
- ]
- );
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
-
-
- $this->artisan('firefly-iii:cc-liabilities')
- ->expectsOutput('No incorrectly stored credit card liabilities.')
- ->assertExitCode(0);
- $type->forceDelete();
- // nothing changed, so nothing to verify.
- }
-
- /**
- * Add some things to make it trigger.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
- */
- public function testHandleCase(): void
- {
- $type = AccountType::create(
- [
- 'type' => AccountType::CREDITCARD,
- ]
- );
-
- $account = Account::create(
- [
- 'name' => 'CC',
- 'user_id' => 1,
- 'account_type_id' => $type->id,
-
- ]
- );
-
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
-
-
- $this->artisan('firefly-iii:cc-liabilities')
- ->expectsOutput(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id))
- ->expectsOutput('Credit card liability types are no longer supported and have been converted to generic debts. See: http://bit.ly/FF3-credit-cards')
- ->assertExitCode(0);
-
- // verify new type.
- $this->assertCount(0, Account::where('id', $account->id)->where('account_type_id', $type->id)->get());
-
- $account->forceDelete();
- $type->forceDelete();
-
- }
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/MigrateAttachmentsTest.php b/tests/Feature/Console/Commands/Upgrade/MigrateAttachmentsTest.php
deleted file mode 100644
index aa0afee4bb..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/MigrateAttachmentsTest.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * MigrateAttachmentsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class MigrateAttachmentsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MigrateAttachmentsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
- */
- public function testHandle(): void
- {
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
- // assume all is well.
- $this->artisan('firefly-iii:migrate-attachments')
- ->expectsOutput('All attachments are OK.')
- ->assertExitCode(0);
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
- */
- public function testHandleMigrate(): void
- {
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
-
- $attachment = Attachment::create(
- [
- 'user_id' => 1,
- 'attachable_id' => 1,
- 'attachable_type' => TransactionJournal::class,
- 'description' => 'Hello',
- 'md5' => md5('hello'),
- 'filename' => 'test.pdf',
- 'mime' => 'text/plain',
- 'size' => 1,
- ]);
-
- // assume all is well.
- $this->artisan('firefly-iii:migrate-attachments')
- ->expectsOutput('Updated 1 attachment(s).')
- ->assertExitCode(0);
-
- $this->assertCount(0, Attachment::where('id', $attachment->id)->where('description', '!=', '')->get());
- $this->assertCount(1, Attachment::where('id', $attachment->id)->where('description', '=', '')->get());
- $this->assertCount(1, Note::where('noteable_id', $attachment->id)->where('noteable_type', Attachment::class)->get());
-
- $attachment->forceDelete();
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/MigrateJournalNotesTest.php b/tests/Feature/Console/Commands/Upgrade/MigrateJournalNotesTest.php
deleted file mode 100644
index 22c86ec0f5..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/MigrateJournalNotesTest.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-/**
- * MigrateJournalNotesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\TransactionJournalMeta;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class MigrateJournalNotesTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MigrateJournalNotesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
- */
- public function testHandle(): void
- {
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:migrate-notes')
- ->expectsOutput('No notes to migrate.')
- ->assertExitCode(0);
- }
-
- /**
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
- */
- public function testHandleNote(): void
- {
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
-
- $journal = $this->getRandomWithdrawal();
-
- // delete any notes the journal may have already:
- $journal->notes()->forceDelete();
-
- $meta = TransactionJournalMeta::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'name' => 'notes',
- 'data' => json_encode('Some note.'),
- 'hash' => 'Some hash',
- ]
- );
- // assume one is fixed.
- $this->artisan('firefly-iii:migrate-notes')
- ->expectsOutput('Migrated 1 note(s).')
- ->assertExitCode(0);
-
- $this->assertCount(0, TransactionJournalMeta
- ::where('name', 'notes')
- ->where('id', $meta->id)
- ->whereNull('deleted_at')
- ->get());
-
- }
-
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/MigrateToGroupsTest.php b/tests/Feature/Console/Commands/Upgrade/MigrateToGroupsTest.php
deleted file mode 100644
index 2ee7a01541..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/MigrateToGroupsTest.php
+++ /dev/null
@@ -1,264 +0,0 @@
-<?php
-/**
- * MigrateToGroupsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-use FireflyConfig;
-use FireflyIII\Factory\TransactionGroupFactory;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class MigrateToGroupsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MigrateToGroupsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
- */
- public function testHandle(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $service = $this->mock(JournalDestroyService::class);
- $groupFactory = $this->mock(TransactionGroupFactory::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
-
- // mock calls:
- $cliRepos->shouldReceive('getSplitJournals')
- ->atLeast()->once()
- ->andReturn(new Collection);
- $cliRepos->shouldReceive('getJournalsWithoutGroup')
- ->atLeast()->once()
- ->andReturn([]);
-
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:migrate-to-groups')
- ->expectsOutput('No journals to migrate to groups.')
- ->assertExitCode(0);
- }
-
- /**
- * Return a journal without a group.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
- */
- public function testHandleNoGroup(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $service = $this->mock(JournalDestroyService::class);
- $groupFactory = $this->mock(TransactionGroupFactory::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
-
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $journal = TransactionJournal::create(
- [
- 'user_id' => 1,
- 'transaction_currency_id' => 1,
- 'transaction_type_id' => 1,
- 'description' => 'Test',
- 'tag_count' => 0,
- 'date' => '2019-01-01',
- ]
- );
- $one = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-10',
- 'identifier' => 1,
- ]
- );
- $two = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $expense->id,
- 'amount' => '10',
- 'identifier' => 1,
- ]
- );
- $array = $journal->toArray();
-
- // mock calls:
- $cliRepos->shouldReceive('getSplitJournals')
- ->atLeast()->once()
- ->andReturn(new Collection);
- $cliRepos->shouldReceive('getJournalsWithoutGroup')
- ->atLeast()->once()
- ->andReturn([$array]);
-
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:migrate-to-groups')
- ->expectsOutput('Migrated 1 transaction journal(s).')
- ->assertExitCode(0);
-
- // no longer without a group.
- $this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('transaction_group_id')->get());
- $journal->transactionGroup()->forceDelete();
- $one->forceDelete();
- $two->forceDelete();
- $journal->forceDelete();
- }
-
- /**
- * Create split withdrawal and see what the system will do.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
- */
- public function testHandleSplitJournal(): void
- {
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $group = $this->getRandomWithdrawalGroup();
- $journal = TransactionJournal::create(
- [
- 'user_id' => 1,
- 'transaction_currency_id' => 1,
- 'transaction_type_id' => 1,
- 'description' => 'Test',
- 'tag_count' => 0,
- 'date' => '2019-01-01',
- ]
- );
- $one = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-10',
- 'identifier' => 1,
- ]
- );
- $two = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $expense->id,
- 'amount' => '10',
- 'identifier' => 1,
- ]
- );
- $three = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-12',
- 'identifier' => 2,
- ]
- );
- $four = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $expense->id,
- 'amount' => '12',
- 'identifier' => 2,
- ]
- );
-
-
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $service = $this->mock(JournalDestroyService::class);
- $factory = $this->mock(TransactionGroupFactory::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
-
- // mock calls:
- $cliRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock journal things:
- $cliRepos->shouldReceive('getJournalBudgetId')->atLeast()->once()->andReturn(0);
- $cliRepos->shouldReceive('getJournalCategoryId')->atLeast()->once()->andReturn(0);
- $cliRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Some note.');
- $cliRepos->shouldReceive('getTags')->atLeast()->once()->andReturn(['A', 'B']);
- $cliRepos->shouldReceive('getMetaField')->atLeast()
- ->withArgs([Mockery::any(), Mockery::any()])
- ->once()->andReturn(null);
- $cliRepos->shouldReceive('getMetaDate')->atLeast()
- ->withArgs([Mockery::any(), Mockery::any()])
- ->once()->andReturn(null);
-
- // create a group
- $factory->shouldReceive('create')->atLeast()->once()->andReturn($group);
- $service->shouldReceive('destroy')->atLeast()->once();
-
- $factory->shouldReceive('setUser')->atLeast()->once();
-
- $cliRepos->shouldReceive('getSplitJournals')
- ->atLeast()->once()
- ->andReturn(new Collection([$journal]));
- $cliRepos->shouldReceive('getJournalsWithoutGroup')
- ->atLeast()->once()
- ->andReturn([]);
-
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
-
- $this->artisan('firefly-iii:migrate-to-groups')
- ->expectsOutput('Migrated 1 transaction journal(s).')
- ->assertExitCode(0);
-
- // delete the created stuff:
- $one->forceDelete();
- $two->forceDelete();
- $three->forceDelete();
- $four->forceDelete();
- $journal->forceDelete();
-
- // the calls above let me know it's OK.
- }
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/MigrateToRulesTest.php b/tests/Feature/Console/Commands/Upgrade/MigrateToRulesTest.php
deleted file mode 100644
index 8d3e6159d3..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/MigrateToRulesTest.php
+++ /dev/null
@@ -1,330 +0,0 @@
-<?php
-/**
- * MigrateToRulesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Bill;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class MigrateToRulesTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MigrateToRulesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
- */
- public function testHandle(): void
- {
-
- // mock repositories:
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
- $billRepository = $this->mock(BillRepositoryInterface::class);
- $ruleRepository = $this->mock(RuleRepositoryInterface::class);
- $group = $this->user()->ruleGroups()->inRandomOrder()->first();
- $bill = $this->user()->bills()->inRandomOrder()->first();
- // mock all calls.
- $userRepository->shouldReceive('all')->atLeast()->once()
- ->andReturn(new Collection([$this->user()]));
- $ruleRepository->shouldReceive('setUser')->atLeast()->once();
-
- $ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepository->shouldReceive('findByTitle')
- ->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
- // rule group repos should try to store a rule group in response to the result above.
- $ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- // bill repos should return one rule.
- $billRepository->shouldReceive('setUser')->atLeast()->once();
- $billRepository->shouldReceive('getBills')->atLeast()->once()
- ->andReturn(new Collection([$bill]));
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
-
- // preferences
- $language = new Preference;
- $language->data = 'en_US';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
-
-
- // assume all is well.
- $this->artisan('firefly-iii:bills-to-rules')
- ->expectsOutput('All bills are OK.')
- ->assertExitCode(0);
- }
-
- /**
- * Basic test. Give command an unmigrated bill. This bill has the same amount_min
- * as amount_max
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
- */
- public function testHandleEvenBill(): void
- {
- $billName = 'I am a bill #' . $this->randomInt();
- $bill = Bill::create(
- [
- 'user_id' => $this->user()->id,
- 'transaction_currency_id' => null,
- 'name' => $billName,
- 'match' => 'some,kind,of,match',
- 'amount_min' => '30',
- 'amount_max' => '30',
- 'date' => '2019-01-01',
- 'repeat_freq' => 'monthly',
- ]
- );
-
- // mock repositories:
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
- $billRepository = $this->mock(BillRepositoryInterface::class);
- $ruleRepository = $this->mock(RuleRepositoryInterface::class);
- $group = $this->user()->ruleGroups()->inRandomOrder()->first();
- // mock all calls.
- $userRepository->shouldReceive('all')->atLeast()->once()
- ->andReturn(new Collection([$this->user()]));
- $ruleRepository->shouldReceive('setUser')->atLeast()->once();
-
- // this is what rule repos should receive:
- $argumentRule = [
- 'rule_group_id' => $group->id,
- 'active' => true,
- 'strict' => false,
- 'stop_processing' => false, // field is no longer used.
- 'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
- 'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
- 'trigger' => 'store-journal',
- 'triggers' => [
- [
- 'type' => 'description_contains',
- 'value' => 'some kind of match',
- ],
- [
- 'type' => 'amount_exactly',
- 'value' => $bill->amount_min,
- ],
- ],
- 'actions' => [
- [
- 'type' => 'link_to_bill',
- 'value' => $bill->name,
- ],
- ],
- ];
-
- // this is what the bill repos should receive:
- $argumentBill = [
- 'currency_id' => $bill->transaction_currency_id,
- 'name' => $bill->name,
- 'match' => 'MIGRATED_TO_RULES',
- 'amount_min' => $bill->amount_min,
- 'amount_max' => $bill->amount_max,
- 'date' => $bill->date,
- 'repeat_freq' => $bill->repeat_freq,
- 'skip' => $bill->skip,
- 'active' => $bill->active,
- ];
-
-
- $ruleRepository->shouldReceive('store')->atLeast()->once()->withArgs([$argumentRule]);
-
- // rule group repos should try to store a rule group in response to the result above.
- $ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepository->shouldReceive('findByTitle')
- ->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
-
- $ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- // bill repos should return one rule.
- $billRepository->shouldReceive('setUser')->atLeast()->once();
- $billRepository->shouldReceive('getBills')->atLeast()->once()
- ->andReturn(new Collection([$bill]));
- $billRepository->shouldReceive('update')->atLeast()->once()
- ->withArgs([Mockery::any(), $argumentBill]);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
-
- // preferences
- $language = new Preference;
- $language->data = 'en_US';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
-
-
- // assume all is well.
- $this->artisan('firefly-iii:bills-to-rules')
- ->expectsOutput('Verified and fixed 1 bill(s).')
- ->assertExitCode(0);
- }
-
- /**
- * Basic test. Give command an unmigrated bill. This bill has a different amount_min
- * from the amount_max
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
- */
- public function testHandleUnevenBill(): void
- {
- $billName = 'I am a bill #' . $this->randomInt();
- $bill = Bill::create(
- [
- 'user_id' => $this->user()->id,
- 'transaction_currency_id' => null,
- 'name' => $billName,
- 'match' => 'some,kind,of,match',
- 'amount_min' => '30',
- 'amount_max' => '40',
- 'date' => '2019-01-01',
- 'repeat_freq' => 'monthly',
- ]
- );
-
- // mock repositories:
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
- $billRepository = $this->mock(BillRepositoryInterface::class);
- $ruleRepository = $this->mock(RuleRepositoryInterface::class);
- $group = $this->user()->ruleGroups()->inRandomOrder()->first();
- // mock all calls.
- $userRepository->shouldReceive('all')->atLeast()->once()
- ->andReturn(new Collection([$this->user()]));
- $ruleRepository->shouldReceive('setUser')->atLeast()->once();
-
- // this is what rule repos should receive:
- $argumentRule = [
- 'rule_group_id' => $group->id,
- 'active' => true,
- 'strict' => false,
- 'stop_processing' => false, // field is no longer used.
- 'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
- 'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
- 'trigger' => 'store-journal',
- 'triggers' => [
- [
- 'type' => 'description_contains',
- 'value' => 'some kind of match',
- ],
- [
- 'type' => 'amount_less',
- 'value' => $bill->amount_max,
- ],
- [
- 'type' => 'amount_more',
- 'value' => $bill->amount_min,
- ],
- ],
- 'actions' => [
- [
- 'type' => 'link_to_bill',
- 'value' => $bill->name,
- ],
- ],
- ];
-
- // this is what the bill repos should receive:
- $argumentBill = [
- 'currency_id' => $bill->transaction_currency_id,
- 'name' => $bill->name,
- 'match' => 'MIGRATED_TO_RULES',
- 'amount_min' => $bill->amount_min,
- 'amount_max' => $bill->amount_max,
- 'date' => $bill->date,
- 'repeat_freq' => $bill->repeat_freq,
- 'skip' => $bill->skip,
- 'active' => $bill->active,
- ];
-
-
- $ruleRepository->shouldReceive('store')->atLeast()->once()->withArgs([$argumentRule]);
-
- // rule group repos should try to store a rule group in response to the result above.
- $ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
- $ruleGroupRepository->shouldReceive('findByTitle')
- ->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
-
- $ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- // bill repos should return one rule.
- $billRepository->shouldReceive('setUser')->atLeast()->once();
- $billRepository->shouldReceive('getBills')->atLeast()->once()
- ->andReturn(new Collection([$bill]));
- $billRepository->shouldReceive('update')->atLeast()->once()
- ->withArgs([Mockery::any(), $argumentBill]);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
-
- // preferences
- $language = new Preference;
- $language->data = 'en_US';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
-
-
- // assume all is well.
- $this->artisan('firefly-iii:bills-to-rules')
- ->expectsOutput('Verified and fixed 1 bill(s).')
- ->assertExitCode(0);
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php b/tests/Feature/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php
deleted file mode 100644
index 250b0b3c85..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php
+++ /dev/null
@@ -1,277 +0,0 @@
-<?php
-/**
- * OtherCurrenciesCorrectionsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class OtherCurrenciesCorrectionsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class OtherCurrenciesCorrectionsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong. Submit a withdrawal and a deposit.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
- */
- public function testHandle(): void
- {
- // mock classes:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $withdrawal = $this->getRandomWithdrawal();
- $deposit = $this->getRandomDeposit();
- $euro = $this->getEuro();
-
- // collect all journals:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('getAllJournals')
- ->atLeast()->once()
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
- ->andReturn(new Collection([$withdrawal, $deposit]));
-
- // account repos
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- #$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()
- # ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- // collect currency
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- #$currencyRepos->shouldReceive('findNull')->atLeast()->once()
- # ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:other-currencies')
- ->expectsOutput('Verified 2 transaction(s) and journal(s).')
- ->assertExitCode(0);
- }
-
- /**
- * Basic test. Assume nothing is wrong. Submit an opening balance.
- * Also fixes transaction currency ID.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
- */
- public function testHandleOB(): void
- {
- $type = TransactionType::where('type', TransactionType::OPENING_BALANCE)->first();
- $asset = $this->getRandomAsset();
- $initial = $this->getRandomInitialBalance();
- $journal = TransactionJournal::create(
- [
- 'user_id' => 1,
- 'transaction_currency_id' => 1,
- 'transaction_type_id' => $type->id,
- 'description' => 'Test',
- 'tag_count' => 0,
- 'date' => '2019-01-01',
- ]
- );
- $one = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-10',
- 'identifier' => 1,
- ]
- );
- $two = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $initial->id,
- 'amount' => '10',
- 'identifier' => 1,
- ]
- );
-
-
- // mock classes:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $euro = $this->getEuro();
-
- // collect all journals:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('getAllJournals')
- ->atLeast()->once()
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
- ->andReturn(new Collection([$journal]));
-
- // account repos
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // collect currency
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- #$currencyRepos->shouldReceive('findNull')->atLeast()->once()
- # ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
-
- $this->artisan('firefly-iii:other-currencies')
- ->expectsOutput('Verified 1 transaction(s) and journal(s).')
- ->assertExitCode(0);
-
- // assume currency has been fixed for both transactions:
- $this->assertCount(1, Transaction::where('id', $one->id)->where('transaction_currency_id', $euro->id)->get());
- $this->assertCount(1, Transaction::where('id', $two->id)->where('transaction_currency_id', $euro->id)->get());
-
- $one->forceDelete();
- $two->forceDelete();
- $journal->forceDelete();
- }
-
- /**
- * Basic test. Assume nothing is wrong. Submit an opening balance.
- * Also fixes bad transaction currency ID.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
- */
- public function testHandleReconciliation(): void
- {
- $type = TransactionType::where('type', TransactionType::RECONCILIATION)->first();
- $asset = $this->getRandomAsset();
- $reconciliation = $this->getRandomReconciliation();
- $journal = TransactionJournal::create(
- [
- 'user_id' => 1,
- 'transaction_currency_id' => 1,
- 'transaction_type_id' => $type->id,
- 'description' => 'Test',
- 'tag_count' => 0,
- 'date' => '2019-01-01',
- ]
- );
- $one = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-10',
- 'identifier' => 1,
- 'transaction_currency_id' => 2,
- ]
- );
- $two = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $reconciliation->id,
- 'amount' => '10',
- 'identifier' => 1,
- 'transaction_currency_id' => 2,
- ]
- );
-
-
- // mock classes:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $euro = $this->getEuro();
-
- // collect all journals:
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('setUser')->atLeast()->once();
- $cliRepos->shouldReceive('getAllJournals')
- ->atLeast()->once()
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
- ->andReturn(new Collection([$journal]));
-
- // account repos
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- #$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()
- # ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- // collect currency
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- #$currencyRepos->shouldReceive('findNull')->atLeast()->once()
- # ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
-
- $this->artisan('firefly-iii:other-currencies')
- ->expectsOutput('Verified 1 transaction(s) and journal(s).')
- ->assertExitCode(0);
-
- // assume currency has been fixed for both transactions:
- $this->assertCount(1, Transaction::where('id', $one->id)->where('transaction_currency_id', $euro->id)->get());
- $this->assertCount(1, Transaction::where('id', $two->id)->where('transaction_currency_id', $euro->id)->get());
- $this->assertCount(1, Transaction::where('id', $one->id)->where('foreign_currency_id', 2)->get());
- $this->assertCount(1, Transaction::where('id', $two->id)->where('foreign_currency_id', 2)->get());
-
- $one->forceDelete();
- $two->forceDelete();
- $journal->forceDelete();
- }
-
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/RenameAccountMetaTest.php b/tests/Feature/Console/Commands/Upgrade/RenameAccountMetaTest.php
deleted file mode 100644
index f678f7725c..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/RenameAccountMetaTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-/**
- * RenameAccountMetaTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\Configuration;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class RenameAccountMetaTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RenameAccountMetaTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\RenameAccountMeta
- */
- public function testHandle(): void
- {
- $false = new Configuration;
- $false->data = false;
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:rename-account-meta')
- ->expectsOutput('All account meta is OK.')
- ->assertExitCode(0);
-
- }
-
- /**
- * Create bad entry, then check if its renamed.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\RenameAccountMeta
- */
- public function testHandleRename(): void
- {
- $false = new Configuration;
- $false->data = false;
- // check config
- FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);
-
-
- $expense = $this->getRandomExpense();
-
- $meta = AccountMeta::create(
- [
- 'name' => 'accountRole',
- 'data' => 'defaultAsset',
- 'account_id' => $expense->id,
- ]
- );
-
-
- // assume all is well.
- $this->artisan('firefly-iii:rename-account-meta')
- ->expectsOutput('Renamed 1 account meta entries (entry).')
- ->assertExitCode(0);
- $this->assertCount(0, AccountMeta::where('id', $meta->id)->where('name', 'accountRole')->get());
- $this->assertCount(1, AccountMeta::where('id', $meta->id)->where('name', 'account_role')->get());
-
- $meta->forceDelete();
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/TransactionIdentifierTest.php b/tests/Feature/Console/Commands/Upgrade/TransactionIdentifierTest.php
deleted file mode 100644
index 619cc05a09..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/TransactionIdentifierTest.php
+++ /dev/null
@@ -1,161 +0,0 @@
-<?php
-/**
- * TransactionIdentifierTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionIdentifierTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionIdentifierTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
- */
- public function testHandle(): void
- {
- // mock classes:
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- // commands:
- $cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
- ->atLeast()->once();
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:transaction-identifiers')
- ->expectsOutput('All split journal transaction identifiers are correct.')
- ->assertExitCode(0);
-
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
- */
- public function testHandleSplit(): void
- {
- // create a split journal:
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $journal = TransactionJournal::create(
- [
- 'user_id' => 1,
- 'transaction_currency_id' => 1,
- 'transaction_type_id' => 1,
- 'description' => 'Test',
- 'tag_count' => 0,
- 'date' => '2019-01-01',
- ]
- );
- $one = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-10',
- 'identifier' => 0,
- ]
- );
- $two = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $expense->id,
- 'amount' => '10',
- 'identifier' => 0,
- ]
- );
- $three = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $asset->id,
- 'amount' => '-12',
- 'identifier' => 0,
- ]
- );
- $four = Transaction::create(
- [
- 'transaction_journal_id' => $journal->id,
- 'account_id' => $expense->id,
- 'amount' => '12',
- 'identifier' => 0,
- ]
- );
-
- // mock classes:
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- // commands:
- $cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
- ->atLeast()->once();
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:transaction-identifiers')
- ->expectsOutput('Fixed 2 split journal transaction identifier(s).')
- ->assertExitCode(0);
-
- // see results:
- $this->assertCount(1, Transaction::where('id', $one->id)->where('identifier', 0)->get());
- $this->assertCount(1, Transaction::where('id', $three->id)->where('identifier', 1)->get());
-
- }
-
-}
diff --git a/tests/Feature/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php b/tests/Feature/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php
deleted file mode 100644
index 322eebdffc..0000000000
--- a/tests/Feature/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php
+++ /dev/null
@@ -1,562 +0,0 @@
-<?php
-/**
- * TransferCurrenciesCorrectionsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Console\Commands\Upgrade;
-
-
-use FireflyConfig;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class TransferCurrenciesCorrectionsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransferCurrenciesCorrectionsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Assume nothing is wrong.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandle(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('All transfers have correct currency information.')
- ->assertExitCode(0);
- }
-
- /**
- * Basic test. Assume the transfer is OK.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleCorrectTransfer(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- #$accountRepos->shouldReceive('getMetaValue')
- # ->atLeast()->once()
- # ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // currency repos
- #$currencyRepos->shouldReceive('findNull')
- # ->atLeast()->once()
- # ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- // assume all is well.
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('All transfers have correct currency information.')
- ->assertExitCode(0);
- }
-
- /**
- * Journal has bad currency info.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleInvalidJournalCurrency(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
- $transfer->transaction_currency_id = $dollar->id;
- $transfer->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- #$accountRepos->shouldReceive('getMetaValue')
- # ->atLeast()->once()
- # ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // currency repos
- #$currencyRepos->shouldReceive('findNull')
- # ->atLeast()->once()
- # ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- $this->assertCount(1, TransactionJournal::where('id', $transfer->id)->where('transaction_currency_id', 1)->get());
- }
-
- /**
- * Missing source foreign amount information.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleMissingSourceForeignAmount(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
-
- /** @var Transaction $destination */
- $destination = $transfer->transactions()->where('amount', '>', 0)->first();
- $destination->foreign_amount = '100';
- $destination->save();
-
- /** @var Transaction $destination */
- $source = $transfer->transactions()->where('amount', '<', 0)->first();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([$dollar->id])->andReturn($dollar);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 2 transfer(s).')
- ->assertExitCode(0);
-
- $this->assertCount(1, Transaction::where('id', $source->id)
- ->where('foreign_amount', '-100')->get()
- );
- }
-
-
- /**
- * Missing source foreign amount information.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleMissingDestForeignAmount(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
-
- /** @var Transaction $destination */
- $destination = $transfer->transactions()->where('amount', '>', 0)->first();
- $destination->foreign_amount = null;
- $destination->save();
-
- /** @var Transaction $destination */
- $source = $transfer->transactions()->where('amount', '<', 0)->first();
- $source->foreign_amount = '-100';
- $source->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1', $dollar->id);
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([1])->andReturn($euro);
-
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([$dollar->id])->andReturn($dollar);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 3 transfer(s).')
- ->assertExitCode(0);
-
- $this->assertCount(1, Transaction::where('id', $destination->id)
- ->where('foreign_amount', '100')->get()
- );
- }
-
-
- /**
- * Basic test. The foreign currency is broken and should be corrected.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleMismatchedForeignCurrency(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
-
- // make sure that source and destination have the right currencies beforehand
- $source = $transfer->transactions()->where('amount', '<', 0)->first();
- $source->transaction_currency_id = $euro->id;
- $source->save();
-
- $dest = $transfer->transactions()->where('amount', '>', 0)->first();
- $dest->transaction_currency_id = $dollar->id;
- $dest->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1', $dollar->id);
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([1])->andReturn($euro);
-
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([$dollar->id])->andReturn($dollar);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- // source and destination transaction should be corrected:
- $this->assertCount(1, Transaction::where('id', $source->id)
- ->where('transaction_currency_id', $euro->id)
- ->where('foreign_currency_id', $dollar->id)
- ->get());
- }
-
-
- /**
- * Basic test. Source transaction has no currency.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleTransferNoSourceCurrency(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
-
- // get source transaction and remove currency:
- /** @var Transaction $source */
- $source = $transfer->transactions()->where('amount', '<', 0)->first();
- $source->transaction_currency_id = null;
- $source->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- // assume problem is fixed:
- $this->assertCount(1, Transaction::where('id', $source->id)->where('transaction_currency_id', 1)->get());
- }
-
- /**
- * Basic test. Destination transaction has no currency.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleTransferNoDestCurrency(): void
- {
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
-
- // get source transaction and remove currency:
- /** @var Transaction $destination */
- $destination = $transfer->transactions()->where('amount', '>', 0)->first();
- $destination->transaction_currency_id = null;
- $destination->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- // assume problem is fixed:
- $this->assertCount(1, Transaction::where('id', $destination->id)->where('transaction_currency_id', 1)->get());
- }
-
- /**
- * Basic test. Source transaction has bad currency.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleTransferBadSourceCurrency(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
-
- // get source transaction and remove currency:
- /** @var Transaction $source */
- $source = $transfer->transactions()->where('amount', '<', 0)->first();
- $source->transaction_currency_id = 2;
- $source->foreign_amount = null;
- $source->save();
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')
- ->atLeast()->once()
- ->withArgs([1])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- // assume problem is fixed:
- $this->assertCount(1, Transaction::where('id', $source->id)->where('transaction_currency_id', 1)->get());
- }
-
- /**
- * Basic test. Source transaction has bad currency, and this must be fixed.
- *
- * TODO something in this test is too random, and it fails. Not sure why.
- *
- * @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
- */
- public function testHandleTransferBadDestCurrency(): void
- {
- Log::warning(sprintf('Now in test %s.', __METHOD__));
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
- // get destination transaction and remove currency:
- $transfer->transaction_currency_id = $euro->id;
- $transfer->save();
-
- Log::debug(sprintf('Gave transfer #%d currency EUR', $transfer->id));
-
-
- /** @var Transaction $destination */
- $destination = $transfer->transactions()->where('amount', '>', 0)->first();
- $destination->transaction_currency_id = $dollar->id;
- $destination->save();
-
- Log::debug(sprintf('Gave transaction #%d currency USD', $destination->id));
-
- // mock calls:
- $cliRepos->shouldReceive('getAllJournals')
- ->withArgs([[TransactionType::TRANSFER]])
- ->atLeast()->once()->andReturn(new Collection([$transfer]));
-
- // account repos
- $accountRepos->shouldReceive('getMetaValue')
- ->atLeast()->once()
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn((string)$euro->id);
-
- // currency repos
- $currencyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$euro->id])->andReturn($euro);
-
- // configuration
- $false = new Configuration;
- $false->data = false;
- FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
- FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
-
- $this->artisan('firefly-iii:transfer-currencies')
- ->expectsOutput('Verified currency information of 1 transfer(s).')
- ->assertExitCode(0);
-
- // assume problem is fixed:
- $this->assertCount(1, Transaction::where('id', $destination->id)->where('transaction_currency_id', $euro->id)->get());
- }
-
-}
diff --git a/tests/Feature/Controllers/Account/CreateControllerTest.php b/tests/Feature/Controllers/Account/CreateControllerTest.php
deleted file mode 100644
index 12b86e5a7b..0000000000
--- a/tests/Feature/Controllers/Account/CreateControllerTest.php
+++ /dev/null
@@ -1,205 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class CreateControllerTest.
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\CreateController
- */
- public function testCreate(): void
- {
- // mock stuff
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('get')->andReturn(new Collection);
-
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- // mock default calls
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_accounts_create_asset');
-
- // get all types:
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
-
- $this->be($this->user());
- $response = $this->get(route('accounts.create', ['asset']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\CreateController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testStore(): void
- {
- // mock stuff
-
- $repository = $this->mock(AccountRepositoryInterface::class);
- $asset = $this->getRandomAsset();
-
- $repository->shouldReceive('store')->once()->andReturn($asset);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- // change the preference:
- $emptyPref = new Preference;
- $emptyPref->data = [];
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $this->session(['accounts.create.uri' => 'http://localhost/x']);
- $this->be($this->user());
- $data = [
- 'name' => 'new account ' . $this->randomInt(),
- 'objectType' => 'asset',
- ];
-
- $response = $this->post(route('accounts.store', ['asset']), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect('http://localhost/x');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\CreateController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testStoreAnother(): void
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $asset = $this->getRandomAsset();
-
- $repository->shouldReceive('store')->once()->andReturn($asset);
-
- // change the preference:
- $emptyPref = new Preference;
- $emptyPref->data = [];
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', [$asset->id]]);
-
-
- // mock default session stuff
- $this->mockDefaultSession();
-
-
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $this->session(['accounts.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $data = [
- 'name' => 'new account ' . $this->randomInt(),
- 'objectType' => 'asset',
- 'create_another' => 1,
- ];
-
-
- $response = $this->post(route('accounts.store', ['asset']), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect('http://localhost/accounts/create/asset');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\CreateController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testStoreLiability(): void
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $liability = $this->getRandomLoan();
- $loan = AccountType::where('type', AccountType::LOAN)->first();
- $repository->shouldReceive('store')->once()->andReturn($liability);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- // change the preference:
- $emptyPref = new Preference;
- $emptyPref->data = [];
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $this->session(['accounts.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $data = [
- 'name' => 'new liability account ' . $this->randomInt(),
- 'objectType' => 'liabilities',
- 'liability_type_id' => $loan->id,
- 'opening_balance' => '-100',
- 'opening_balance_date' => '2018-01-01',
- ];
-
- $response = $this->post(route('accounts.store', ['liabilities']), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Account/DeleteControllerTest.php b/tests/Feature/Controllers/Account/DeleteControllerTest.php
deleted file mode 100644
index 306366a578..0000000000
--- a/tests/Feature/Controllers/Account/DeleteControllerTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-
-/**
- *
- * Class DeleteControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\DeleteController
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testDelete(): void
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $asset = $this->getRandomAsset();
-
- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('accounts.delete', [$asset->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\DeleteController
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testDestroy(): void
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $asset = $this->getRandomAsset();
- $repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
- $repository->shouldReceive('destroy')->andReturn(true);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']);
-
- $this->be($this->user());
- $response = $this->post(route('accounts.destroy', [$asset->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php
deleted file mode 100644
index 74ca47fb9c..0000000000
--- a/tests/Feature/Controllers/Account/EditControllerTest.php
+++ /dev/null
@@ -1,268 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class EditControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\EditController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- */
- public function testEdit(): void
- {
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
-
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $repository->shouldReceive('get')->andReturn(new Collection)->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull()->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull()->atLeast()->once();
- //$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly')->atLeast()->once();
-
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all types:
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
-
- $this->be($this->user());
- $response = $this->get(route('accounts.edit', [$asset->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee('Some text');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\EditController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- */
- public function testEditLiability(): void
- {
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
- $loan = $this->getRandomLoan();
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- //$repository->shouldReceive('findNull')->once()->andReturn($euro);
- $repository->shouldReceive('get')->andReturn(new Collection);
-
- $accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
- //$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
-
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all types:
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('accounts.edit', [$loan->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee('Some text');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\EditController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- */
- public function testEditNull(): void
- {
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $repository->shouldReceive('get')->andReturn(new Collection);
- $accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once();
-
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- // get all types:
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
- $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once();
-
- $this->be($this->user());
- $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
- $response = $this->get(route('accounts.edit', [$account->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee('Some text');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\EditController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testUpdate(): void
- {
- // mock stuff
- $account = $this->getRandomAsset();
- $repository = $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
-
- $repository->shouldReceive('update')->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']);
- $this->be($this->user());
- $data = [
- 'name' => 'updated account ' . $this->randomInt(),
- 'active' => 1,
- 'what' => 'asset',
- ];
-
- $response = $this->post(route('accounts.update', [$account->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\EditController
- * @covers \FireflyIII\Http\Requests\AccountFormRequest
- * @covers \FireflyIII\Http\Controllers\Controller
- */
- public function testUpdateAgain(): void
- {
- // mock stuff
- $account = $this->getRandomAsset();
- $repository = $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('update')->once();
-
- $this->session(['accounts.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $data = [
- 'name' => 'updated account ' . $this->randomInt(),
- 'active' => 1,
- 'what' => 'asset',
- 'return_to_edit' => '1',
- ];
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $response = $this->post(route('accounts.update', [$account->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-}
diff --git a/tests/Feature/Controllers/Account/IndexControllerTest.php b/tests/Feature/Controllers/Account/IndexControllerTest.php
deleted file mode 100644
index 4a2579a992..0000000000
--- a/tests/Feature/Controllers/Account/IndexControllerTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-use Amount;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-
-/**
- * Class IndexControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IndexControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\IndexController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- */
- public function testIndex(string $range): void
- {
- // mock stuff
- $this->mock(CurrencyRepositoryInterface::class);
- $account = $this->getRandomAsset();
- $repository = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $repository->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
- $repository->shouldReceive('getInactiveAccountsByType')->andReturn(new Collection);
-
- $repository->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $repository->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
- //
-
- Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
- Steam::shouldReceive('getLastActivities')->andReturn([]);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- Amount::shouldReceive('formatAnything')->andReturn('123');
-
- $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
- $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
- $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('accounts.index', ['asset']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php
deleted file mode 100644
index 50bdd35330..0000000000
--- a/tests/Feature/Controllers/Account/ReconcileControllerTest.php
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-/**
- * ReconcileControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\TransactionGroupFactory;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class ConfigurationControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ReconcileControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * Test showing the reconciliation.
- *
- * @covers \FireflyIII\Http\Controllers\Account\ReconcileController
- */
- public function testReconcile(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $this->mock(GroupCollectorInterface::class);
- $euro = $this->getEuro();
- $asset = $this->getRandomAsset();
- $date = new Carbon;
-
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturnTrue();
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('accounts.reconcile', [$asset->id, '20170101', '20170131']));
- $response->assertStatus(200);
-
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * Submit reconciliation.
- *
- * @covers \FireflyIII\Http\Controllers\Account\ReconcileController
- * @covers \FireflyIII\Http\Requests\ReconciliationStoreRequest
- */
- public function testSubmit(): void
- {
- $repository = $this->mock(AccountRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
- $date = new Carbon;
- $factory = $this->mock(TransactionGroupFactory::class);
- $group = $this->getRandomWithdrawalGroup();
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(GroupCollectorInterface::class);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $journalRepos->shouldReceive('reconcileById')->times(3);
- $repository->shouldReceive('getReconciliation')->atLeast()->once()->andReturn($asset);
- $repository->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $factory->shouldReceive('setUser')->atLeast()->once();
- $factory->shouldReceive('create')->andReturn($group);
-
-
- $data = [
- 'journals' => [1, 2, 3],
- 'reconcile' => 'create',
- 'difference' => '5',
- 'start' => '20170101',
- 'end' => '20170131',
- ];
- $this->be($this->user());
- $response = $this->post(route('accounts.reconcile.submit', [$asset->id, '20170101', '20170131']), $data);
-
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * Submit reconciliation, but throw an error.
- *
- * @covers \FireflyIII\Http\Controllers\Account\ReconcileController
- * @covers \FireflyIII\Http\Requests\ReconciliationStoreRequest
- */
- public function testSubmitError(): void
- {
- $repository = $this->mock(AccountRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
- $date = new Carbon;
- $factory = $this->mock(TransactionGroupFactory::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(GroupCollectorInterface::class);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $journalRepos->shouldReceive('reconcileById')->times(3);
- $repository->shouldReceive('getReconciliation')->atLeast()->once()->andReturn($asset);
- $repository->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $factory->shouldReceive('setUser')->atLeast()->once();
- $factory->shouldReceive('create')->andThrow(new FireflyException('Some error'));
-
- $data = [
- 'journals' => [1, 2, 3],
- 'reconcile' => 'create',
- 'difference' => '5',
- 'start' => '20170101',
- 'end' => '20170131',
- ];
- $this->be($this->user());
- $response = $this->post(route('accounts.reconcile.submit', [$asset->id, '20170101', '20170131']), $data);
-
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-}
diff --git a/tests/Feature/Controllers/Account/ShowControllerTest.php b/tests/Feature/Controllers/Account/ShowControllerTest.php
deleted file mode 100644
index 27177a7ee0..0000000000
--- a/tests/Feature/Controllers/Account/ShowControllerTest.php
+++ /dev/null
@@ -1,175 +0,0 @@
-<?php
-/**
- * ShowControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Account;
-
-use Amount;
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Account\AccountTaskerInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class ShowControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ShowControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testShow(string $range): void
- {
- $date = new Carbon;
- $this->session(['start' => $date, 'end' => clone $date]);
-
- // mock stuff:
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
- $journal = $this->getRandomWithdrawalAsArray();
- $group = $this->getRandomWithdrawalGroup();
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
-
- $this->mockDefaultSession();
-
- // amount mocks:
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- $repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
- $repository->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- $this->mockLastActivity();
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf();
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
- $collector->shouldReceive('withAccountInformation')->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
-
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('accounts.show', [$asset->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Account\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testShowAll(string $range): void
- {
- $date = new Carbon;
- $this->session(['start' => $date, 'end' => clone $date]);
- // mock stuff:
- $this->mock(AccountTaskerInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
- $journal = $this->getRandomWithdrawalAsArray();
- $group = $this->getRandomWithdrawalGroup();
- $euro = $this->getEuro();
- $asset = $this->getRandomAsset();
-
- $this->mockDefaultSession();
-
- $repository->shouldReceive('isLiability')->andReturn(false)->atLeast()->once();
- $repository->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
- $repository->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- // mock hasRole for user repository:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$journal]);
- $collector->shouldReceive('withAccountInformation')->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$group], 0, 10));
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('accounts.show.all', [$asset->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php b/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php
deleted file mode 100644
index 7a45574c00..0000000000
--- a/tests/Feature/Controllers/Admin/ConfigurationControllerTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/**
- * ConfigurationControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Admin;
-
-use FireflyConfig;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class ConfigurationControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ConfigurationControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // for session
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- //Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
- $this->mockDefaultPreferences();
-
- $this->be($this->user());
- $falseConfig = new Configuration;
- $falseConfig->data = false;
-
- $trueConfig = new Configuration;
- $trueConfig->data = true;
-
- FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode', true])->once()->andReturn($trueConfig);
- //FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->times(2)->andReturn($falseConfig);
-
- $response = $this->get(route('admin.configuration.index'));
- $response->assertStatus(200);
-
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
- * @covers \FireflyIII\Http\Requests\ConfigurationRequest
- */
- public function testPostIndex(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // for session
-
-
- //Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
- $this->mockDefaultPreferences();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- $falseConfig = new Configuration;
- $falseConfig->data = false;
-
- //FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
- FireflyConfig::shouldReceive('set')->withArgs(['single_user_mode', false])->once();
- FireflyConfig::shouldReceive('set')->withArgs(['is_demo_site', false])->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('admin.configuration.index.post'));
- $response->assertSessionHas('success');
- $response->assertStatus(302);
- }
-}
diff --git a/tests/Feature/Controllers/Admin/HomeControllerTest.php b/tests/Feature/Controllers/Admin/HomeControllerTest.php
deleted file mode 100644
index 40a6040453..0000000000
--- a/tests/Feature/Controllers/Admin/HomeControllerTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * HomeControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Admin;
-
-use Event;
-use FireflyIII\Events\AdminRequestedTestMessage;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class HomeControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HomeControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\HomeController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // default for session
- $this->mockDefaultPreferences();
- $this->mockDefaultConfiguration();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('admin.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\HomeController
- */
- public function testTestMessage(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultPreferences();
- $this->mockDefaultConfiguration();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- Event::fake();
-
- $this->be($this->user());
- $response = $this->post(route('admin.test-message'));
- $response->assertStatus(302);
-
- Event::assertDispatched(AdminRequestedTestMessage::class);
- }
-}
diff --git a/tests/Feature/Controllers/Admin/LinkControllerTest.php b/tests/Feature/Controllers/Admin/LinkControllerTest.php
deleted file mode 100644
index f786f6408e..0000000000
--- a/tests/Feature/Controllers/Admin/LinkControllerTest.php
+++ /dev/null
@@ -1,387 +0,0 @@
-<?php
-/**
- * LinkControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Admin;
-
-use FireflyIII\Models\LinkType;
-use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class LinkControllerTest
- *
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class LinkControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testCreate(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->be($this->user());
- $response = $this->get(route('admin.links.create'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testDeleteEditable(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- // create editable link type just in case:
- $newType = LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- $linkType = LinkType::where('editable', 1)->first();
- $another = LinkType::where('editable', 0)->first();
- $repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType, $another]));
- $repository->shouldReceive('countJournals')->andReturn(2);
- $this->be($this->user());
- $response = $this->get(route('admin.links.delete', [$linkType->id]));
- $response->assertStatus(200);
-
- $newType->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testDeleteNonEditable(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
- $linkType = LinkType::where('editable', 0)->first();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->be($this->user());
- $response = $this->get(route('admin.links.delete', [$linkType->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testDestroy(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // create editable link type just in case:
- LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
-
- $linkType = LinkType::where('editable', 1)->first();
- $repository->shouldReceive('findNull')->andReturn($linkType);
- $repository->shouldReceive('destroy');
- $this->be($this->user());
- $this->session(['link_types.delete.uri' => 'http://localhost']);
- $response = $this->post(route('admin.links.destroy', [$linkType->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testEditEditable(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- // create editable link type just in case:
- LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
-
- $linkType = LinkType::where('editable', 1)->first();
- $this->be($this->user());
- $response = $this->get(route('admin.links.edit', [$linkType->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testEditNonEditable(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
-
- $linkType = LinkType::where('editable', 0)->first();
- $this->be($this->user());
- $response = $this->get(route('admin.links.edit', [$linkType->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testIndex(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
- //Preferences::shouldReceive('mark')->atLeast()->once();
-
- $linkTypes = LinkType::inRandomOrder()->take(3)->get();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $repository->shouldReceive('get')->andReturn($linkTypes);
- $repository->shouldReceive('countJournals')->andReturn(3);
- $this->be($this->user());
- $response = $this->get(route('admin.links.index'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- */
- public function testShow(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('getJournalLinks')->andReturn(new Collection);
- $this->mockDefaultSession();
-
-
- $linkType = LinkType::first();
- $this->be($this->user());
- $response = $this->get(route('admin.links.show', [$linkType->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- * @covers \FireflyIII\Http\Requests\LinkTypeFormRequest
- */
- public function testStore(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $data = [
- 'name' => sprintf('test %d', $this->randomInt()),
- 'inward' => sprintf('test inward %d', $this->randomInt()),
- 'outward' => sprintf('test outward %d', $this->randomInt()),
- ];
- $repository->shouldReceive('store')->once()->andReturn(LinkType::first());
- $repository->shouldReceive('findNull')->andReturn(LinkType::first());
-
- $this->session(['link_types.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('admin.links.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- * @covers \FireflyIII\Http\Requests\LinkTypeFormRequest
- */
- public function testStoreRedirect(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
-
- $data = [
- 'name' => sprintf('test %d', $this->randomInt()),
- 'inward' => sprintf('test inward %d', $this->randomInt()),
- 'outward' => sprintf('test outward %d', $this->randomInt()),
- 'create_another' => '1',
- ];
- $repository->shouldReceive('store')->once()->andReturn(new LinkType);
- $this->session(['link_types.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('admin.links.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- * @covers \FireflyIII\Http\Requests\LinkTypeFormRequest
- */
- public function testUpdate(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // create editable link type just in case:
- $linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
- $repository->shouldReceive('update')->once()->andReturn(new $linkType);
-
- // mock default session stuff
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'name' => sprintf('test %d', $this->randomInt()),
- 'inward' => sprintf('test inward %d', $this->randomInt()),
- 'outward' => sprintf('test outward %d', $this->randomInt()),
- ];
- $this->session(['link_types.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('admin.links.update', [$linkType->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- * @covers \FireflyIII\Http\Requests\LinkTypeFormRequest
- */
- public function testUpdateNonEditable(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // mock default session stuff
- $this->mockDefaultSession();
- $linkType = LinkType::where('editable', 0)->first();
-
- $data = [
- 'name' => sprintf('test %d', $this->randomInt()),
- 'inward' => sprintf('test inward %d', $this->randomInt()),
- 'outward' => sprintf('test outward %d', $this->randomInt()),
- 'return_to_edit' => '1',
- ];
- $this->session(['link_types.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('admin.links.update', [$linkType->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\LinkController
- * @covers \FireflyIII\Http\Requests\LinkTypeFormRequest
- */
- public function testUpdateRedirect(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
-
- // create editable link type just in case:
- $linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
-
- // mock default session stuff
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'name' => sprintf('test %d', $this->randomInt()),
- 'inward' => sprintf('test inward %d', $this->randomInt()),
- 'outward' => sprintf('test outward %d', $this->randomInt()),
- 'return_to_edit' => '1',
- ];
- $repository->shouldReceive('update')->once()->andReturn(new $linkType);
- $this->session(['link_types.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('admin.links.update', [$linkType->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Admin/UpdateControllerTest.php b/tests/Feature/Controllers/Admin/UpdateControllerTest.php
deleted file mode 100644
index dcee520968..0000000000
--- a/tests/Feature/Controllers/Admin/UpdateControllerTest.php
+++ /dev/null
@@ -1,246 +0,0 @@
-<?php
-/**
- * UpdateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Admin;
-
-use Carbon\Carbon;
-use FireflyConfig;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequest;
-use FireflyIII\Services\Github\Object\Release;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class UpdateControllerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UpdateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- */
- public function testIndex(): void
- {
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // mock calls
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $this->mockDefaultSession();
-
- // mock update calls.
- $config = new Configuration;
- $config->data = -1;
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
-
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
- // call service
- $this->be($this->user());
- $response = $this->get(route('admin.update-check'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- */
- public function testPost(): void
- {
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // mock calls
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->mockDefaultSession();
-
- // mock update calls
- FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
- FireflyConfig::shouldReceive('set')->withArgs(['update_channel','stable'])->once()->andReturn(new Configuration);
- //FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
-
- // call service
- $this->be($this->user());
- $response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
- $response->assertSessionHas('success');
- $response->assertStatus(302);
- $response->assertRedirect(route('admin.update-check'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testUpdateCheck(): void
- {
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // mock calls
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
- $this->mockDefaultSession();
-
- $return = [
- 'version' => '2.0.0',
- 'date' => '2020-01-01'
- ];
-
- // set some data
- $updater = $this->mock(UpdateRequest::class);
- $updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
- ->andReturn($return);
-
-
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
-
- $this->be($this->user());
- $response = $this->post(route('admin.update-check.manual'));
- $response->assertStatus(200);
- $response->assertSee(config('firefly.version'));
- $response->assertSee('which is newer than the latest release');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testUpdateCheckCurrent(): void
- {
-
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->mockDefaultSession();
-
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
-
- $return = [
- 'version' => config('firefly.version'),
- 'date' => '2020-01-01'
- ];
-
- // set some data
- $updater = $this->mock(UpdateRequest::class);
- $updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
- ->andReturn($return);
-
- $this->be($this->user());
- $response = $this->post(route('admin.update-check.manual'));
- $response->assertStatus(200);
- $response->assertSee(config('firefly.version'));
- $response->assertSee('the latest available release');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testUpdateCheckError(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->mockDefaultSession();
-
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
-
- $updater = $this->mock(UpdateRequest::class);
- $updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
- ->andThrow(new FireflyException('Something broke.'));
-
-
-
- $this->be($this->user());
- $response = $this->post(route('admin.update-check.manual'));
- $response->assertStatus(200);
- $response->assertSee('An error occurred while checking');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UpdateController
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testUpdateCheckNewer(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
- $this->mockDefaultSession();
-
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
-
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
-
- $return = [
- 'version' => '100',
- 'date' => '2020-01-01'
- ];
-
- // set some data
- $updater = $this->mock(UpdateRequest::class);
- $updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
- ->andReturn($return);
-
- // expect a new release (because of .1)
- $this->be($this->user());
- $response = $this->post(route('admin.update-check.manual'));
- $response->assertStatus(200);
- $response->assertSee('A new version of Firefly III is available');
- }
-}
diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php
deleted file mode 100644
index 26d823d232..0000000000
--- a/tests/Feature/Controllers/Admin/UserControllerTest.php
+++ /dev/null
@@ -1,176 +0,0 @@
-<?php
-/**
- * UserControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Admin;
-
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class UserControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UserControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- */
- public function testDelete(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('admin.users.delete', [$this->user()->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- */
- public function testDestroy(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('destroy')->once();
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->post(route('admin.users.destroy', [$this->user()->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- */
- public function testEdit(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('admin.users.edit', [$this->user()->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- */
- public function testIndex(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(3)->andReturn(true);
- $user = $this->user();
- $repository->shouldReceive('all')->andReturn(new Collection([$user]));
- $this->mockDefaultSession();
-
- $this->be($user);
- $response = $this->get(route('admin.users'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- */
- public function testShow(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
- $repository->shouldReceive('getUserData')->andReturn(
- [
- 'export_jobs_success' => 0,
- 'attachments_size' => 0,
- ]
- );
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('admin.users.show', [$this->user()->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Admin\UserController
- * @covers \FireflyIII\Http\Requests\UserFormRequest
- */
- public function testUpdate(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('changePassword')->once();
- $repository->shouldReceive('changeStatus')->once();
- $repository->shouldReceive('updateEmail')->once();
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark');
-
- $data = [
- 'id' => 1,
- 'email' => '[email protected]',
- 'password' => 'james',
- 'password_confirmation' => 'james',
- 'blocked_code' => 'blocked',
- 'blocked' => 1,
- ];
-
- $this->be($this->user());
- $response = $this->post(route('admin.users.update', ['1']), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php
deleted file mode 100644
index 716253ed71..0000000000
--- a/tests/Feature/Controllers/AttachmentControllerTest.php
+++ /dev/null
@@ -1,238 +0,0 @@
-<?php
-/**
- * AttachmentControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Models\Attachment;
-use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class AttachmentControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class AttachmentControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
-
- // data
- $attachment = $this->getRandomAttachment();
-
- // mock stuff
- $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('attachments.delete', [$attachment->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $attachment = $this->getRandomAttachment();
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $repository->shouldReceive('destroy')->andReturn(true);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['attachments.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('attachments.destroy', [$attachment->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testDownload(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $attachment = $this->getRandomAttachment();
- $repository = $this->mock(AttachmentRepositoryInterface::class);
-
- $repository->shouldReceive('exists')->once()->andReturn(true);
- $repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
-
- $this->be($this->user());
- $response = $this->get(route('attachments.download', [$attachment->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('This is attachment number one.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testDownloadFail(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $attachment = $this->getRandomAttachment();
- $repository = $this->mock(AttachmentRepositoryInterface::class);
-
- $repository->shouldReceive('exists')->once()->andReturn(false);
-
-
- Log::warning('The following error is part of a test.');
- $this->be($this->user());
- $response = $this->get(route('attachments.download', [$attachment->id]));
- $response->assertStatus(500);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
- $attachRepository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $attachment = $this->getRandomAttachment();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $attachRepository->shouldReceive('getNoteText')->andReturn('OK');
- $this->be($this->user());
- $response = $this->get(route('attachments.edit', [$attachment->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('get')->andReturn(new Collection([Attachment::first()]))->once();
- $repository->shouldReceive('exists')->andReturn(true)->once();
-
- $this->be($this->user());
- $response = $this->get(route('attachments.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $attachment = $this->getRandomAttachment();
- $repository->shouldReceive('update')->once();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['attachments.edit.uri' => 'http://localhost']);
- $data = [
- 'title' => 'Some updated title ' . $this->randomInt(),
- 'notes' => 'A',
- 'description' => 'B',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('attachments.update', [$attachment->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testView(): void
- {
- $attachment = $this->getRandomAttachment();
- $this->mockDefaultSession();
-
- $repository = $this->mock(AttachmentRepositoryInterface::class);
-
- $repository->shouldReceive('exists')->once()->andReturn(true);
- $repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
-
-
- $this->be($this->user());
- $response = $this->get(route('attachments.view', [$attachment->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\AttachmentController
- */
- public function testViewFail(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $attachment = $this->getRandomAttachment();
-
- $repository->shouldReceive('exists')->once()->andReturn(false);
-
-
- $this->be($this->user());
- $response = $this->get(route('attachments.view', [$attachment->id]));
- $response->assertStatus(500);
- }
-}
diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php
deleted file mode 100644
index 565b788199..0000000000
--- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * TwoFactorControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Auth;
-
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Preference;
-use Google2FA;
-use Log;
-use Preferences;
-use Tests\TestCase;
-use FireflyConfig;
-/**
- * Class TwoFactorControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TwoFactorControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
- */
- public function testLostTwoFactor(): void
- {
- $this->be($this->user());
- $langPreference = new Preference;
- $langPreference->data = 'en_US';
-
- $falseConfig = new Configuration;
- $falseConfig->data = false;
-
- FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig);
-
- Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
-
- $response = $this->get(route('two-factor.lost'));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
deleted file mode 100644
index a78ee6685b..0000000000
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ /dev/null
@@ -1,490 +0,0 @@
-<?php
-/**
- * BillControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Bill;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\TransactionRules\TransactionMatcher;
-use FireflyIII\Transformers\BillTransformer;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-use Illuminate\Support\MessageBag;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class BillControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class BillControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_bills_create');
-
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(AttachmentHelperInterface::class);
- $this->mock(BillRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('bills.create'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- $bill = $this->getRandomBill();
-
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(AttachmentHelperInterface::class);
- $this->mock(BillRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('bills.delete', [$bill->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(BillRepositoryInterface::class);
- $this->mock(AttachmentHelperInterface::class);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('destroy')->andReturn(true);
-
- $this->session(['bills.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('bills.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $this->mock(AttachmentHelperInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
-
- $billRepos->shouldReceive('getNoteText')->andReturn('Hello');
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('bills.edit', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_bills_index');
-
- Amount::shouldReceive('getDefaultCurrency')->andReturn($this->getEuro());
-
- // mock stuff
- $this->mock(AttachmentHelperInterface::class);
- $bill = $this->getRandomBill();
- $repository = $this->mock(BillRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
- $euro = $this->getEuro();
- //$pref = new Preference;
- //$pref->data = 50;
- //Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
-
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- ['id' => 5, 'active' => true,
- 'name' => 'x', 'next_expected_match' => '2018-01-01',
- 'amount_min' => '10',
- 'amount_max' => '10',
- 'currency' => $this->getEuro(),
- 'currency_id' => $euro->id,
- 'currency_code' => $euro->code,
- 'pay_dates' => [],
- 'currency_symbol' => $euro->symbol,
- 'currency_decimal_places' => $euro->decimal_places,
- ]
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collection = new Collection([$bill]);
- $repository->shouldReceive('getBills')->andReturn($collection)->once();
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('getNoteText')->andReturn('Hi there');
- $repository->shouldReceive('getRulesForBills')->andReturn([]);
-
-
- $this->be($this->user());
- $response = $this->get(route('bills.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testRescan(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $rule = $this->getRandomRule();
- $repository = $this->mock(BillRepositoryInterface::class);
- $this->mock(AttachmentHelperInterface::class);
-
-
- $repository->shouldReceive('getRulesForBill')->andReturn(new Collection([$rule]));
- $repository->shouldReceive('unlinkAll')->atLeast()->once();
-
- //calls for transaction matcher:
- $matcher = $this->mock(TransactionMatcher::class);
- $matcher->shouldReceive('setSearchLimit')->once()->withArgs([100000]);
- $matcher->shouldReceive('setTriggeredLimit')->once()->withArgs([100000]);
- $matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
- $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
-
- $repository->shouldReceive('linkCollectionToBill')->once();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('bills.rescan', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testRescanInactive(): void
- {
- $this->mockDefaultSession();
- $bill = $this->getRandomInactiveBill();
- $this->mock(AttachmentHelperInterface::class);
- $this->mock(BillRepositoryInterface::class);
-
- $this->be($this->user());
- $response = $this->get(route('bills.rescan', [$bill->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('warning');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- */
- public function testShow(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_bills_show');
-
- // mock stuff
- $repository = $this->mock(BillRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(BillTransformer::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $group = $this->getRandomWithdrawalGroup();
- $this->mock(AttachmentHelperInterface::class);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
-
- // mock collector:
- $collector->shouldReceive('setBill')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
-
- Amount::shouldReceive('formatAnything')->andReturn('-100');
-
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('setCurrentScope')->atLeast()->once();
- $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once();
- $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once();
- $repository->shouldReceive('getAttachments')->atLeast()->once()->andReturn(new Collection);
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- ['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
- 'currency_symbol' => 'x', 'amount_min' => '10', 'amount_max' => '15',
- ]
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('getYearAverage')->andReturn('0');
- $repository->shouldReceive('getOverallAverage')->andReturn('0');
- $repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
-
- $this->be($this->user());
- $response = $this->get(route('bills.show', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- * @covers \FireflyIII\Http\Requests\BillFormRequest
- * @covers \FireflyIII\Http\Requests\Request
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $bill = $this->user()->bills()->first();
- // mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
-
- $repository->shouldReceive('store')->andReturn($bill);
- $attachHelper->shouldReceive('saveAttachmentsForModel');
- $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'name' => 'New Bill ' . $this->randomInt(),
- 'amount_min' => '100',
- 'transaction_currency_id' => 1,
- 'skip' => 0,
- 'strict' => 1,
- 'amount_max' => '100',
- 'date' => '2016-01-01',
- 'repeat_freq' => 'monthly',
- ];
- $this->session(['bills.create.uri' => 'http://localhost']);
-
- $response = $this->post(route('bills.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- * @covers \FireflyIII\Http\Requests\BillFormRequest
- * @covers \FireflyIII\Http\Requests\Request
- */
- public function testStoreCreateAnother(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $bill = $this->getRandomBill();
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
-
- $repository->shouldReceive('store')->andReturn($bill);
- $attachHelper->shouldReceive('saveAttachmentsForModel');
- $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'name' => 'New Bill ' . $this->randomInt(),
- 'amount_min' => '100',
- 'transaction_currency_id' => 1,
- 'skip' => 0,
- 'create_another' => '1',
- 'strict' => 1,
- 'amount_max' => '100',
- 'date' => '2016-01-01',
- 'repeat_freq' => 'monthly',
- ];
- $this->session(['bills.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('bills.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- * @covers \FireflyIII\Http\Requests\BillFormRequest
- * @covers \FireflyIII\Http\Requests\Request
- */
- public function testStoreError(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(BillRepositoryInterface::class);
-
- $this->mock(AttachmentHelperInterface::class);
- $repository->shouldReceive('store')->andThrow(new FireflyException('Could not store.'));
-
- $data = [
- 'name' => 'New Bill ' . $this->randomInt(),
- 'amount_min' => '100',
- 'transaction_currency_id' => 1,
- 'skip' => 0,
- 'strict' => 1,
- 'amount_max' => '100',
- 'date' => '2016-01-01',
- 'repeat_freq' => 'monthly',
- ];
- $this->be($this->user());
- $response = $this->post(route('bills.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- $response->assertRedirect(route('bills.create'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- * @covers \FireflyIII\Http\Requests\BillFormRequest
- * @covers \FireflyIII\Http\Requests\Request
- */
- public function testStoreNoGroup(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $bill = $this->getRandomBill();
- $repository->shouldReceive('store')->andReturn($bill);
- $attachHelper->shouldReceive('saveAttachmentsForModel');
- $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'name' => 'New Bill ' . $this->randomInt(),
- 'amount_min' => '100',
- 'transaction_currency_id' => 1,
- 'skip' => 0,
- 'create_another' => '1',
- 'strict' => 1,
- 'amount_max' => '100',
- 'date' => '2016-01-01',
- 'repeat_freq' => 'monthly',
- ];
- $this->session(['bills.create.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('bills.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\BillController
- * @covers \FireflyIII\Http\Requests\BillFormRequest
- * @covers \FireflyIII\Http\Requests\Request
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $attachHelper = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
-
- $repository->shouldReceive('update')->andReturn(new Bill);
- $attachHelper->shouldReceive('saveAttachmentsForModel');
- $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'id' => 1,
- 'name' => 'Updated Bill ' . $this->randomInt(),
- 'amount_min' => '100',
- 'transaction_currency_id' => 1,
- 'skip' => 0,
- 'amount_max' => '100',
- 'date' => '2016-01-01',
- 'repeat_freq' => 'monthly',
- ];
- $this->session(['bills.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('bills.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Budget/CreateControllerTest.php b/tests/Feature/Controllers/Budget/CreateControllerTest.php
deleted file mode 100644
index 9fe5a390cb..0000000000
--- a/tests/Feature/Controllers/Budget/CreateControllerTest.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Budget;
-
-
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\CreateController
- */
- public function testCreate(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $this->mockDefaultSession();
-
-
- $this->be($this->user());
- $response = $this->get(route('budgets.create'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\CreateController
- */
- public function testStore(): void
- {
- Log::debug('Now in testStore()');
- // mock stuff
- $budget = $this->getRandomBudget();
- $repository = $this->mock(BudgetRepositoryInterface::class);
-
- $repository->shouldReceive('findNull')->andReturn($budget);
- $repository->shouldReceive('store')->andReturn($budget);
- $repository->shouldReceive('cleanupBudgets');
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['budgets.create.uri' => 'http://localhost']);
-
- $data = [
- 'name' => sprintf('New Budget %s', $this->randomInt()),
- ];
- $this->be($this->user());
- $response = $this->post(route('budgets.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-}
diff --git a/tests/Feature/Controllers/Budget/DeleteControllerTest.php b/tests/Feature/Controllers/Budget/DeleteControllerTest.php
deleted file mode 100644
index aa76edcea7..0000000000
--- a/tests/Feature/Controllers/Budget/DeleteControllerTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Budget;
-
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class DeleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\DeleteController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- $budget = $this->getRandomBudget();
- Log::debug('Now in testDelete()');
- // mock stuff
- $this->mock(BudgetRepositoryInterface::class);
-
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('budgets.delete', [$budget->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\DeleteController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- $budget = $this->getRandomBudget();
- Log::debug('Now in testDestroy()');
- // mock stuff
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
-
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('destroy')->andReturn(true);
-
- $this->session(['budgets.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('budgets.destroy', [$budget->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Budget/EditControllerTest.php b/tests/Feature/Controllers/Budget/EditControllerTest.php
deleted file mode 100644
index b7b018ac84..0000000000
--- a/tests/Feature/Controllers/Budget/EditControllerTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Budget;
-
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\EditController
- */
- public function testEdit(): void
- {
- Log::debug('Now in testEdit()');
- // mock stuff
- $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $this->mockDefaultSession();
- $this->be($this->user());
- $response = $this->get(route('budgets.edit', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\EditController
- */
- public function testUpdate(): void
- {
- Log::debug('Now in testUpdate()');
- // mock stuff
- $budget = $this->getRandomBudget();
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
-
- $repository->shouldReceive('findNull')->andReturn($budget);
- $repository->shouldReceive('update');
- $repository->shouldReceive('cleanupBudgets');
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['budgets.edit.uri' => 'http://localhost']);
-
- $data = [
- 'name' => 'Updated Budget ' . $this->randomInt(),
- 'active' => 1,
- ];
- $this->be($this->user());
- $response = $this->post(route('budgets.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Budget/IndexControllerTest.php b/tests/Feature/Controllers/Budget/IndexControllerTest.php
deleted file mode 100644
index 51136bcc98..0000000000
--- a/tests/Feature/Controllers/Budget/IndexControllerTest.php
+++ /dev/null
@@ -1,302 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Budget;
-
-use Amount;
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- *
- * Class IndexControllerTest
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class IndexControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\IndexController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testIndex(string $range): void
- {
- // mock stuff
- $budget = $this->getRandomBudget();
- $budgetLimit = $this->getRandomBudgetLimit();
- $budgetLimit->start_date = Carbon::now()->startOfMonth();
- $budgetLimit->end_date = Carbon::now()->endOfMonth();
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $repository->shouldReceive('cleanupBudgets')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
- $repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
-
- $abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
-
- $blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
-
- $currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
-
-
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_budgets_index');
- Amount::shouldReceive('formatAnything')->andReturn('123');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\IndexController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- * @throws Exception
- */
- public function testIndexOutOfRange(string $range): void
- {
- $budget = $this->getRandomBudget();
- $budgetLimit = $this->getRandomBudgetLimit();
- $budgetInfo = [
- $budget->id => [
- 'spent' => '0',
- 'budgeted' => '0',
- 'currentRep' => false,
- ],
- ];
-
- // set budget limit to current month:
- $budgetLimit->start_date = Carbon::now()->startOfMonth();
- $budgetLimit->end_date = Carbon::now()->endOfMonth();
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
-
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('cleanupBudgets')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
- $repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
-
- $abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
- $blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
- $currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
-
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_budgets_index');
- Amount::shouldReceive('formatAnything')->andReturn('123');
-
- $this->be($this->user());
- $today = new Carbon;
- $today->startOfMonth();
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.index', [$today->format('Y-m-d')]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\IndexController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- * @throws Exception
- */
- public function testIndexWithDate(string $range): void
- {
- $budget = $this->getRandomBudget();
- $budgetLimit = $this->getRandomBudgetLimit();
- $budgetInfo = [
- $budget->id => [
- 'spent' => '0',
- 'budgeted' => '0',
- 'currentRep' => false,
- ],
- ];
-
- // set budget limit to current month:
- $budgetLimit->start_date = Carbon::now()->startOfMonth();
- $budgetLimit->end_date = Carbon::now()->endOfMonth();
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('cleanupBudgets')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
- $repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection)->atLeast()->once();
-
- $abRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
- $blRepos->shouldReceive('budgeted')->andReturn('1')->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
- $currencyRepos->shouldReceive('getEnabled')->atLeast()->once()->andReturn(new Collection([$this->getEuro()]));
-
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_budgets_index');
- Amount::shouldReceive('formatAnything')->andReturn('123');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.index', ['2017-01-01']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\IndexController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- * @throws Exception
- */
- public function testIndexWithInvalidDate(string $range): void
- {
- $budgetLimit = $this->getRandomBudgetLimit();
-
- // set budget limit to current month:
- $budgetLimit->start_date = Carbon::now()->startOfMonth();
- $budgetLimit->end_date = Carbon::now()->endOfMonth();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
- $repository->shouldReceive('cleanupBudgets');
-
- $this->mockDefaultSession();
- Amount::shouldReceive('formatAnything')->andReturn('123');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.index', ['Hello-there']));
- $response->assertStatus(404);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\IndexController
- */
- public function testReorder(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $data = [
- 'budgetIds' => [1, 2],
- 'page' => 1,
- ];
-
- $repository->shouldReceive('cleanupBudgets')->atLeast()->once();
- $repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new Budget);
- $repository->shouldReceive('setBudgetOrder')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('budgets.reorder', $data));
- $response->assertStatus(200);
-
- }
-}
diff --git a/tests/Feature/Controllers/Budget/ShowControllerTest.php b/tests/Feature/Controllers/Budget/ShowControllerTest.php
deleted file mode 100644
index 77ffdecdb7..0000000000
--- a/tests/Feature/Controllers/Budget/ShowControllerTest.php
+++ /dev/null
@@ -1,264 +0,0 @@
-<?php
-/**
- * ShowControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Budget;
-
-use Amount;
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class ShowControllerTest
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ShowControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- */
- public function testNoBudget(string $range): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = null;
- $this->mockDefaultSession();
-
- try {
- $date = new Carbon;
- } catch (Exception $e) {
- $e->getMessage();
- }
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
-
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
-
- $this->session(['start' => $date, 'end' => clone $date]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.no-budget', ['2019-01-01', '2019-01-31']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testNoBudgetAll(string $range): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $date = null;
- $this->mockDefaultSession();
- try {
- $date = new Carbon;
- } catch (Exception $e) {
- $e->getMessage();
- }
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
-
- try {
- $date = new Carbon;
- } catch (Exception $e) {
- $e->getMessage();
- }
- $this->session(['start' => $date, 'end' => clone $date]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.no-budget', ['all']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testShow(string $range): void
- {
- $budgetLimit = $this->getRandomBudgetLimit();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $this->mockDefaultSession();
-
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
-
- $blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]))->atLeast()->once();
- $opsRepos->shouldReceive('spentInPeriod')->andReturn('-1')->atLeast()->once();
-
- try {
- $date = new Carbon;
- $date->subDay();
- $this->session(['first' => $date]);
- } catch (Exception $e) {
- $e->getMessage();
- }
-
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.show', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Budget\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testShowByBudgetLimit(string $range): void
- {
- $accountRepository = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->andReturn(new Collection)->atLeast()->once();
-
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('budgets.show.limit', [1, 1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Category/CreateControllerTest.php b/tests/Feature/Controllers/Category/CreateControllerTest.php
deleted file mode 100644
index e001a04a60..0000000000
--- a/tests/Feature/Controllers/Category/CreateControllerTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use FireflyIII\Models\Category;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\CreateController
- */
- public function testCreate(): void
- {
- Log::debug('TestCreate()');
- // mock stuff
- $this->mock(CategoryRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('categories.create'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\CreateController
- * @covers \FireflyIII\Http\Requests\CategoryFormRequest
- */
- public function testStore(): void
- {
- Log::debug('Test store()');
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
- $repository->shouldReceive('findNull')->andReturn(new Category);
- $repository->shouldReceive('store')->andReturn(new Category);
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $this->session(['categories.create.uri' => 'http://localhost']);
-
- $data = [
- 'name' => 'New Category ' . $this->randomInt(),
- ];
- $this->be($this->user());
- $response = $this->post(route('categories.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Category/DeleteControllerTest.php b/tests/Feature/Controllers/Category/DeleteControllerTest.php
deleted file mode 100644
index ea049a0c44..0000000000
--- a/tests/Feature/Controllers/Category/DeleteControllerTest.php
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class DeleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\DeleteController
- */
- public function testDelete(): void
- {
- Log::debug('Test Delete()');
- // mock stuff
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('categories.delete', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\DeleteController
- */
- public function testDestroy(): void
- {
- Log::debug('Test destroy()');
- // mock stuff
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
- $categoryRepos->shouldReceive('destroy')->andReturn(true);
-
- $this->session(['categories.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('categories.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Category/EditControllerTest.php b/tests/Feature/Controllers/Category/EditControllerTest.php
deleted file mode 100644
index bed5cccd45..0000000000
--- a/tests/Feature/Controllers/Category/EditControllerTest.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use FireflyIII\Models\Category;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\EditController
- */
- public function testEdit(): void
- {
- Log::debug('Test edit()');
- // mock stuff
- $this->mock(CategoryRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('categories.edit', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\EditController
- * @covers \FireflyIII\Http\Requests\CategoryFormRequest
- */
- public function testUpdate(): void
- {
- Log::debug('Test update()');
- $category = Category::first();
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $repository->shouldReceive('update');
- $repository->shouldReceive('findNull')->andReturn($category);
-
- $this->session(['categories.edit.uri' => 'http://localhost']);
-
- $data = [
- 'name' => 'Updated Category ' . $this->randomInt(),
- 'active' => 1,
- ];
- $this->be($this->user());
- $response = $this->post(route('categories.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Category/IndexControllerTest.php b/tests/Feature/Controllers/Category/IndexControllerTest.php
deleted file mode 100644
index 7973c5b198..0000000000
--- a/tests/Feature/Controllers/Category/IndexControllerTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use Carbon\Carbon;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class IndexControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IndexControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\IndexController
- */
- public function testIndex(): void
- {
- Log::debug('Test index()');
- // mock stuff
- $category = $this->getRandomCategory();
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
- $categoryRepos->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->mockDefaultSession();
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
-
- $this->be($this->user());
- $response = $this->get(route('categories.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Category/NoCategoryControllerTest.php b/tests/Feature/Controllers/Category/NoCategoryControllerTest.php
deleted file mode 100644
index 96c813b49e..0000000000
--- a/tests/Feature/Controllers/Category/NoCategoryControllerTest.php
+++ /dev/null
@@ -1,202 +0,0 @@
-<?php
-/**
- * NoCategoryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Log;
-use Mockery;
-use Navigation;
-use Preferences;
-use Tests\TestCase;
-
-
-/**
- *
- * Class NoCategoryControllerTest
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NoCategoryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testNoCategory(string $range): void
- {
- $collector = $this->mock(GroupCollectorInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- $this->mockLastActivity();
-
- // get the journal with the most recent date for firstNull:
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
-
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('categories.no-category'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testNoCategoryAll(string $range): void
- {
- $collector = $this->mock(GroupCollectorInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
-
- $this->mockDefaultSession();
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
-
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('categories.no-category', ['all']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\NoCategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testNoCategoryDate(string $range): void
- {
- $collector = $this->mock(GroupCollectorInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $this->mockDefaultSession();
- // list size
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- $this->mockLastActivity();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withoutCategory')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
-
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
-
- Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
- Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);
- Navigation::shouldReceive('startOfPeriod')->andReturn(new Carbon);
- Navigation::shouldReceive('endOfPeriod')->andReturn(new Carbon);
- Navigation::shouldReceive('periodShow')->andReturn('Some date');
- Navigation::shouldReceive('blockPeriods')->andReturn([['period' => '1M', 'start' => new Carbon, 'end' => new Carbon]])->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('categories.no-category', ['2016-01-01']));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Category/ShowControllerTest.php b/tests/Feature/Controllers/Category/ShowControllerTest.php
deleted file mode 100644
index 6cde1424f7..0000000000
--- a/tests/Feature/Controllers/Category/ShowControllerTest.php
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-/**
- * ShowControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Category;
-
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Navigation;
-use Preferences;
-use Tests\TestCase;
-
-
-/**
- *
- * Class ShowControllerTest
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ShowControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\ShowController
- *
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testShow(string $range): void
- {
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- // mock stuff
- $categoryRepos->shouldReceive('spentInPeriodCollection')->andReturn(new Collection);
- $categoryRepos->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection);
- $categoryRepos->shouldReceive('firstUseDate')->andReturnNull();
-
-
- $collector->shouldReceive('setPage')->andReturnSelf()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->times(2);
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
- $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast()->times(2);
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
-
- Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
- Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon);
- Navigation::shouldReceive('startOfPeriod')->andReturn(new Carbon);
- Navigation::shouldReceive('endOfPeriod')->andReturn(new Carbon);
- Navigation::shouldReceive('periodShow')->andReturn('Some date');
- Navigation::shouldReceive('blockPeriods')->andReturn([['period' => '1M', 'start' => new Carbon, 'end' => new Carbon]])->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('categories.show', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Category\ShowController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testShowAll(string $range): void
- {
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $collector->shouldReceive('setPage')->andReturnSelf()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
- $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
-
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('categories.show', [1, 'all']));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Feature/Controllers/Chart/AccountControllerTest.php b/tests/Feature/Controllers/Chart/AccountControllerTest.php
deleted file mode 100644
index 9525e906d8..0000000000
--- a/tests/Feature/Controllers/Chart/AccountControllerTest.php
+++ /dev/null
@@ -1,498 +0,0 @@
-<?php
-/**
- * AccountControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class AccountControllerTest
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseAccounts(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
-
- // grab two expense accounts from the current user.
- $accounts = $this->user()->accounts()->where('account_type_id', 4)->take(2)->get();
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $firstId = $accounts->first()->id;
- $secondId = $accounts->first()->id;
- // for each a set of balances:
- $start = [$firstId => [1 => '123.45', 2 => '200.01',], $secondId => [1 => '123.45', 2 => '200.01',],];
- $end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
-
- // return them when collected:
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])->andReturn($accounts);
-
- // and return start and end balances:
- Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
-
- // currency should be looking for the currency ID's:
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($euro);
- $currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn($dollar);
-
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.expense'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testExpenseBudget(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $budget = $this->user()->budgets()->find($withdrawal['budget_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->atLeast()->once();
- $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseBudgetAll(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(FiscalHelperInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $budget = $this->user()->budgets()->find($withdrawal['budget_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
- $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
- $accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.expense-budget-all', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testExpenseCategory(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $category = $this->user()->categories()->find($withdrawal['category_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseCategoryAll(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $category = $this->user()->categories()->find($withdrawal['category_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
- $accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.expense-category-all', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testFrontpage(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
-
- // change the preference:
- $emptyPref = new Preference;
- $emptyPref->data = [];
- Preferences::shouldReceive('get')->atLeast()->once()->withArgs(['frontPageAccounts', []])->andReturn($emptyPref);
- Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', []]);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
- Steam::shouldReceive('balanceInRange')->andReturn([]);
- $generator->shouldReceive('multiSet')->andReturn([]);
-
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.frontpage'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testIncomeCategory(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $category = $this->user()->categories()->find($withdrawal['category_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testIncomeCategoryAll(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $category = $this->user()->categories()->find($withdrawal['category_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([]);
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
- $accountRepos->shouldReceive('oldestJournalDate')->andReturn(Carbon::createFromFormat('U', time())->startOfMonth());
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.income-category-all', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testPeriod(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
- Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
- $generator->shouldReceive('singleSet')->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.period', [1, '2012-01-01', '2012-01-31']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- */
- public function testReport(): void
- {
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
-
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro(), null);
-
- $generator->shouldReceive('multiSet')->andReturn([]);
- Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
-
- $this->be($this->user());
- $response = $this->get(route('chart.account.report', ['1,2', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\AccountController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- * @throws Exception
- */
- public function testRevenueAccounts(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->andReturn(new Carbon);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->andReturn(new Carbon);
- // grab two expense accounts from the current user.
- $accounts = $this->user()->accounts()->where('account_type_id', 5)->take(2)->get();
-
- $firstId = $accounts->first()->id;
- $secondId = $accounts->first()->id;
- // for each a set of balances:
- $start = [$firstId => [1 => '123.45', 2 => '200.01',], $secondId => [1 => '123.45', 2 => '200.01',],];
- $end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
-
- // return them when collected:
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->andReturn($accounts);
-
- // and return start and end balances:
- Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
-
- // currency should be looking for the currency ID's:
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($this->getEuro());
- $currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));
-
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.account.revenue'));
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Feature/Controllers/Chart/BillControllerTest.php b/tests/Feature/Controllers/Chart/BillControllerTest.php
deleted file mode 100644
index 604a3b1cd9..0000000000
--- a/tests/Feature/Controllers/Chart/BillControllerTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-/**
- * BillControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class BillControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BillControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BillController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testFrontpage(string $range): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $repository = $this->mock(BillRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $amounts = [
- 1 => '100',
- 2 => '100',
- ];
-
- $currencyRepos->shouldReceive('findNull')->once()->andReturn($this->getEuro())->withArgs([1]);
- $currencyRepos->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(2))->withArgs([2]);
-
- $repository->shouldReceive('getBillsPaidInRangePerCurrency')->once()->andReturn($amounts);
- $repository->shouldReceive('getBillsUnpaidInRangePerCurrency')->once()->andReturn($amounts);
- $generator->shouldReceive('multiCurrencyPieChart')->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.bill.frontpage'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BillController
- */
- public function testSingle(): void
- {
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $collector->shouldReceive('setBill')->andReturnSelf()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->once();
- $generator->shouldReceive('multiSet')->once()->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('chart.bill.single', [1]));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/BudgetControllerTest.php b/tests/Feature/Controllers/Chart/BudgetControllerTest.php
deleted file mode 100644
index c809c9f54e..0000000000
--- a/tests/Feature/Controllers/Chart/BudgetControllerTest.php
+++ /dev/null
@@ -1,444 +0,0 @@
-<?php
-/**
- * BudgetControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- * Class BudgetControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testBudget(string $range): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- try {
- $date = new Carbon('2015-01-01');
- } catch (Exception $e) {
- $e->getMessage();
- }
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('firstUseDate')->andReturn($date)->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->andReturn([])->atLeast()->once();
-
-
- // multiSet
- $generator->shouldReceive('multiSet')->andReturn([])->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.budget', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testBudgetLimit(string $range): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
- $generator->shouldReceive('singleSet')->andReturn([])->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.budget-limit', [1, 1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- */
- public function testBudgetLimitWrongLimit(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(GeneratorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $budget = $this->getRandomBudget();
- $limit = BudgetLimit::where('budget_id', '!=', $budget->id)->first();
-
- // mock default session
- $this->mockDefaultSession();
-
- Log::warning('The following error is part of a test.');
- $this->be($this->user());
- $response = $this->get(route('chart.budget.budget-limit', [$budget->id, $limit->id]));
- $response->assertStatus(500);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseAsset(string $range): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->atLeast()->once();
- $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setCurrency')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->atLeast()->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.expense-asset', [1, 1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseCategory(string $range): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $category = $this->user()->categories()->find($withdrawal['category_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
- $collector->shouldReceive('setCurrency')->andReturnSelf()->atLeast()->once();
-
- $catRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.expense-category', [1, 1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testExpenseExpense(string $range): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setCurrency')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->atLeast()->once();
-
- $generator->shouldReceive('multiCurrencyPieChart')->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.expense-expense', [1, 1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testFrontPage(string $range): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $budget = $this->getRandomBudget();
- $budgetLimit = $this->getRandomBudgetLimit();
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->atLeast()->once()->andReturn(new Collection([$budgetLimit]));
- //$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
-
- //$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
- //$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- //$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
- //$collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
-
- $generator->shouldReceive('multiSet')->andReturn([])->atLeast()->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.frontpage'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testFrontpageMultiLimit(string $range): void
- {
-
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $budget = $this->getRandomBudget();
- $limit1 = $this->getRandomBudgetLimit();
- $limit2 = $this->getRandomBudgetLimit();
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
- $blRepos->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$limit1, $limit2]));
- //$opsRepos->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
-
-// $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
-// $collector->shouldReceive('setRange')->andReturnSelf()->once();
-// $collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
-// $collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
-
- $generator->shouldReceive('multiSet')->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.frontpage'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testFrontpageNoLimits(string $range): void
- {
-
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $budget = $this->getRandomBudget();
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->atLeast()->once();
- $blRepos->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
- $generator->shouldReceive('multiSet')->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.budget.frontpage'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- */
- public function testPeriod(): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $budgetLimit = $this->getRandomBudgetLimit();
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $date = new Carbon;
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $blRepos->shouldReceive('find')->atLeast()->once()->andReturn($budgetLimit);
- $generator->shouldReceive('multiSet')->once()->andReturn([]);
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
-
- $this->be($this->user());
- $response = $this->get(route('chart.budget.period', [$budgetLimit->budget_id, 1, 1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
- */
- public function testPeriodNoBudget(): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
-
- $date = new Carbon;
-
- // mock default session
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('singleSet')->once()->andReturn([]);
-
- $nbRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->budgetSumExpenses());
-
- $this->be($this->user());
- $response = $this->get(route('chart.budget.period.no-budget', ['1','1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php b/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
deleted file mode 100644
index 5e0ed6299d..0000000000
--- a/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-/**
- * BudgetReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-
-/**
- * Class BudgetReportControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetReportControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
- */
- public function testBudgetExpense(): void
- {
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
-
- // mock default session
- $this->mockDefaultSession();
- //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.budget.budget-expense', ['1', '1', '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * TODO something in this method makes it return a 404.
- *
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetReportController
- */
- public function testMainChart(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $asset = $this->getRandomAsset();
- $budget = $this->getRandomBudget();
- $limit1 = $this->getRandomBudgetLimit();
- $limit2 = $this->getRandomBudgetLimit();
-
- // need to update at least one budget limit so it fits the limits that have been set below.
- $limit3 = new BudgetLimit;
- $limit3->budget_id = $budget->id;
- $limit3->start_date = new Carbon('2012-01-01');
- $limit3->end_date = new Carbon('2012-01-31');
- $limit3->amount = '100';
- $limit3->save();
-
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $this->mockDefaultSession();
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
-
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.budget.main', [$asset->id, $budget->id, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/CategoryControllerTest.php b/tests/Feature/Controllers/Chart/CategoryControllerTest.php
deleted file mode 100644
index e0e50c9c37..0000000000
--- a/tests/Feature/Controllers/Chart/CategoryControllerTest.php
+++ /dev/null
@@ -1,243 +0,0 @@
-<?php
-/**
- * CategoryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use FireflyIII\Support\Chart\Category\WholePeriodChartGenerator;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- * Class CategoryControllerTest
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- * @throws FireflyException
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function testAll(string $range): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $chartGen = $this->mock(WholePeriodChartGenerator::class);
- $firstUseDate = null;
-
- switch ($range) {
- default:
- throw new FireflyException(sprintf('No case for %s', $range));
- case '1D':
- $firstUseDate = Carbon::now()->subDays(3);
- break;
- case '1W':
- $firstUseDate = Carbon::now()->subDays(12);
- break;
- case '1M':
- $firstUseDate = Carbon::now()->subDays(40);
- break;
- case '3M':
- $firstUseDate = Carbon::now()->subDays(120);
- break;
- case '6M':
- $firstUseDate = Carbon::now()->subDays(160);
- break;
- case '1Y':
- $firstUseDate = Carbon::now()->subDays(365);
- break;
- case 'custom':
- $firstUseDate = Carbon::now()->subDays(20);
- break;
- }
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $chartGen->shouldReceive('generate')->atLeast()->once()->andReturn([]);
-
- $repository->shouldReceive('firstUseDate')->andReturn($firstUseDate)->once();
- $generator->shouldReceive('multiSet')->once()->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.category.all', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- */
- public function testFrontPage(string $range): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $category = $this->getRandomCategory();
- $account = $this->getRandomAsset();
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->categorySumExpenses());
- $noCatRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($this->categorySumExpenses());
-
- $repository->shouldReceive('getCategories')->atLeast()->once()->andReturn(new Collection([$category]));
- $accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(
- new Collection([$account])
- );
- $generator->shouldReceive('multiSet')->andReturn([]);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.category.frontpage', [1]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryController
- */
- public function testReportPeriod(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
- $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.category.period', [1, '1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryController
- */
- public function testReportPeriodNoCategory(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $date = new Carbon;
-
- $noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
- $noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.category.period.no-category', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryController
- * @dataProvider dateRangeProvider
- *
- * @param string $range
- *
- * @throws Exception
- */
- public function testSpecificPeriod(string $range): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $chartGen = $this->mock(WholePeriodChartGenerator::class);
- $account = $this->getRandomAsset();
- $date = new Carbon;
-
- $this->mockDefaultSession();
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $chartGen->shouldReceive('generate')->atLeast()->once()->andReturn([]);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('chart.category.specific', ['1', '2012-01-01']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php b/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php
deleted file mode 100644
index ac28ea7ae5..0000000000
--- a/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-/**
- * CategoryReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-
-/**
- * Class CategoryReportControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryReportControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
- */
- public function testCategoryExpense(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
-
- $this->mockDefaultSession();
- //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
-
- $this->be($this->user());
- $response = $this->get(route('chart.category.category-expense', ['1', '1', '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
- */
- public function testCategoryIncome(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
-
- $this->mockDefaultSession();
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
-
- $this->be($this->user());
- $response = $this->get(route('chart.category.category-income', ['1', '1', '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController
- */
- public function testMainChart(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
- $withdrawal = $this->getRandomWithdrawalAsArray();
-
- $this->mockDefaultSession();
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiSet')->andReturn([])->once();
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
- $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
-
- $this->be($this->user());
- $response = $this->get(route('chart.category.main', ['1', '1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php b/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php
deleted file mode 100644
index b76cf85543..0000000000
--- a/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/**
- * PiggyBankControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Models\PiggyBankEvent;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\PiggyBankController
- */
- public function testHistory(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- /** @var PiggyBankEvent $event */
- $event = PiggyBankEvent::inRandomOrder()->first();
- $piggy = $event->piggy_bank_id;
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('getEvents')->andReturn(new Collection([$event]));
- $generator->shouldReceive('singleSet')->once()->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('chart.piggy-bank.history', [$piggy]));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/ReportControllerTest.php b/tests/Feature/Controllers/Chart/ReportControllerTest.php
deleted file mode 100644
index e821975d18..0000000000
--- a/tests/Feature/Controllers/Chart/ReportControllerTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * ReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Helpers\Report\NetWorthInterface;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Account\AccountTaskerInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class ReportControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ReportControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\ReportController
- */
- public function testNetWorth(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $netWorth = $this->mock(NetWorthInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $netWorth->shouldReceive('getNetWorthByCurrency')->andReturn(
- [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '123',
- ],
- ]
- );
- $netWorth->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls:
- $accountRepos->shouldReceive('setUser');
-
- $accountRepos->shouldReceive('getMetaValue')->times(2)
- ->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1', '0');
- $accountRepos->shouldReceive('getMetaValue')
- ->withArgs([Mockery::any(), 'currency_id'])->andReturn(1);
- $accountRepos->shouldReceive('getMetaValue')
- ->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
-
-
- Steam::shouldReceive('balancesByAccounts')->andReturn(['5', '10']);
- $generator->shouldReceive('multiSet')->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('chart.report.net-worth', ['1,2', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\ReportController
- */
- public function testOperations(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tasker = $this->mock(AccountTaskerInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $income = [
- 'accounts' => [
- 1 => ['sum' => '100']]];
- $expense = [
- 'accounts' => [
- 2 => ['sum' => '-100']]];
- $generator->shouldReceive('multiSet')->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('chart.report.operations', [1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Chart/TagReportControllerTest.php b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
deleted file mode 100644
index 54fab76315..0000000000
--- a/tests/Feature/Controllers/Chart/TagReportControllerTest.php
+++ /dev/null
@@ -1,217 +0,0 @@
-<?php
-/**
- * TagReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Chart;
-
-use Carbon\Carbon;
-use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Tag\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Tag\TagRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- * Class TagReportControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TagReportControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testBudgetExpense(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
-
-
- $tag = $this->user()->tags()->first();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $this->mockDefaultSession();
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.tag.budget-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testCategoryExpense(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $tag = $this->user()->tags()->first();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
-
- $this->mockDefaultSession();
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.tag.category-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * TODO something in this test sometimes gives a 404 but not sure yet what it is.
- *
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testMainChart(): void
- {
- $this->mock(AccountRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
- $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->tagListIncome());
-
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $tag = $this->user()->tags()->where('tag', 'Expensive')->first();
- $date = new Carbon;
- $false = new Preference;
- $false->data = false;
-
- $this->mockDefaultSession();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($false);
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('multiSet')->andReturn([])->once()->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.tag.main', ['1', $tag->id, '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testTagExpense(): void
- {
- $this->mockDefaultSession();
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
-
- $this->mock(AccountRepositoryInterface::class);
-
- $tag = $this->user()->tags()->first();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.tag.tag-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testTagIncome(): void
- {
- $this->mockDefaultSession();
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
-
- $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->tagListIncome());
-
- $tag = $this->user()->tags()->first();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
-
- $this->be($this->user());
- $response = $this->get(route('chart.tag.tag-income', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.php
deleted file mode 100644
index 58af428f32..0000000000
--- a/tests/Feature/Controllers/CurrencyControllerTest.php
+++ /dev/null
@@ -1,533 +0,0 @@
-<?php
-/**
- * CurrencyControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CurrencyControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class CurrencyControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testCannotCreate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_currencies_create');
-
- // mock stuff
- $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.create'));
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testCannotDelete(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $repository->shouldReceive('currencyInUse')->andReturn(true);
- $repository->shouldReceive('currencyInUseAt')->andReturn('something');
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.delete', [$euro->id]));
- $response->assertStatus(302);
- // has bread crumb
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testCannotDestroy(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $repository->shouldReceive('currencyInUse')->andReturn(true);
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
-
-
- $this->session(['currencies.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('currencies.destroy', [$euro->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_currencies_create');
-
- // mock stuff
- $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.create'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDefaultCurrency(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
- $currencyRepos->shouldReceive('enable')->once();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('currencies.default', [$euro->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
-
- $repository->shouldReceive('currencyInUse')->andReturn(false);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.delete', [$euro->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $repository->shouldReceive('currencyInUse')->andReturn(false);
- $repository->shouldReceive('destroy')->andReturn(true)->once();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(1)->andReturn(true);
-
- $this->session(['currencies.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('currencies.destroy', [$euro->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDisable(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection([$euro]));
-
- $this->be($this->user());
- $response = $this->get(route('currencies.disable', [$euro->id]));
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDisableEnableFirst(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
- $repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$euro]));
- $repository->shouldReceive('enable')->atLeast()->once()->andReturn(true);
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('currencies.disable', [$euro->id]));
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDisableInUse(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('currencyInUseAt')->atLeast()->once()->andReturn('accounts');
-
- $repository->shouldNotReceive('disable');
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('currencies.disable', [$euro->id]));
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testDisableNothingLeft(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
- $repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- Log::warning('The following error is part of a test.');
- $this->be($this->user());
- $response = $this->get(route('currencies.disable', [$euro->id]));
- $response->assertStatus(500);
- $response->assertSee('No currencies found.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.edit', [$euro->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testEnable(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $repository->shouldReceive('enable')->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('currencies.enable', [$euro->id]));
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_currencies_index');
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $currencies = TransactionCurrency::get();
-
-
- $repository->shouldReceive('getCurrencyByPreference')->andReturn($currencies->first());
- $repository->shouldReceive('getAll')->andReturn($currencies);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $pref = new Preference;
- $pref->data = 'EUR';
- Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- */
- public function testIndexNoRights(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_currencies_index');
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
- $repository->shouldReceive('getAll')->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(false);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $pref = new Preference;
- $pref->data = 'EUR';
- Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->get(route('currencies.index'));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSessionHas('info');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- * @covers \FireflyIII\Http\Requests\CurrencyFormRequest
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('store')->andReturn(new TransactionCurrency);
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
-
- $this->session(['currencies.create.uri' => 'http://localhost']);
- $data = [
- 'name' => 'XX',
- 'code' => 'XXX',
- 'symbol' => 'x',
- 'decimal_places' => 2,
- ];
- $this->be($this->user());
- $response = $this->post(route('currencies.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- * @covers \FireflyIII\Http\Requests\CurrencyFormRequest
- */
- public function testStoreError(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('store')->andThrow(new FireflyException('Could not store'));
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
-
- $this->session(['currencies.create.uri' => 'http://localhost']);
- $data = [
- 'name' => 'XX',
- 'code' => 'XXX',
- 'symbol' => 'x',
- 'decimal_places' => 2,
- ];
- $this->be($this->user());
- $response = $this->post(route('currencies.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error', 'Could not store the new currency.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- * @covers \FireflyIII\Http\Requests\CurrencyFormRequest
- */
- public function testStoreNoRights(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('store')->andReturn(new TransactionCurrency);
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
-
- $this->session(['currencies.create.uri' => 'http://localhost']);
- $data = [
- 'name' => 'XX',
- 'code' => 'XXX',
- 'symbol' => 'x',
- 'decimal_places' => 2,
- ];
- $this->be($this->user());
- $response = $this->post(route('currencies.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\CurrencyController
- * @covers \FireflyIII\Http\Requests\CurrencyFormRequest
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('update')->andReturn(new TransactionCurrency);
- $userRepos->shouldReceive('hasRole')->once()->andReturn(true);
- $repository->shouldReceive('currencyInUse')->atLeast()->once()->andReturn(true);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['currencies.edit.uri' => 'http://localhost']);
- $data = [
- 'id' => 2,
- 'name' => 'XA',
- 'code' => 'XAX',
- 'symbol' => 'a',
- 'decimal_places' => 2,
- ];
- $this->be($this->user());
- $response = $this->post(route('currencies.update', [2]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/DebugControllerTest.php b/tests/Feature/Controllers/DebugControllerTest.php
deleted file mode 100644
index a4d44af664..0000000000
--- a/tests/Feature/Controllers/DebugControllerTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * DebugControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class HomeControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class DebugControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\DebugController
- */
- public function testDisplayError(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('error'));
- $response->assertStatus(500);
- $response->assertSee('A very simple test error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\DebugController
- */
- public function testFlush(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('flush'));
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\DebugController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('debug'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\DebugController
- */
- public function testRoutes(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('routes'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\DebugController
- */
- public function testTestFlash(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('test-flash'));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertSessionHas('info');
- $response->assertSessionHas('warning');
- $response->assertSessionHas('error');
- }
-
-}
diff --git a/tests/Feature/Controllers/HelpControllerTest.php b/tests/Feature/Controllers/HelpControllerTest.php
deleted file mode 100644
index 89b5cd58ab..0000000000
--- a/tests/Feature/Controllers/HelpControllerTest.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-/**
- * HelpControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Helpers\Help\HelpInterface;
-use FireflyIII\Models\Preference;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class HelpControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class HelpControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HelpController
- */
- public function testShow(): void
- {
- $this->mockDefaultSession();
-
- $help = $this->mock(HelpInterface::class);
- $help->shouldReceive('hasRoute')->andReturn(true)->once();
- $help->shouldReceive('inCache')->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->andReturn('Recent new content here.')->once();
- $help->shouldReceive('putInCache')->once();
-
- $this->be($this->user());
- $response = $this->get(route('help.show', ['index']));
- $response->assertStatus(200);
- $response->assertSee('Recent new content here.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HelpController
- */
- public function testShowBackupFromCache(): void
- {
- $this->mockDefaultSession();
-
- $help = $this->mock(HelpInterface::class);
- $help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
- $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
-
- // is US in cache?
- $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once();
- $help->shouldReceive('getFromCache')->withArgs(['index', 'en_US'])->andReturn('US from cache.')->once();
-
- $this->be($this->user());
- $response = $this->get(route('help.show', ['index']));
- $response->assertStatus(200);
- $response->assertSee('US from cache.');
-
- // put English back:
- Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
- Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HelpController
- */
- public function testShowBackupFromGithub(): void
- {
- $this->mockDefaultSession();
-
- $help = $this->mock(HelpInterface::class);
- $help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
- $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
-
- // is US in cache?
- $help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
- $help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
-
- $help->shouldReceive('putInCache')->once();
-
- $this->be($this->user());
- $response = $this->get(route('help.show', ['index']));
- $response->assertStatus(200);
- $response->assertSee('This help text is not yet available in your language');
-
- // put English back:
- Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
- Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HelpController
- */
- public function testShowCached(): void
- {
- $this->mockDefaultSession();
-
- $help = $this->mock(HelpInterface::class);
- $help->shouldReceive('hasRoute')->andReturn(true)->once();
- $help->shouldReceive('inCache')->andReturn(true)->once();
- $help->shouldReceive('getFromCache')->andReturn('Cached help content here.')->once();
-
- $this->be($this->user());
- $response = $this->get(route('help.show', ['index']));
- $response->assertStatus(200);
- $response->assertSee('Cached help content here.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HelpController
- */
- public function testShowNoRoute(): void
- {
- $this->mockDefaultSession();
-
- $help = $this->mock(HelpInterface::class);
- $help->shouldReceive('hasRoute')->andReturn(false)->once();
-
- $this->be($this->user());
- $response = $this->get(route('help.show', ['index']));
- $response->assertStatus(200);
- $response->assertSee('There is no help for this route.');
- }
-}
diff --git a/tests/Feature/Controllers/HomeControllerTest.php b/tests/Feature/Controllers/HomeControllerTest.php
deleted file mode 100644
index 66d8c8acf2..0000000000
--- a/tests/Feature/Controllers/HomeControllerTest.php
+++ /dev/null
@@ -1,174 +0,0 @@
-<?php
-/**
- * HomeControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use Event;
-use FireflyIII\Events\RequestedVersionCheckStatus;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class HomeControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class HomeControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\HomeController
- */
- public function testDateRange(): void
- {
- $this->mockDefaultSession();
- $this->be($this->user());
-
- $args = [
- 'start' => '2012-01-01',
- 'end' => '2012-04-01',
- ];
-
- $response = $this->post(route('daterange'), $args);
- $response->assertStatus(200);
- $response->assertSessionHas('warning', '91 days of data may take a while to load.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HomeController
- */
- public function testDateRangeCustom(): void
- {
- $this->mockDefaultSession();
- $this->be($this->user());
-
- $args = [
- 'start' => '2012-01-01',
- 'end' => '2012-04-01',
- 'label' => 'Custom range',
- ];
-
- $response = $this->post(route('daterange'), $args);
- $response->assertStatus(200);
- $response->assertSessionHas('warning', '91 days of data may take a while to load.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HomeController
- * @covers \FireflyIII\Http\Controllers\Controller
- * @dataProvider dateRangeProvider
- *
- * @param $range
- */
- public function testIndex(string $range): void
- {
- Event::fake();
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_index');
- $account = $this->getRandomAsset();
-
- $pref = new Preference;
- $pref->data = [$account->id];
- Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$account->id]])->atLeast()->once()->andReturn($pref);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('5');
- // mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $euro = $this->getEuro();
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $accountRepos->shouldReceive('count')->andReturn(1)->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->atLeast()->once();
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]))->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $billRepos->shouldReceive('getBills')->andReturn(new Collection)->atLeast()->once();
-// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
-
-
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
-
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection);
-
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('index'));
- $response->assertStatus(200);
- Event::assertDispatched(RequestedVersionCheckStatus::class);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\HomeController
- * @covers \FireflyIII\Http\Controllers\Controller
- * @dataProvider dateRangeProvider
- *
- * @param $range
- */
- public function testIndexEmpty(string $range): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_index');
- // mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('count')->andReturn(0);
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('index'));
- $response->assertStatus(302);
- }
-
-
-}
diff --git a/tests/Feature/Controllers/JavascriptControllerTest.php b/tests/Feature/Controllers/JavascriptControllerTest.php
deleted file mode 100644
index ef93e0b100..0000000000
--- a/tests/Feature/Controllers/JavascriptControllerTest.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-/**
- * JavascriptControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class JavascriptControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class JavascriptControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\JavascriptController
- */
- public function testAccounts(): void
- {
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $pref = new Preference;
- $pref->data = 'EUR';
-
- Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
-
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))->withArgs([[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]])->once();
- $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn($euro);
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- $this->be($this->user());
- $response = $this->get(route('javascript.accounts'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\JavascriptController
- */
- public function testCurrencies(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $euro = $this->getEuro();
- $repository->shouldReceive('get')->andReturn(new Collection([$euro]));
-
- $this->be($this->user());
- $response = $this->get(route('javascript.currencies'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\JavascriptController
- *
- * @param string $range
- *
- * @dataProvider dateRangeProvider
- */
- public function testVariables(string $range): void
- {
- $this->mockDefaultSession();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($account);
- $currencyRepos->shouldReceive('findNull')->andReturn($euro);
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('javascript.variables'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\JavascriptController
- *
- * @param string $range
- *
- * @dataProvider dateRangeProvider
- */
- public function testVariablesCustom(string $range): void
- {
- $this->mockDefaultSession();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($account);
- $currencyRepos->shouldReceive('findNull')->andReturn($euro);
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
-
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $this->session(['is_custom_range' => true]);
- $response = $this->get(route('javascript.variables'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\JavascriptController
- *
- * @param string $range
- *
- * @dataProvider dateRangeProvider
- */
- public function testVariablesNull(string $range): void
- {
- $this->mockDefaultSession();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- //Amount::shouldReceive('getDefaultCurrency')->andReturn($euro)->times(2);
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn($account);
- $currencyRepos->shouldReceive('findNull')->andReturn(null);
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $this->be($this->user());
- $this->changeDateRange($this->user(), $range);
- $response = $this->get(route('javascript.variables'));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php
deleted file mode 100644
index ade514d567..0000000000
--- a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-/**
- * AutoCompleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AutoCompleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AutoCompleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Request a list of asset accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testAccounts(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
-
- $accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $httpQuery = http_build_query(['types' => AccountType::ASSET]);
- $response = $this->get(route('json.autocomplete.accounts') . '?' . $httpQuery);
- $response->assertStatus(200);
- $response->assertSee($account->name);
- }
-
-
- /**
- * Request a list of revenue accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testRevenueAccounts(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $account = $this->getRandomAsset();
-
- $accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('json.autocomplete.revenue-accounts'));
- $response->assertStatus(200);
- $response->assertSee($account->name);
- }
-
- /**
- * Request a list of expense accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testExpenseAccounts(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $account = $this->getRandomAsset();
-
- $accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('json.autocomplete.expense-accounts'));
- $response->assertStatus(200);
- $response->assertSee($account->name);
- }
-
-
- /**
- * Request a list of expense accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testAllJournals(): void
- {
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $journal = $this->getRandomWithdrawalAsArray();
-
- $journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
-
-
- $this->be($this->user());
- $response = $this->get(route('json.autocomplete.all-journals'));
- $response->assertStatus(200);
- $response->assertSee($journal['description']);
- }
-
- /**
- * Request a list of expense accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testAllJournalsWithId(): void
- {
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $journal = $this->getRandomWithdrawalAsArray();
-
- $journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
-
-
- $this->be($this->user());
- $response = $this->get(route('json.autocomplete.all-journals-with-id'));
- $response->assertStatus(200);
- $response->assertSee($journal['description']);
- $response->assertSee($journal['id']);
- }
-
-
- /**
- * Request a list of expense accounts
- *
- * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
- */
- public function testAllJournalsWithIdNumeric(): void
- {
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $journal = $this->getRandomWithdrawalAsArray();
- $journalObject = $this->getRandomWithdrawalGroup();
-
- $journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
- $groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject);
-
-
- $this->be($this->user());
- $response = $this->get(route('json.autocomplete.all-journals-with-id') . '?search=' . $journal['id']);
- $response->assertStatus(200);
- $response->assertSee($journal['description']);
- $response->assertSee($journal['id']);
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Json/BoxControllerTest.php b/tests/Feature/Controllers/Json/BoxControllerTest.php
deleted file mode 100644
index e521d073a9..0000000000
--- a/tests/Feature/Controllers/Json/BoxControllerTest.php
+++ /dev/null
@@ -1,398 +0,0 @@
-<?php
-/**
- * BoxControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Report\NetWorthInterface;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class BoxControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BoxControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testAvailable(): void
- {
- $this->mockDefaultSession();
- $return = [
- 0 => [
- 'spent' => '-1200', // more than budgeted.
- ],
- ];
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
-
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- $abRepository->shouldReceive('getAvailableBudget')->andReturn('1000');
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
- $opsRepository->shouldReceive('collectBudgetInformation')->andReturn($return);
-
- $this->be($this->user());
- $response = $this->get(route('json.box.available'));
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testAvailableDays(): void
- {
- $this->mockDefaultSession();
- $return = [
- 0 => [
- 'spent' => '-800', // more than budgeted.
- ],
- ];
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
-
- $abRepository->shouldReceive('getAvailableBudget')->andReturn('1000');
- $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
- $opsRepository->shouldReceive('collectBudgetInformation')->andReturn($return);
-
- $this->be($this->user());
- $response = $this->get(route('json.box.available'));
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testBalance(): void
- {
- $this->mockDefaultSession();
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- // try a collector for income:
-
- //$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- //$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('json.box.balance'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testBalanceTransactions(): void
- {
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $euro = $this->getEuro();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- // try a collector for income:
-
- //$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- //$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
-
- $currencyRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($euro);
-
- $this->be($this->user());
- $response = $this->get(route('json.box.balance'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testBills(): void
- {
- $this->mockDefaultSession();
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $billRepos->shouldReceive('getBillsPaidInRange')->andReturn('0');
- $billRepos->shouldReceive('getBillsUnpaidInRange')->andReturn('0');
-
- $this->be($this->user());
- $response = $this->get(route('json.box.bills'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorth(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
-
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
-
-
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorthFuture(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
-
- $start = new Carbon;
- $start->addMonths(6)->startOfMonth();
- $end = clone $start;
- $end->endOfMonth();
- $this->session(['start' => $start, 'end' => $end]);
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorthPast(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
-
- $start = new Carbon;
- $start->subMonths(6)->startOfMonth();
- $end = clone $start;
- $end->endOfMonth();
- $this->session(['start' => $start, 'end' => $end]);
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorthNoCurrency(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
- $currencyRepos->shouldReceive('findNull')->andReturn(null);
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
-
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorthNoInclude(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
-
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('0');
-
-
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\BoxController
- */
- public function testNetWorthVirtual(): void
- {
- $this->mockDefaultSession();
- $result = [
- [
- 'currency' => $this->getEuro(),
- 'balance' => '3',
- ],
- ];
-
- $account = $this->user()->accounts()->first();
- $account->virtual_balance = '1000';
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- $netWorthHelper = $this->mock(NetWorthInterface::class);
- $netWorthHelper->shouldReceive('setUser')->once();
- $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
- $currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
-
- $this->be($this->user());
- $response = $this->get(route('json.box.net-worth'));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Json/ExchangeControllerTest.php b/tests/Feature/Controllers/Json/ExchangeControllerTest.php
deleted file mode 100644
index a73c171ec7..0000000000
--- a/tests/Feature/Controllers/Json/ExchangeControllerTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/**
- * ExchangeControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Services\Currency\ExchangeRateInterface;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ExchangeControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ExchangeControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\ExchangeController
- */
- public function testGetRate(): void
- {
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
-
- $this->mockDefaultSession();
-
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $rate = $this->getRandomCer();
- $repository->shouldReceive('getExchangeRate')->andReturn($rate);
-
- $this->be($this->user());
- $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\ExchangeController
- */
- public function testGetRateAmount(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $rate = $this->getRandomCer();
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $repository->shouldReceive('getExchangeRate')->andReturn($rate);
-
- $this->be($this->user());
- $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']) . '?amount=10');
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\ExchangeController
- */
- public function testGetRateNull(): void
- {
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $rate = $this->getRandomCer();
- $repository->shouldReceive('getExchangeRate')->andReturnNull();
- $interface = $this->mock(ExchangeRateInterface::class);
- $interface->shouldReceive('setUser')->once();
- $interface->shouldReceive('getRate')->andReturn($rate);
-
- $this->be($this->user());
- $response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Json/FrontpageControllerTest.php b/tests/Feature/Controllers/Json/FrontpageControllerTest.php
deleted file mode 100644
index 7d40de889e..0000000000
--- a/tests/Feature/Controllers/Json/FrontpageControllerTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
- * FrontpageControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-use Amount;
-
-/**
- * Class FrontpageControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class FrontpageControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\FrontpageController
- */
- public function testPiggyBanks(): void
- {
- $this->mockDefaultSession();
-
- $piggy = $this->user()->piggyBanks()->first();
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy]));
- $repository->shouldReceive('getCurrentAmount')->andReturn('10');
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $this->be($this->user());
- $response = $this->get(route('json.fp.piggy-banks'));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Json/IntroControllerTest.php b/tests/Feature/Controllers/Json/IntroControllerTest.php
deleted file mode 100644
index 7162b43c71..0000000000
--- a/tests/Feature/Controllers/Json/IntroControllerTest.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-/**
- * IntroControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class IntroControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class IntroControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\IntroController
- */
- public function testGetIntroSteps(): void
- {
- $this->mockDefaultSession();
- $this->be($this->user());
- $response = $this->get(route('json.intro', ['index']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\IntroController
- */
- public function testGetIntroStepsAsset(): void
- {
- $this->mockDefaultSession();
- $this->be($this->user());
- $response = $this->get(route('json.intro', ['accounts_create', 'asset']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\IntroController
- */
- public function testGetIntroStepsOutro(): void
- {
- $this->mockDefaultSession();
- $this->be($this->user());
- $response = $this->get(route('json.intro', ['reports_report', 'category']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\IntroController
- */
- public function testPostEnable(): void
- {
- $this->mockDefaultSession();
-
- Preferences::shouldReceive('set')->withArgs(['shown_demo_accounts_create_asset', false])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('json.intro.enable', ['accounts_create', 'asset']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\IntroController
- */
- public function testPostFinished(): void
- {
- $this->mockDefaultSession();
-
- Preferences::shouldReceive('set')->withArgs(['shown_demo_accounts_create_asset', true])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('json.intro.finished', ['accounts_create', 'asset']));
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Feature/Controllers/Json/ReconcileControllerTest.php b/tests/Feature/Controllers/Json/ReconcileControllerTest.php
deleted file mode 100644
index 23ab91d7d8..0000000000
--- a/tests/Feature/Controllers/Json/ReconcileControllerTest.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-/**
- * ReconcileControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-use Steam;
-
-/**
- *
- * Class ReconcileControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ReconcileControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test overview of reconciliation.
- *
- * @covers \FireflyIII\Http\Controllers\Json\ReconcileController
- */
- public function testOverview(): void
- {
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $euro = $this->getEuro();
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $date = new Carbon;
- $account = $this->user()->accounts()->where('id', $withdrawal['source_account_id'])->first();
-
- // make sure it falls into the current range
- $withdrawal['date'] = new Carbon('2017-01-30');
-
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- $collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawal]);
-
- Amount::shouldReceive('formatAnything')->andReturn('-100');
- Amount::shouldReceive('getDefaultCurrency')->andReturn($euro);
-
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $parameters = [
- 'startBalance' => '0',
- 'endBalance' => '10',
- 'journals' => [1, 2, 3],
- 'cleared' => [4, 5, 6],
- ];
- $this->be($this->user());
- $response = $this->get(route('accounts.reconcile.overview', [$account->id, '20170101', '20170131']) . '?' . http_build_query($parameters));
- $response->assertStatus(200);
- $response->assertSee('-100');
- }
-
- /**
- * List transactions for reconciliation view.
- *
- * @covers \FireflyIII\Http\Controllers\Json\ReconcileController
- */
- public function testTransactions(): void
- {
- $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $date = new Carbon;
- $euro = $this->getEuro();
- $withdrawal = $this->getRandomWithdrawalAsArray();
-
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('20');
-
-
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->andReturn('-100');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- //$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
-
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawal]);
-
-
- $this->be($this->user());
- $response = $this->get(route('accounts.reconcile.transactions', [1, '20170101', '20170131']));
- $response->assertStatus(200);
- $response->assertSee('-100');
- }
-}
diff --git a/tests/Feature/Controllers/Json/RecurrenceControllerTest.php b/tests/Feature/Controllers/Json/RecurrenceControllerTest.php
deleted file mode 100644
index dbdf912933..0000000000
--- a/tests/Feature/Controllers/Json/RecurrenceControllerTest.php
+++ /dev/null
@@ -1,375 +0,0 @@
-<?php
-/**
- * RecurrenceControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-
-use Carbon\Carbon;
-use FireflyIII\Models\RecurrenceRepetition;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class RecurrenceControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RecurrenceControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Ndom test
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsNdom(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
- // collection of dates:
- $dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
- $repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
- ->andReturn($dates);
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-01-01',
- 'ends' => 'forever',
- 'type' => 'ndom,1,1', // weekly on Monday
- 'reps' => 0,
- 'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
- 'skip' => 0,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- // expected data:
- $expected = [
- [
- 'id' => 'ndom20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-01',
- 'end' => '2018-01-01',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- [
- 'id' => 'ndom20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-07',
- 'end' => '2018-01-07',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- ];
-
- $response->assertExactJson($expected);
- }
-
- /**
- * yearly, until date
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsNumberOfEvents(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- // collection of dates:
- $dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
- $repository->shouldReceive('getXOccurrences')->withAnyArgs()->once()
- ->andReturn($dates);
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-01-01',
- 'ends' => 'times',
- 'type' => 'yearly,1,1', // weekly on Monday
- 'reps' => 0,
- 'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
- 'skip' => 0,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- // expected data:
- $expected = [
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-01',
- 'end' => '2018-01-01',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-07',
- 'end' => '2018-01-07',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- ];
-
- $response->assertExactJson($expected);
- }
-
- /**
- * First date is after range, so nothing happens.
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsStartAfterEnd(): void
- {
- $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-02-01',
- 'ends' => '',
- 'type' => 'daily,',
- 'reps' => 1,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
- $response->assertExactJson([]);
- }
-
- /**
- * yearly, until date
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsUntilDate(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- // collection of dates:
- $dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
- $repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
- ->andReturn($dates);
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-01-01',
- 'ends' => 'until_date',
- 'type' => 'yearly,1,1', // weekly on Monday
- 'reps' => 0,
- 'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
- 'skip' => 0,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- // expected data:
- $expected = [
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-01',
- 'end' => '2018-01-01',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-07',
- 'end' => '2018-01-07',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- ];
-
- $response->assertExactJson($expected);
- }
-
- /**
- * Every week on Monday.
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsWeeklyMonday(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- // collection of dates:
- $dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
- $repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
- ->andReturn($dates);
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-01-01',
- 'ends' => 'forever',
- 'type' => 'weekly,1', // weekly on Monday
- 'reps' => 0,
- 'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
- 'skip' => 0,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- // expected data:
- $expected = [
- [
- 'id' => 'weekly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-01',
- 'end' => '2018-01-01',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- [
- 'id' => 'weekly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-07',
- 'end' => '2018-01-07',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- ];
-
- $response->assertExactJson($expected);
- }
-
- /**
- * yearly
- *
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testEventsYearly(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- // collection of dates:
- $dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
- $repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
- ->andReturn($dates);
-
- $parameters = [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'first_date' => '2018-01-01',
- 'ends' => 'forever',
- 'type' => 'yearly,1,1', // weekly on Monday
- 'reps' => 0,
- 'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
- 'skip' => 0,
- ];
- $this->be($this->user());
- $response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- // expected data:
- $expected = [
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-01',
- 'end' => '2018-01-01',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- [
- 'id' => 'yearly20180101',
- 'title' => 'X',
- 'allDay' => true,
- 'start' => '2018-01-07',
- 'end' => '2018-01-07',
- 'editable' => false,
- 'rendering' => 'background',
- ],
- ];
-
- $response->assertExactJson($expected);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
- */
- public function testSuggest(): void
- {
- $this->mock(RecurringRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $this->be($this->user());
-
- $parameters = [
- 'past' => 'true',
- 'pre_select' => 'daily',
- 'date' => '2018-01-01',
- ];
-
- $response = $this->get(route('recurring.suggest') . '?' . http_build_query($parameters));
- $response->assertStatus(200);
-
- $expected = [
- 'daily' => ['label' => 'Every day', 'selected' => true],
- 'monthly,1' => ['label' => 'Every month on the 1(st/nd/rd/th) day', 'selected' => false],
- 'ndom,1,1' => ['label' => 'Every month on the 1(st/nd/rd/th) Monday', 'selected' => false],
- 'weekly,1' => ['label' => 'Every week on Monday', 'selected' => false],
- 'yearly,2018-01-01' => ['label' => 'Every year on January 1', 'selected' => false],
- ];
-
- $response->assertExactJson($expected);
- }
-}
diff --git a/tests/Feature/Controllers/Json/RuleControllerTest.php b/tests/Feature/Controllers/Json/RuleControllerTest.php
deleted file mode 100644
index baba251b24..0000000000
--- a/tests/Feature/Controllers/Json/RuleControllerTest.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/**
- * RuleControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Json;
-
-use Log;
-use Tests\TestCase;
-
-/**
- * Class RuleControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class RuleControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\RuleController
- */
- public function testAction(): void
- {
- $this->mockDefaultSession();
- // mock stuff
-
- $this->be($this->user());
- $response = $this->get(route('json.action'));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Json\RuleController
- */
- public function testTrigger(): void
- {
- $this->mockDefaultSession();
- // mock stuff
-
- $this->be($this->user());
- $response = $this->get(route('json.trigger'));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/NewUserControllerTest.php b/tests/Feature/Controllers/NewUserControllerTest.php
deleted file mode 100644
index d4986e438c..0000000000
--- a/tests/Feature/Controllers/NewUserControllerTest.php
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-/**
- * NewUserControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class NewUserControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class NewUserControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\NewUserController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos->shouldReceive('count')->andReturn(0);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $this->be($this->emptyUser());
- $response = $this->get(route('new-user.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\NewUserController
- */
- public function testIndexExisting(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('count')->andReturn(1);
-
- $this->be($this->user());
- $response = $this->get(route('new-user.index'));
- $response->assertStatus(302);
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\NewUserController
- */
- public function testSubmit(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $euro = $this->getEuro();
- $accountRepos->shouldReceive('store')->times(3);
- $currencyRepos->shouldReceive('findNull')->andReturn($euro);
- $currencyRepos->shouldReceive('enable')->once();
-
- Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'bank_name' => 'New bank',
- 'savings_balance' => '1000',
- 'bank_balance' => '100',
- 'language' => 'en_US',
- 'amount_currency_id_bank_balance' => 1,
- ];
- $this->be($this->emptyUser());
- $response = $this->post(route('new-user.submit'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\NewUserController
- */
- public function testSubmitNull(): void
- {
- $euro = $this->getEuro();
- $this->mockDefaultSession();
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('store')->times(3);
- $currencyRepos->shouldReceive('findNull')->andReturn(null);
- $currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn($euro)->once();
- $currencyRepos->shouldReceive('enable')->once();
-
- Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'bank_name' => 'New bank',
- 'savings_balance' => '1000',
- 'bank_balance' => '100',
- 'language' => 'en_US',
- 'amount_currency_id_bank_balance' => 1,
- ];
- $this->be($this->emptyUser());
- $response = $this->post(route('new-user.submit'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\NewUserController
- */
- public function testSubmitSingle(): void
- {
- $this->mockDefaultSession();
- $euro = $this->getEuro();
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('store')->times(3);
- $currencyRepos->shouldReceive('findNull')->andReturn($euro);
- $currencyRepos->shouldReceive('enable')->once();
-
- Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $data = [
- 'bank_name' => 'New bank',
- 'bank_balance' => '100',
- 'amount_currency_id_bank_balance' => 1,
- ];
- $this->be($this->emptyUser());
- $response = $this->post(route('new-user.submit'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php
deleted file mode 100644
index 2a2f1cbcd7..0000000000
--- a/tests/Feature/Controllers/PiggyBankControllerTest.php
+++ /dev/null
@@ -1,563 +0,0 @@
-<?php
-/**
- * PiggyBankControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\PiggyBank;
-use FireflyIII\Models\PiggyBankRepetition;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\AccountTransformer;
-use FireflyIII\Transformers\PiggyBankTransformer;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class PiggyBankControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testAdd(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
-
-
- $piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
- $piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.add', [$piggyBank->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testAddMobile(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
-
-
- $piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
- $piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.add-money-mobile', [$piggyBank->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_piggy-banks_create');
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(PiggyBankRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- // new account list thing.
- $currency = $this->getEuro();
- $currencyRepos->shouldReceive('findNull')->andReturn($currency);
-
- Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
- Amount::shouldReceive('balance')->andReturn('0');
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.create'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(PiggyBankRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.delete', [$piggyBank->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
-
- $repository->shouldReceive('destroy')->andReturn(true);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['piggy-banks.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.destroy', [$piggyBank->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(PiggyBankRepositoryInterface::class);
-
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('123');
-
- // mock stuff
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- // mock stuff for new account list thing.
- $currency = $this->getEuro();
- $account = $this->getRandomAsset();
-
- $currencyRepos->shouldReceive('findNull')->andReturn($currency);
-
-
- $accountRepos->shouldReceive('getAccountsByType')
- ->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(new Collection([$account]))->once();
-
- Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
- Amount::shouldReceive('balance')->andReturn('0');
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.edit', [$piggyBank->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_piggy-banks_index');
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(PiggyBankTransformer::class);
- $accountTransformer = $this->mock(AccountTransformer::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- ['id' => 5, 'current_amount' => '10', 'target_amount' => '10', 'currency_symbol' => 'x']
- );
-
- // mock transformer again
- $accountTransformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $accountTransformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- ['id' => 5, 'current_balance' => '10', 'name' => 'Account', 'current_amount' => '5', 'currency_symbol' => 'x']
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $first = $this->user()->transactionJournals()->inRandomOrder()->first();
- $piggies = $this->user()->piggyBanks()->take(2)->get();
- $journalRepos->shouldReceive('firstNull')->once()->andReturn($first);
- $repository->shouldReceive('getPiggyBanks')->andReturn($piggies);
- $repository->shouldReceive('getCurrentAmount')->andReturn('10');
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('correctOrder');
- $repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('1');
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testPostAdd(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('canAddAmount')->once()->andReturn(true);
- $repository->shouldReceive('addAmount')->once()->andReturn(true);
-
- $data = ['amount' => '1.123'];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.add', [$piggyBank]), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('piggy-banks.index'));
- $response->assertSessionHas('success');
- }
-
- /**
- * Add way too much
- *
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testPostAddTooMuch(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
-
- $repository->shouldReceive('canAddAmount')->once()->andReturn(false);
-
- $data = ['amount' => '1000'];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.add', [$piggyBank->id]), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('piggy-banks.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testPostRemove(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('canRemoveAmount')->once()->andReturn(true);
- $repository->shouldReceive('removeAmount')->once()->andReturn(true);
-
- $data = ['amount' => '1.123'];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.remove', [$piggyBank->id]), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('piggy-banks.index'));
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testPostRemoveTooMuch(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $repository->shouldReceive('canRemoveAmount')->once()->andReturn(false);
-
- $data = ['amount' => '1.123'];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.remove', [$piggyBank->id]), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('piggy-banks.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testRemove(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $repetition = PiggyBankRepetition::first();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- $piggyRepos->shouldReceive('getRepetition')->once()->andReturn($repetition);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.remove', [$piggyBank->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testRemoveMobile(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $repetition = PiggyBankRepetition::first();
- $piggyBank = $this->getRandomPiggyBank();
-
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $piggyRepos->shouldReceive('getRepetition')->once()->andReturn($repetition);
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.remove-money-mobile', [$piggyBank->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * Test setting of order/
- *
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testSetOrder(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $repository->shouldReceive('setOrder')->once()->withArgs([Mockery::any(), 3])->andReturn(false);
-
- $data = ['order' => '3'];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.set-order', [$piggyBank->id]), $data);
- $response->assertStatus(200);
- $response->assertExactJson(['data' => 'OK']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- */
- public function testShow(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_piggy-banks_show');
- // mock stuff
- $first = $this->user()->transactionJournals()->inRandomOrder()->first();
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(PiggyBankTransformer::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- // mock transformer
- $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- ['id' => 5, 'current_amount' => '5', 'currency_symbol' => 'x', 'target_amount' => '5', 'left_to_save' => '5', 'save_per_month' => '5']
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $journalRepos->shouldReceive('firstNull')->andReturn($first)->atLeast()->once();
- $repository->shouldReceive('getEvents')->andReturn(new Collection)->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
-
- $this->be($this->user());
- $response = $this->get(route('piggy-banks.show', [$piggyBank->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- * @covers \FireflyIII\Http\Requests\PiggyBankFormRequest
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $repository->shouldReceive('store')->andReturn(new PiggyBank);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['piggy-banks.create.uri' => 'http://localhost']);
- $data = [
- 'name' => 'Piggy ' . $this->randomInt(),
- 'targetamount' => '100.123',
- 'account_id' => 2,
- 'amount_currency_id_targetamount' => 1,
- ];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PiggyBankController
- * @covers \FireflyIII\Http\Requests\PiggyBankFormRequest
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(PiggyBankRepositoryInterface::class);
- $piggyBank = $this->getRandomPiggyBank();
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $repository->shouldReceive('update')->andReturn(new PiggyBank);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['piggy-banks.edit.uri' => 'http://localhost']);
- $data = [
- 'id' => 3,
- 'name' => 'Updated Piggy ' . $this->randomInt(),
- 'targetamount' => '100.123',
- 'account_id' => 2,
- 'amount_currency_id_targetamount' => 1,
- ];
- $this->be($this->user());
- $response = $this->post(route('piggy-banks.update', [$piggyBank->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-}
diff --git a/tests/Feature/Controllers/Popup/ReportControllerTest.php b/tests/Feature/Controllers/Popup/ReportControllerTest.php
deleted file mode 100644
index 890a86ce23..0000000000
--- a/tests/Feature/Controllers/Popup/ReportControllerTest.php
+++ /dev/null
@@ -1,418 +0,0 @@
-<?php
-/**
- * ReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Popup;
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Report\PopupReportInterface;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ReportControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ReportControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testBadEndDate(): void
- {
- $this->mock(PopupReportInterface::class);
-
- $this->mockDefaultSession();
-
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'bla-bla',
- 'startDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'endDate' => 'bla-bla',
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertSee('Firefly III cannot handle');
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testBadStartDate(): void
- {
- $this->mock(PopupReportInterface::class);
-
- $this->be($this->user());
- $this->mockDefaultSession();
-
- $arguments = [
- 'attributes' => [
- 'location' => 'bla-bla',
- 'startDate' => 'bla-bla',
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertSee('Firefly III cannot handle');
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testBudgetSpentAmount(): void
- {
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $budget = $this->getRandomBudget();
-
- $this->mockDefaultSession();
- $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
- $popupHelper->shouldReceive('byBudget')->andReturn([]);
-
- //Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'budget-spent-amount',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'currencyId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testBudgetSpentAmountNoBudget(): void
- {
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
-
- //Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
-
- $this->mockDefaultSession();
- $budgetRepos->shouldReceive('findNull')->andReturnNull()->once()->withArgs([1]);
- $popupHelper->shouldReceive('byBudget')->andReturn([]);
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'budget-spent-amount',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testCategoryEntry(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $category = $this->getRandomCategory();
-
- $this->mockDefaultSession();
- $categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]);
- $popupHelper->shouldReceive('byCategory')->andReturn([]);
-
- //Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'category-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testCategoryEntryUnknown(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
-
- $this->mockDefaultSession();
- $categoryRepos->shouldReceive('findNull')->andReturn(null)->once()->withArgs([1]);
- $popupHelper->shouldReceive('byCategory')->andReturn([]);
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'category-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- $response->assertSee('This is an unknown category. Apologies.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testExpenseEntry(): void
- {
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $account = $this->getRandomAsset();
-
- //Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
-
- $this->mockDefaultSession();
- $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
- $popupHelper->shouldReceive('byExpenses')->andReturn([]);
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'expense-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testExpenseEntryUnknown(): void
- {
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
- $popupHelper->shouldReceive('byExpenses')->andReturn([]);
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'expense-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- $response->assertSee('This is an unknown account. Apologies.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testIncomeEntry(): void
- {
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $account = $this->getRandomAsset();
-
- $this->mockDefaultSession();
- $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
- $popupHelper->shouldReceive('byIncome')->andReturn([]);
-
- //Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'income-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- */
- public function testIncomeEntryUnknown(): void
- {
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $popupHelper = $this->mock(PopupReportInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
- $popupHelper->shouldReceive('byIncome')->andReturn([]);
-
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'income-entry',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Popup\ReportController
- * @expectedExceptionMessage Firefly cannot handle
- */
- public function testWrongLocation(): void
- {
- $popupReport = $this->mock(PopupReportInterface::class);
-
- $this->mockDefaultSession();
- $this->be($this->user());
- $arguments = [
- 'attributes' => [
- 'location' => 'bla-bla',
- 'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
- 'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
- 'accounts' => 1,
- 'accountId' => 1,
- 'categoryId' => 1,
- 'budgetId' => 1,
- ],
- ];
- $uri = route('popup.general') . '?' . http_build_query($arguments);
- $response = $this->get($uri);
- $response->assertStatus(200);
- $response->assertDontSee('Firefly III could not render the view. Please see the log files.');
- }
-}
diff --git a/tests/Feature/Controllers/PreferencesControllerTest.php b/tests/Feature/Controllers/PreferencesControllerTest.php
deleted file mode 100644
index 96b503f52f..0000000000
--- a/tests/Feature/Controllers/PreferencesControllerTest.php
+++ /dev/null
@@ -1,138 +0,0 @@
-<?php
-/**
- * PreferencesControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class PreferencesControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class PreferencesControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\PreferencesController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_preferences_index');
- // mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
-
- // mock get preferences:
-
- $frontPage = new Preference;
- $frontPage->data = [];
- Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', []])->andReturn($frontPage)->atLeast()->once();
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $pref = new Preference;
- $pref->data = 0;
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', 0])->atLeast()->once()->andReturn($pref);
-
- $pref = new Preference;
- $pref->data = '01-01';
- Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once()->andReturn($pref);
-
- $pref = new Preference;
- $pref->data = [];
- Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($pref);
-
-
- $this->be($this->user());
- $response = $this->get(route('preferences.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\PreferencesController
- */
- public function testPostIndex(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->andReturn(false);
-
- $data = [
- 'fiscalYearStart' => '2016-01-01',
- 'frontPageAccounts' => [1],
- 'viewRange' => '1M',
- 'customFiscalYear' => 0,
- 'showDepositsFrontpage' => 0,
- 'listPageSize' => 100,
- 'language' => 'en_US',
- 'tj' => [],
- ];
-
- Preferences::shouldReceive('set')->withArgs(['frontPageAccounts', [1]])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['viewRange', '1M'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['customFiscalYear', false])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['listPageSize', 100])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['listPageSize', 50])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
- Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('preferences.update'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('preferences.index'));
- }
-}
diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php
deleted file mode 100644
index ae0ba0ebe2..0000000000
--- a/tests/Feature/Controllers/ProfileControllerTest.php
+++ /dev/null
@@ -1,609 +0,0 @@
-<?php
-/**
- * ProfileControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\User;
-use Google2FA;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use stdClass;
-use Tests\TestCase;
-
-/**
- * Class ProfileControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ProfileControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testChangeEmail(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('profile.change-email'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testChangePassword(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('profile.change-password'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testCode(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');
- Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');
-
- $this->be($this->user());
- $response = $this->get(route('profile.code'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testConfirmEmailChangeNoToken(): void
- {
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
-
- Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());
-
- Log::warning('The following error is part of a test.');
- $response = $this->get(route('profile.confirm-email-change', ['some-fake-token']));
- $response->assertStatus(500);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testConfirmEmailWithToken(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(UserRepositoryInterface::class);
-
- $repository->shouldReceive('unblockUser');
- $preference = new Preference;
- $preference->data = 'existing-token';
- /** @var stdClass $preference */
- $preference->user = $this->user();
- Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection([$preference]));
- // email_change_confirm_token
- $response = $this->get(route('profile.confirm-email-change', ['existing-token']));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testDeleteAccount(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('profile.delete-account'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testDeleteCode(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), null])->atLeast()->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('profile.delete-code'));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertSessionHas('info');
- $response->assertRedirect(route('profile.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testEnable2FANoSecret(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
-
- $this->be($this->user());
- $response = $this->post(route('profile.enable2FA'));
- $response->assertStatus(302);
- $response->assertRedirect(route('profile.code'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testEnable2FASecret(): void
- {
- //$this->mockDefaultSession(); // DISABLED ON PURPOSE
- $this->mockDefaultConfiguration();
- $repository = $this->mock(UserRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- $journalRepos->shouldReceive('firstNull')->andReturnNull();
-
- $euro = $this->getEuro();
-
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
-
- $view = new Preference;
- $view->data = '1M';
- Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view)->atLeast()->once();
-
- $lang = new Preference;
- $lang->data = 'en_US';
- Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($lang)->atLeast()->once();
-
- $list = new Preference;
- $list->data = 50;
- Preferences::shouldReceive('get')->withArgs(['list-length', 10])->andReturn($list)->atLeast()->once();
-
- Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
-
- $this->session(['rule-groups.delete.uri' => 'http://localhost']);
-
- $this->be($this->user());
- $response = $this->post(route('profile.enable2FA'));
- $response->assertStatus(302);
- $response->assertRedirect(route('profile.code'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
-
- $pref = new Preference;
- $pref->data = 'token';
-
-
-
- Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturn($pref);
-
- $arrayPref = new Preference;
- $arrayPref->data = [];
- Preferences::shouldReceive('get')->withArgs(['mfa_recovery', []])->atLeast()->once()->andReturn($arrayPref);
- Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->get(route('profile.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testIndexEmptyToken(): void
- {
- $this->mockDefaultSession();
- // mock stuff
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $pref = new Preference;
- $pref->data = 'token';
-
- Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturnNull();
- Preferences::shouldReceive('set')->withArgs(['access_token', Mockery::any()])->atLeast()->once()->andReturn($pref);
-
- $arrayPref = new Preference;
- $arrayPref->data = [];
- Preferences::shouldReceive('get')->withArgs(['mfa_recovery', []])->atLeast()->once()->andReturn($arrayPref);
-
- Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->get(route('profile.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangeEmail(): void
- {
- $this->mockDefaultSession();
- $data = [
- 'email' => '[email protected]',
- ];
- $repository = $this->mock(UserRepositoryInterface::class);
-
- $repository->shouldReceive('findByEmail')->once()->andReturn(null);
- $repository->shouldReceive('changeEmail')->once()->andReturn(true);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- $pref = new Preference;
- $pref->data = 'invalid';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_confirm_token', 'invalid'])->andReturn($pref);
- $pref = new Preference;
- $pref->data = 'invalid';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_undo_token', 'invalid'])->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->post(route('profile.change-email.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangeEmailExisting(): void
- {
- $this->mockDefaultSession();
- $data = [
- 'email' => '[email protected]',
- ];
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('findByEmail')->once()->andReturn(new User);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->post(route('profile.change-email.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangeEmailSame(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $data = [
- 'email' => $this->user()->email,
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.change-email.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- $response->assertRedirect(route('profile.change-email'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangePassword(): void
- {
- $this->mockDefaultSession();
- // mock stuff
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('changePassword');
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- $data = [
- 'current_password' => 'james',
- 'new_password' => 'james2',
- 'new_password_confirmation' => 'james2',
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.change-password.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangePasswordNotCorrect(): void
- {
- $this->mockDefaultSession();
- // mock stuff
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('changePassword');
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- $data = [
- 'current_password' => 'james3',
- 'new_password' => 'james2',
- 'new_password_confirmation' => 'james2',
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.change-password.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostChangePasswordSameNew(): void
- {
- $this->mockDefaultSession();
- // mock stuff
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('changePassword');
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- $data = [
- 'current_password' => 'james',
- 'new_password' => 'james',
- 'new_password_confirmation' => 'james',
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.change-password.post'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostCode(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
-
-
- $secret = '0123456789abcde';
- $key = '123456';
-
- $this->withoutMiddleware();
- $this->session(['two-factor-secret' => $secret]);
-
- $userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), $secret])->atLeast()->once();
-
- // set recovery history
- Preferences::shouldReceive('set')->withArgs(['mfa_history', Mockery::any()])->atLeast()->once();
-
- // set recovery codes.
- Preferences::shouldReceive('set')->withArgs(['mfa_recovery', null])->atLeast()->once();
-
- $pref = new Preference;
- $pref->data= [];
- Preferences::shouldReceive('get')->withArgs(['mfa_history', []])->atLeast()->once()->andReturn($pref);
-
- Preferences::shouldReceive('mark')->once();
- Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
-
- $data = [
- 'code' => $key,
- ];
-
- $this->be($this->user());
- $response = $this->post(route('profile.code.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostDeleteAccount(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- // mock stuff
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('destroy')->once();
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $data = [
- 'password' => 'james',
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.delete-account.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testPostDeleteAccountWrong(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- // mock stuff
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
- $data = [
- 'password' => 'james2',
- ];
- $this->be($this->user());
- $response = $this->post(route('profile.delete-account.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('profile.delete-account'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testRegenerate(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- Preferences::shouldReceive('set')->withArgs(['access_token', Mockery::any()])->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('profile.regenerate'));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('profile.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testUndoEmailChange(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- $hash = hash('sha256', '[email protected]');
- $tokenPreference = new Preference;
- $tokenPreference->data = 'token';
- /** @var stdClass $tokenPreference */
- $tokenPreference->user = $this->user();
-
- $hashPreference = new Preference;
- $hashPreference->data = '[email protected]';
- /** @var stdClass $hashPreference */
- $hashPreference->user = $this->user();
-
- Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
- Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
-
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('changeEmail')->once();
- $repository->shouldReceive('unblockUser')->once();
-
- $response = $this->get(route('profile.undo-email-change', ['token', $hash]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('login'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- * @expectedExceptionMessage Invalid token
- */
- public function testUndoEmailChangeBadHash(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- $hash = hash('sha256', '[email protected]');
- $tokenPreference = new Preference;
- $tokenPreference->data = 'token';
- /** @var stdClass $tokenPreference */
- $tokenPreference->user = $this->user();
-
- $hashPreference = new Preference;
- $hashPreference->data = '[email protected]';
- /** @var stdClass $hashPreference */
- $hashPreference->user = $this->user();
-
- Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
- Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
-
- Log::warning('The following error is part of a test.');
- $response = $this->get(route('profile.undo-email-change', ['token', $hash]));
- $response->assertStatus(500);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ProfileController
- */
- public function testUndoEmailChangeBadToken(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- Preferences::shouldReceive('findByName')->once()->andReturn(new Collection);
-
- $response = $this->get(route('profile.undo-email-change', ['token', 'some-hash']));
- $response->assertStatus(500);
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Recurring/CreateControllerTest.php b/tests/Feature/Controllers/Recurring/CreateControllerTest.php
deleted file mode 100644
index 8c008b7e7d..0000000000
--- a/tests/Feature/Controllers/Recurring/CreateControllerTest.php
+++ /dev/null
@@ -1,728 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Recurring;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Validation\AccountValidator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- *
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- */
- public function testCreate(): void
- {
- // mock repositories, even if not used.
- $this->mock(RecurringRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(PiggyBankRepositoryInterface::class);
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $euro = $this->getEuro();
- $asset = $this->getRandomAsset();
- $cash = $this->getRandomAsset();
- $this->mockDefaultSession();
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
-
-
- // for view:
- $accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->andReturn(new Collection([$asset]));
- Steam::shouldReceive('balance')->andReturn('100')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);
- //Amount::shouldReceive('getDefaultCurrency')->andReturn($euro)->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');
-
-
- $this->be($this->user());
- $response = $this->get(route('recurring.create'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee('source_id_holder');
- $response->assertSee('deposit_source_id');
- $response->assertSee('withdrawal_destination_id');
-
- }
-
- /**
- * Stores a withdrawal. From Asset account to Expense account
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreWithdrawalExpense(): void
- {
- // mock repositories, even if not used.
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-
- /**
- * Stores a withdrawal, but destination is invalid
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreWithdrawalInvalidDest(): void
- {
- // mock repositories, even if not used.
- $this->mock(BudgetRepositoryInterface::class);
-
- $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
-
- $this->mockDefaultSession();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);
-
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('errors');
- }
-
- /**
- * Try to store withdrawal, but the source account is invalid.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreWithdrawalInvalidSource(): void
- {
- $this->mockDefaultSession();
- // mock repositories, even if not used.
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
-
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- // source account is invalid.
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false);
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('errors');
- }
-
- /**
- * Stores a withdrawal. But throw error.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreError(): void
- {
- // mock repositories, even if not used.
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
-
- $this->mockDefaultSession();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andThrow(new FireflyException('Some exception'));
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error', 'Some exception');
- }
-
- /**
- * Store a deposit from Revenue to Asset.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreDepositRevenue(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomRevenue();
- $destination = $this->getRandomAsset();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
- $data = [
- 'title' => 'hello' . $this->randomInt(),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => 'Some descr' . $this->randomInt(),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'deposit',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'deposit_source_id' => $source->id,
- 'destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * Store a withdrawal but it's monthly, not daily.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreMonthly(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'monthly,5',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * Store a withdrawal but use ndom.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreNdom(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'ndom,3,5',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreTransfer(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomAsset($source->id);
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['transfer'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
-
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
- $data = [
- 'title' => 'hello' . $this->randomInt(),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => 'Some descr' . $this->randomInt(),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'transfer',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreUntilDate(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'until_date',
- 'repeat_until' => $tomorrow->format('Y-m-d'),
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\CreateController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testStoreYearly(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- $data = [
- 'title' => sprintf('hello %d', $this->randomInt()),
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'yearly,2018-01-01',
- 'skip' => 0,
- 'recurring_description' => sprintf('Some descr %d', $this->randomInt()),
- 'active' => '1',
- 'apply_rules' => '1',
- 'foreign_amount' => '1',
- 'foreign_currency_id' => '2',
-
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
-
- // mandatory account info:
- 'source_id' => $source->id,
- 'withdrawal_destination_id' => $destination->id,
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
- $recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
-
- $this->be($this->user());
- $response = $this->post(route('recurring.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Recurring/DeleteControllerTest.php b/tests/Feature/Controllers/Recurring/DeleteControllerTest.php
deleted file mode 100644
index 4c69925e3d..0000000000
--- a/tests/Feature/Controllers/Recurring/DeleteControllerTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Recurring;
-
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class DeleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
- */
- public function testDelete(): void
- {
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- $recurringRepos->shouldReceive('getTransactions')->andReturn(new Collection)->once();
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('recurring.delete', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
- */
- public function testDestroy(): void
- {
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $recurringRepos->shouldReceive('destroy')->once();
-
-
- $this->be($this->user());
- $response = $this->post(route('recurring.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Recurring/EditControllerTest.php b/tests/Feature/Controllers/Recurring/EditControllerTest.php
deleted file mode 100644
index fe338053cf..0000000000
--- a/tests/Feature/Controllers/Recurring/EditControllerTest.php
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Recurring;
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\RecurrenceTransformer;
-use FireflyIII\Validation\AccountValidator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- *
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\EditController
- */
- public function testEdit(): void
- {
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(PiggyBankRepositoryInterface::class);
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
- $asset = $this->getRandomAsset();
- $euro = $this->getEuro();
- $cash = $this->getRandomAsset();
- $this->mockDefaultSession();
-
- $transformed = [
- 'transactions' => [
- [
- 'source_id' => 1,
- 'destination_id' => 1,
- ],
- ],
- ];
-
- // for view:
- $accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()->andReturn(new Collection([$asset]));
- Steam::shouldReceive('balance')->andReturn('100')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);
- //Amount::shouldReceive('getDefaultCurrency')->andReturn($euro)->atLeast()->once();
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');
-
- // transform recurrence.
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn($transformed);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- // get stuff from recurrence.
- $recurringRepos->shouldReceive('setUser');
- $recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
- $recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
- $recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
- $budgetRepos->shouldReceive('findNull')->andReturn($this->user()->budgets()->first());
-
-
- $budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
- //\Amount::shouldReceive('getDefaultCurrency')->andReturn($this->getEuro());
-
-
- $this->be($this->user());
- $response = $this->get(route('recurring.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee('deposit_source_id');
- $response->assertSee('withdrawal_destination_id');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\EditController
- * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
- */
- public function testUpdate(): void
- {
- $this->mock(BudgetRepositoryInterface::class);
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $validator = $this->mock(AccountValidator::class);
- $expense = $this->getRandomExpense();
-
- $this->mockDefaultSession();
-
- $recurringRepos->shouldReceive('update')->once();
-
- // validator:
- $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
- Preferences::shouldReceive('mark')->once();
-
- $tomorrow = Carbon::now()->addDays(2);
- $recurrence = $this->user()->recurrences()->first();
- $data = [
- 'id' => $recurrence->id,
- 'title' => 'hello',
- 'first_date' => $tomorrow->format('Y-m-d'),
- 'repetition_type' => 'daily',
- 'skip' => 0,
- 'recurring_description' => 'Some descr',
- 'active' => '1',
- 'apply_rules' => '1',
- 'return_to_edit' => '1',
- // mandatory for transaction:
- 'transaction_description' => 'Some descr',
- 'transaction_type' => 'withdrawal',
- 'transaction_currency_id' => '1',
- 'amount' => '30',
- // mandatory account info:
- 'source_id' => '1',
- 'source_name' => '',
- 'withdrawal_destination_id' => $expense->id,
- 'destination_id' => '',
- 'destination_name' => 'Some Expense',
-
- // optional fields:
- 'budget_id' => '1',
- 'category' => 'CategoryA',
- 'tags' => 'A,B,C',
- 'create_another' => '1',
- 'repetition_end' => 'times',
- 'repetitions' => 3,
- ];
-
-
- $this->be($this->user());
- $response = $this->post(route('recurring.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-}
diff --git a/tests/Feature/Controllers/Recurring/IndexControllerTest.php b/tests/Feature/Controllers/Recurring/IndexControllerTest.php
deleted file mode 100644
index 7814f01e65..0000000000
--- a/tests/Feature/Controllers/Recurring/IndexControllerTest.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Recurring;
-
-use FireflyConfig;
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\RecurrenceTransformer;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class IndexControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IndexControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\IndexController
- */
- public function testIndex(): void
- {
-
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $repository->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
-
- $this->mockDefaultSession();
-
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- [
- 'id' => 5,
- 'first_date' => '2018-01-01',
- 'repeat_until' => null,
- 'latest_date' => null,
- ]
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $config = new Configuration;
- $config->data = 0;
-
- $falseConfig = new Configuration;
- $falseConfig->data = false;
-
- $collection = $this->user()->recurrences()->take(2)->get();
-
- // mock cron job config:
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
-
- $repository->shouldReceive('get')->andReturn($collection)->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('recurring.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * The last time the recurring job fired it was a long time ago.
- *
- * @covers \FireflyIII\Http\Controllers\Recurring\IndexController
- */
- public function testIndexLongAgo(): void
- {
-
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
-
- // mock calls
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $repository->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
-
- $this->mockDefaultSession();
-
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- [
- 'id' => 5,
- 'first_date' => '2018-01-01',
- 'repeat_until' => null,
- 'latest_date' => null,
- ]
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $config = new Configuration;
- $config->data = 1;
-
- $falseConfig = new Configuration;
- $falseConfig->data = false;
-
- $collection = $this->user()->recurrences()->take(2)->get();
-
- // mock cron job config:
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
-
- $repository->shouldReceive('get')->andReturn($collection)->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('recurring.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSessionHas('warning');
- }
-
-
-
-}
diff --git a/tests/Feature/Controllers/Recurring/ShowControllerTest.php b/tests/Feature/Controllers/Recurring/ShowControllerTest.php
deleted file mode 100644
index a67af938d4..0000000000
--- a/tests/Feature/Controllers/Recurring/ShowControllerTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * ShowControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Recurring;
-
-
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\RecurrenceTransformer;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-use Log;
-use Mockery;
-
-/**
- *
- * Class ShowControllerTest
- */
-class ShowControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Recurring\IndexController
- */
- public function testShow(): void
- {
- $repository = $this->mock(RecurringRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $transformer = $this->mock(RecurrenceTransformer::class);
-
- $this->mockDefaultSession();
-
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
- [
- 'id' => 5,
- 'first_date' => '2018-01-01',
- 'repeat_until' => null,
- 'latest_date' => null,
- 'repetitions' => [
- [
- 'occurrences' => [
- '2019-01-01',
- ],
- ],
- ],
- ]
- );
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $recurrence = $this->user()->recurrences()->first();
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('recurring.show', [$recurrence->id]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-}
diff --git a/tests/Feature/Controllers/Report/AccountControllerTest.php b/tests/Feature/Controllers/Report/AccountControllerTest.php
deleted file mode 100644
index f49ce87ade..0000000000
--- a/tests/Feature/Controllers/Report/AccountControllerTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-/**
- * AccountControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Report;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Account\AccountTaskerInterface;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class AccountControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class AccountControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\AccountController
- */
- public function testGeneral(): void
- {
- $this->mockDefaultSession();
- $return = [
- 'accounts' => [],
- 'start' => '0',
- 'end' => '0',
- 'difference' => '0',
- ];
-
- $tasker = $this->mock(AccountTaskerInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $tasker->shouldReceive('getAccountReport')->andReturn($return);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.account.general', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Report/BalanceControllerTest.php b/tests/Feature/Controllers/Report/BalanceControllerTest.php
deleted file mode 100644
index c569230122..0000000000
--- a/tests/Feature/Controllers/Report/BalanceControllerTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/**
- * BalanceControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Report;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class BalanceControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class BalanceControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\BalanceController
- */
- public function testGeneral(): void
- {
- $this->mockDefaultSession();
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $date = new Carbon;
- $budget = $this->getRandomBudget();
-
- $repository->shouldReceive('getBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.balance.general', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Report/BudgetControllerTest.php b/tests/Feature/Controllers/Report/BudgetControllerTest.php
deleted file mode 100644
index 85fe737bac..0000000000
--- a/tests/Feature/Controllers/Report/BudgetControllerTest.php
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
- * BudgetControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Report;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Amount;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- * Class BudgetControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class BudgetControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\BudgetController
- */
- public function testGeneral(): void
- {
- $this->mockDefaultSession();
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
- $budget = $this->getRandomBudget();
- $limit = $this->getRandomBudgetLimit();
-
- $repository->shouldReceive('getBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- $blRepos->shouldReceive('getBudgetLimits')->atLeast()->once()->andReturn(new Collection([$limit]));
-
- $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
- $nbRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
-
- $date = new Carbon;
-
- //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.budget.general', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\BudgetController
- */
- public function testPeriod(): void
- {
- $this->mockDefaultSession();
- $first = [1 => ['entries' => ['1', '1']]];
- $second = ['entries' => ['1', '1']];
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $date = new Carbon;
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- //Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $repository->shouldReceive('getBudgets')->andReturn(new Collection);
- $repository->shouldReceive('getBudgetPeriodReport')->andReturn($first);
- $repository->shouldReceive('getNoBudgetPeriodReport')->andReturn($second);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.budget.period', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Report/CategoryControllerTest.php b/tests/Feature/Controllers/Report/CategoryControllerTest.php
deleted file mode 100644
index de01eeef67..0000000000
--- a/tests/Feature/Controllers/Report/CategoryControllerTest.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-/**
- * CategoryControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Report;
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Preferences;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-/**
- * Class CategoryControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class CategoryControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\CategoryController
- */
- public function testExpenses(): void
- {
- $this->mockDefaultSession();
- $first = [1 => ['entries' => ['1', '1']]];
- $second = ['entries' => ['1', '1']];
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
- $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $repository->shouldReceive('getCategories')->andReturn(new Collection);
- $repository->shouldReceive('periodExpenses')->andReturn($first);
- $repository->shouldReceive('periodExpensesNoCategory')->andReturn($second);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.category.expenses', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\CategoryController
- */
- public function testIncome(): void
- {
- $this->mockDefaultSession();
- $first = [
- 1 => ['entries' => ['1', '1']],
- 2 => ['entries' => ['0']],
- ];
- $second = ['entries' => ['1', '1']];
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
- $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $repository->shouldReceive('getCategories')->andReturn(new Collection);
- $repository->shouldReceive('periodIncome')->andReturn($first);
- $repository->shouldReceive('periodIncomeNoCategory')->andReturn($second);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.category.income', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\CategoryController
- */
- public function testOperations(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(CategoryRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);
- $category = $this->getRandomCategory();
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
- $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
-
- $opsRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
- $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
- $repository->shouldReceive('spentInPeriod')->andReturn([]);
- $repository->shouldReceive('earnedInPeriod')->andReturn([]);
-
-
- $this->be($this->user());
- $response = $this->get(route('report-data.category.operations', ['1', '20120101', '20120131']));
- $response->assertStatus(200);
- $response->assertDontSee('An error prevented Firefly III from rendering: %s. Apologies.');
- }
-}
diff --git a/tests/Feature/Controllers/Report/OperationsControllerTest.php b/tests/Feature/Controllers/Report/OperationsControllerTest.php
deleted file mode 100644
index baaff32fa8..0000000000
--- a/tests/Feature/Controllers/Report/OperationsControllerTest.php
+++ /dev/null
@@ -1,133 +0,0 @@
-<?php
-/**
- * OperationsControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Report;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Repositories\Account\AccountTaskerInterface;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class OperationsControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class OperationsControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\OperationsController
- */
- public function testExpenses(): void
- {
- $this->mockDefaultSession();
- $return = [
- 1 => [
- 'id' => 1,
- 'name' => 'Some name',
- 'sum' => '5',
- 'average' => '5',
- 'count' => 1,
- ],
- ];
- $tasker = $this->mock(AccountTaskerInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $tasker->shouldReceive('getExpenseReport')->andReturn($return);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.operations.expenses', ['1', '20160101', '20160131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\OperationsController
- */
- public function testIncome(): void
- {
- $this->mockDefaultSession();
- $tasker = $this->mock(AccountTaskerInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $tasker->shouldReceive('getIncomeReport')->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.operations.income', ['1', '20160101', '20160131']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Report\OperationsController
- */
- public function testOperations(): void
- {
- $this->mockDefaultSession();
- $return = [
- 'sums' => [],
- 1 => [
- 'id' => 1,
- 'name' => 'Some name',
- 'sum' => '5',
- 'average' => '5',
- 'count' => 1,
- ],
- ];
-
- $tasker = $this->mock(AccountTaskerInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $tasker->shouldReceive('getExpenseReport')->andReturn($return);
- $tasker->shouldReceive('getIncomeReport')->andReturn($return);
-
- $this->be($this->user());
- $response = $this->get(route('report-data.operations.operations', ['1', '20160101', '20160131']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/ReportControllerTest.php b/tests/Feature/Controllers/ReportControllerTest.php
deleted file mode 100644
index a4621e81f5..0000000000
--- a/tests/Feature/Controllers/ReportControllerTest.php
+++ /dev/null
@@ -1,804 +0,0 @@
-<?php
-/**
- * ReportControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Carbon\Carbon;
-use FireflyIII\Generator\Report\Account\YearReportGenerator as AcYRG;
-use FireflyIII\Generator\Report\Audit\YearReportGenerator as AYRG;
-use FireflyIII\Generator\Report\Budget\YearReportGenerator as BYRG;
-use FireflyIII\Generator\Report\Category\YearReportGenerator as CYRG;
-use FireflyIII\Generator\Report\Standard\YearReportGenerator as SYRG;
-use FireflyIII\Generator\Report\Tag\YearReportGenerator as TYRG;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Helpers\Report\ReportHelperInterface;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Tag;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Tag\TagRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class ReportControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.TooManyMethods)
- */
-class ReportControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testDoubleReport(): void
- {
- $this->mockDefaultSession();
- $this->mock(ReportHelperInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $generator = $this->mock(AcYRG::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
- $account = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
-
- $budgetRepository->shouldReceive('cleanupBudgets');
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('setExpense')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.double', [$account->id, $expense->id, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testAuditReport(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_report_audit');
- $this->mock(ReportHelperInterface::class);
-
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $generator = $this->mock(AYRG::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
- $account = $this->getRandomAsset();
-
- $budgetRepository->shouldReceive('cleanupBudgets');
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.audit', [$account->id, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testBudgetReport(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_report_budget');
- $this->mock(ReportHelperInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $generator = $this->mock(BYRG::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
-
- $budgetRepository->shouldReceive('cleanupBudgets');
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('setBudgets')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.budget', [1, 1, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testCategoryReport(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_report_category');
- $this->mock(ReportHelperInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $generator = $this->mock(CYRG::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
-
- $budgetRepository->shouldReceive('cleanupBudgets');
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
-
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('setCategories')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.category', [1, 1, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testDefaultReport(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_report_default');
- $this->mock(ReportHelperInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $generator = $this->mock(SYRG::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
-
- $budgetRepository->shouldReceive('cleanupBudgets');
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.default', [1, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testDefaultReportBadDate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_report_default');
- $this->mock(ReportHelperInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
- $budgetRepository->shouldReceive('cleanupBudgets');
-
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.default', [1, '20160101', '20150131']));
- $response->assertStatus(200);
- $response->assertSee('End date of report must be after start date.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testIndex(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_reports_index');
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $helper = $this->mock(ReportHelperInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $budgetRepository->shouldReceive('cleanupBudgets');
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $helper->shouldReceive('listOfMonths')->andReturn([]);
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
-
- // get some preferences:
- $false = new Preference;
- $false->data = false;
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($false);
-
-
- $this->be($this->user());
- $response = $this->get(route('reports.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testOptions(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
-
- $this->be($this->user());
- $response = $this->get(route('reports.options', ['default']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testOptionsDouble(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
-
- $account = new Account();
- $account->name = 'Something';
- $account->id = 3;
- $collection = new Collection([$account]);
-
-
- $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->once()->andReturn($collection);
- $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->once()->andReturn($collection);
-
- $this->be($this->user());
- $response = $this->get(route('reports.options', ['double']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testOptionsBudget(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(ReportHelperInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $budget = $this->getRandomBudget();
-
-
- $budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
-
- $this->be($this->user());
- $response = $this->get(route('reports.options', ['budget']));
- $response->assertStatus(200);
- $response->assertSee($budget->name);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testOptionsCategory(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $category = $this->getRandomCategory();
-
-
- $categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
-
- $this->be($this->user());
- $response = $this->get(route('reports.options', ['category']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testOptionsTag(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->getRandomTag();
-
-
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $this->be($this->user());
- $response = $this->get(route('reports.options', ['tag']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexDoubleError(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $asset = $this->getRandomAsset();
- // find the user's asset account
- $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($asset)->atLeast()->once();
-
- // do not find the exp_rev things.
- $accountRepos->shouldReceive('findNull')->withArgs([4])->andReturnNull()->atLeast()->once();
-
-
- $data = [
- 'accounts' => ['1'],
- 'double' => ['4'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'double',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexDoubleOK(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->times(4);
-
-
- $data = [
- 'accounts' => ['1'],
- 'double' => ['4'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'double',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.double', ['1', '1', '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexAuditOK(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'audit',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.audit', ['1', '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexBudgetError(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'budget' => [],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'budget',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexBudgetOK(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
- $budgetRepository->shouldReceive('findNull')->andReturn($this->user()->budgets()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'budget' => ['1'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'budget',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.budget', ['1', '1', '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexCategoryError(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'category' => [],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'category',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexCategoryOK(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
-
- $categoryRepos->shouldReceive('findNull')->andReturn($this->user()->categories()->find(1))->twice();
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'category' => ['1'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'category',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.category', ['1', '1', '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexDefaultOK(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'default',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.default', ['1', '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexDefaultStartEnd(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'daterange' => '2016-01-01 - 2015-01-31',
- 'report_type' => 'default',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(200);
- $response->assertSee('End date of report must be after start date.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexTagError(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $data = [
- 'accounts' => ['1'],
- 'tag' => [],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'tag',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexTagOK(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
-
- /** @var Tag $tag */
- $tag = $this->user()->tags()->find(1);
- $tag2 = $this->user()->tags()->find(3);
-
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $tagRepos->shouldReceive('findByTag')->andReturn($tag, null)->times(4);
- $tagRepos->shouldReceive('findNull')->andReturn($tag2)->times(3);
-
- $data = [
- 'accounts' => ['1'],
- 'tag' => ['housing', '3'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'tag',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.tag', ['1', $tag->id . ',' . $tag2->id, '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexTagOKNoID(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- Log::debug(sprintf('Now in test %s', __METHOD__));
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
-
-
- $tag2 = $this->user()->tags()->find(3);
-
-
- $accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
-
- $tagRepos->shouldReceive('findByTag')->andReturn(null)->times(4);
- $tagRepos->shouldReceive('findNull')->andReturn($tag2)->times(4);
-
- $data = [
- 'accounts' => ['1'],
- 'tag' => ['housing', '3'],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'tag',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.report.tag', ['1', $tag2->id . ',' . $tag2->id, '20160101', '20160131']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- * @covers \FireflyIII\Http\Requests\ReportFormRequest
- */
- public function testPostIndexZeroAccounts(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $data = [
- 'accounts' => [],
- 'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'default',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('reports.index.post'), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('reports.index'));
- $response->assertSessionHas('error');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\ReportController
- */
- public function testTagReport(): void
- {
- $this->mockDefaultSession();
- $this->mock(BudgetRepositoryInterface::class);
- $this->mock(ReportHelperInterface::class);
- $this->mock(CategoryRepositoryInterface::class);
- $this->mock(TagRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
- $this->mockIntroPreference('shown_demo_reports_report_tag');
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $generator = $this->mock(TYRG::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $tag = $this->user()->tags()->find(1);
- $start = Carbon::now()->startOfYear();
- $end = Carbon::now()->endOfYear();
-
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($start);
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($end);
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $budgetRepository->shouldReceive('cleanupBudgets');
-
- $generator->shouldReceive('setStartDate')->once();
- $generator->shouldReceive('setEndDate')->once();
- $generator->shouldReceive('setAccounts')->once();
- $generator->shouldReceive('setTags')->once();
- $generator->shouldReceive('generate')->once()->andReturn('here-be-report');
-
- $this->be($this->user());
- $response = $this->get(route('reports.report.tag', [1, $tag->tag, '20160101', '20161231']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Rule/CreateControllerTest.php b/tests/Feature/Controllers/Rule/CreateControllerTest.php
deleted file mode 100644
index 1334af4484..0000000000
--- a/tests/Feature/Controllers/Rule/CreateControllerTest.php
+++ /dev/null
@@ -1,185 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Rule;
-
-
-use FireflyIII\Models\Rule;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\CreateController
- */
- public function testCreate(): void
- {
- // mock stuff
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_rules_create');
-
- $ruleGroupRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $ruleRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rules.create', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\CreateController
- */
- public function testCreateFromBill(): void
- {
- // mock stuff
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- $ruleGroupRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $ruleRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $this->be($this->user());
- $response = $this->get(route('rules.create-from-bill', [1, 1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\CreateController
- */
- public function testCreatePreviousInput(): void
- {
- $old = [
- 'rule-trigger' => ['description_is'],
- 'rule-trigger-stop' => ['1'],
- 'rule-trigger-value' => ['X'],
- 'rule-action' => ['set_category'],
- 'rule-action-stop' => ['1'],
- 'rule-action-value' => ['x'],
- ];
- $this->session(['_old_input' => $old]);
-
- // mock stuff
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_rules_create');
-
- $ruleGroupRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $ruleRepos->shouldReceive('count')->atLeast()->once()->andReturn(1);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rules.create', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\CreateController
- * @covers \FireflyIII\Http\Requests\RuleFormRequest
- */
- public function testStore(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $this->mock(RuleGroupRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $repository->shouldReceive('store')->andReturn(new Rule);
-
- $this->session(['rules.create.uri' => 'http://localhost']);
- $data = [
- 'rule_group_id' => 1,
- 'active' => 1,
- 'title' => 'A',
- 'trigger' => 'store-journal',
- 'description' => 'D',
- 'triggers' => [
- [
- 'type' => 'description_is',
- 'value' => 'A',
- 'stop_processing' => '0',
-
- ],
- ],
- 'actions' => [
- [
- 'type' => 'set_category',
- 'value' => 'C',
- 'stop_processing' => '0',
-
- ],
- ],
- ];
- $this->be($this->user());
- $response = $this->post(route('rules.store', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Rule/DeleteControllerTest.php b/tests/Feature/Controllers/Rule/DeleteControllerTest.php
deleted file mode 100644
index 7ba6dbebef..0000000000
--- a/tests/Feature/Controllers/Rule/DeleteControllerTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Rule;
-
-
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class DeleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\DeleteController
- */
- public function testDelete(): void
- {
- // mock stuff
- $ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $this->be($this->user());
- $response = $this->get(route('rules.delete', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\DeleteController
- */
- public function testDestroy(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $repository->shouldReceive('destroy');
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['rules.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('rules.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-}
diff --git a/tests/Feature/Controllers/Rule/EditControllerTest.php b/tests/Feature/Controllers/Rule/EditControllerTest.php
deleted file mode 100644
index d052ffcd7f..0000000000
--- a/tests/Feature/Controllers/Rule/EditControllerTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Rule;
-
-
-use FireflyIII\Models\Rule;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\EditController
- */
- public function testEdit(): void
- {
- // mock stuff
- $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $repository = $this->mock(RuleRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
- $groupRepos->shouldReceive('get')->andReturn(new Collection);
-
- $this->be($this->user());
- $response = $this->get(route('rules.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\EditController
- */
- public function testEditPreviousInput(): void
- {
- $old = [
- 'rule-trigger' => ['description_is'],
- 'rule-trigger-stop' => ['1'],
- 'rule-trigger-value' => ['X'],
- 'rule-action' => ['set_category'],
- 'rule-action-stop' => ['1'],
- 'rule-action-value' => ['x'],
- ];
- $this->session(['_old_input' => $old]);
-
- // mock stuff
- $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $repository = $this->mock(RuleRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $this->mockDefaultSession();
-
-
- $repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
- $groupRepos->shouldReceive('get')->andReturn(new Collection);
-
- $this->be($this->user());
- $response = $this->get(route('rules.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\EditController
- * @covers \FireflyIII\Http\Requests\RuleFormRequest
- */
- public function testUpdate(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('update');
-
- $data = [
- 'rule_group_id' => 1,
- 'id' => 1,
- 'title' => 'Your first default rule',
- 'trigger' => 'store-journal',
- 'active' => 1,
- 'description' => 'This rule is an example. You can safely delete it.',
- 'rule-trigger' => [
- 1 => 'description_is',
- ],
- 'rule-trigger-value' => [
- 1 => 'something',
- ],
- 'rule-action' => [
- 1 => 'prepend_description',
- ],
- 'rule-action-value' => [
- 1 => 'Bla bla',
- ],
- ];
- $this->session(['rules.edit.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('rules.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Rule/IndexControllerTest.php b/tests/Feature/Controllers/Rule/IndexControllerTest.php
deleted file mode 100644
index 19d365939f..0000000000
--- a/tests/Feature/Controllers/Rule/IndexControllerTest.php
+++ /dev/null
@@ -1,163 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Rule;
-
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class IndexControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class IndexControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\IndexController
- */
- public function testDown(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $repository->shouldReceive('moveDown');
- $this->mockDefaultSession();
-
-
- $this->be($this->user());
- $response = $this->get(route('rules.down', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\IndexController
- */
- public function testIndex(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_rules_index');
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $ruleGroupRepos->shouldReceive('count')->andReturn(0);
- $ruleGroupRepos->shouldReceive('store');
- $repository->shouldReceive('getFirstRuleGroup')->andReturn(new RuleGroup);
- $ruleGroupRepos->shouldReceive('getRuleGroupsWithRules')->andReturn(new Collection);
- $repository->shouldReceive('count')->andReturn(0);
- $repository->shouldReceive('store');
-
- $this->be($this->user());
- $response = $this->get(route('rules.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\IndexController
- */
- public function testReorderRuleActions(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
-
- $data = ['actions' => [1, 2, 3]];
- $repository->shouldReceive('reorderRuleActions')->once();
-
- $this->be($this->user());
- $response = $this->post(route('rules.reorder-actions', [1]), $data);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\IndexController
- */
- public function testReorderRuleTriggers(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $data = ['triggers' => [1, 2, 3]];
- $repository->shouldReceive('reorderRuleTriggers')->once();
-
- $this->be($this->user());
- $response = $this->post(route('rules.reorder-triggers', [1]), $data);
- $response->assertStatus(200);
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\IndexController
- */
- public function testUp(): void
- {
- // mock stuff
- $repository = $this->mock(RuleRepositoryInterface::class);
- $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mockDefaultSession();
-
-
- $repository->shouldReceive('moveUp');
-
- $this->be($this->user());
- $response = $this->get(route('rules.up', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
-}
diff --git a/tests/Feature/Controllers/Rule/SelectControllerTest.php b/tests/Feature/Controllers/Rule/SelectControllerTest.php
deleted file mode 100644
index 93556fca51..0000000000
--- a/tests/Feature/Controllers/Rule/SelectControllerTest.php
+++ /dev/null
@@ -1,219 +0,0 @@
-<?php
-/**
- * SelectControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Rule;
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use FireflyIII\TransactionRules\TransactionMatcher;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-
-/**
- * Class SelectControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class SelectControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testExecute(): void
- {
- $this->mockDefaultSession();
- $account = $this->user()->accounts()->find(1);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(RuleRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
-
-
- $this->session(['first' => new Carbon('2010-01-01')]);
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
-
- // new mocks for ruleEngine
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
-
- $collector->shouldReceive('setAccounts')->atLeast()->once();
- $collector->shouldReceive('setRange')->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
-
-
- $data = [
- 'accounts' => [1],
- 'start_date' => '2017-01-01',
- 'end_date' => '2017-01-02',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('rules.execute', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testSelectTransactions(): void
- {
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
-
- $this->be($this->user());
- $response = $this->get(route('rules.select-transactions', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testTestTriggers(): void
- {
- $data = [
- 'triggers' => [
- 'name' => 'description',
- 'value' => 'Bla bla',
- 'stop_processing' => 1,
- ],
- ];
-
- // mock stuff
- $matcher = $this->mock(TransactionMatcher::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $matcher->shouldReceive('setStrict')->once()->withArgs([false])->andReturnSelf();
- $matcher->shouldReceive('setTriggeredLimit')->withArgs([10])->andReturnSelf()->once();
- $matcher->shouldReceive('setSearchLimit')->withArgs([200])->andReturnSelf()->once();
- $matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
- $matcher->shouldReceive('findTransactionsByTriggers')->andReturn([]);
-
- $this->be($this->user());
- $uri = route('rules.test-triggers') . '?' . http_build_query($data);
- $response = $this->get($uri);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testTestTriggersByRule(): void
- {
- $matcher = $this->mock(TransactionMatcher::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $matcher->shouldReceive('setTriggeredLimit')->withArgs([10])->andReturnSelf()->once();
- $matcher->shouldReceive('setSearchLimit')->withArgs([200])->andReturnSelf()->once();
- $matcher->shouldReceive('setRule')->andReturnSelf()->once();
- $matcher->shouldReceive('findTransactionsByRule')->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('rules.test-triggers-rule', [1]));
- $response->assertStatus(200);
-
- }
-
- /**
- * This actually hits an error and not the actually code but OK.
- *
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testTestTriggersError(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $uri = route('rules.test-triggers');
- $response = $this->get($uri);
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Rule\SelectController
- */
- public function testTestTriggersMax(): void
- {
- $this->mockDefaultSession();
- $data = [
- 'triggers' => [
- 'name' => 'description',
- 'value' => 'Bla bla',
- 'stop_processing' => 1,
- ],
- ];
-
- // mock stuff
- $matcher = $this->mock(TransactionMatcher::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
-
- $matcher->shouldReceive('setStrict')->once()->withArgs([false]);
-
- $matcher->shouldReceive('setTriggeredLimit')->withArgs([10])->andReturnSelf()->once();
- $matcher->shouldReceive('setSearchLimit')->withArgs([200])->andReturnSelf()->once();
- $matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
- $matcher->shouldReceive('findTransactionsByTriggers')->andReturn([]);
-
- $this->be($this->user());
- $uri = route('rules.test-triggers') . '?' . http_build_query($data);
- $response = $this->get($uri);
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php b/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php
deleted file mode 100644
index d9bcb57b64..0000000000
--- a/tests/Feature/Controllers/RuleGroup/CreateControllerTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\RuleGroup;
-
-
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\CreateController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.create'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\CreateController
- * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['rule-groups.create.uri' => 'http://localhost']);
- $repository->shouldReceive('store')->andReturn(new RuleGroup);
- $repository->shouldReceive('find')->andReturn(new RuleGroup);
- $data = [
- 'title' => 'A',
- 'active' => '1',
- 'description' => 'No description',
- ];
-
- $this->be($this->user());
- $response = $this->post(route('rule-groups.store', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-}
diff --git a/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php b/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php
deleted file mode 100644
index 5d3455d185..0000000000
--- a/tests/Feature/Controllers/RuleGroup/DeleteControllerTest.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-/**
- * DeleteControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\RuleGroup;
-
-
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class DeleteControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DeleteControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\DeleteController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('get')->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.delete', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\DeleteController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
- $repository->shouldReceive('destroy');
- $repository->shouldReceive('find')->atLeast()->once()->andReturnNull();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['rule-groups.delete.uri' => 'http://localhost']);
- $this->be($this->user());
- $response = $this->post(route('rule-groups.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('index'));
- }
-}
diff --git a/tests/Feature/Controllers/RuleGroup/EditControllerTest.php b/tests/Feature/Controllers/RuleGroup/EditControllerTest.php
deleted file mode 100644
index 59a7cf6b61..0000000000
--- a/tests/Feature/Controllers/RuleGroup/EditControllerTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\RuleGroup;
-
-
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
- */
- public function testDown(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
-
- $repository->shouldReceive('moveDown');
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.down', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- /** @var RuleGroup $ruleGroup */
- $ruleGroup = $this->user()->ruleGroups()->first();
- $ruleGroup->description = 'Some description ' . $this->randomInt();
- $ruleGroup->save();
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- $response->assertSee($ruleGroup->description);
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
- */
- public function testUp(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
-
- $repository->shouldReceive('moveUp');
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.up', [1]));
- $response->assertStatus(302);
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\EditController
- * @covers \FireflyIII\Http\Requests\RuleGroupFormRequest
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(RuleGroupRepositoryInterface::class);
-
- $data = [
- 'id' => 1,
- 'title' => 'C',
- 'description' => 'XX',
- ];
- $this->session(['rule-groups.edit.uri' => 'http://localhost']);
-
- $repository->shouldReceive('update');
- $repository->shouldReceive('find')->andReturn(RuleGroup::first());
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('rule-groups.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
deleted file mode 100644
index 3e7c96efe3..0000000000
--- a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * ExecutionControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\RuleGroup;
-
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ExecutionControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ExecutionControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
- */
- public function testExecute(): void
- {
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $ruleEngine = $this->mock(RuleEngine::class);
-
- $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
- $groupRepos->shouldReceive('getActiveRules')->atLeast()->once()->andReturn(new Collection);
- // new mocks for ruleEngine
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
- $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
-
- $collector->shouldReceive('setAccounts')->atLeast()->once();
- $collector->shouldReceive('setRange')->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
-
- $this->session(['first' => new Carbon('2010-01-01')]);
- $data = [
- 'accounts' => [1],
- 'start_date' => '2010-01-02',
- 'end_date' => '2010-01-02',
- ];
- $this->be($this->user());
- $response = $this->post(route('rule-groups.execute', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('rules.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
- */
- public function testSelectTransactions(): void
- {
- $this->mockDefaultSession();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('rule-groups.select-transactions', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
-}
diff --git a/tests/Feature/Controllers/SearchControllerTest.php b/tests/Feature/Controllers/SearchControllerTest.php
deleted file mode 100644
index 481e4ad0b2..0000000000
--- a/tests/Feature/Controllers/SearchControllerTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-/**
- * SearchControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Support\Search\SearchInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class SearchControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class SearchControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\SearchController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $search = $this->mock(SearchInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $search->shouldReceive('parseQuery')->once();
- $search->shouldReceive('getWordsAsString')->once()->andReturn('test');
- $search->shouldReceive('getModifiers')->once()->andReturn(new Collection);
- $this->be($this->user());
- $response = $this->get(route('search.index') . '?q=test');
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\SearchController
- */
- public function testSearch(): void
- {
- $this->mockDefaultSession();
- $search = $this->mock(SearchInterface::class);
-
- $search->shouldReceive('parseQuery')->once();
- $search->shouldReceive('setLimit')->withArgs([50])->once();
- $search->shouldReceive('searchTransactions')->once()->andReturn(new LengthAwarePaginator([], 0, 10));
- $search->shouldReceive('searchTime')->once()->andReturn(0.2);
-
- $this->be($this->user());
-
- $response = $this->get(route('search.search') . '?query=test');
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/System/CronControllerTest.php b/tests/Feature/Controllers/System/CronControllerTest.php
deleted file mode 100644
index cfa1a7cbd7..0000000000
--- a/tests/Feature/Controllers/System/CronControllerTest.php
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-/**
- * CronControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\System;
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Support\Cronjobs\RecurringCronjob;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- *
- * Class CronControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CronControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\System\CronController
- * @covers \FireflyIII\Support\Binder\CLIToken
- */
- public function testCron(): void
- {
- $users = new Collection([$this->user()]);
- $job = $this->mock(RecurringCronjob::class);
- $preference = new Preference();
- $preference->data = 'token';
- $job->shouldReceive('fire')->once()->andReturn(true);
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('all')->andReturn($users);
- Preferences::shouldReceive('getForUser')
- ->withArgs([Mockery::any(), 'access_token', null])
- ->andReturn($preference)->once();
- $response = $this->get(route('cron.cron', ['token']));
- $response->assertStatus(200);
- $response->assertSee('The recurring transaction cron job fired successfully.');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\System\CronController
- * @covers \FireflyIII\Support\Binder\CLIToken
- */
- public function testCronException(): void
- {
- $users = new Collection([$this->user()]);
- $job = $this->mock(RecurringCronjob::class);
- $preference = new Preference();
- $preference->data = 'token';
- $job->shouldReceive('fire')->once()->andThrow(new FireflyException('Exception noted.'));
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('all')->andReturn($users);
- Preferences::shouldReceive('getForUser')
- ->withArgs([Mockery::any(), 'access_token', null])
- ->andReturn($preference)->once();
- $response = $this->get(route('cron.cron', ['token']));
- $response->assertStatus(200);
- $response->assertSee('Exception noted.');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\System\CronController
- * @covers \FireflyIII\Support\Binder\CLIToken
- */
- public function testCronFalse(): void
- {
- $users = new Collection([$this->user()]);
- $job = $this->mock(RecurringCronjob::class);
- $preference = new Preference();
- $preference->data = 'token';
- $job->shouldReceive('fire')->once()->andReturn(false);
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('all')->andReturn($users);
- Preferences::shouldReceive('getForUser')
- ->withArgs([Mockery::any(), 'access_token', null])
- ->andReturn($preference)->once();
- $response = $this->get(route('cron.cron', ['token']));
- $response->assertStatus(200);
- $response->assertSee('The recurring transaction cron job did not fire.');
-
- }
-
-}
diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php
deleted file mode 100644
index ee4681ba3f..0000000000
--- a/tests/Feature/Controllers/TagControllerTest.php
+++ /dev/null
@@ -1,375 +0,0 @@
-<?php
-/**
- * TagControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers;
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Tag;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Tag\TagRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class TagControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class TagControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('tags.create'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('tags.delete', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(TagRepositoryInterface::class);
-
- $repository->shouldReceive('destroy');
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('tags.destroy', [1]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testEdit(): void
- {
- $this->mockDefaultSession();
- $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('tags.edit', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
-
- $repository->shouldReceive('count')->andReturn(0);
- $repository->shouldReceive('tagCloud')->andReturn([]);
- $repository->shouldReceive('oldestTag')->andReturn(null)->once();
- $repository->shouldReceive('newestTag')->andReturn(null)->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('tags.index'));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testShow(): void
- {
- $this->mockDefaultSession();
-
- $amounts = [
- TransactionType::WITHDRAWAL => '0',
- TransactionType::TRANSFER => '0',
- TransactionType::DEPOSIT => '0',
- ];
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- // mock stuff
- $group = $this->getRandomWithdrawalGroup();
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- $repository = $this->mock(TagRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $repository->shouldReceive('setUser')->atLeast()->once();
- //$repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
-
-
- //Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
- $repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
-
- //$repository->shouldReceive('expenseInPeriod')->andReturn(new Collection)->atLeast()->times(1);
- //$repository->shouldReceive('incomeInPeriod')->andReturn(new Collection)->atLeast()->times(1);
- //$repository->shouldReceive('transferredInPeriod')->andReturn(new Collection)->atLeast()->times(1);
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTag')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator)->atLeast()->once();
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('tags.show', [1]));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testShowAll(): void
- {
- $this->mockDefaultSession();
-
- $amounts = [
- TransactionType::WITHDRAWAL => '0',
- TransactionType::TRANSFER => '0',
- TransactionType::DEPOSIT => '0',
- ];
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- // mock stuff
- $group = $this->getRandomWithdrawalGroup();
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- $repository = $this->mock(TagRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
-
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
- $repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
-
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTag')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator)->atLeast()->once();
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('tags.show', [1, 'all']));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- */
- public function testShowDate(): void
- {
- $this->mockDefaultSession();
-
- $amounts = [
- TransactionType::WITHDRAWAL => '0',
- TransactionType::TRANSFER => '0',
- TransactionType::DEPOSIT => '0',
- ];
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- // mock stuff
- $helper = $this->mock(FiscalHelperInterface::class);
-
- $helper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn(new Carbon);
- $helper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn(new Carbon);
-
- $group = $this->getRandomWithdrawalGroup();
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- $repository = $this->mock(TagRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());
-
-
- //Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
- $repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
-
- $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTag')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator)->atLeast()->once();
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([]);
-
-
- $this->be($this->user());
- $response = $this->get(route('tags.show', [1, '2016-01-01']));
- $response->assertStatus(200);
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- * @covers \FireflyIII\Http\Requests\TagFormRequest
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(TagRepositoryInterface::class);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('findNull')->andReturn(null);
- $repository->shouldReceive('store')->andReturn(new Tag);
-
- $this->session(['tags.create.uri' => 'http://localhost']);
- $data = [
- 'tag' => 'Hello new tag' . $this->randomInt(),
- 'tagMode' => 'nothing',
- 'tag_position_has_tag' => 'true',
-
- ];
- $this->be($this->user());
- $response = $this->post(route('tags.store'), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\TagController
- * @covers \FireflyIII\Http\Requests\TagFormRequest
- */
- public function testUpdate(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(TagRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $this->session(['tags.edit.uri' => 'http://localhost']);
- $data = [
- 'id' => 1,
- 'tag' => 'Hello updated tag' . $this->randomInt(),
- 'tagMode' => 'nothing',
- ];
-
- $repository->shouldReceive('update');
- $repository->shouldReceive('findNull')->andReturn(Tag::first());
-
- $this->be($this->user());
- $response = $this->post(route('tags.update', [1]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/BulkControllerTest.php b/tests/Feature/Controllers/Transaction/BulkControllerTest.php
deleted file mode 100644
index 8deae8a4d3..0000000000
--- a/tests/Feature/Controllers/Transaction/BulkControllerTest.php
+++ /dev/null
@@ -1,168 +0,0 @@
-<?php
-/**
- * BulkControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-use Amount;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class BulkControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class BulkControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\BulkController
- */
- public function testEditWithdrawal(): void
- {
- // mock stuff:
- $journalRepos = $this->mockDefaultSession();
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawalArray = $this->getRandomWithdrawalAsArray();
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
-
- $collector->shouldReceive('setTypes')
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]])->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setJournalIds')->atLeast()->once()->withArgs([[$withdrawal->id]])->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawalArray]);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
- $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
- $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
- $journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
- $journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
-
- $this->be($this->user());
- $response = $this->get(route('transactions.bulk.edit', [$withdrawal->id]));
- $response->assertStatus(200);
- $response->assertSee('Bulk edit a number of transactions');
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\BulkController
- * @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
- */
- public function testUpdate(): void
- {
- $tags = ['a', 'b', 'c'];
- $budget = $this->getRandomBudget();
- $category = $this->getRandomCategory();
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $data = [
- 'category' => $category->name,
- 'budget_id' => $budget->id,
- 'tags' => 'a,b,c',
- 'journals' => [$withdrawal['transaction_journal_id']],
- ];
-
- $repository = $this->mockDefaultSession();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('updateBudget')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $data['budget_id']]);
- $repository->shouldReceive('updateCategory')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $data['category']]);
- $repository->shouldReceive('updateTags')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $tags]);
-
- $repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new TransactionJournal);
-
-
- $route = route('transactions.bulk.update');
- $this->be($this->user());
- $response = $this->post($route, $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\BulkController
- * @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
- */
- public function testUpdateIgnoreAll(): void
- {
- $budget = $this->getRandomBudget();
- $category = $this->getRandomCategory();
- $withdrawal = $this->getRandomWithdrawalAsArray();
- $data = [
- 'category' => $category->name,
- 'budget_id' => $budget->id,
- 'tags' => 'a,b,c',
- 'journals' => [$withdrawal['transaction_journal_id']],
- 'ignore_category' => '1',
- 'ignore_budget' => '1',
- 'ignore_tags' => '1',
- ];
-
- $repository = $this->mockDefaultSession();
-
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldNotReceive('updateBudget');
- $repository->shouldNotReceive('updateCategory');
- $repository->shouldNotReceive('updateTags');
- $repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new TransactionJournal);
-
-
- $route = route('transactions.bulk.update');
- $this->be($this->user());
- $response = $this->post($route, $data);
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/ConvertControllerTest.php b/tests/Feature/Controllers/Transaction/ConvertControllerTest.php
deleted file mode 100644
index c0c05a3590..0000000000
--- a/tests/Feature/Controllers/Transaction/ConvertControllerTest.php
+++ /dev/null
@@ -1,317 +0,0 @@
-<?php
-/**
- * ConvertControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-use Amount;
-use FireflyIII\Factory\TagFactory;
-use FireflyIII\Factory\TransactionFactory;
-use FireflyIII\Factory\TransactionTypeFactory;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepository;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use FireflyIII\Validation\AccountValidator;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Steam;
-use Tests\TestCase;
-
-/**
- * Class ConvertControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class ConvertControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
- */
- public function testIndexDepositTransfer(): void
- {
- // mock stuff:
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $journalRepos = $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
-
- $revenue = $this->getRandomRevenue();
- $deposit = $this->getRandomDepositGroup();
- $euro = $this->getEuro();
- $asset = $this->getRandomAsset();
- $loan = $this->getRandomLoan();
- $expense = $this->getRandomExpense();
-
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
-
- // mock calls:
- $transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn([]);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$revenue]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$expense]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$loan]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::ASSET]])
- ->andReturn(new Collection([$asset]));
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'account_role'])->andReturn('', 'defaultAsset');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- // $journalRepos->shouldReceive('firstNull')->andReturn($deposit);
- // $journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
- // $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
- // $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
-
- // Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
- Amount::shouldReceive('formatAnything')->andReturn('0')->atLeast()->once();
-
- $this->be($this->user());
-
- $response = $this->get(route('transactions.convert.index', ['transfer', $deposit->id]));
- $response->assertStatus(200);
- $response->assertSee('Convert a deposit into a transfer');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
- */
- public function testIndexSameType(): void
- {
- // mock stuff:
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- $this->mock(CurrencyRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
-
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
-
- $revenue = $this->getRandomRevenue();
- $deposit = $this->getRandomDepositGroup();
- $euro = $this->getEuro();
- $asset = $this->getRandomAsset();
- $loan = $this->getRandomLoan();
- $expense = $this->getRandomExpense();
-
- Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
-
- // mock calls:
- $transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn([]);
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$revenue]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$expense]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
- ->andReturn(new Collection([$loan]));
-
- $accountRepos->shouldReceive('getActiveAccountsByType')
- ->atLeast()->once()->withArgs([[AccountType::ASSET]])
- ->andReturn(new Collection([$asset]));
-
-
- $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'account_role'])->andReturn('', 'defaultAsset');
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- Amount::shouldReceive('formatAnything')->andReturn('0')->atLeast()->once();
-
- $this->be($this->user());
-
- $response = $this->get(route('transactions.convert.index', ['deposit', $deposit->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('info');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
- */
- public function testPostIndexBadDestination(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(RuleGroupRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
-
-
- $validator = $this->mock(AccountValidator::class);
- $deposit = $this->getRandomDepositGroup();
-
- // first journal:
- $journal = $deposit->transactionJournals()->first();
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);
-
-
- $data = ['source_account_id' => 1];
- $this->be($this->user());
- $response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));
- $response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
- */
- public function testPostIndexBadSource(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mockDefaultSession();
- $this->mock(UserRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
- $this->mock(RuleGroupRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
-
-
- $validator = $this->mock(AccountValidator::class);
- $deposit = $this->getRandomDepositGroup();
-
- // first journal:
- $journal = $deposit->transactionJournals()->first();
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
-
- $data = ['source_account_id' => 1];
- $this->be($this->user());
- $response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error', sprintf('Source information is invalid for transaction #%d.', $journal->id));
- $response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
- */
- public function testPostIndexDepositTransfer(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $this->mock(UserRepositoryInterface::class);
- $this->mock(AccountRepositoryInterface::class);
-
-
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $categoryRepos = $this->mock(CategoryRepositoryInterface::class);
- $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $currencyRepos = $this->mock(CurrencyRepository::class);
- $validator = $this->mock(AccountValidator::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $ruleGroup = $this->mock(RuleGroupRepositoryInterface::class);
-
- $type = TransactionType::first();
- $typeFactory->shouldReceive('find')->atLeast()->once()->andReturn($type);
-
- $this->mockDefaultSession();
-
-
- $deposit = $this->getRandomDepositGroup();
-
- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
-
- $data = ['source_account_id' => 1];
- $this->be($this->user());
- $response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
- $response->assertStatus(302);
- $response->assertRedirect(route('transactions.show', [$deposit->id]));
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/CreateControllerTest.php b/tests/Feature/Controllers/Transaction/CreateControllerTest.php
deleted file mode 100644
index 4626158629..0000000000
--- a/tests/Feature/Controllers/Transaction/CreateControllerTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-/**
- * CreateControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\CreateController
- */
- public function testCreate(): void
- {
- $this->mockDefaultSession();
- $this->mockIntroPreference('shown_demo_transactions_create_withdrawal');
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $cash = $this->getRandomAsset();
- $empty = new Preference;
- $empty->data = [];
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);
- $accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);
-
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($empty);
-
-
- $this->be($this->user());
- $response = $this->get(route('transactions.create', ['withdrawal']));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/EditControllerTest.php b/tests/Feature/Controllers/Transaction/EditControllerTest.php
deleted file mode 100644
index e987e7aa0b..0000000000
--- a/tests/Feature/Controllers/Transaction/EditControllerTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * EditControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class EditControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class EditControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- public function testEdit(): void
- {
- $group = $this->getRandomWithdrawalGroup();
- $account = $this->getRandomAsset();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->mockDefaultSession();
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
- $accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($account);
-
-
- $this->be($this->user());
- $response = $this->get(route('transactions.edit', [$group->id]));
- $response->assertStatus(200);
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/IndexControllerTest.php b/tests/Feature/Controllers/Transaction/IndexControllerTest.php
deleted file mode 100644
index 8511a27a11..0000000000
--- a/tests/Feature/Controllers/Transaction/IndexControllerTest.php
+++ /dev/null
@@ -1,227 +0,0 @@
-<?php
-/**
- * IndexControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-
-use Amount;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Pagination\LengthAwarePaginator;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class IndexControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IndexControllerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\IndexController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $group = $this->getRandomWithdrawalGroup();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // generic set for the info blocks:
- $groupArray = [
- $this->getRandomWithdrawalAsArray(),
- $this->getRandomDepositAsArray(),
- $this->getRandomTransferAsArray(),
- ];
-
- // role?
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);
-
- // make paginator.
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');
-
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);
-
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $this->be($this->user());
- $response = $this->get(route('transactions.index', ['withdrawal']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\IndexController
- */
- public function testIndexDeposit(): void
- {
- $this->mockDefaultSession();
- $group = $this->getRandomWithdrawalGroup();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // generic set for the info blocks:
- $groupArray = [
- $this->getRandomWithdrawalAsArray(),
- $this->getRandomDepositAsArray(),
- $this->getRandomTransferAsArray(),
- ];
-
- // role?
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);
-
- // make paginator.
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');
-
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);
-
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $this->be($this->user());
- $response = $this->get(route('transactions.index', ['deposit']));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\IndexController
- */
- public function testIndexTransfers(): void
- {
- $this->mockDefaultSession();
- $group = $this->getRandomWithdrawalGroup();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // generic set for the info blocks:
- $groupArray = [
- $this->getRandomWithdrawalAsArray(),
- $this->getRandomDepositAsArray(),
- $this->getRandomTransferAsArray(),
- ];
-
- // role?
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);
-
- // make paginator.
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10');
-
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray);
-
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $this->be($this->user());
- $response = $this->get(route('transactions.index', ['transfers']));
- $response->assertStatus(200);
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\IndexController
- */
- public function testIndexAll(): void
- {
- $this->mockDefaultSession();
- $group = $this->getRandomWithdrawalGroup();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // role?
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);
-
- // make paginator.
- $paginator = new LengthAwarePaginator([$group], 1, 40, 1);
-
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
-
- $pref = new Preference;
- $pref->data = 50;
- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
-
- $this->be($this->user());
- $response = $this->get(route('transactions.index.all', ['withdrawal']));
- $response->assertStatus(200);
- }
-
-}
diff --git a/tests/Feature/Controllers/Transaction/LinkControllerTest.php b/tests/Feature/Controllers/Transaction/LinkControllerTest.php
deleted file mode 100644
index 80b92a19fb..0000000000
--- a/tests/Feature/Controllers/Transaction/LinkControllerTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-/**
- * LinkControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionJournalLink;
-use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class LinkControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class LinkControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- */
- public function testDelete(): void
- {
- $this->mockDefaultSession();
- $this->mock(LinkTypeRepositoryInterface::class);
- $link = $this->getRandomLink();
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('transactions.link.delete', [$link->id]));
- $response->assertStatus(200);
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- */
- public function testModal(): void
- {
- $this->mockDefaultSession();
- $journal = $this->getRandomWithdrawal();
- $linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
-
-
- $linkRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
-
- $this->be($this->user());
- $response = $this->get(route('transactions.link.modal', [$journal->id]));
- $response->assertStatus(200);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- */
- public function testDestroy(): void
- {
- $this->mockDefaultSession();
- $link = $this->getRandomLink();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
-
- Preferences::shouldReceive('mark')->once();
-
-
- $repository->shouldReceive('destroyLink')->atLeast()->once();
- $this->be($this->user());
- $this->session(['journal_links.delete.uri' => 'http://localhost/']);
-
- $response = $this->post(route('transactions.link.destroy', [$link->id]));
- $response->assertStatus(302);
- $response->assertSessionHas('success');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- * @covers \FireflyIII\Http\Requests\JournalLinkRequest
- */
- public function testStore(): void
- {
- $this->mockDefaultSession();
- $withdrawal = $this->getRandomWithdrawal();
- $deposit = $this->getRandomDeposit();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
-
- $data = [
- 'opposing' => $deposit->id,
- 'link_type' => '1_inward',
- ];
-
- //$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
- $journalRepos->shouldReceive('findNull')->andReturn($deposit)->atLeast()->once();
- $repository->shouldReceive('findLink')->andReturn(false)->atLeast()->once();
- $repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('transactions.link.store', [$withdrawal->id]), $data);
-
- $response->assertStatus(302);
- $response->assertSessionHas('success');
- $response->assertRedirect(route('transactions.show', [$withdrawal->transaction_group_id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- * @covers \FireflyIII\Http\Requests\JournalLinkRequest
- */
- public function testStoreAlreadyLinked(): void
- {
- $this->mockDefaultSession();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $link = $this->getRandomLink();
-
- $data = [
- 'opposing' => $link->source_id,
- 'link_type' => '1_inward',
- ];
-
- $journalRepos->shouldReceive('findNull')->andReturn(new TransactionJournal)->atLeast()->once();
- $repository->shouldReceive('findLink')->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('transactions.link.store', [$link->destination_id]), $data);
-
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- $response->assertRedirect(route('transactions.show', [$link->destination_id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- * @covers \FireflyIII\Http\Requests\JournalLinkRequest
- */
- public function testStoreInvalid(): void
- {
- $this->mockDefaultSession();
- $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
- $withdrawal = $this->getRandomWithdrawal();
-
- $data = [
- 'opposing' => 0,
- 'link_type' => '1_inward',
- ];
-
- $journalRepos->shouldReceive('findNull')->andReturn(null)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('transactions.link.store', [$withdrawal->id]), $data);
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- $response->assertRedirect(route('transactions.show', [$withdrawal->id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- * @covers \FireflyIII\Http\Requests\JournalLinkRequest
- */
- public function testStoreSame(): void
- {
- $this->mockDefaultSession();
- $withdrawal = $this->getRandomWithdrawal();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $journalRepos = $this->mockDefaultSession();
-
- $data = [
- 'link_other' => $withdrawal->id,
- 'link_type' => '1_inward',
- ];
- $journalRepos->shouldReceive('findNull')->andReturn($withdrawal)->atLeast()->once();
- $repository->shouldReceive('findLink')->andReturn(false)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->post(route('transactions.link.store', [$withdrawal->id]), $data);
-
- $response->assertStatus(302);
- $response->assertSessionHas('error');
- $response->assertRedirect(route('transactions.show', [$withdrawal->id]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\LinkController
- */
- public function testSwitchLink(): void
- {
- $this->mockDefaultSession();
- $link = $this->getRandomLink();
- $repository = $this->mock(LinkTypeRepositoryInterface::class);
- $this->mock(UserRepositoryInterface::class);
-
-
- $repository->shouldReceive('switchLink')->andReturn(false);
- $this->be($this->user());
- $response = $this->get(route('transactions.link.switch', [$link->id]));
-
-
- $response->assertStatus(302);
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/MassControllerTest.php b/tests/Feature/Controllers/Transaction/MassControllerTest.php
deleted file mode 100644
index 4b9f230a7d..0000000000
--- a/tests/Feature/Controllers/Transaction/MassControllerTest.php
+++ /dev/null
@@ -1,191 +0,0 @@
-<?php
-/**
- * MassControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-
-use Amount;
-use FireflyIII\Events\UpdatedTransactionGroup;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Services\Internal\Update\JournalUpdateService;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class MassControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class MassControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\MassController
- */
- public function testDelete(): void
- {
-
- $this->mockDefaultSession();
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawalArray = $this->getRandomWithdrawalAsArray();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $collector = $this->mock(GroupCollectorInterface::class);
- $collector->shouldReceive('setTypes')
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]])->atLeast()->once()->andReturnSelf();
-
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setJournalIds')->withArgs([[$withdrawal->id]])->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawalArray]);
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
- $this->be($this->user());
- $response = $this->get(route('transactions.mass.delete', [$withdrawal->id]));
- $response->assertStatus(200);
- $response->assertSee('Delete a number of transactions');
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\MassController
- */
- public function testDestroy(): void
- {
- $repository = $this->mockDefaultSession();
- $deposit = $this->getRandomDeposit();
-
- $repository->shouldReceive('findNull')->atLeast()->once()->andReturn($deposit);
- $repository->shouldReceive('destroyJournal')->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $this->session(['transactions.mass-delete.uri' => 'http://localhost']);
-
- $data = ['confirm_mass_delete' => [$deposit->id],];
- $this->be($this->user());
- $response = $this->post(route('transactions.mass.destroy'), $data);
- $response->assertSessionHas('success');
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\MassController
- */
- public function testEdit(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawalArray = $this->getRandomWithdrawalAsArray();
- $asset = $this->getRandomAsset();
- $budget = $this->getRandomBudget();
-
- $journalRepos = $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
-
-
- $collector = $this->mock(GroupCollectorInterface::class);
- $collector->shouldReceive('setTypes')
- ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]])->atLeast()->once()->andReturnSelf();
-
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setJournalIds')->withArgs([[$withdrawal->id]])->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawalArray]);
-
- $repository->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$asset]));
- $budgetRepos->shouldReceive('getBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('transactions.mass.edit', [$withdrawal->id]));
- $response->assertStatus(200);
- $response->assertSee('Edit a number of transactions');
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\MassController
- */
- public function testUpdate(): void
- {
- $deposit = $this->getRandomDeposit();
- $repository = $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $updateService = $this->mock(JournalUpdateService::class);
-
- $this->expectsEvents(UpdatedTransactionGroup::class);
-
- $updateService->shouldReceive('setTransactionJournal')->atLeast()->once();
- $updateService->shouldReceive('setData')->atLeast()->once();
- $updateService->shouldReceive('update')->atLeast()->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $repository->shouldReceive('findNull')->atLeast()->once()->andReturn($deposit);
-
- $this->session(['transactions.mass-edit.uri' => 'http://localhost']);
-
- $data = [
- 'journals' => [$deposit->id],
- 'description' => [$deposit->id => 'Updated salary thing'],
- 'amount' => [$deposit->id => 1600],
- 'date' => [$deposit->id => '2014-07-24'],
- 'source_name' => [$deposit->id => 'Job'],
- 'destination_id' => [$deposit->id => 1],
- 'category' => [$deposit->id => 'Salary'],
- ];
-
- $this->be($this->user());
- $response = $this->post(route('transactions.mass.update', [$deposit->id]), $data);
- $response->assertSessionHas('success');
- $response->assertStatus(302);
- }
-}
diff --git a/tests/Feature/Controllers/Transaction/ShowControllerTest.php b/tests/Feature/Controllers/Transaction/ShowControllerTest.php
deleted file mode 100644
index 1b9352f0c8..0000000000
--- a/tests/Feature/Controllers/Transaction/ShowControllerTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-/**
- * ShowControllerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Feature\Controllers\Transaction;
-
-
-use Amount;
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ShowControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ShowControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
- return;
-parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\ShowController
- */
- public function testShow(): void
- {
- $this->mockDefaultSession();
-
- // values
- $withdrawal = $this->getRandomWithdrawalGroup();
- $array = $this->getRandomWithdrawalGroupAsArray();
-
- $array['transactions'][0]['foreign_amount'] = '10';
- $array['transactions'][0]['foreign_currency_symbol'] = 'x';
- $array['transactions'][0]['foreign_currency_decimal_places'] = 2;
-
- $groupRepository = $this->mock(TransactionGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $transformer = $this->mock(TransactionGroupTransformer::class);
-
- // mock for transformer:
- $transformer->shouldReceive('setParameters')->atLeast()->once();
- $transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array);
-
- // mock for repos
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $groupRepository->shouldReceive('getPiggyEvents')->atLeast()->once()->andReturn([]);
- $groupRepository->shouldReceive('getAttachments')->atLeast()->once()->andReturn([]);
- $groupRepository->shouldReceive('getLinks')->atLeast()->once()->andReturn([]);
-
- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
-
-
- $this->be($this->user());
- $response = $this->get(route('transactions.show', [$withdrawal->id]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('<ol class="breadcrumb">');
- }
-}
diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php
deleted file mode 100644
index 19ce10657a..0000000000
--- a/tests/Unit/Factory/AccountFactoryTest.php
+++ /dev/null
@@ -1,494 +0,0 @@
-<?php
-/**
- * AccountFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Factory\AccountMetaFactory;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Factory\TransactionGroupFactory;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class AccountFactoryTest
- */
-class AccountFactoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test minimal set of data to make factory work (asset account).
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateAsset(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
-
- }
-
-
- /**
- * Test minimal set of data to make factory work (asset account).
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateAssetLocation(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- 'store_location' => true,
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertCount(1, $account->locations()->get());
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
- /**
- * Submit invalid IBAN, so assume NULL on final result.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateInvalidIBAN(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => 'IAMINVALID',
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertNull($account->iban);
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
- /**
- * Submit invalid IBAN, so assume NULL on final result.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateValidIBAN(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => 'NL83ABNA8548609842', // fake IBAN, ABN AMRO IBAN's are always "ABNA0".
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertEquals($data['iban'], $account->iban);
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
- /**
- * Create asset, include opening balance.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateAssetOpeningBalance(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '1234.56',
- 'opening_balance_date' => today(),
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertCount(1, $account->transactions()->get());
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
- /**
- * Create asset, include opening balance.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateAssetNegOb(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '-1234.56',
- 'opening_balance_date' => today(),
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertCount(1, $account->transactions()->get());
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
- /**
- * Create asset, include opening balance.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateAssetZeroOb(): void
- {
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '0',
- 'opening_balance_date' => today(),
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::ASSET, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
- $this->assertCount(0, $account->transactions()->get());
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
-
- /**
- * Create expense account.
- *
- * - Virtual balance must become NULL despite being set.
- * - Account type is found by ID
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateExpense(): void
- {
- $expense = AccountType::where('type', AccountType::EXPENSE)->first();
- $data = [
- 'account_type_id' => $expense->id ?? null,
- 'iban' => null,
- 'name' => sprintf('Basic expense account #%d', $this->randomInt()),
- 'virtual_balance' => '1234.56',
- 'active' => true,
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $account = $factory->create($data);
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
-
- // assert stuff about account:
- $this->assertEquals($account->name, $data['name']);
- $this->assertEquals(AccountType::EXPENSE, $account->accountType->type);
- $this->assertEquals('', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals(0, $account->order);
- $this->assertNull($account->virtual_balance);
-
- // use delete service:
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
- }
-
-
- /**
- * Unknown type.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testCreateErrorType(): void
- {
- // mock repositories
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'bad-type',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
- try {
- $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertEquals($e->getMessage(), 'AccountFactory::create() was unable to find account type #0 ("bad-type").');
-
- return;
- }
- $this->assertTrue(false, 'Should not reach here.');
- }
-
- /**
- * Find expense account we know doesn't exist.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- * @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
- */
- public function testFindOrCreate(): void
- {
- $name = sprintf('Basic account #%d', $this->randomInt());
- $type = AccountType::EXPENSE;
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
-
- try {
- $account = $factory->findOrCreate($name, $type);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- return;
- }
- $this->assertEquals($name, $account->name);
- $this->assertEquals($type, $account->accountType->type);
-
- }
-}
diff --git a/tests/Unit/Factory/AccountMetaFactoryTest.php b/tests/Unit/Factory/AccountMetaFactoryTest.php
deleted file mode 100644
index b2134e35a1..0000000000
--- a/tests/Unit/Factory/AccountMetaFactoryTest.php
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-/**
- * AccountMetaFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\AccountMetaFactory;
-use FireflyIII\Models\AccountMeta;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class AccountMetaFactoryTest
- */
-class AccountMetaFactoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\AccountMetaFactory
- */
- public function testCreate(): void
- {
- // make new account, or get one from DB?
- $account = $this->getRandomAsset();
- $data = [
- 'account_id' => $account->id,
- 'name' => 'Some name',
- 'data' => 'Some value',
- ];
-
- $factory = app(AccountMetaFactory::class);
- $result = $factory->create($data);
- $this->assertEquals($data['name'], $result->name);
- $result->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Factory\AccountMetaFactory
- */
- public function testCrudDelete(): void
- {
- $factory = app(AccountMetaFactory::class);
- $account = $this->getRandomAsset();
- $data = [
- 'account_id' => $account->id,
- 'name' => sprintf('Some name %d', $this->randomInt()),
- 'data' => 'Some value',
- ];
-
- $new = $factory->create($data);
-
- // update existing one
- $result = $factory->crud($account, $data['name'], '');
- $this->assertNull($result);
- $this->assertCount(0, AccountMeta::where('id', $new->id)->get());
- }
-
- /**
- * @covers \FireflyIII\Factory\AccountMetaFactory
- */
- public function testCrudExisting(): void
- {
- $factory = app(AccountMetaFactory::class);
- $account = $this->getRandomAsset();
- $data = [
- 'account_id' => $account->id,
- 'name' => sprintf('Some name %d', $this->randomInt()),
- 'data' => 'Some value',
- ];
-
- $existing = $factory->create($data);
-
- // update existing one
- $result = $factory->crud($account, $data['name'], 'Some NEW value');
- $this->assertNotNull($result);
- $this->assertEquals($result->account_id, $account->id);
- $this->assertEquals($existing->name, $result->name);
- $this->assertEquals('Some NEW value', $result->data);
- }
-
- /**
- * @covers \FireflyIII\Factory\AccountMetaFactory
- */
- public function testCrudNew(): void
- {
- $factory = app(AccountMetaFactory::class);
- $account = $this->getRandomAsset();
- $result = $factory->crud($account, 'random name ' . $this->randomInt(), 'Some value');
- $this->assertNotNull($result);
- $this->assertEquals($result->account_id, $account->id);
-
- }
-}
diff --git a/tests/Unit/Factory/AttachmentFactoryTest.php b/tests/Unit/Factory/AttachmentFactoryTest.php
deleted file mode 100644
index 226d435565..0000000000
--- a/tests/Unit/Factory/AttachmentFactoryTest.php
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-/**
- * AttachmentFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AttachmentFactory;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class AttachmentFactoryTest
- */
-class AttachmentFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\AttachmentFactory
- */
- public function testCreate(): void
- {
-
- $journal = $this->getRandomWithdrawal();
- $data = [
- 'model_id' => $journal->id,
- 'model' => TransactionJournal::class,
- 'filename' => 'testfile.pdf',
- 'title' => 'File name',
- 'notes' => 'Some notes',
- ];
-
- /** @var AttachmentFactory $factory */
- $factory = app(AttachmentFactory::class);
- $factory->setUser($this->user());
- try {
- $result = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($data['title'], $result->title);
- $this->assertEquals(1, $result->notes()->count());
-
- $result->forceDelete();
-
- }
-
- /**
- * @covers \FireflyIII\Factory\AttachmentFactory
- */
- public function testCreateWithTransaction(): void
- {
-
- $journal = $this->getRandomWithdrawal();
- $transaction = $journal->transactions()->first();
- $data = [
- 'model_id' => $transaction->id,
- 'model' => Transaction::class,
- 'filename' => 'testfile.pdf',
- 'title' => 'File name',
- 'notes' => 'Some notes',
- ];
-
- /** @var AttachmentFactory $factory */
- $factory = app(AttachmentFactory::class);
- $factory->setUser($this->user());
- try {
- $result = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($data['title'], $result->title);
- $this->assertEquals(1, $result->notes()->count());
- $this->assertEquals($journal->id, $result->attachable_id);
-
- $result->forceDelete();
-
-
- }
-}
diff --git a/tests/Unit/Factory/BillFactoryTest.php b/tests/Unit/Factory/BillFactoryTest.php
deleted file mode 100644
index 5125193a32..0000000000
--- a/tests/Unit/Factory/BillFactoryTest.php
+++ /dev/null
@@ -1,293 +0,0 @@
-<?php
-/**
- * BillFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\BillFactory;
-use FireflyIII\Models\ObjectGroup;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BillFactoryTest
- */
-class BillFactoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\BillFactory
- * @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
- */
- public function testCreateBasic(): void
- {
- $data = [
- 'name' => sprintf('Some new bill #%d', $this->randomInt()),
- 'amount_min' => '5',
- 'currency_id' => 1,
- 'currency_code' => '',
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'automatch' => true,
- 'active' => true,
- 'notes' => 'Hello!',
- ];
-
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- try {
- $bill = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- $this->assertEquals($data['name'], $bill->name);
- $this->assertEquals($data['amount_min'], $bill->amount_min);
- $this->assertEquals(1, $bill->transaction_currency_id);
- $this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
- $note = $bill->notes()->first();
- $this->assertEquals($data['notes'], $note->text);
-
- }
-
- /**
- * @covers \FireflyIII\Factory\BillFactory
- * @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
- */
- public function testCreateQueryException(): void
- {
- $data = [
- 'name' => sprintf('Some new bill #%d', $this->randomInt()),
- 'amount_min' => '5',
- 'currency_id' => 1,
- 'currency_code' => '',
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'automatch' => true,
- 'active' => 'I AM A STRING',
- 'notes' => 'Hello!',
- ];
-
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- try {
- $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertEquals('400000: Could not store bill.', $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Factory\BillFactory
- * @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
- * @covers \FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups
- */
- public function testCreateObjectGroup(): void
- {
- $data = [
- 'name' => sprintf('Some new bill #%d', $this->randomInt()),
- 'amount_min' => '5',
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'object_group' => 'Test',
- 'automatch' => true,
- 'active' => 1,
- 'notes' => 'Hello!',
- ];
-
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- try {
- $bill = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- return;
- }
- $this->assertCount(1, $bill->objectGroups()->get());
- }
-
-
- /**
- * @covers \FireflyIII\Factory\BillFactory
- * @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
- * @covers \FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups
- */
- public function testCreateObjectGroupById(): void
- {
- $group = ObjectGroup::create(
- [
- 'user_id' => $this->user()->id,
- 'title' => sprintf('Random object group #%d', $this->randomInt()),
- 'order' => 1,
- ]
- );
- $data = [
- 'name' => sprintf('Some new bill #%d', $this->randomInt()),
- 'amount_min' => '5',
- 'currency_id' => 1,
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'skip' => 0,
- 'object_group_id' => $group->id,
- 'automatch' => true,
- 'active' => 1,
- 'notes' => 'Hello!',
- ];
-
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- try {
- $bill = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- return;
- }
- $this->assertCount(1, $bill->objectGroups()->get());
- }
-
-
- /**
- * @covers \FireflyIII\Factory\BillFactory
- * @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
- */
- public function testCreateEmptyNotes(): void
- {
- $euro = $this->getEuro();
- $data = [
- 'name' => sprintf('Some new bill #%d', $this->randomInt()),
- 'amount_min' => '5',
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'currency_id' => $euro->id,
- 'currency_code' => '',
- 'skip' => 0,
- 'automatch' => true,
- 'active' => true,
- 'notes' => '',
- ];
-
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- try {
- $bill = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- $this->assertEquals($data['name'], $bill->name);
- $this->assertEquals($euro->id, $bill->transaction_currency_id);
- $this->assertEquals($data['amount_min'], $bill->amount_min);
- $this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
- $this->assertEquals(0, $bill->notes()->count());
-
- }
-
- /**
- * Find by ID
- *
- * @covers \FireflyIII\Factory\BillFactory
- *
- */
- public function testFindById(): void
- {
- $existing = $this->user()->piggyBanks()->first();
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- $piggy = $factory->find($existing->id, null);
- $this->assertEquals($existing->id, $piggy->id);
- }
-
- /**
- * Find by name
- *
- * @covers \FireflyIII\Factory\BillFactory
- *
- */
- public function testFindByName(): void
- {
- $existing = $this->user()->bills()->first();
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- $piggy = $factory->find(null, $existing->name);
-
- $this->assertEquals($existing->id, $piggy->id);
- }
-
- /**
- * Find by unknown name
- *
- * @covers \FireflyIII\Factory\BillFactory
- *
- */
- public function testFindByUnknownName(): void
- {
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- $piggy = $factory->find(null, sprintf('I dont exist #%d', $this->randomInt()));
-
- $this->assertNull($piggy);
- }
-
- /**
- * Find NULL
- *
- * @covers \FireflyIII\Factory\BillFactory
- *
- */
- public function testFindNull(): void
- {
- /** @var BillFactory $factory */
- $factory = app(BillFactory::class);
- $factory->setUser($this->user());
- $this->assertNull($factory->find(null, null));
- }
-
-}
diff --git a/tests/Unit/Factory/BudgetFactoryTest.php b/tests/Unit/Factory/BudgetFactoryTest.php
deleted file mode 100644
index 9ae1d72498..0000000000
--- a/tests/Unit/Factory/BudgetFactoryTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * BudgetFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\BudgetFactory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BudgetFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Put in ID, return it.
- *
- * @covers \FireflyIII\Factory\BudgetFactory
- */
- public function testFindById(): void
- {
- $existing = $this->user()->budgets()->first();
- /** @var BudgetFactory $factory */
- $factory = app(BudgetFactory::class);
- $factory->setUser($this->user());
-
- $budget = $factory->find($existing->id, null);
- $this->assertEquals($existing->id, $budget->id);
-
- }
-
- /**
- * Put in name, return it.
- *
- * @covers \FireflyIII\Factory\BudgetFactory
- */
- public function testFindByName(): void
- {
- $existing = $this->user()->budgets()->first();
- /** @var BudgetFactory $factory */
- $factory = app(BudgetFactory::class);
- $factory->setUser($this->user());
-
- $budget = $factory->find(null, $existing->name);
- $this->assertEquals($existing->id, $budget->id);
-
- }
-
- /**
- * Put in NULL, will find NULL.
- *
- * @covers \FireflyIII\Factory\BudgetFactory
- */
- public function testFindNull(): void
- {
- /** @var BudgetFactory $factory */
- $factory = app(BudgetFactory::class);
- $factory->setUser($this->user());
-
- $this->assertNull($factory->find(null, null));
-
- }
-
- /**
- * Put in unknown, get NULL
- *
- * @covers \FireflyIII\Factory\BudgetFactory
- */
- public function testFindUnknown(): void
- {
- /** @var BudgetFactory $factory */
- $factory = app(BudgetFactory::class);
- $factory->setUser($this->user());
- $this->assertNull($factory->find(null, sprintf('I dont exist %d', $this->randomInt())));
- }
-
-}
diff --git a/tests/Unit/Factory/CategoryFactoryTest.php b/tests/Unit/Factory/CategoryFactoryTest.php
deleted file mode 100644
index fc8e415377..0000000000
--- a/tests/Unit/Factory/CategoryFactoryTest.php
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/**
- * CategoryFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-use FireflyIII\Factory\CategoryFactory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class CategoryFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\CategoryFactory
- */
- public function testFindOrCreateExistingID(): void
- {
- $existing = $this->user()->categories()->first();
-
- /** @var CategoryFactory $factory */
- $factory = app(CategoryFactory::class);
- $factory->setUser($this->user());
- $category = $factory->findOrCreate($existing->id, null);
- $this->assertEquals($existing->id, $category->id);
- }
-
- /**
- * @covers \FireflyIII\Factory\CategoryFactory
- */
- public function testFindOrCreateExistingName(): void
- {
- $existing = $this->user()->categories()->first();
-
- /** @var CategoryFactory $factory */
- $factory = app(CategoryFactory::class);
- $factory->setUser($this->user());
- $category = $factory->findOrCreate(null, $existing->name);
- $this->assertEquals($existing->id, $category->id);
- }
-
- /**
- * You can force a NULL result by presenting an invalid ID and no valid name.
- *
- * @covers \FireflyIII\Factory\CategoryFactory
- */
- public function testFindOrCreateInvalidID(): void
- {
- $existing = $this->user()->categories()->max('id');
- $existing += 4;
-
- /** @var CategoryFactory $factory */
- $factory = app(CategoryFactory::class);
- $factory->setUser($this->user());
- $this->assertNull($factory->findOrCreate($existing, ''));
- }
-
- /**
- * @covers \FireflyIII\Factory\CategoryFactory
- */
- public function testFindOrCreateNewName(): void
- {
- $name = sprintf('Some new category #%d', $this->randomInt());
-
- /** @var CategoryFactory $factory */
- $factory = app(CategoryFactory::class);
- $factory->setUser($this->user());
- $category = $factory->findOrCreate(null, $name);
- $this->assertEquals($name, $category->name);
- }
-
- /**
- * @covers \FireflyIII\Factory\CategoryFactory
- */
- public function testFindOrCreateNull(): void
- {
- /** @var CategoryFactory $factory */
- $factory = app(CategoryFactory::class);
- $factory->setUser($this->user());
- $this->assertNull($factory->findOrCreate(null, null));
- }
-
-}
diff --git a/tests/Unit/Factory/PiggyBankEventFactoryTest.php b/tests/Unit/Factory/PiggyBankEventFactoryTest.php
deleted file mode 100644
index a8c3fcf130..0000000000
--- a/tests/Unit/Factory/PiggyBankEventFactoryTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-/**
- * PiggyBankEventFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\PiggyBankEventFactory;
-use FireflyIII\Models\PiggyBankEvent;
-use FireflyIII\Models\PiggyBankRepetition;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankEventFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankEventFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\PiggyBankEventFactory
- */
- public function testCreateAmountZero(): void
- {
- $transfer = $this->getRandomTransfer();
- $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
- $repetition = PiggyBankRepetition::first();
- $repos = $this->mock(PiggyBankRepositoryInterface::class);
- /** @var PiggyBankEventFactory $factory */
- $factory = app(PiggyBankEventFactory::class);
-
- // mock:
- $repos->shouldReceive('setUser');
- $repos->shouldReceive('getRepetition')->andReturn($repetition);
- $repos->shouldReceive('getExactAmount')->andReturn('0');
-
- $this->assertNull($factory->create($transfer, $piggy));
- }
-
- /**
- * @covers \FireflyIII\Factory\PiggyBankEventFactory
- */
- public function testCreateNoPiggy(): void
- {
- $this->mock(PiggyBankRepositoryInterface::class);
- $transfer = $this->getRandomTransfer();
-
- /** @var PiggyBankEventFactory $factory */
- $factory = app(PiggyBankEventFactory::class);
-
- $this->assertNull($factory->create($transfer, null));
- }
-
- /**
- * Test for withdrawal where piggy has no repetition.
- *
- * @covers \FireflyIII\Factory\PiggyBankEventFactory
- */
- public function testCreateNoRep(): void
- {
- $transfer = $this->getRandomTransfer();
- $piggy = $this->user()->piggyBanks()->first();
- $repos = $this->mock(PiggyBankRepositoryInterface::class);
- /** @var PiggyBankEventFactory $factory */
- $factory = app(PiggyBankEventFactory::class);
-
- // mock:
- $repos->shouldReceive('setUser');
- $repos->shouldReceive('getRepetition')->andReturn(null);
- $repos->shouldReceive('getExactAmount')->andReturn('0');
-
- Log::warning('The following error is part of a test.');
- $this->assertNull($factory->create($transfer, $piggy));
- }
-
- /**
- * @covers \FireflyIII\Factory\PiggyBankEventFactory
- */
- public function testCreateNotTransfer(): void
- {
- $this->mock(PiggyBankRepositoryInterface::class);
- $deposit = $this->getRandomDeposit();
-
- $piggy = $this->user()->piggyBanks()->first();
- /** @var PiggyBankEventFactory $factory */
- $factory = app(PiggyBankEventFactory::class);
- Log::warning('The following error is part of a test.');
- $this->assertNull($factory->create($deposit, $piggy));
- }
-
- /**
- * @covers \FireflyIII\Factory\PiggyBankEventFactory
- */
- public function testCreateSuccess(): void
- {
- $transfer = $this->getRandomTransfer();
- $piggy = $this->user()->piggyBanks()->first();
- $repetition = PiggyBankRepetition::first();
- $event = PiggyBankEvent::first();
- $repos = $this->mock(PiggyBankRepositoryInterface::class);
-
- /** @var PiggyBankEventFactory $factory */
- $factory = app(PiggyBankEventFactory::class);
-
- // mock:
- $repos->shouldReceive('setUser');
- $repos->shouldReceive('getRepetition')->andReturn($repetition);
- $repos->shouldReceive('getExactAmount')->andReturn('5');
- $repos->shouldReceive('addAmountToRepetition')->once();
- $repos->shouldReceive('createEventWithJournal')->once()->andReturn($event);
-
- $result = $factory->create($transfer, $piggy);
- $this->assertNotnull($result);
- $this->assertEquals($result->id, $event->id);
- }
-
-}
diff --git a/tests/Unit/Factory/PiggyBankFactoryTest.php b/tests/Unit/Factory/PiggyBankFactoryTest.php
deleted file mode 100644
index 14294188b2..0000000000
--- a/tests/Unit/Factory/PiggyBankFactoryTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * PiggyBankFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\PiggyBankFactory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Put in ID, return it.
- *
- * @covers \FireflyIII\Factory\PiggyBankFactory
- */
- public function testFindById(): void
- {
- $existing = $this->user()->piggyBanks()->first();
- /** @var PiggyBankFactory $factory */
- $factory = app(PiggyBankFactory::class);
- $factory->setUser($this->user());
-
- $piggyBank = $factory->find($existing->id, null);
- $this->assertEquals($existing->id, $piggyBank->id);
-
- }
-
- /**
- * Put in name, return it.
- *
- * @covers \FireflyIII\Factory\PiggyBankFactory
- */
- public function testFindByName(): void
- {
- $existing = $this->user()->piggyBanks()->first();
- /** @var PiggyBankFactory $factory */
- $factory = app(PiggyBankFactory::class);
- $factory->setUser($this->user());
-
- $piggyBank = $factory->find(null, $existing->name);
- $this->assertEquals($existing->id, $piggyBank->id);
-
- }
-
- /**
- * Put in NULL, will find NULL.
- *
- * @covers \FireflyIII\Factory\PiggyBankFactory
- */
- public function testFindNull(): void
- {
- /** @var PiggyBankFactory $factory */
- $factory = app(PiggyBankFactory::class);
- $factory->setUser($this->user());
-
- $this->assertNull($factory->find(null, null));
-
- }
-
- /**
- * Put in unknown, get NULL
- *
- * @covers \FireflyIII\Factory\PiggyBankFactory
- */
- public function testFindUnknown(): void
- {
- /** @var PiggyBankFactory $factory */
- $factory = app(PiggyBankFactory::class);
- $factory->setUser($this->user());
- $this->assertNull($factory->find(null, 'I dont exist.' . $this->randomInt()));
- }
-}
diff --git a/tests/Unit/Factory/RecurrenceFactoryTest.php b/tests/Unit/Factory/RecurrenceFactoryTest.php
deleted file mode 100644
index b42d94b403..0000000000
--- a/tests/Unit/Factory/RecurrenceFactoryTest.php
+++ /dev/null
@@ -1,836 +0,0 @@
-<?php
-/**
- * RecurrenceFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Factory\BudgetFactory;
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Factory\PiggyBankFactory;
-use FireflyIII\Factory\RecurrenceFactory;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Factory\TransactionTypeFactory;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Validation\AccountValidator;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Test different combinations:
- * Transfer
- * Withdrawal
- * Deposit
- *
- * With the correct types.
- *
- * Class RecurrenceFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RecurrenceFactoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * With piggy bank. With tags. With budget. With category.
- * This is a withdrawal
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreate(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
- $euro = $this->getEuro();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
- $piggyFactory->shouldReceive('setUser')->atLeast()->once();
- $budgetFactory->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->twice();
- $categoryFactory->shouldReceive('setUser')->once();
-
-
- $piggyFactory->shouldReceive('find')->atLeast()->once()->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'withdrawal',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some other name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * @covers \FireflyIII\Factory\RecurrenceFactory
- */
- public function testCreateBadTransactionType(): void
- {
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $data = [
- 'recurrence' => [
- 'type' => 'bad type',
- ],
- ];
-
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(null);
-
-
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
- $result = null;
- Log::warning('The following error is part of a test.');
- try {
- $result = $factory->create($data);
- } catch (FireflyException $e) {
- $this->assertEquals('Cannot make a recurring transaction of type "bad type"', $e->getMessage());
- $this->assertTrue(true);
- }
- $this->assertNull($result);
- }
-
- /**
- * With piggy bank. With tags. With budget. With category.
- * Submit account names, not types. This is a withdrawal.
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateByName(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
- $euro = $this->getEuro();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
- $piggyFactory->shouldReceive('setUser')->atLeast()->once();
- $budgetFactory->shouldReceive('setUser')->atLeast()->once();
- $categoryFactory->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->twice();
- //$accountFactory->shouldReceive('setUser')->atLeast()->once();
-
- $piggyFactory->shouldReceive('find')->atLeast()->once()->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
-
- // return NULL for account ID's.
- $accountRepos->shouldReceive('findNull')->twice()->andReturn(null, null);
- // but find them by name:
- $accountRepos->shouldReceive('findByName')->twice()->andReturn($source, $destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'withdrawal',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some other name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * Deposit. With piggy bank. With tags. With budget. With category.
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateDeposit(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomRevenue();
- $destination = $this->getRandomAsset();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
- $piggyFactory->shouldReceive('setUser')->once();
- $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
-
- $accountRepos->shouldReceive('setUser')->twice();
- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
-
- $budgetFactory->shouldReceive('setUser')->once();
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
-
- $categoryFactory->shouldReceive('setUser')->once();
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'deposit',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some otjer name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
-
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(2));
-
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * With piggy bank. With tags. With budget. With category.
- * Submit account names, not types. Also a withdrawal
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateNewByName(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
- $euro = $this->getEuro();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
- $piggyFactory->shouldReceive('setUser')->atLeast()->once();
- $budgetFactory->shouldReceive('setUser')->atLeast()->once();
- $categoryFactory->shouldReceive('setUser')->once();
-
- $accountRepos->shouldReceive('setUser')->twice();
- $piggyFactory->shouldReceive('find')->atLeast()->once()->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
-
- // return NULL for account ID's.
- $accountRepos->shouldReceive('findNull')->twice()->andReturn(null, null);
- // but find them by name (at least the first one):
- $accountRepos->shouldReceive('findByName')->twice()->andReturn($source, null);
-
- // this activates the "create by name" routine (account factory):
- $accountFactory->shouldReceive('setUser')->atLeast()->once();
- $accountFactory->shouldReceive('findOrCreate')->atLeast()->once()
- ->andReturn($destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
-
-
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'withdrawal',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some other name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * No piggy bank. With tags. With budget. With category. Withdrawal.
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateNoPiggybank(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
- $piggyFactory->shouldReceive('setUser')->once();
- $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn(null);
-
- $accountRepos->shouldReceive('setUser')->twice();
- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
-
- $budgetFactory->shouldReceive('setUser')->once();
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
-
- $categoryFactory->shouldReceive('setUser')->once();
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'withdrawal',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
-
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some otjer name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * With piggy bank. With tags. With budget. With category. Withdrawal
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateNoTags(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
- $piggyFactory->shouldReceive('setUser')->once();
- $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
-
- $accountRepos->shouldReceive('setUser')->twice();
- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
-
- $budgetFactory->shouldReceive('setUser')->once();
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
-
- $categoryFactory->shouldReceive('setUser')->once();
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'withdrawal',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some otjer name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => [],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
- /**
- * Deposit. With piggy bank. With tags. With budget. With category.
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateTransfer(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomAsset();
- $destination = $this->getRandomAsset($source->id);
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
- $validator = $this->mock(AccountValidator::class);
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
-
- // mock calls:
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
- $piggyFactory->shouldReceive('setUser')->once();
- $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
-
- $accountRepos->shouldReceive('setUser')->twice();
- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);
-
- $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
- $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
-
- $budgetFactory->shouldReceive('setUser')->once();
- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
-
- $categoryFactory->shouldReceive('setUser')->once();
- $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
-
- // validator:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'transfer',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
-
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some otjer name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
-
- ],
- ],
- ];
-
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(3));
-
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
-
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
-}
diff --git a/tests/Unit/Factory/TagFactoryTest.php b/tests/Unit/Factory/TagFactoryTest.php
deleted file mode 100644
index f7b34a67b1..0000000000
--- a/tests/Unit/Factory/TagFactoryTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * TagFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\TagFactory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TagFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TagFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\TagFactory
- */
- public function testFindOrCreateExisting(): void
- {
- $tag = $this->user()->tags()->first();
- /** @var TagFactory $factory */
- $factory = app(TagFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->findOrCreate($tag->tag);
- $this->assertEquals($tag->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Factory\TagFactory
- */
- public function testFindOrCreateNew(): void
- {
- $tag = sprintf('Some new tag %d', $this->randomInt());
- /** @var TagFactory $factory */
- $factory = app(TagFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->findOrCreate($tag);
- $this->assertEquals($tag, $result->tag);
- }
-
-}
diff --git a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php b/tests/Unit/Factory/TransactionCurrencyFactoryTest.php
deleted file mode 100644
index 93772f96d4..0000000000
--- a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php
+++ /dev/null
@@ -1,138 +0,0 @@
-<?php
-/**
- * TransactionCurrencyFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Models\TransactionCurrency;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionCurrencyFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionCurrencyFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testCreate(): void
- {
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $result = $factory->create(['name' => 'OK', 'code' => 'XXA', 'symbol' => 'Z', 'decimal_places' => 2, 'enabled' => true]);
- $this->assertNotNull($result);
- $this->assertEquals('XXA', $result->code);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testCreateEmpty(): void
- {
- $this->expectException(FireflyException::class);
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- Log::warning('The following error is part of a test.');
- $result = $factory->create(['name' => null, 'code' => null, 'symbol' => null, 'decimal_places' => null, 'enabled' => true]);
- $this->assertNull($result);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testFindByBadCode(): void
- {
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $this->assertNull($factory->find(null, 'BAD CODE'));
-
- }
-
- /**
- * submit ID = 1000
- *
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testFindByBadID(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $result = $factory->find(1000, $currency->code);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testFindByCode(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $result = $factory->find(null, $currency->code);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testFindByID(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $result = $factory->find($currency->id, null);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionCurrencyFactory
- */
- public function testFindNull(): void
- {
- /** @var TransactionCurrencyFactory $factory */
- $factory = app(TransactionCurrencyFactory::class);
- $this->assertNull($factory->find(null, null));
- }
-
-}
diff --git a/tests/Unit/Factory/TransactionFactoryTest.php b/tests/Unit/Factory/TransactionFactoryTest.php
deleted file mode 100644
index 1812071ecb..0000000000
--- a/tests/Unit/Factory/TransactionFactoryTest.php
+++ /dev/null
@@ -1,181 +0,0 @@
-<?php
-/**
- * TransactionFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\TransactionFactory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionFactory
- */
- public function testCreateNegative(): void
- {
- // data used in calls.
- $journal = $this->getRandomWithdrawal();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $amount = '10';
-
- /** @var TransactionFactory $factory */
- $factory = app(TransactionFactory::class);
-
-
- // set details:
- $factory->setUser($this->user());
- $factory->setJournal($journal);
- $factory->setAccount($account);
- $factory->setCurrency($euro);
- $factory->setReconciled(false);
-
- // create negative
- $transaction = $factory->createNegative($amount, null);
-
- $this->assertEquals($transaction->account_id, $account->id);
- $this->assertEquals('-10.000000000000', $transaction->amount);
- $transaction->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionFactory
- */
- public function testCreatePositive(): void
- {
- // data used in calls.
- $journal = $this->getRandomWithdrawal();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $amount = '10';
-
- /** @var TransactionFactory $factory */
- $factory = app(TransactionFactory::class);
-
-
- // set details:
- $factory->setUser($this->user());
- $factory->setJournal($journal);
- $factory->setAccount($account);
- $factory->setCurrency($euro);
- $factory->setReconciled(false);
-
- // create positive
- $transaction = $factory->createPositive($amount, null);
-
- $this->assertEquals($transaction->account_id, $account->id);
- $this->assertEquals('10', $transaction->amount);
- $transaction->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionFactory
- */
- public function testCreateNegativeForeign(): void
- {
- // data used in calls.
- $journal = $this->getRandomWithdrawal();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
- $amount = '10';
-
- /** @var TransactionFactory $factory */
- $factory = app(TransactionFactory::class);
-
-
- // set details:
- $factory->setUser($this->user());
- $factory->setJournal($journal);
- $factory->setAccount($account);
- $factory->setCurrency($euro);
- $factory->setForeignCurrency($dollar);
- $factory->setReconciled(false);
-
- // create negative
- $transaction = $factory->createNegative($amount, $amount);
-
- $this->assertEquals($transaction->account_id, $account->id);
- $this->assertEquals('-10.000000000000', $transaction->amount);
- $this->assertEquals('-10.000000000000', $transaction->foreign_amount);
- $this->assertEquals($euro->id, $transaction->transaction_currency_id);
- $this->assertEquals($dollar->id, $transaction->foreign_currency_id);
- $transaction->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionFactory
- */
- public function testCreatePositiveForeign(): void
- {
- // data used in calls.
- $journal = $this->getRandomWithdrawal();
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
- $amount = '10';
-
- /** @var TransactionFactory $factory */
- $factory = app(TransactionFactory::class);
-
-
- // set details:
- $factory->setUser($this->user());
- $factory->setJournal($journal);
- $factory->setAccount($account);
- $factory->setCurrency($euro);
- $factory->setForeignCurrency($dollar);
- $factory->setReconciled(false);
-
- // create positive
- $transaction = $factory->createPositive($amount, $amount);
- $this->assertEquals($transaction->account_id, $account->id);
- $this->assertEquals('10', $transaction->amount);
- $this->assertEquals('10', $transaction->foreign_amount);
- $this->assertEquals($euro->id, $transaction->transaction_currency_id);
- $this->assertEquals($dollar->id, $transaction->foreign_currency_id);
-
- $transaction->forceDelete();
- }
-}
diff --git a/tests/Unit/Factory/TransactionJournalFactoryTest.php b/tests/Unit/Factory/TransactionJournalFactoryTest.php
deleted file mode 100644
index 3dfe51a227..0000000000
--- a/tests/Unit/Factory/TransactionJournalFactoryTest.php
+++ /dev/null
@@ -1,903 +0,0 @@
-<?php
-/**
- * TransactionJournalFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use Amount;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Factory\PiggyBankEventFactory;
-use FireflyIII\Factory\TagFactory;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Factory\TransactionFactory;
-use FireflyIII\Factory\TransactionJournalFactory;
-use FireflyIII\Factory\TransactionJournalMetaFactory;
-use FireflyIII\Models\PiggyBankEvent;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
-use FireflyIII\Validation\AccountValidator;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionJournalFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionJournalFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Submit empty array.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreate(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $validator = $this->mock(AccountValidator::class);
- $submission = [];
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
- Log::warning('The following error is part of a test.');
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(0, $collection);
- }
-
- /**
- * Submit minimal array for a withdrawal.
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateWithdrawal(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
-
-
- // data
- $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $euro = $this->getEuro();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $expense->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
-
- /**
- * Submit minimal array for a deposit.
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateDeposit(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();
- $asset = $this->getRandomAsset();
- $revenue = $this->getRandomRevenue();
- $euro = $this->getEuro();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'deposit',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $revenue->id,
- 'destination_id' => $asset->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'deposit'])->atLeast()->once()->andReturn($deposit);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$revenue->id])->atLeast()->once()->andReturn($revenue);
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
-
- /**
- * Submit array for a withdrawal. Include tag info.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateWithdrawalTags(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
- $asset = $this->getRandomAsset();
- $tag = $this->user()->tags()->inRandomOrder()->first();
- $expense = $this->getRandomExpense();
- $euro = $this->getEuro();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $expense->id,
- 'tags' => ['a'],
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
- $tagFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn($tag);
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
-
- /**
- * Submit minimal array for a withdrawal.
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateWithdrawalNote(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $euro = $this->getEuro();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $expense->id,
- 'notes' => 'I am a note',
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $budgetRepos->shouldReceive('findBudget')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $this->assertCount(1, $first->notes()->get());
- $first->forceDelete();
- }
-
- /**
- * Submit array for a withdrawal.
- *
- * Include budget, category.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateWithdrawalMeta(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
- $euro = $this->getEuro();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'withdrawal',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'budget_id' => $budget->id,
- 'category_id' => $category->id,
- 'destination_id' => $expense->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'withdrawal'])->atLeast()->once()->andReturn($withdrawal);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$expense->id])->atLeast()->once()->andReturn($expense);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $budgetRepos->shouldReceive('findBudget')->withArgs([$budget->id, null])->atLeast()->once()->andReturn($budget);
- $catRepos->shouldReceive('findCategory')->withArgs([$category->id, null])->atLeast()->once()->andReturn($category);
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
- /**
- * Submit minimal array for a withdrawal.
- * Includes piggy bank data, but the piggy bank is invalid.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateTransferInvalidPiggie(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();
- $asset = $this->getRandomAsset();
- $otherAsset = $this->getRandomAsset($asset->id);
- $euro = $this->getEuro();
- $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'transfer',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $otherAsset->id,
- 'piggy_bank_id' => $piggy->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
- $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn(null);
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
-
- /**
- * Submit minimal array for a withdrawal.
- * Includes piggy bank data.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateTransfer(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();
- $asset = $this->getRandomAsset();
- $otherAsset = $this->getRandomAsset($asset->id);
- $euro = $this->getEuro();
- $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'transfer',
- 'amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $otherAsset->id,
- 'piggy_bank_id' => $piggy->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
- $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn($piggy);
- $eventFactory->shouldReceive('create')->atLeast()->once()->andReturn(new PiggyBankEvent);
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-
-
- /**
- * Submit minimal array for a withdrawal.
- * Includes piggy bank data.
- * Includes foreign amounts but foreign currency is missing or invalid.
- * Will be solved by getting users default currency.
- *
- * @covers \FireflyIII\Factory\TransactionJournalFactory
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testCreateTransferForeign(): void
- {
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
- $curRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $tagFactory = $this->mock(TagFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class);
- $eventFactory = $this->mock(PiggyBankEventFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
- $transactionFactory = $this->mock(TransactionFactory::class);
- $validator = $this->mock(AccountValidator::class);
-
- $validator->shouldReceive('setUser')->atLeast()->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue();
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue();
-
- // data
- $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first();
- $asset = $this->getRandomAsset();
- $otherAsset = $this->getRandomAsset($asset->id);
- $euro = $this->getEuro();
- $piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
- $submission = [
- 'transactions' => [
- [
- 'type' => 'transfer',
- 'amount' => '10',
- 'foreign_amount' => '10',
- 'description' => sprintf('I am a test #%d', $this->randomInt()),
- 'source_id' => $asset->id,
- 'destination_id' => $otherAsset->id,
- 'piggy_bank_id' => $piggy->id,
- ],
- ],
- ];
-
-
- // mock calls to all repositories
- $curRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
- $catRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $tagFactory->shouldReceive('setUser')->atLeast()->once();
- $transactionFactory->shouldReceive('setUser')->atLeast()->once();
-
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($euro);
-
- $transactionFactory->shouldReceive('setJournal')->atLeast()->once();
- $transactionFactory->shouldReceive('setAccount')->atLeast()->once();
- $transactionFactory->shouldReceive('setCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setForeignCurrency')->atLeast()->once();
- $transactionFactory->shouldReceive('setReconciled')->atLeast()->once();
- $transactionFactory->shouldReceive('createNegative')->atLeast()->once()->andReturn(new Transaction);
- $transactionFactory->shouldReceive('createPositive')->atLeast()->once()->andReturn(new Transaction);
-
- $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->atLeast()->once()->andReturn($transfer);
- $curRepos->shouldReceive('findCurrency')->atLeast()->once()->withArgs([0, null])->andReturn($euro);
- $curRepos->shouldReceive('findCurrencyNull')->atLeast()->once()->withArgs([0, null])->andReturnNull();
- $billRepos->shouldReceive('findBill')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->atLeast()->once()->andReturn($asset);
- $accountRepos->shouldReceive('findNull')->withArgs([$otherAsset->id])->atLeast()->once()->andReturn($otherAsset);
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro, null);
- $catRepos->shouldReceive('findCategory')->withArgs([0, null])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once();
- $piggyRepos->shouldReceive('findPiggyBank')->withArgs([$piggy->id, null])->atLeast()->once()->andReturn($piggy);
- $eventFactory->shouldReceive('create')->atLeast()->once()->andReturn(new PiggyBankEvent);
-
-
- /** @var TransactionJournalFactory $factory */
- $factory = app(TransactionJournalFactory::class);
- $factory->setUser($this->user());
-
- try {
- $collection = $factory->create($submission);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
-
- return;
- }
- $this->assertCount(1, $collection);
- /** @var TransactionJournal $first */
- $first = $collection->first();
- $this->assertEquals($first->description, $submission['transactions'][0]['description']);
- $first->forceDelete();
- }
-}
diff --git a/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php b/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php
deleted file mode 100644
index 2b63f389bc..0000000000
--- a/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php
+++ /dev/null
@@ -1,175 +0,0 @@
-<?php
-/**
- * TransactionJournalMetaFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-use Carbon\Carbon;
-use FireflyIII\Factory\TransactionJournalMetaFactory;
-use FireflyIII\Models\TransactionJournalMeta;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionJournalMetaFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionJournalMetaFactoryTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionJournalMetaFactory
- */
- public function testUpdateOrCreateBasic(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawal->transactionJournalMeta()->delete();
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => 'bye!',
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $result = $factory->updateOrCreate($set);
-
- $this->assertEquals(1, $withdrawal->transactionJournalMeta()->count());
- $this->assertEquals($set['data'], $result->data);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionJournalMetaFactory
- */
- public function testUpdateOrCreateDate(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawal->transactionJournalMeta()->delete();
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => new Carbon('2012-01-01'),
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $result = $factory->updateOrCreate($set);
-
- $this->assertEquals(1, $withdrawal->transactionJournalMeta()->count());
- $this->assertEquals($set['data']->toW3cString(), $result->data);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionJournalMetaFactory
- */
- public function testUpdateOrCreateDeleteExisting(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- TransactionJournalMeta::create(
- [
- 'transaction_journal_id' => $withdrawal->id,
- 'name' => 'hello',
- 'data' => 'bye!',
- ]
- );
- $count = $withdrawal->transactionJournalMeta()->count();
-
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => null,
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $factory->updateOrCreate($set);
-
- $this->assertEquals($count - 1, $withdrawal->transactionJournalMeta()->count());
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionJournalMetaFactory
- */
- public function testUpdateOrCreateEmpty(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawal->transactionJournalMeta()->delete();
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => '',
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $result = $factory->updateOrCreate($set);
-
- $this->assertEquals(0, $withdrawal->transactionJournalMeta()->count());
- $this->assertNull($result);
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionJournalMetaFactory
- */
- public function testUpdateOrCreateExistingEmpty(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawal->transactionJournalMeta()->delete();
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => 'SomeData',
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $result = $factory->updateOrCreate($set);
-
- $this->assertEquals(1, $withdrawal->transactionJournalMeta()->count());
- $this->assertNotNull($result);
-
- // overrule with empty entry:
- $set = [
- 'journal' => $withdrawal,
- 'name' => 'hello',
- 'data' => '',
- ];
- /** @var TransactionJournalMetaFactory $factory */
- $factory = app(TransactionJournalMetaFactory::class);
- $result = $factory->updateOrCreate($set);
-
- $this->assertEquals(0, $withdrawal->transactionJournalMeta()->count());
- $this->assertNull($result);
-
- }
-
-
-}
diff --git a/tests/Unit/Factory/TransactionTypeFactoryTest.php b/tests/Unit/Factory/TransactionTypeFactoryTest.php
deleted file mode 100644
index 18ba3e6a95..0000000000
--- a/tests/Unit/Factory/TransactionTypeFactoryTest.php
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-/**
- * TransactionTypeFactoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Factory;
-
-
-use FireflyIII\Factory\TransactionTypeFactory;
-use FireflyIII\Models\TransactionType;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class TransactionTypeFactoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionTypeFactoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Factory\TransactionTypeFactory
- */
- public function testFind(): void
- {
- /** @var TransactionType $type */
- $type = TransactionType::first();
- /** @var TransactionTypeFactory $factory */
- $factory = app(TransactionTypeFactory::class);
-
- $result = $factory->find($type->type);
-
- $this->assertEquals($result->id, $type->id);
- }
-
-}
diff --git a/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php b/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php
deleted file mode 100644
index 7631ae366c..0000000000
--- a/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php
+++ /dev/null
@@ -1,204 +0,0 @@
-<?php
-/**
- * ChartJsGeneratorTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Generator\Chart\Basic;
-
-use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class ChartJsGeneratorTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ChartJsGeneratorTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testBasic(): void
- {
-
- $data = [
- [
- 'label' => 'Today',
- 'fill' => '#abcdef',
- 'yAxisID' => 'a',
- 'entries' => [
- 'one' => 1,
- 'two' => 2,
- 'three' => 3,
- 'four' => 4,
- 'five' => 5,
- ],
- ],
- [
-
- 'currency_symbol' => 'X',
- 'backgroundColor' => '#123456',
- 'label' => 'Tomorrow',
- 'entries' => [
- 'one' => 6,
- 'two' => 7,
- 'three' => 8,
- 'four' => 9,
- 'five' => 10,
- ],
- ],
- ];
-
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
-
- $result = $generator->multiSet($data);
- $this->assertEquals('one', $result['labels'][0]);
- $this->assertEquals(2, $result['count']);
- $this->assertCount(2, $result['datasets']);
-
- $this->assertEquals('a', $result['datasets'][0]['yAxisID']);
- $this->assertEquals('#abcdef', $result['datasets'][0]['fill']);
-
- $this->assertEquals('X', $result['datasets'][1]['currency_symbol']);
- $this->assertEquals('#123456', $result['datasets'][1]['backgroundColor']);
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testMultiCurrencyPieChart(): void
- {
-
- $data = [
- 'one' => ['amount' => -1, 'currency_symbol' => 'a'],
- 'two' => ['amount' => -2, 'currency_symbol' => 'b'],
- 'three' => ['amount' => -3, 'currency_symbol' => 'c'],
- ];
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
- $result = $generator->multiCurrencyPieChart($data);
-
- $this->assertEquals('three', $result['labels'][0]);
- $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
-
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testMultiCurrencyPieChartPositive(): void
- {
-
- $data = [
- 'one' => ['amount' => 1, 'currency_symbol' => 'a'],
- 'two' => ['amount' => 2, 'currency_symbol' => 'b'],
- 'three' => ['amount' => 3, 'currency_symbol' => 'c'],
- ];
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
- $result = $generator->multiCurrencyPieChart($data);
-
- $this->assertEquals('three', $result['labels'][0]);
- $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
-
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testPieChart(): void
- {
-
- $data = [
- 'one' => -1,
- 'two' => -2,
- 'three' => -3,
- ];
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
- $result = $generator->pieChart($data);
-
- $this->assertEquals('three', $result['labels'][0]);
- $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
-
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testPieChartReversed(): void
- {
-
- $data = [
- 'one' => 1,
- 'two' => 2,
- 'three' => 3,
- ];
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
- $result = $generator->pieChart($data);
-
- $this->assertEquals('three', $result['labels'][0]);
- $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
-
- }
-
- /**
- * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
- */
- public function testSingleSet(): void
- {
- $data = [
- 'one' => '1',
- 'two' => '2',
- 'three' => '3',
- ];
-
- /** @var ChartJsGenerator $generator */
- $generator = app(ChartJsGenerator::class);
- $result = $generator->singleSet('Some label', $data);
-
- $this->assertEquals('one', $result['labels'][0]);
- $this->assertEquals(1.0, $result['datasets'][0]['data'][0]);
- }
-
-}
diff --git a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php b/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php
deleted file mode 100644
index 6f8f94f131..0000000000
--- a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * MonthReportGeneratorTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Generator\Report\Audit;
-
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Generator\Report\Audit\MonthReportGenerator;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Steam;
-use Tests\TestCase;
-
-/**
- *
- * Class MonthReportGeneratorTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MonthReportGeneratorTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
- */
- public function testGetAuditReport(): void
- {
- $asset = $this->getRandomAsset();
- $date = new Carbon;
- $start = Carbon::now()->startOfMonth();
- $end = Carbon::now()->endOfMonth();
- $collection = new Collection([$asset]);
- $euro = $this->getEuro();
- $dollar = $this->getDollar();
- $return = [
- [
- 'description' => 'Hello',
- 'amount' => '10',
- 'foreign_currency_id' => null,
- 'currency_id' => $euro->id,
- 'source_id' => $asset->id,
- 'source_name' => $asset->name,
- 'transaction_journal_id' => 1,
- 'destination_account_id' => 8,
- ],
- [
- 'description' => 'Hello2',
- 'amount' => '10',
- 'foreign_amount' => '10',
- 'foreign_currency_id' => $euro->id,
- 'currency_id' => $dollar->id,
- 'source_id' => $asset->id,
- 'source_name' => $asset->name,
- 'transaction_journal_id' => 1,
- 'destination_account_id' => 8,
-
- ],
- ];
-
- /** @var MonthReportGenerator $generator */
- $generator = app(MonthReportGenerator::class);
-
- $generator->setStartDate($start);
- $generator->setEndDate($end);
- $generator->setAccounts($collection);
-
- // mock stuff
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $collector = $this->mock(GroupCollectorInterface::class);
-
- // mock calls
- Steam::shouldReceive('balance')->times(2)->andReturn('100');
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
-
- // mock collector:
- $collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBillInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($return);
- //$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
-
- try {
- $result = $generator->getAuditReport($asset, $date);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result['exists']);
- $this->assertEquals('100', $result['endBalance']);
- }
-}
diff --git a/tests/Unit/Handlers/Events/APIEventHandlerTest.php b/tests/Unit/Handlers/Events/APIEventHandlerTest.php
deleted file mode 100644
index 0c2ab475a8..0000000000
--- a/tests/Unit/Handlers/Events/APIEventHandlerTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-/**
- * APIEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-
-use FireflyIII\Handlers\Events\APIEventHandler;
-use FireflyIII\Mail\AccessTokenCreatedMail;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Facades\Mail;
-use Laravel\Passport\Events\AccessTokenCreated;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class APIEventHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class APIEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\APIEventHandler
- */
- public function testAccessTokenCreated(): void
- {
- Mail::fake();
- // mock objects.
- $repository = $this->mock(UserRepositoryInterface::class);
-
- // mock calls.
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($this->user())->once();
-
-
- $event = new AccessTokenCreated('1', '1', '1');
- $handler = new APIEventHandler;
- $handler->accessTokenCreated($event);
-
- // assert a message was sent.
- Mail::assertSent(
- AccessTokenCreatedMail::class, function ($mail) {
- return $mail->hasTo('[email protected]') && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
- }
-
-}
diff --git a/tests/Unit/Handlers/Events/AdminEventHandlerTest.php b/tests/Unit/Handlers/Events/AdminEventHandlerTest.php
deleted file mode 100644
index 4e83e60f88..0000000000
--- a/tests/Unit/Handlers/Events/AdminEventHandlerTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * AdminEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-
-use FireflyIII\Events\AdminRequestedTestMessage;
-use FireflyIII\Handlers\Events\AdminEventHandler;
-use FireflyIII\Mail\AdminTestMail;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Facades\Mail;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class AdminEventHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AdminEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Handlers\Events\AdminEventHandler
- * @covers \FireflyIII\Events\AdminRequestedTestMessage
- */
- public function testSendNoMessage(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $event = new AdminRequestedTestMessage($this->user(), '127.0.0.1');
-
-
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false)->once();
-
- $listener = new AdminEventHandler();
- $this->assertTrue($listener->sendTestMessage($event));
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\AdminEventHandler
- * @covers \FireflyIII\Events\AdminRequestedTestMessage
- */
- public function testSendTestMessage(): void
- {
- Mail::fake();
- $repository = $this->mock(UserRepositoryInterface::class);
- $event = new AdminRequestedTestMessage($this->user(), '127.0.0.1');
-
-
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->once();
-
- $listener = new AdminEventHandler();
- $this->assertTrue($listener->sendTestMessage($event));
-
- // assert a message was sent.
- Mail::assertSent(
- AdminTestMail::class, function ($mail) {
- return $mail->hasTo('[email protected]') && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
-
- }
-}
diff --git a/tests/Unit/Handlers/Events/AutomationHandlerTest.php b/tests/Unit/Handlers/Events/AutomationHandlerTest.php
deleted file mode 100644
index 90d3af6016..0000000000
--- a/tests/Unit/Handlers/Events/AutomationHandlerTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * AutomationHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-
-use FireflyIII\Events\RequestedReportOnJournals;
-use FireflyIII\Handlers\Events\AutomationHandler;
-use FireflyIII\Mail\ReportNewJournalsMail;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Mail;
-use Log;
-use stdClass;
-use Tests\TestCase;
-
-/**
- *
- * Class AutomationHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AutomationHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Handlers\Events\AutomationHandler
- * @covers \FireflyIII\Events\RequestedReportOnJournals
- */
- public function testReportJournals(): void
- {
- Mail::fake();
- // mock repositories
- $repository = $this->mock(UserRepositoryInterface::class);
- $journals = new Collection;
- $journals->push(new stdClass);
-
- // mock calls.
- $repository->shouldReceive('findNull')->withArgs([1])->andReturn($this->user())->once();
-
- $event = new RequestedReportOnJournals(1, $journals);
- $handler = new AutomationHandler();
-
- $handler->reportJournals($event);
-
- // assert a message was sent.
- Mail::assertSent(
- ReportNewJournalsMail::class, function ($mail) {
- return $mail->hasTo('[email protected]') && '127.0.0.1' === $mail->ipAddress;
- }
- );
- }
-}
diff --git a/tests/Unit/Handlers/Events/StoredGroupEventHandlerTest.php b/tests/Unit/Handlers/Events/StoredGroupEventHandlerTest.php
deleted file mode 100644
index 1b71f71968..0000000000
--- a/tests/Unit/Handlers/Events/StoredGroupEventHandlerTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * StoredGroupEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-
-use FireflyIII\Events\StoredTransactionGroup;
-use FireflyIII\Handlers\Events\StoredGroupEventHandler;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class StoredGroupEventHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StoredGroupEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\StoredGroupEventHandler
- */
- public function testProcessRules(): void
- {
- $group = $this->getRandomWithdrawalGroup();
- $ruleEngine = $this->mock(RuleEngine::class);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setAllRules')->atLeast()->once()->withArgs([true]);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
- $ruleEngine->shouldReceive('processTransactionJournal')->atLeast()->once();
-
- $event = new StoredTransactionGroup($group, true);
- $handler = new StoredGroupEventHandler;
- $handler->processRules($event);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\StoredGroupEventHandler
- */
- public function testNoProcessRules(): void
- {
- $group = $this->getRandomWithdrawalGroup();
- $this->mock(RuleEngine::class);
-
- $event = new StoredTransactionGroup($group, false);
- $handler = new StoredGroupEventHandler;
- $handler->processRules($event);
- $this->assertTrue(true);
-
- }
-}
diff --git a/tests/Unit/Handlers/Events/UpdatedGroupEventHandlerTest.php b/tests/Unit/Handlers/Events/UpdatedGroupEventHandlerTest.php
deleted file mode 100644
index 27f785be5f..0000000000
--- a/tests/Unit/Handlers/Events/UpdatedGroupEventHandlerTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/**
- * UpdatedGroupEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-use FireflyIII\Events\UpdatedTransactionGroup;
-use FireflyIII\Handlers\Events\UpdatedGroupEventHandler;
-use FireflyIII\TransactionRules\Engine\RuleEngine;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class UpdatedJournalEventHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UpdatedGroupEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Handlers\Events\UpdatedGroupEventHandler
- */
- public function testProcessRules(): void
- {
- $group = $this->getRandomWithdrawalGroup();
- $ruleEngine = $this->mock(RuleEngine::class);
-
- $ruleEngine->shouldReceive('setUser')->atLeast()->once();
- $ruleEngine->shouldReceive('setAllRules')->atLeast()->once()->withArgs([true]);
- $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_UPDATE]);
- $ruleEngine->shouldReceive('processTransactionJournal')->atLeast()->once();
-
- $event = new UpdatedTransactionGroup($group);
- $handler = new UpdatedGroupEventHandler;
- $handler->processRules($event);
- }
-
-}
diff --git a/tests/Unit/Handlers/Events/UserEventHandlerTest.php b/tests/Unit/Handlers/Events/UserEventHandlerTest.php
deleted file mode 100644
index d94a50e13a..0000000000
--- a/tests/Unit/Handlers/Events/UserEventHandlerTest.php
+++ /dev/null
@@ -1,284 +0,0 @@
-<?php
-/**
- * UserEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-use FireflyIII\Events\RegisteredUser;
-use FireflyIII\Events\RequestedNewPassword;
-use FireflyIII\Events\UserChangedEmail;
-use FireflyIII\Handlers\Events\UserEventHandler;
-use FireflyIII\Mail\ConfirmEmailChangeMail;
-use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
-use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
-use FireflyIII\Mail\UndoEmailChangeMail;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Role;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Auth\Events\Login;
-use Illuminate\Support\Facades\Mail;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class UserEventHandlerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class UserEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- * @covers \FireflyIII\Events\RegisteredUser
- */
- public function testAttachUserRole(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->emptyUser();
- $event = new RegisteredUser($user, '127.0.0.1');
-
- $repository->shouldReceive('count')->andReturn(1)->once();
- $repository->shouldReceive('attachRole')->withArgs([$user, 'owner'])->andReturn(true)->once();
- $listener = new UserEventHandler();
- $listener->attachUserRole($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- */
- public function testCheckSingleUserIsAdminMulti(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->user();
- $event = new Login(null, $user, true);
- $listener = new UserEventHandler();
-
- // mock stuff
- $repository->shouldReceive('count')->once()->andReturn(2);
-
-
- $listener->checkSingleUserIsAdmin($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- */
- public function testCheckSingleUserIsAdminNoRole(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->emptyUser();
- $event = new Login(null, $user, true);
- $listener = new UserEventHandler();
-
- // mock stuff
-
- $repository->shouldReceive('hasRole')->once()->andReturn(false);
- $repository->shouldReceive('count')->once()->andReturn(1);
- $repository->shouldReceive('getRole')->once()->andReturn(null);
- $repository->shouldReceive('attachRole')->once()->withArgs([Mockery::any(), 'owner']);
- $repository->shouldReceive('createRole')->once()->withArgs(['owner', 'Site Owner', 'User runs this instance of FF3'])->andReturn(new Role);
- Log::warning('The following error is part of a test.');
- $listener->checkSingleUserIsAdmin($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- */
- public function testCheckSingleUserIsAdminNotAdmin(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->emptyUser();
- $event = new Login(null, $user, true);
- $listener = new UserEventHandler();
-
- // mock stuff
- $repository->shouldReceive('hasRole')->once()->andReturn(false);
- $repository->shouldReceive('count')->once()->andReturn(1);
- $repository->shouldReceive('getRole')->once()->andReturn(new Role);
- $repository->shouldReceive('attachRole')->once()->withArgs([Mockery::any(), 'owner']);
-
- $listener->checkSingleUserIsAdmin($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- */
- public function testCheckSingleUserIsAdminSingle(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->user();
- $event = new Login(null, $user, true);
- $listener = new UserEventHandler();
-
- // mock stuff
- $repository->shouldReceive('hasRole')->once()->andReturn(true);
- $repository->shouldReceive('count')->once()->andReturn(1);
-
- $listener->checkSingleUserIsAdmin($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- */
- public function testDemoUserBackToEnglish(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $user = $this->emptyUser();
- $event = new Login(null, $user, true);
- $listener = new UserEventHandler();
-
- // mock stuff
- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(true);
-
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->once();
- Preferences::shouldReceive('mark')->once();
-
- $listener->demoUserBackToEnglish($event);
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- * @covers \FireflyIII\Events\UserChangedEmail
- */
- public function testSendEmailChangeConfirmMail(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Mail::fake();
-
- $tokenPref = new Preference;
- $tokenPref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_confirm_token', 'invalid'])->andReturn($tokenPref);
-
- $user = $this->emptyUser();
- $event = new UserChangedEmail($user, 'new@new', 'old@old', '127.0.0.1');
- $listener = new UserEventHandler;
- $listener->sendEmailChangeConfirmMail($event);
-
- // must send user an email:
-
- Mail::assertSent(
- ConfirmEmailChangeMail::class, function ($mail) {
- return $mail->hasTo('new@new') && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- * @covers \FireflyIII\Events\UserChangedEmail
- */
- public function testSendEmailChangeUndoMail(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Mail::fake();
-
- $tokenPref = new Preference;
- $tokenPref->data = 'token';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_undo_token', 'invalid'])->andReturn($tokenPref);
-
- $user = $this->emptyUser();
- $event = new UserChangedEmail($user, 'new@new', 'old@old', '127.0.0.1');
- $listener = new UserEventHandler;
- $listener->sendEmailChangeUndoMail($event);
-
- Mail::assertSent(
- UndoEmailChangeMail::class, function ($mail) {
- return $mail->hasTo('old@old') && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
- $this->assertTrue(true);
- }
-
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- * @covers \FireflyIII\Events\RequestedNewPassword
- */
- public function testSendNewPassword(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Mail::fake();
- $user = $this->emptyUser();
- $event = new RequestedNewPassword($user, 'token', '127.0.0.1');
- $listener = new UserEventHandler;
- $listener->sendNewPassword($event);
-
- // must send user an email:
-
- Mail::assertSent(
- RequestedNewPasswordMail::class, function ($mail) use ($user) {
- return $mail->hasTo($user->email) && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
- $this->assertTrue(true);
- }
-
- /**
- * @covers \FireflyIII\Handlers\Events\UserEventHandler
- * @covers \FireflyIII\Events\RegisteredUser
- */
- public function testSendRegistrationMail(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Mail::fake();
- $user = $this->emptyUser();
- $event = new RegisteredUser($user, '127.0.0.1');
- //config('firefly.send_registration_mail', true);
- \Config::set('firefly.send_registration_mail', true);
- $listener = new UserEventHandler;
- $listener->sendRegistrationMail($event);
-
- // must send user an email:
- Mail::assertSent(
- RegisteredUserMail::class, function ($mail) use ($user) {
- return $mail->hasTo($user->email) && '127.0.0.1' === $mail->ipAddress;
- }
- );
-
- $this->assertTrue(true);
- }
-}
diff --git a/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php b/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php
deleted file mode 100644
index 22cda3ffd5..0000000000
--- a/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php
+++ /dev/null
@@ -1,257 +0,0 @@
-<?php
-/**
- * VersionCheckEventHandlerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Handlers\Events;
-
-
-use FireflyConfig;
-use FireflyIII\Events\RequestedVersionCheckStatus;
-use FireflyIII\Handlers\Events\VersionCheckEventHandler;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Services\Github\Object\Release;
-use FireflyIII\Services\Github\Request\UpdateRequest;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class VersionCheckEventHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class VersionCheckEventHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesError(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = 1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 604810;
-
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
-
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
-
- $event = new RequestedVersionCheckStatus($this->user());
- $request = $this->mock(UpdateRequest::class);
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(true)->once();
-
- // report on config variables:
- FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- // request thing:
- //$request->shouldReceive('call')->once()->andThrow(new FireflyException('Errrr'));
- //$request->shouldNotReceive('getReleases');
-
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesNewer(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = 1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 604800;
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
- $event = new RequestedVersionCheckStatus($this->user());
- $request = $this->mock(UpdateRequest::class);
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(true)->once();
-
- // is newer than default return:
- $version = config('firefly.version');
- $first = new Release(['id' => '1', 'title' => $version . '.1', 'updated' => '2017-05-01', 'content' => '']);
- // report on config variables:
- FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- // request thing:
- //$request->shouldReceive('call')->once();
- //$request->shouldReceive('getReleases')->once()->andReturn([$first]);
-
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesSameVersion(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = 1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 604800;
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
-
- $event = new RequestedVersionCheckStatus($this->user());
- $request = $this->mock(UpdateRequest::class);
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(true)->once();
-
- // is newer than default return:
- $version = config('firefly.version');
- $first = new Release(['id' => '1', 'title' => $version, 'updated' => '2017-05-01', 'content' => '']);
- // report on config variables:
- FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- // request thing:
- //$request->shouldReceive('call')->once();
- //$request->shouldReceive('getReleases')->once()->andReturn([$first]);
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesNoAdmin(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = 1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 604800;
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
-
- $event = new RequestedVersionCheckStatus($this->user());
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(false)->once();
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesNoPermission(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = -1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 604800;
- $channelConfig = new Configuration;
- $channelConfig->data = 'stable';
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
- $event = new RequestedVersionCheckStatus($this->user());
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(true)->once();
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- // report on config variables:
- FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
- /**
- * @covers \FireflyIII\Events\RequestedVersionCheckStatus
- * @covers \FireflyIII\Handlers\Events\VersionCheckEventHandler
- * @covers \FireflyIII\Helpers\Update\UpdateTrait
- */
- public function testCheckForUpdatesTooRecent(): void
- {
- $updateConfig = new Configuration;
- $updateConfig->data = 1;
- $checkConfig = new Configuration;
- $checkConfig->data = time() - 800;
- $permissionConfig = new Configuration;
- $permissionConfig->data = 1;
-
-
- $event = new RequestedVersionCheckStatus($this->user());
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('hasRole')->andReturn(true)->once();
-
- // report on config variables:
- FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
- FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($permissionConfig);
-
- $handler = new VersionCheckEventHandler;
- $handler->checkForUpdates($event);
- }
-
-}
diff --git a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php
deleted file mode 100644
index 8cf541f693..0000000000
--- a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php
+++ /dev/null
@@ -1,210 +0,0 @@
-<?php
-/**
- * AttachmentHelperTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Helpers\Attachments;
-
-use FireflyIII\Helpers\Attachments\AttachmentHelper;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\TransactionJournal;
-use Illuminate\Http\UploadedFile;
-use Illuminate\Support\Facades\Storage;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AttachmentHelperTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class AttachmentHelperTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test invalid mime thing
- *
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testInvalidMime(): void
- {
- $journal = TransactionJournal::first();
- $helper = new AttachmentHelper;
- $path = resource_path('stubs/binary.bin');
- $file = new UploadedFile($path, 'binary.bin', 'application/octet-stream', filesize($path), null, true);
-
- Log::warning('The following error is part of a test.');
- $helper->saveAttachmentsForModel($journal, [$file]);
- $errors = $helper->getErrors();
- $messages = $helper->getMessages();
-
- $this->assertCount(1, $errors);
- $this->assertCount(0, $messages);
- $this->assertEquals('File "binary.bin" is of type "application/octet-stream" which is not accepted as a new upload.', $errors->first());
- }
-
- /**
- * Test valid file upload.
- *
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testSave(): void
- {
- Storage::fake('upload');
-
- $journal = TransactionJournal::first();
- $helper = new AttachmentHelper;
- $path = public_path('apple-touch-icon.png');
- $file = new UploadedFile($path, 'apple-touch-icon.png', 'image/png', filesize($path), null, true);
-
- $helper->saveAttachmentsForModel($journal, [$file]);
- $errors = $helper->getErrors();
- $messages = $helper->getMessages();
- $attachments = $helper->getAttachments();
-
- $this->assertCount(0, $errors);
- $this->assertCount(1, $messages);
- $this->assertEquals('Successfully uploaded file "apple-touch-icon.png".', $messages->first());
-
- // Assert the file was stored...
- Storage::disk('upload')->assertExists(sprintf('at-%d.data', $attachments->first()->id));
- }
-
- /**
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testSaveAttachmentFromApi(): void
- {
- // mock calls:
- Storage::fake('upload');
-
- $path = public_path('apple-touch-icon.png');
- $helper = new AttachmentHelper;
-
- // make new attachment:
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $attachment = Attachment::create(
- [
- 'attachable_id' => $journal->id,
- 'user_id' => $this->user()->id,
- 'attachable_type' => TransactionJournal::class,
- 'md5' => md5('Hello' . $this->randomInt()),
- 'filename' => 'file.txt',
- 'title' => 'Some title',
- 'description' => 'Some descr',
- 'mime' => 'text/plain',
- 'size' => 30,
- 'uploaded' => true,
- ]
- );
-
- // call helper
- $result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
-
- $this->assertTrue($result);
-
- }
-
- /**
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testSaveAttachmentFromApiBadMime(): void
- {
- // mock calls:
- Storage::fake('upload');
-
- $path = public_path('browserconfig.xml');
- $helper = new AttachmentHelper;
-
- // make new attachment:
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $attachment = Attachment::create(
- [
- 'attachable_id' => $journal->id,
- 'user_id' => $this->user()->id,
- 'attachable_type' => TransactionJournal::class,
- 'md5' => md5('Hello' . $this->randomInt()),
- 'filename' => 'file.txt',
- 'title' => 'Some title',
- 'description' => 'Some descr',
- 'mime' => 'text/plain',
- 'size' => 30,
- 'uploaded' => true,
- ]
- );
-
- // call helper
- Log::warning('The following error is part of a test.');
- $result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
-
- $this->assertFalse($result);
-
- }
-
- /**
- * Test double file upload. Needs to be after testSave.
- *
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testSaveEmpty(): void
- {
- $journal = TransactionJournal::first();
- $helper = new AttachmentHelper;
-
- $res = $helper->saveAttachmentsForModel($journal, null);
- $this->assertTrue($res);
- }
-
-
- /**
- * Test double file upload. Needs to be after testSave.
- *
- * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
- */
- public function testSaveSecond(): void
- {
- $journal = TransactionJournal::first();
- $helper = new AttachmentHelper;
- $path = public_path('apple-touch-icon.png');
- $file = new UploadedFile($path, 'apple-touch-icon.png', 'image/png', filesize($path), null, true);
-
- Log::warning('The following error is part of a test.');
- $helper->saveAttachmentsForModel($journal, [$file]);
- $errors = $helper->getErrors();
- $messages = $helper->getMessages();
-
- $this->assertCount(1, $errors);
- $this->assertCount(0, $messages);
- $this->assertEquals('Uploaded file "apple-touch-icon.png" is already attached to this object.', $errors->first());
- }
-}
diff --git a/tests/Unit/Helpers/Fiscal/FiscalHelperTest.php b/tests/Unit/Helpers/Fiscal/FiscalHelperTest.php
deleted file mode 100644
index 92ffda8c69..0000000000
--- a/tests/Unit/Helpers/Fiscal/FiscalHelperTest.php
+++ /dev/null
@@ -1,177 +0,0 @@
-<?php
-/**
- * FiscalHelperTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Helpers\Fiscal;
-
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Fiscal\FiscalHelper;
-use FireflyIII\Models\Preference;
-use Log;
-use Preferences;
-use Tests\TestCase;
-
-
-/**
- *
- * Class FiscalHelperTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FiscalHelperTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Fiscal year starts on April 1st.
- * Current date is June 6th.
- *
- * Fiscal year ends next year on Mar 31.
- *
- * @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
- */
- public function testEndOfFiscalYear(): void
- {
-
- $pref = new Preference;
- $pref->data = true;
-
- $datePref = new Preference;
- $datePref->data = '04-01';
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
- Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
-
- $helper = new FiscalHelper;
- $date = new Carbon('2018-06-06');
- $result = $helper->endOfFiscalYear($date);
- $this->assertEquals('2019-03-31', $result->format('Y-m-d'));
- }
-
- /**
- * No fiscal year
- * Current date is June 6th.
- *
- * Fiscal year ends next year on Dec 31.
- *
- * @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
- */
- public function testEndOfFiscalYearNoPref(): void
- {
-
- $pref = new Preference;
- $pref->data = false;
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
-
- $helper = new FiscalHelper;
- $date = new Carbon('2018-06-06');
- $result = $helper->endOfFiscalYear($date);
- $this->assertEquals('2018-12-31', $result->format('Y-m-d'));
- }
-
- /**
- * Fiscal year starts on April 1st.
- * Current date is June 6th.
- *
- * Fiscal year starts in current year.
- *
- * @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
- */
- public function testStartOfFiscalYear(): void
- {
-
- $pref = new Preference;
- $pref->data = true;
-
- $datePref = new Preference;
- $datePref->data = '04-01';
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
- Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
-
- $helper = new FiscalHelper;
- $date = new Carbon('2018-06-06');
- $result = $helper->startOfFiscalYear($date);
- $this->assertEquals('2018-04-01', $result->format('Y-m-d'));
- }
-
- /**
- * No fiscal year
- * Current date is June 6th.
- *
- * Fiscal year starts Jan 1st.
- *
- * @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
- */
- public function testStartOfFiscalYearNoPref(): void
- {
-
- $pref = new Preference;
- $pref->data = false;
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
-
- $helper = new FiscalHelper;
- $date = new Carbon('2018-06-06');
- $result = $helper->startOfFiscalYear($date);
- $this->assertEquals('2018-01-01', $result->format('Y-m-d'));
- }
-
- /**
- * Fiscal year starts on April 1st.
- * Current date is Feb 6th.
- *
- * Fiscal year starts in previous year.
- *
- * @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
- */
- public function testStartOfFiscalYearPrev(): void
- {
-
- $pref = new Preference;
- $pref->data = true;
-
- $datePref = new Preference;
- $datePref->data = '04-01';
-
- Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
- Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
-
- $helper = new FiscalHelper;
- $date = new Carbon('2018-02-06');
- $result = $helper->startOfFiscalYear($date);
- $this->assertEquals('2017-04-01', $result->format('Y-m-d'));
- }
-}
diff --git a/tests/Unit/Helpers/Help/HelpTest.php b/tests/Unit/Helpers/Help/HelpTest.php
deleted file mode 100644
index 0df003e213..0000000000
--- a/tests/Unit/Helpers/Help/HelpTest.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-/**
- * HelpTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Helpers\Help;
-
-
-use FireflyIII\Helpers\Help\Help;
-use GuzzleHttp\Client;
-use GuzzleHttp\Handler\MockHandler;
-use GuzzleHttp\HandlerStack;
-use GuzzleHttp\Psr7\Response;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class HelpTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HelpTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Helpers\Help\Help
- */
- public function testGetFromGitHub(): void
- {
- $headers = ['Content-Type' => 'application/json'];
- $response = new Response(200, $headers, 'Some help text.');
- $mock = new MockHandler([$response]);
-
- $handler = HandlerStack::create($mock);
- $client = new Client(['handler' => $handler]);
-
- //client instance is bound to the mock here.
- $this->app->instance(Client::class, $client);
-
-
- // now let's see what happens:
- $help = new Help;
- $result = $help->getFromGitHub('test-route', 'en_US');
- $this->assertEquals('<p>Some help text.</p>' . "\n", $result);
- }
-
- /**
- * @covers \FireflyIII\Helpers\Help\Help
- */
- public function testGetFromGitHubError(): void
- {
- $headers = ['Content-Type' => 'application/json'];
- $response = new Response(500, $headers, 'Big bad error.');
- $mock = new MockHandler([$response]);
-
- $handler = HandlerStack::create($mock);
- $client = new Client(['handler' => $handler]);
-
- //client instance is bound to the mock here.
- $this->app->instance(Client::class, $client);
-
- Log::warning('The following error is part of a test.');
- // now let's see what happens:
- $help = new Help;
- $result = $help->getFromGitHub('test-route', 'en_US');
- $this->assertEquals('', $result);
- }
-
-
-}
diff --git a/tests/Unit/Helpers/Report/NetWorthTest.php b/tests/Unit/Helpers/Report/NetWorthTest.php
deleted file mode 100644
index eaa3ba828a..0000000000
--- a/tests/Unit/Helpers/Report/NetWorthTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * NetWorthTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Helpers\Report;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Helpers\Report\NetWorth;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Steam;
-use Tests\TestCase;
-
-/**
- *
- * Class NetWorthTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NetWorthTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Helpers\Report\NetWorth
- */
- public function testGetNetWorthByCurrency(): void
- {
- // variables
- $accounts = $this->user()->accounts()->take(2)->where('account_type_id', 3)->get();
- $date = new Carbon('2018-01-01');
- $balanceInfo = [];
- foreach ($accounts as $account) {
- $balanceInfo[$account->id] = '100';
- }
-
- // mock repositories
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls to facades
- Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn($this->getEuro());
- Steam::shouldReceive('balancesByAccounts')->once()->withAnyArgs()->andReturn($balanceInfo);
-
- // mock other calls:
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset');
- $currencyRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->times(1);
-
-
- $helper = new NetWorth();
- $helper->setUser($this->user());
- $result = $helper->getNetWorthByCurrency($accounts, $date);
-
- $this->assertEquals(200, (int)$result[0]['balance']);
- }
-
- /**
- * @covers \FireflyIII\Helpers\Report\NetWorth
- */
- public function testGetNetWorthByCurrencyWithCC(): void
- {
- // variables
- $first = $this->user()->accounts()->take(1)->where('account_type_id', 3)->first();
- $second = $this->user()->accounts()->take(1)->where('account_type_id', 3)->where('id', '!=', $first->id)->first();
- $second->virtualBalance = '500';
- $date = new Carbon('2018-01-01');
- $balanceInfo = [];
- $balanceInfo[$first->id] = '100';
- $balanceInfo[$second->id] = '100';
-
- // mock repositories
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls to facades
- Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn($this->getEuro());
- Steam::shouldReceive('balancesByAccounts')->once()->withAnyArgs()->andReturn($balanceInfo);
-
- // mock other calls:
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset', 'ccAsset');
- $currencyRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->times(1);
-
-
- $helper = new NetWorth();
- $helper->setUser($this->user());
- $result = $helper->getNetWorthByCurrency(new Collection([$first, $second]), $date);
-
- $this->assertEquals(-300, (int)$result[0]['balance']);
- }
-}
diff --git a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php b/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
deleted file mode 100644
index b8012a1bcd..0000000000
--- a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
+++ /dev/null
@@ -1,602 +0,0 @@
-<?php
-/**
- * CreateRecurringTransactionsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Jobs;
-
-
-use Carbon\Carbon;
-use FireflyIII\Events\StoredTransactionGroup;
-use FireflyIII\Factory\PiggyBankEventFactory;
-use FireflyIII\Factory\PiggyBankFactory;
-use FireflyIII\Jobs\CreateRecurringTransactions;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Event;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateRecurringTransactionsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateRecurringTransactionsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Submit one, offer occurence for today.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testBadJournalCount(): void
- {
- Event::fake();
- $date = new Carbon();
-
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- // overrule some fields in the recurrence to make it seem it hasnt fired yet.
- $carbon = new Carbon;
- $carbon->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $carbon;
- $recurrence->save();
-
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
-
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $job = new CreateRecurringTransactions($date);
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
- }
-
- /**
- * Submit nothing.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testBasic(): void
- {
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
- $job->setForce(false);
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(0, $job->submitted);
-
- }
-
- /**
- * Submit one, offer occurence for today.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testForced(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Event::fake();
- $date = new Carbon();
- $this->expectsEvents([StoredTransactionGroup::class]);
-
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- // overrule some fields in the recurrence.
- $carbon = new Carbon;
- $carbon->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $carbon;
- $recurrence->save();
-
-
- $group = $this->getRandomWithdrawalGroup();
-
- // overrule some fields in the recurrence to make it seem it hasnt fired yet.
- $recurrence->latest_date = null;
- $recurrence->save();
-
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
-
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
- $recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- // return data:
- $recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- // store journal
- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- //Event::assertDispatched(StoredTransactionGroup::class);
-
- $job = new CreateRecurringTransactions($date);
- $job->setForce(true);
- $job->handle();
-
- $this->assertEquals(1, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
- }
-
- /**
- * Submit one, but offer no occurrences.
- *
- * TODO there is a random element in this test that breaks the test.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingle(): void
- {
- Event::fake();
- Log::info(sprintf('Now in test %s.', __METHOD__));
-
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- // mock classes
- $date = new Carbon;
- $date->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $date;
- $recurrence->save();
-
- Log::debug(sprintf('Test is going to use Recurrence #%d', $recurrence->id), $recurrence->toArray());
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
- }
-
- /**
- * Submit one, but has already fired today
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleFiredToday(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = new Carbon;
- $recurrence->save();
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
- $recurrence->latest_date = null;
- $recurrence->save();
- }
-
- /**
- * Submit one, but offer no occurrences.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleFuture(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $future = new Carbon;
- $future->addDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->first_date = $future;
- $recurrence->save();
-
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->first_date = $date;
- $recurrence->save();
- }
-
- /**
- * Submit one, but it's inactive.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleInactive(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $recurrence = $this->getRandomRecurrence();
-
- $recurrence->active = false;
- $recurrence->save();
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->active = true;
- $recurrence->save();
- }
-
- /**
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleNotToday(): void
- {
- Event::fake();
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $date = new Carbon();
- $tomorrow = new Carbon();
- $tomorrow->addDays(2);
-
- // overrule some fields in the recurrence to make it seem it hasnt fired yet.
- $carbon = new Carbon;
- $carbon->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $carbon;
- $recurrence->save();
-
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
-
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- $job = new CreateRecurringTransactions($date);
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- }
-
- /**
- * Submit one, but it has fired enough times already.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleOccurrences(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $recurrence = $this->getRandomRecurrence();
- $recurrence->repetitions = 1;
- $recurrence->save();
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(1);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->repetitions = 0;
- $recurrence->save();
- }
-
- /**
- * Submit one, but should no longer run.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleOverDue(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $date = new Carbon();
- $yesterday = clone $date;
- $yesterday->subDays(3);
- $recurrence = $this->getRandomRecurrence();
-
- $recurrence->repeat_until = $yesterday;
- $recurrence->save();
-
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->repeat_until = null;
- $recurrence->save();
- }
-
- /**
- * Submit one, offer occurence for today.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleToday(): void
- {
- Event::fake();
- $date = new Carbon();
- $this->expectsEvents([StoredTransactionGroup::class]);
-
- // mock classes
- $carbon = new Carbon;
- $carbon->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $carbon;
- $recurrence->save();
-
- $group = $this->getRandomWithdrawalGroup();
-
- // overrule some fields in the recurrence to make it seem it hasnt fired yet.
- $recurrence->latest_date = null;
- $recurrence->save();
-
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
-
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- $recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- // return data:
- $recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- // store journal
- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- //Event::assertDispatched(StoredTransactionGroup::class);
-
- $job = new CreateRecurringTransactions($date);
- $job->handle();
-
- $this->assertEquals(1, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
- }
-
- /**
- * Submit one, offer occurence for today, with piggy
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleTodayPiggy(): void
- {
- Event::fake();
- $date = new Carbon();
- $this->expectsEvents([StoredTransactionGroup::class]);
-
-
- $group = $this->getRandomWithdrawalGroup();
- $piggy = $this->getRandomPiggyBank();
-
- // overrule some fields in the recurrence to make it seem it hasnt fired yet.
- $carbon = new Carbon;
- $carbon->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $carbon;
- $recurrence->save();
-
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
-
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- $recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturn($piggy->id);
- //$piggyEventFactory->shouldReceive('create')->once();
- Preferences::shouldReceive('mark')->atLeast()->once();
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'lastActivity', Mockery::any()])->atLeast()->once();
-
- // return data:
- $recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
- $recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- // store journal
- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
-
- //Event::assertDispatched(StoredTransactionGroup::class);
-
- $job = new CreateRecurringTransactions($date);
- $job->handle();
-
- $this->assertEquals(1, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- }
-}
diff --git a/tests/Unit/Middleware/AuthenticateTest.php b/tests/Unit/Middleware/AuthenticateTest.php
deleted file mode 100644
index a30d546b39..0000000000
--- a/tests/Unit/Middleware/AuthenticateTest.php
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
- * AuthenticateTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use Log;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class AuthenticateTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AuthenticateTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware('auth')->any(
- '/_test/authenticate', function () {
- return 'OK';
- }
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Authenticate
- */
- public function testMiddleware(): void
- {
- Log::debug('Now at testMiddleware');
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertRedirect(route('login'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Authenticate
- */
- public function testMiddlewareAjax(): void
- {
- Log::debug('Now at testMiddlewareAjax');
- $server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
- $response = $this->get('/_test/authenticate', $server);
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Authenticate
- */
- public function testMiddlewareAuth(): void
- {
- Log::debug('Now at testMiddlewareAuth');
- $this->be($this->user());
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Authenticate
- */
- public function testMiddlewareBlockedUser(): void
- {
- Log::debug('Now at testMiddlewareBlockedUser');
- $user = $this->user();
- $user->blocked = 1;
-
- $this->be($user);
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertSessionHas('logoutMessage', (string)trans('firefly.block_account_logout'));
- $response->assertRedirect(route('login'));
-
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Authenticate
- */
- public function testMiddlewareEmail(): void
- {
- Log::debug('Now at testMiddlewareEmail');
- $user = $this->user();
- $user->blocked = 1;
- $user->blocked_code = 'email_changed';
- $this->be($user);
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertSessionHas('logoutMessage', (string)trans('firefly.email_changed_logout'));
- $response->assertRedirect(route('login'));
- }
-}
diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.php
deleted file mode 100644
index 465a649be4..0000000000
--- a/tests/Unit/Middleware/BinderTest.php
+++ /dev/null
@@ -1,1781 +0,0 @@
-<?php
-/**
- * BinderTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-
-use Carbon\Carbon;
-use FireflyIII\Helpers\Collector\GroupCollectorInterface;
-use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Http\Middleware\Binder;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\AvailableBudget;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\Recurrence;
-use FireflyIII\Models\Tag;
-use FireflyIII\Models\TransactionGroup;
-use FireflyIII\Repositories\Tag\TagRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Preferences;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-
-/**
- * Class BinderTest
- * Per object: works, not existing, not logged in + existing
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.TooManyMethods)
- * @SuppressWarnings(PHPMD.ExcessiveClassLength)
- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
- */
-class BinderTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Account
- */
- public function testAccount(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{account}', function () {
- return 'OK';
- }
- );
- Log::info(sprintf('Now in %s.', get_class($this)));
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\AccountList
- */
- public function testAccountList(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{accountList}', function (Collection $accounts) {
- return 'count: ' . $accounts->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/1,2');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 2');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\AccountList
- */
- public function testAccountListAllAssets(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{accountList}', function (Collection $accounts) {
- return 'count: ' . $accounts->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/allAssetAccounts');
- $count = $this->user()->accounts()
- ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
- ->where('account_types.type', AccountType::ASSET)
- ->orderBy('accounts.name', 'ASC')
- ->count();
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee(sprintf('count: %d', $count));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\AccountList
- */
- public function testAccountListEmpty(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{accountList}', static function (Collection $accounts) {
- return 'count: ' . $accounts->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\AccountList
- */
- public function testAccountListInvalid(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{accountList}', function (Collection $accounts) {
- return 'count: ' . $accounts->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/0,1,2');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 2');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\AccountList
- */
- public function testAccountListNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{accountList}', function (Collection $accounts) {
- return 'count: ' . $accounts->count();
- }
- );
- $response = $this->get('/_test/binder/1,2');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Account
- */
- public function testAccountNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{account}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Account
- */
- public function testAccountNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{account}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Attachment
- */
- public function testAttachment(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{attachment}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Attachment
- */
- public function testAttachmentNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{attachment}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Attachment
- */
- public function testAttachmentNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{attachment}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\AvailableBudget
- */
- public function testAvailableBudget(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {
- return $availableBudget->id ?? 0;
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\AvailableBudget
- */
- public function testAvailableBudgetNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {
- return $availableBudget->id ?? 0;
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Bill
- */
- public function testBill(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{bill}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Bill
- */
- public function testBillNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{bill}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Bill
- */
- public function testBillNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{bill}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Budget
- */
- public function testBudget(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budget}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\BudgetLimit
- */
- public function testBudgetLimit(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetLimit}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\BudgetLimit
- */
- public function testBudgetLimitNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetLimit}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\BudgetLimit
- */
- public function testBudgetLimitNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetLimit}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\BudgetList
- */
- public function testBudgetList(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetList}', function (Collection $budgets) {
- return 'count: ' . $budgets->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/0,1,2');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 3');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\BudgetList
- */
- public function testBudgetListEmpty(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetList}', function (Collection $budgets) {
- return 'count: ' . $budgets->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\BudgetList
- */
- public function testBudgetListInvalid(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budgetList}', function (Collection $budgets) {
- return 'count: ' . $budgets->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Budget
- */
- public function testBudgetNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budget}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Budget
- */
- public function testBudgetNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budget}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CLIToken
- */
- public function testCLIToken(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
-
- $token = new Preference;
- $token->data = 'token';
-
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{cliToken}', static function (string $token) {
- return sprintf('token: %s', $token);
- }
- );
-
- $response = $this->get('/_test/binder/token');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('token');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CLIToken
- */
- public function testCLITokenNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $repos = $this->mock(UserRepositoryInterface::class);
- $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
-
- $token = new Preference;
- $token->data = 'token';
-
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{cliToken}', static function (string $token) {
- return sprintf('token: %s', $token);
- }
- );
-
- $response = $this->get('/_test/binder/tokenX');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Category
- */
- public function testCategory(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{category}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CategoryList
- */
- public function testCategoryList(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{categoryList}', function (Collection $categories) {
- return 'count: ' . $categories->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/0,1,2');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 3');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CategoryList
- */
- public function testCategoryListInvalid(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{categoryList}', function (Collection $categories) {
- return 'count: ' . $categories->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Category
- */
- public function testCategoryNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{category}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Category
- */
- public function testCategoryNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{category}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\ConfigurationName
- */
- public function testConfigName(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{configName}', static function (string $name) {
- return sprintf('configName: %s', $name);
- }
- );
-
- $response = $this->get('/_test/binder/is_demo_site');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('is_demo_site');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\ConfigurationName
- */
- public function testConfigNameNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{configName}', static function (string $name) {
- return sprintf('configName: %s', $name);
- }
- );
-
- $response = $this->get('/_test/binder/is_demoX_site');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CurrencyCode
- */
- public function testCurrencyCode(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{fromCurrencyCode}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/USD');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CurrencyCode
- */
- public function testCurrencyCodeNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{fromCurrencyCode}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/ABC');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\CurrencyCode
- */
- public function testCurrencyCodeNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{fromCurrencyCode}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/EUR');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDate(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
-
- // mock fiscal helper:
-
- $helper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/20170917');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: 2017-09-17');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateCurrentMonthEnd(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- Log::debug(sprintf('Received in function: "%s"', $date->format('Y-m-d')));
-
- return 'date: ' . $date->format('Y-m-d');
- }
- );
- $date = new Carbon;
- $date->endOfMonth();
- $testDate = clone $date;
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentMonthEnd');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateCurrentMonthStart(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
- $date = new Carbon;
- $date->startOfMonth();
- $testDate = clone $date;
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentMonthStart');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateCurrentYearEnd(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
- $date = new Carbon;
- $date->endOfYear();
- $testDate = clone $date;
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentYearEnd');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateCurrentYearStart(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- $date = new Carbon;
- $date->startOfYear();
- $testDate = clone $date;
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentYearStart');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateFiscalYearEnd(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
-
- $date = new Carbon;
- $date->endOfYear();
- $testDate = clone $date;
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($testDate)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentFiscalYearEnd');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateFiscalYearStart(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
-
- $date = new Carbon;
- $date->startOfYear();
- $testDate = clone $date;
-
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($testDate)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/currentFiscalYearStart');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('date: ' . $testDate->format('Y-m-d'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\Date
- */
- public function testDateInvalid(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{date}', function (Carbon $date) {
- return 'date: ' . $date->format('Y-m-d');
- }
- );
- $date = new Carbon;
- // mock fiscal helper:
- $helper = $this->mock(FiscalHelperInterface::class);
- $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once();
- $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/fakedate');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\JournalList
- */
- public function testJournalList(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalList}', static function (array $journals) {
- return 'count: ' . count($journals);
- }
- );
- $withdrawalArray = $this->getRandomWithdrawalAsArray();
- $collector = $this->mock(GroupCollectorInterface::class);
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($withdrawalArray);
-
- $this->be($this->user());
- $withdrawal = $this->getRandomWithdrawal();
- $deposit = $this->getRandomDeposit();
- $response = $this->get(sprintf('/_test/binder/%d,%d', $withdrawal->id, $deposit->id));
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 2');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\JournalList
- */
- public function testJournalListEmpty(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalList}', static function (array $journals) {
- return 'count: ' . count($journals);
- }
- );
-
- $collector = $this->mock(GroupCollectorInterface::class);
- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();
- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([]);
-
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * Not logged in.
- *
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\JournalList
- */
- public function testJournalListNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalList}', static function (array $journals) {
- return 'count: ' . count($journals);
- }
- );
-
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\LinkType
- */
- public function testLinkType(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{linkType}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\LinkType
- */
- public function testLinkTypeNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{linkType}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\LinkType
- */
- public function testLinkTypeNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{linkType}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\PiggyBank
- */
- public function testPiggyBank(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{piggyBank}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\PiggyBank
- */
- public function testPiggyBankNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{piggyBank}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\PiggyBank
- */
- public function testPiggyBankNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{piggyBank}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Preference
- */
- public function testPreference(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{preference}', static function (?Preference $preference) {
- return $preference->name ?? 'unknown';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/frontPageAccounts');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('frontPageAccounts');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Preference
- */
- public function testPreferenceNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{preference}', static function (?Preference $preference) {
- return $preference->name ?? 'unknown';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/frontPageAccountsX');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Recurrence
- */
- public function testRecurrence(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
- return $recurrence->description ?? 'unknown';
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Recurrence
- */
- public function testRecurrenceNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
- return $recurrence->description ?? 'unknown';
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Rule
- */
- public function testRule(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{rule}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\RuleGroup
- */
- public function testRuleGroup(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{ruleGroup}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\RuleGroup
- */
- public function testRuleGroupNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{ruleGroup}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\RuleGroup
- */
- public function testRuleGroupNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{ruleGroup}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Rule
- */
- public function testRuleNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{rule}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Rule
- */
- public function testRuleNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{rule}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournal
- */
- public function testTJ(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tj}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournal
- */
- public function testTJNotFound(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tj}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournal
- */
- public function testTJNotLoggedIn(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tj}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Tag
- */
- public function testTag(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tag}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagList
- */
- public function testTagList(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tagRepos->shouldReceive('setUser');
- $tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
- $tagRepos->shouldReceive('get')->once()->andReturn($tags);
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagList}', function (Collection $tags) {
- return 'count: ' . $tags->count();
- }
- );
-
- $names = implode(',', $tags->pluck('tag')->toArray());
-
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/' . $names);
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 2');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagList
- */
- public function testTagListEmpty(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->once()->andReturn(new Collection());
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagList}', function (Collection $tags) {
- return 'count: ' . $tags->count();
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/noblaexista');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagList
- */
- public function testTagListWithId(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tagRepos->shouldReceive('setUser');
- $tags = $this->user()->tags()->whereIn('id', [1, 2, 3])->get(['tags.*']);
- $tagRepos->shouldReceive('get')->once()->andReturn($tags);
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagList}', function (Collection $tags) {
- return 'count: ' . $tags->count();
- }
- );
- $first = $tags->get(0);
- $second = $tags->get(1);
-
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%s,%d,bleep', $first->tag, $second->id));
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('count: 2');
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Tag
- */
- public function testTagNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tag}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Tag
- */
- public function testTagNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tag}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdBothNull(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->getRandomTag();
-
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();
- $tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturnNull()->atLeast()->once();
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdById(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->getRandomTag();
-
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();
- $tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturn($tag)->atLeast()->once();
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- $response->assertSee($tag->tag);
- }
-
- /**
- * TODO there is a random element in this test that breaks the middleware.
- *
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdByTag(): void
- {
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $tag = $this->getRandomTag();
-
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('findByTag')->withArgs([$tag->tag])->andReturn($tag)->atLeast()->once();
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%s', $tag->tag));
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- $response->assertSee($tag->tag);
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $response = $this->get(sprintf('/_test/binder/%d', 4));
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionCurrency
- */
- public function testTransactionCurrency(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{currency}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionCurrency
- */
- public function testTransactionCurrencyNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{currency}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionCurrency
- */
- public function testTransactionCurrencyNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{currency}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionGroup
- */
- public function testTransactionGroup(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {
- return $transactionGroup->title ?? 'unknown';
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionGroup
- */
- public function testTransactionGroupNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {
- return $transactionGroup->title ?? 'unknown';
- }
- );
- $this->be($this->user());
- $response = $this->get('/_test/binder/-1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournalLink
- */
- public function testTransactionJournalLink(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalLink}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournalLink
- */
- public function testTransactionJournalLinkNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalLink}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/0');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionJournalLink
- */
- public function testTransactionJournalLinkNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{journalLink}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionType
- */
- public function testTransactionType(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{transactionType}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/withdrawal');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionType
- */
- public function testTransactionTypeNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{transactionType}', function () {
- return 'OK';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/unknown');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionType
- */
- public function testTransactionTypeNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{transactionType}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/withdrawal');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-}
diff --git a/tests/Unit/Middleware/IsAdminTest.php b/tests/Unit/Middleware/IsAdminTest.php
deleted file mode 100644
index 292f8978a7..0000000000
--- a/tests/Unit/Middleware/IsAdminTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * IsAdminTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use FireflyIII\Http\Middleware\IsAdmin;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class IsAdminTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsAdminTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware(IsAdmin::class)->any(
- '/_test/is-admin', function () {
- return 'OK';
- }
- );
-
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsAdmin
- */
- public function testMiddleware(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $this->withoutExceptionHandling();
- $response = $this->get('/_test/is-admin');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertRedirect(route('login'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsAdmin
- */
- public function testMiddlewareAjax(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
- $this->withoutExceptionHandling();
- $response = $this->get('/_test/is-admin', $server);
- $this->assertEquals(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsAdmin
- */
- public function testMiddlewareNotOwner(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
-
- $this->withoutExceptionHandling();
- $this->be($this->emptyUser());
- $response = $this->get('/_test/is-admin');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertRedirect(route('home'));
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsAdmin
- */
- public function testMiddlewareOwner(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
-
- $this->be($this->user());
- $this->withoutExceptionHandling();
- $response = $this->get('/_test/is-admin');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-}
diff --git a/tests/Unit/Middleware/IsDemoUserTest.php b/tests/Unit/Middleware/IsDemoUserTest.php
deleted file mode 100644
index 6d220f9eba..0000000000
--- a/tests/Unit/Middleware/IsDemoUserTest.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-/**
- * IsDemoUserTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use FireflyIII\Http\Middleware\IsDemoUser;
-use FireflyIII\Http\Middleware\StartFireflySession;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class IsDemoUserTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsDemoUserTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware([StartFireflySession::class, IsDemoUser::class])->any(
- '/_test/is-demo', static function () {
- return 'OK';
- }
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsDemoUser
- */
- public function testMiddlewareAuthenticated(): void
- {
- $userRepos =$this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnFalse();
-
- $this->be($this->user());
- $response = $this->get('/_test/is-demo');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsDemoUser
- */
- public function testMiddlewareIsDemoUser(): void
- {
- $userRepos =$this->mock(UserRepositoryInterface::class);
-
- $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnTrue();
-
- $this->be($this->demoUser());
- $response = $this->get('/_test/is-demo');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertSessionHas('info');
-
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\IsDemoUser
- */
- public function testMiddlewareNotAuthenticated(): void
- {
- $response = $this->get('/_test/is-demo');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-}
diff --git a/tests/Unit/Middleware/RangeTest.php b/tests/Unit/Middleware/RangeTest.php
deleted file mode 100644
index 90da0262cb..0000000000
--- a/tests/Unit/Middleware/RangeTest.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-/**
- * RangeTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use Amount;
-use FireflyIII\Http\Middleware\Range;
-use FireflyIII\Models\Preference;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use Log;
-use Preferences;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class RangeTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RangeTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware(Range::class)->any(
- '/_test/range', function () {
- return view('test.test');
- }
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Range
- */
- public function testMiddlewareAuthenticated(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $repository->shouldReceive('firstNull')->andReturn(TransactionJournal::first());
- $this->withoutExceptionHandling();
-
- $viewPreference = new Preference;
- $viewPreference->data = '1M';
-
- $langPreference = new Preference;
- $langPreference->data = 'en_US';
-
- $currPreference = new Preference;
- $currPreference->data = 'EUR';
-
- $listPreference = new Preference;
- $listPreference->data = 10;
-
-
- Preferences::shouldReceive('get')->withArgs(['viewRange','1M'])->atLeast()->once()->andReturn($viewPreference);
- Preferences::shouldReceive('get')->withArgs(['language','en_US'])->atLeast()->once()->andReturn($langPreference);
- Preferences::shouldReceive('get')->withArgs(['list-length',10])->atLeast()->once()->andReturn($listPreference);
- Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($this->getEuro());
- //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
-
- $this->be($this->user());
- $response = $this->get('/_test/range');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- // view has list length
- $response->assertSeeText('list-length: 10');
-
- // assert some session stuff?
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Range
- */
- public function testMiddlewareNotAuthenticated(): void
- {
- $this->withoutExceptionHandling();
- $response = $this->get('/_test/range');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-}
diff --git a/tests/Unit/Middleware/RedirectIfAuthenticatedTest.php b/tests/Unit/Middleware/RedirectIfAuthenticatedTest.php
deleted file mode 100644
index 9f5e118b91..0000000000
--- a/tests/Unit/Middleware/RedirectIfAuthenticatedTest.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
- * RedirectIfAuthenticatedTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use FireflyIII\Http\Middleware\RedirectIfAuthenticated;
-use Log;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class RedirectIfAuthenticatedTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RedirectIfAuthenticatedTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware(RedirectIfAuthenticated::class)->any(
- '/_test/authenticate', function () {
- return 'OK';
- }
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\RedirectIfAuthenticated
- */
- public function testMiddleware(): void
- {
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\RedirectIfAuthenticated
- */
- public function testMiddlewareAuthenticated(): void
- {
- $this->be($this->user());
- $response = $this->get('/_test/authenticate');
- $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
- $response->assertRedirect(route('index'));
- }
-}
diff --git a/tests/Unit/Middleware/SecureHeadersTest.php b/tests/Unit/Middleware/SecureHeadersTest.php
deleted file mode 100644
index ea08974d22..0000000000
--- a/tests/Unit/Middleware/SecureHeadersTest.php
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
- * SecureHeadersTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Middleware;
-
-use Config;
-use FireflyIII\Http\Middleware\SecureHeaders;
-use Log;
-use Route;
-use Symfony\Component\HttpFoundation\Response;
-use Tests\TestCase;
-
-/**
- * Class SecureHeadersTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class SecureHeadersTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- Route::middleware(SecureHeaders::class)->any(
- '/_test/secureheaders', static function () {
- return view('test.test');
- }
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\SecureHeaders
- */
- public function testMiddlewareBasic(): void
- {
- $response = $this->get('/_test/secureheaders');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- // verify headers
-
- //$response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' ; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com ; manifest-src 'self'; form-action 'self'");
- $response->assertheader('X-XSS-Protection', '1; mode=block');
- $response->assertHeader('X-Frame-Options', 'deny');
- $response->assertheader('X-Content-Type-Options', 'nosniff');
- $response->assertheader('Referrer-Policy', 'no-referrer');
- $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'");
- }
-
- /**
- * TODO this test tests nothing.
- *
- * @covers \FireflyIII\Http\Middleware\SecureHeaders
- */
- public function testMiddlewareGoogleAnalytics(): void
- {
- // response changes when config value is different.
- Config::set('firefly.analytics_id', 'abc');
-
- $response = $this->get('/_test/secureheaders');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- // verify headers
-
- //$response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com/gtag/js https://www.google-analytics.com/analytics.js; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com https://www.google-analytics.com/; manifest-src 'self'; form-action 'self'");
- $response->assertheader('X-XSS-Protection', '1; mode=block');
- $response->assertheader('X-Content-Type-Options', 'nosniff');
- $response->assertheader('Referrer-Policy', 'no-referrer');
- $response->assertHeader('X-Frame-Options', 'deny');
- $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'");
- }
-
-
- /**
- * @covers \FireflyIII\Http\Middleware\SecureHeaders
- */
- public function testMiddlewareFrameHeader(): void
- {
- // response changes when config value is different.
- Config::set('firefly.disable_frame_header', true);
-
- $response = $this->get('/_test/secureheaders');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- // verify headers
-
- //$response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' ; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com ; manifest-src 'self'; form-action 'self'");
- $response->assertheader('X-XSS-Protection', '1; mode=block');
- $response->assertheader('X-Content-Type-Options', 'nosniff');
- $response->assertheader('Referrer-Policy', 'no-referrer');
- $response->assertHeaderMissing('X-Frame-Options');
- $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'");
- }
-
-}
diff --git a/tests/Unit/Rules/BelongsUserTest.php b/tests/Unit/Rules/BelongsUserTest.php
deleted file mode 100644
index 50ee2f5f32..0000000000
--- a/tests/Unit/Rules/BelongsUserTest.php
+++ /dev/null
@@ -1,354 +0,0 @@
-<?php
-/**
- * BelongsUserTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Rules\BelongsUser;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class BelongsUserTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BelongsUserTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBillId(): void
- {
- $attribute = 'bill_id';
- $bill = $this->getRandomBill();
- $value = $bill->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBillIdFalse(): void
- {
- $attribute = 'bill_id';
- $value = '-1';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBillName(): void
- {
- $attribute = 'bill_name';
- $bill = $this->getRandomBill();
- $value = $bill->name;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBillNameFalse(): void
- {
- $attribute = 'bill_name';
- $value = 'Some random name';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testAccountIdFalse(): void
- {
- $attribute = 'source_id';
- $value = '-1';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testAccountId(): void
- {
- $attribute = 'destination_id';
- $asset =$this->getRandomAsset();
- $value = $asset->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBudgetId(): void
- {
- $attribute = 'budget_id';
- $budget = $this->getRandomBudget();
- $value = $budget->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBudgetIdFalse(): void
- {
- $attribute = 'budget_id';
- $value = '-1';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBudgetName(): void
- {
- $attribute = 'budget_name';
- $budget = $this->getRandomBudget();
- $value = $budget->name;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testBudgetNameFalse(): void
- {
- $attribute = 'budget_name';
- $value = 'Some random budget';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testCategoryId(): void
- {
- $attribute = 'category_id';
- $category = $this->getRandomCategory();
- $value = $category->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testCategoryIdFalse(): void
- {
- $attribute = 'category_id';
- $value = '-1';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testPiggyBankId(): void
- {
- $attribute = 'piggy_bank_id';
- $piggyBank = $this->getRandomPiggyBank();
- $value = $piggyBank->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testPiggyBankIdFalse(): void
- {
- $attribute = 'piggy_bank_id';
- $value = '-1';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testPiggyBankIdLongAttribute(): void
- {
- $attribute = 'a.b.piggy_bank_id';
- $piggyBank = $this->getRandomPiggyBank();
- $value = $piggyBank->id;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testPiggyBankName(): void
- {
- $attribute = 'piggy_bank_name';
- $piggyBank = $this->getRandomPiggyBank();
- $value = $piggyBank->name;
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertTrue($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\BelongsUser
- */
- public function testPiggyBankNameFalse(): void
- {
- $attribute = 'piggy_bank_name';
- $value = 'Some random name';
-
- $this->be($this->user());
- $engine = new BelongsUser;
- try {
- $this->assertFalse($engine->passes($attribute, $value));
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
-}
diff --git a/tests/Unit/Rules/IsAssetAccountIdTest.php b/tests/Unit/Rules/IsAssetAccountIdTest.php
deleted file mode 100644
index 5ab5b39275..0000000000
--- a/tests/Unit/Rules/IsAssetAccountIdTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/**
- * IsAssetAccountIdTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Rules\IsAssetAccountId;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class IsAssetAccountIdTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsAssetAccountIdTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsAssetAccountId
- */
- public function testNotAsset(): void
- {
- $attribute = 'not-used';
- $expense = $this->getRandomExpense();
- $value = $expense->id;
-
- $engine = new IsAssetAccountId();
- $this->assertFalse($engine->passes($attribute, $value));
- }
-
-
- /**
- * @covers \FireflyIII\Rules\IsAssetAccountId
- */
- public function testAsset(): void
- {
- $attribute = 'not-used';
- $asset = $this->getRandomAsset();
- $value = $asset->id;
-
- $engine = new IsAssetAccountId();
- $this->assertTrue($engine->passes($attribute, $value));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsAssetAccountId
- */
- public function testNull(): void
- {
- $attribute = 'not-used';
- $value = '-1';
-
- $engine = new IsAssetAccountId();
- $this->assertFalse($engine->passes($attribute, $value));
- }
-
-}
diff --git a/tests/Unit/Rules/IsBooleanTest.php b/tests/Unit/Rules/IsBooleanTest.php
deleted file mode 100644
index 3c1bf65de4..0000000000
--- a/tests/Unit/Rules/IsBooleanTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * IsBooleanTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Rules\IsBoolean;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class IsBooleanTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsBooleanTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsBoolean
- */
- public function testFalse(): void
- {
- $attribute = 'not-important';
-
- $false = ['not', 2, -1, []];
-
- /** @var mixed $value */
- foreach ($false as $value) {
-
- $engine = new IsBoolean();
- $this->assertFalse($engine->passes($attribute, $value));
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\IsBoolean
- */
- public function testTrue(): void
- {
- $attribute = 'not-important';
-
- $true = [true, false, 0, 1, '0', '1', 'true', 'false', 'yes', 'no', 'on', 'off'];
-
- /** @var mixed $value */
- foreach ($true as $value) {
-
- $engine = new IsBoolean();
- $this->assertTrue($engine->passes($attribute, $value));
- }
- }
-
-}
diff --git a/tests/Unit/Rules/IsDateOrTimeTest.php b/tests/Unit/Rules/IsDateOrTimeTest.php
deleted file mode 100644
index 33b67f6a7a..0000000000
--- a/tests/Unit/Rules/IsDateOrTimeTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-/**
- * IsDateOrTimeTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Rules\IsDateOrTime;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class IsDateOrTimeTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsDateOrTimeTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsDateOrTime
- */
- public function testFalse(): void
- {
- $attribute = 'not-important';
- $values = ['20xx-01-x','1234567890', '2xx0101', '', false];
-
- /** @var mixed $value */
- foreach ($values as $value) {
- $engine = new IsDateOrTime();
- $this->assertFalse($engine->passes($attribute, $value), sprintf('%s', var_export($value, true)));
- }
- }
-
- /**
- * @covers \FireflyIII\Rules\IsDateOrTime
- */
- public function testTrue(): void
- {
- $attribute = 'not-important';
- $values = ['2019-01-01', '20190101', '2019-01-01 12:12:12', '12:12:12'];
-
- /** @var mixed $value */
- foreach ($values as $value) {
- $engine = new IsDateOrTime();
- $this->assertTrue($engine->passes($attribute, $value));
- }
- }
-
-
-}
diff --git a/tests/Unit/Rules/IsValidAttachmentModelTest.php b/tests/Unit/Rules/IsValidAttachmentModelTest.php
deleted file mode 100644
index e814b6973f..0000000000
--- a/tests/Unit/Rules/IsValidAttachmentModelTest.php
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-/**
- * IsValidAttachmentModelTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Models\Bill;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Rules\IsValidAttachmentModel;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class IsValidAttachmentModelTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class IsValidAttachmentModelTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testBillFull(): void
- {
- $bill = $this->getRandomBill();
- $billRepos = $this->mock(BillRepositoryInterface::class);
-
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('find')->atLeast()->once()->withArgs([$bill->id])->andReturn($bill);
-
- $value = $bill->id;
- $attribute = 'not-important';
- $this->be($this->user());
- $engine = new IsValidAttachmentModel(Bill::class);
- $this->assertTrue($engine->passes($attribute, $value));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testTransaction(): void
- {
- $transaction = $this->getRandomWithdrawal()->transactions()->first();
- $apiJournalRepos = $this->mock(JournalAPIRepositoryInterface::class);
-
- $apiJournalRepos->shouldReceive('setUser')->atLeast()->once();
- $apiJournalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
-
- $value = $transaction->id;
- $attribute = 'not-important';
- $this->be($this->user());
- $engine = new IsValidAttachmentModel(Transaction::class);
- $this->assertTrue($engine->passes($attribute, $value));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testTransactionJournal(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
-
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$journal->id])->andReturn($journal);
-
- $value = $journal->id;
- $attribute = 'not-important';
- $this->be($this->user());
- $engine = new IsValidAttachmentModel(TransactionJournal::class);
- $this->assertTrue($engine->passes($attribute, $value));
- }
-
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testBadModel(): void
- {
- $value = '123';
- $attribute = 'not-important';
- $this->be($this->user());
- $engine = new IsValidAttachmentModel('False');
- $this->assertFalse($engine->passes($attribute, $value));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testBillPartial(): void
- {
- $bill = $this->getRandomBill();
- $billRepos = $this->mock(BillRepositoryInterface::class);
-
- $billRepos->shouldReceive('setUser')->atLeast()->once();
- $billRepos->shouldReceive('find')->atLeast()->once()->withAnyArgs([$bill->id])->andReturn($bill);
-
- $value = $bill->id;
- $attribute = 'not-important';
- $this->be($this->user());
- $engine = new IsValidAttachmentModel('Bill');
- $this->assertTrue($engine->passes($attribute, $value));
- }
-
- /**
- * @covers \FireflyIII\Rules\IsValidAttachmentModel
- */
- public function testNotLoggedIn(): void
- {
- $value = '1';
- $attribute = 'not-important';
- $engine = new IsValidAttachmentModel(Bill::class);
- $this->assertFalse($engine->passes($attribute, $value));
- }
-
-}
diff --git a/tests/Unit/Rules/UniqueIbanTest.php b/tests/Unit/Rules/UniqueIbanTest.php
deleted file mode 100644
index 61585f27bb..0000000000
--- a/tests/Unit/Rules/UniqueIbanTest.php
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-/**
- * UniqueIbanTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Rules;
-
-
-use FireflyIII\Rules\UniqueIban;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class UniqueIbanTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UniqueIbanTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Rules\UniqueIban
- */
- public function testBasic(): void
- {
- $asset = $this->getRandomAsset();
- $iban = $asset->iban;
- $asset->iban = 'NL123';
- $asset->save();
-
- $this->be($this->user());
-
- $engine = new UniqueIban(null, 'asset');
- $this->assertFalse($engine->passes('not-important', $asset->iban));
-
- $asset->iban = $iban;
- $asset->save();
- }
-
- /**
- * @covers \FireflyIII\Rules\UniqueIban
- */
- public function testBasicSkipExisting(): void
- {
- $asset = $this->getRandomAsset();
- $iban = $asset->iban;
- $asset->iban = 'NL123';
- $asset->save();
-
- $this->be($this->user());
-
- $engine = new UniqueIban($asset, 'asset');
- $this->assertTrue($engine->passes('not-important', $asset->iban));
-
- $asset->iban = $iban;
- $asset->save();
- }
-
- /**
- * @covers \FireflyIII\Rules\UniqueIban
- */
- public function testRevenue(): void
- {
- // give revenue account new IBAN.
- // should be OK to give it to an expense account
- $revenue = $this->getRandomRevenue();
- $iban = $revenue->iban;
- $revenue->iban = 'NL123';
- $revenue->save();
-
- $this->be($this->user());
-
- // returns true because this mix is OK.
- $engine = new UniqueIban(null, 'expense');
- $this->assertTrue($engine->passes('not-important', 'NL123'));
-
-
- $revenue->iban = $iban;
- $revenue->save();
- }
-
-
- /**
- * @covers \FireflyIII\Rules\UniqueIban
- */
- public function testExpense(): void
- {
- // give expense account new IBAN.
- // should be OK to give it to an expense account
- $expense = $this->getRandomExpense();
- $iban = $expense->iban;
- $expense->iban = 'NL123';
- $expense->save();
-
- $this->be($this->user());
-
- // returns true because this mix is OK.
- $engine = new UniqueIban(null, 'revenue');
- $this->assertTrue($engine->passes('not-important', 'NL123'));
-
- $expense->iban = $iban;
- $expense->save();
- }
-
- /**
- * @covers \FireflyIII\Rules\UniqueIban
- */
- public function testRevenueAsset(): void
- {
- // give revenue account new IBAN.
- // should be OK to give it to an expense account
- $revenue = $this->getRandomRevenue();
- $iban = $revenue->iban;
- $revenue->iban = 'NL123';
- $revenue->save();
-
- $this->be($this->user());
-
- // returns false because this mix is not OK.
- $engine = new UniqueIban(null, 'asset');
- $this->assertFalse($engine->passes('not-important', 'NL123'));
-
-
- $revenue->iban = $iban;
- $revenue->save();
- }
-
-}
diff --git a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php b/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php
deleted file mode 100644
index b80d13cc58..0000000000
--- a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/**
- * AccountDestroyServiceTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Services\Internal\Destroy;
-
-use FireflyIII\Models\Account;
-use FireflyIII\Models\RecurrenceTransaction;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
-use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
-use FireflyIII\Services\Internal\Destroy\RecurrenceDestroyService;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AccountDestroyServiceTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountDestroyServiceTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
- */
- public function testDestroyBasic(): void
- {
- $this->mock(RecurrenceDestroyService::class);
- $this->mock(JournalDestroyService::class);
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- /** @var AccountDestroyService $service */
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
-
- $this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
- }
-
-
- /**
- * @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
- */
- public function testDestroyWithRecurrence(): void
- {
- $recService = $this->mock(RecurrenceDestroyService::class);
- $this->mock(JournalDestroyService::class);
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
-
- $recurrence = $this->getRandomRecurrence();
- $transaction = RecurrenceTransaction::create(
- [
- 'recurrence_id' => $recurrence->id,
- 'transaction_currency_id' => $this->getEuro()->id,
- 'source_id' => $account->id,
- 'destination_id' => $account->id,
- 'amount' => 10,
- 'description' => 'Hello',
- ]
- );
-
- $recService->shouldReceive('destroyById')->once()
- ->withAnyArgs([$transaction->id]);
-
- /** @var AccountDestroyService $service */
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
-
- $this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
-
- $transaction->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
- */
- public function testDestroyDontMove(): void
- {
- $this->mock(RecurrenceDestroyService::class);
- $this->mock(JournalDestroyService::class);
- // create objects:
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
-
- // mock delete service:
- $service = $this->mock(JournalDestroyService::class);
- $service->shouldReceive('destroy')->once();
-
- /** @var AccountDestroyService $service */
- $service = app(AccountDestroyService::class);
- $service->destroy($account, null);
-
- $this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
- */
- public function testDestroyMove(): void
- {
- $this->mock(RecurrenceDestroyService::class);
- $this->mock(JournalDestroyService::class);
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $move = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $transaction = Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
- /** @var AccountDestroyService $service */
- $service = app(AccountDestroyService::class);
- $service->destroy($account, $move);
-
- $this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
- $this->assertDatabaseMissing('transactions', ['account_id' => $account->id]);
- $this->assertDatabaseHas('transactions', ['id' => $transaction->id, 'account_id' => $move->id]);
- }
-
-}
diff --git a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php
deleted file mode 100644
index d25d65609d..0000000000
--- a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php
+++ /dev/null
@@ -1,310 +0,0 @@
-<?php
-/**
- * AccountUpdateServiceTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Services\Internal\Update;
-
-
-use Carbon\Carbon;
-use FireflyIII\Factory\AccountMetaFactory;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\Note;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
-use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
-use FireflyIII\Services\Internal\Update\AccountUpdateService;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AccountUpdateServiceTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountUpdateServiceTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testDeleteExistingIB(): void
- {
- $group = $this->getRandomWithdrawalGroup();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $destroySerice = $this->mock(TransactionGroupDestroyService::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());
- $metaFactory->shouldReceive('crud');
-
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);
- $destroySerice->shouldReceive('destroy')->atLeast()->once();
- $account = $this->getRandomAsset();
-
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- 'notes' => 'Hello',
- 'currency_id' => 1,
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- /** @var Note $note */
- $note = $account->notes()->first();
- $this->assertEquals($data['notes'], $note->text);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateBasic(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $metaFactory->shouldReceive('crud');
- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();
-
- /** @var Account $account */
- $account = $this->user()->accounts()->first();
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateBasicEmptyNote(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $metaFactory->shouldReceive('crud');
-
- /** @var Account $account */
- $account = $this->user()->accounts()->first();
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- 'notes' => '',
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- $this->assertEquals(0, $account->notes()->count());
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateBasicExistingNote(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- $metaFactory->shouldReceive('crud');
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();
-
- /** @var Account $account */
- $account = $this->user()->accounts()->first();
- $note = new Note;
- $note->noteable()->associate($account);
- $note->text = 'Hi there';
- $note->save();
-
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- 'notes' => '',
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- $this->assertEquals(0, $account->notes()->count());
- }
-
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateExistingIB(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $destroySerice = $this->mock(TransactionGroupDestroyService::class);
- $group = $this->getRandomWithdrawalGroup();
-
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- // make sure one transaction has the account as the asset.
- $journal = $group->transactionJournals()->first();
- $account = $journal->transactions()->first()->account;
-
- $metaFactory->shouldReceive('crud');
- $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);
-
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '105',
- 'opening_balance_date' => new Carbon('2018-01-01'),
- 'notes' => 'Hello',
- 'currency_id' => 1,
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- /** @var Note $note */
- $note = $account->notes()->first();
- $this->assertEquals($data['notes'], $note->text);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateExistingIBZero(): void
- {
-
- $deleteService = $this->mock(JournalDestroyService::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
-
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());
- $metaFactory->shouldReceive('crud');
-
- /** @var Account $account */
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $opposing = $this->user()->accounts()->first();
- $journal = TransactionJournal::create(
- ['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
- 'date' => '2018-01-01', 'completed' => true, 'tag_count' => 0,
- ]
- );
- // transactions:
- Transaction::create(
- ['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
- );
- Transaction::create(
- ['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
- );
-
-
- $data = [
- 'name' => 'Some new name #' . $this->randomInt(),
- 'active' => true,
- 'virtual_balance' => '0',
- 'iban' => null,
- 'account_role' => 'defaultAsset',
- 'opening_balance' => '0',
- 'opening_balance_date' => new Carbon('2018-01-01'),
- 'notes' => 'Hello',
- 'currency_id' => 1,
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- $this->assertEquals(1, $account->transactions()->count());
- $this->assertEquals(100, $account->transactions()->first()->amount);
- /** @var Note $note */
- $note = $account->notes()->first();
- $this->assertEquals($data['notes'], $note->text);
- }
-
-}
diff --git a/tests/Unit/Support/AmountTest.php b/tests/Unit/Support/AmountTest.php
deleted file mode 100644
index f11697a2a5..0000000000
--- a/tests/Unit/Support/AmountTest.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-
-namespace Tests\Unit\Support;
-
-use FireflyIII\Support\Amount;
-use Tests\TestCase;
-use Steam;
-
-/**
- * Class AmountTest
- */
-class AmountTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @dataProvider getTestLocales
- * @param string $locale
- * @param string $expectedAmount
- * @param string $symbol
- * @param int $decimalPlaces
- * @param string $amount
- */
- public function testFormatFlat(string $locale, string $expectedAmount, string $symbol, int $decimalPlaces, string $amount)
- {
- $this->mockDefaultConfiguration();
- Steam::shouldReceive('getLocale')->andReturn($locale);
- Steam::shouldReceive('getLocaleArray')->andReturn([$locale . ".UTF-8"]);
-
- $amountObj = new Amount();
- $result = $amountObj->formatFlat($symbol, $decimalPlaces, $amount, false);
- $this->assertEquals($expectedAmount, $result);
- }
-
- public function getTestLocales()
- {
- return [
- ['en_US', '£6,000.00', '£', 2, '6000.00000000'],
- ['en_US', '-£6,000.00', '£', 2, '-6000.00000000'],
- ['en_US', '$6,000.00', '$', 2, '6000.00000000'],
- ['en_US', '-$6,000.00', '$', 2, '-6000.00000000'],
- ['en_GB', '£6,000.00', '£', 2, '6000.00000000'],
- ['en_GB', '-£6,000.00', '£', 2, '-6000.00000000'],
- ['en_GB', '$6,000.00', '$', 2, '6000.00000000'],
- ['en_GB', '-$6,000.00', '$', 2, '-6000.00000000'],
- ['cs_CZ', '6 000,00 Kč', 'Kč', 2, '6000.00000000'],
- ['cs_CZ', '-6 000,00 Kč', 'Kč', 2, '-6000.00000000'],
- ['el_GR', '6.000,00 €', '€', 2, '6000.00000000'],
- ['el_GR', '-6.000,00 €', '€', 2, '-6000.00000000'],
- ['es_ES', '6.000,00 €', '€', 2, '6000.00000000'],
- ['es_ES', '-6.000,00 €', '€', 2, '-6000.00000000'],
- ['de_DE', '6.000,00 €', '€', 2, '6000.00000000'],
- ['de_DE', '-6.000,00 €', '€', 2, '-6000.00000000'],
- ['fr_FR', '6 000,00 €', '€', 2, '6000.00000000'],
- ['fr_FR', '-6 000,00 €', '€', 2, '-6000.00000000'],
- ['it_IT', '6.000,00 €', '€', 2, '6000.00000000'],
- ['it_IT', '-6.000,00 €', '€', 2, '-6000.00000000'],
- ['nb_NO', 'kr 6 000,00', 'kr', 2, '6000.00000000'],
- ['nb_NO', '−kr 6 000,00', 'kr', 2, '-6000.00000000'],
- ['nl_NL', '€ 6.000,00', '€', 2, '6000.00000000'],
- ['nl_NL', '€ -6.000,00', '€', 2, '-6000.00000000'],
- ['pl_PL', '6 000,00 zł', 'zł', 2, '6000.00000000'],
- ['pl_PL', '-6 000,00 zł', 'zł', 2, '-6000.00000000'],
- ['pt_BR', 'R$ 6.000,00', 'R$', 2, '6000.00000000'],
- ['pt_BR', '-R$ 6.000,00', 'R$', 2, '-6000.00000000'],
- ['ro_RO', '6.000,00 lei', 'lei', 2, '6000.00000000'],
- ['ro_RO', '-6.000,00 lei', 'lei', 2, '-6000.00000000'],
- ['ru_RU', '6 000,00 ₽', '₽', 2, '6000.00000000'],
- ['ru_RU', '-6 000,00 ₽', '₽', 2, '-6000.00000000'],
- ['zh_TW', 'NT$6,000.00', 'NT$', 2, '6000.00000000'],
- ['zh_TW', '-NT$6,000.00', 'NT$', 2, '-6000.00000000'],
- ['zh_CN', '¥6,000.00', '¥', 2, '6000.00000000'],
- ['zh_CN', '-¥6,000.00', '¥', 2, '-6000.00000000'],
- ['hu_HU', '6 000,00 Ft', 'Ft', 2, '6000.00000000'],
- ['hu_HU', '-6 000,00 Ft', 'Ft', 2, '-6000.00000000'],
- ['sv_SE', '6 000,00 kr', 'kr', 2, '6000.00000000'],
- ['sv_SE', '−6 000,00 kr', 'kr', 2, '-6000.00000000'],
- ['fi_FI', '6 000,00 €', '€', 2, '6000.00000000'],
- ['fi_FI', '−6 000,00 €', '€', 2, '-6000.00000000'],
- ['vi_VN', '6.000,00 đ', 'đ', 2, '6000.00000000'],
- ['vi_VN', '-6.000,00 đ', 'đ', 2, '-6000.00000000'],
- ];
- }
-}
diff --git a/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php b/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php
deleted file mode 100644
index 2dc37269c1..0000000000
--- a/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-/**
- * RecurringCronjobTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Support\Cronjobs;
-
-
-use Carbon\Carbon;
-use FireflyConfig;
-use FireflyIII\Jobs\CreateRecurringTransactions;
-use FireflyIII\Models\Configuration;
-use FireflyIII\Support\Cronjobs\RecurringCronjob;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class RecurringCronjobTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RecurringCronjobTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
- */
- public function testBasic(): void
- {
- $class = $this->mock(CreateRecurringTransactions::class);
- $force = false;
- $date = new Carbon;
- $config = new Configuration;
- $config->data = 0;
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
-
- $class->shouldReceive('setDate')->atleast()->once();
- $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
- $class->shouldReceive('handle')->atleast()->once();
-
- FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
-
- $job = new RecurringCronjob;
- $job->setDate($date);
- $job->setForce($force);
- $job->fire();
- }
-
- /**
- * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
- */
- public function testShort(): void
- {
- $this->mock(CreateRecurringTransactions::class);
- $force = false;
- $date = new Carbon;
- $time = time() - 100;
- $config = new Configuration;
- $config->data = $time;
-
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
-
- $job = new RecurringCronjob;
- $job->setDate($date);
- $job->setForce($force);
- $job->fire();
- }
-
- /**
- * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
- */
- public function testShortForced(): void
- {
- $class = $this->mock(CreateRecurringTransactions::class);
- $force = true;
- $date = new Carbon;
- $time = time() - 100;
- $config = new Configuration;
- $config->data = $time;
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
-
- $class->shouldReceive('setDate')->atleast()->once();
- $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
- $class->shouldReceive('handle')->atleast()->once();
-
- FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
-
- $job = new RecurringCronjob;
- $job->setDate($date);
- $job->setForce($force);
- $job->fire();
- }
-
- /**
- * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
- */
- public function testTwoDays(): void
- {
- $class = $this->mock(CreateRecurringTransactions::class);
- $force = false;
- $date = new Carbon;
- $time = time() - 43300;
- $config = new Configuration;
- $config->data = $time;
- FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
-
- $class->shouldReceive('setDate')->atleast()->once();
- $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
- $class->shouldReceive('handle')->atleast()->once();
-
- FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
-
- $job = new RecurringCronjob;
- $job->setDate($date);
- $job->setForce($force);
- $job->fire();
- }
-
-}
diff --git a/tests/Unit/Support/NavigationTest.php b/tests/Unit/Support/NavigationTest.php
deleted file mode 100644
index 8bd88ecfc4..0000000000
--- a/tests/Unit/Support/NavigationTest.php
+++ /dev/null
@@ -1,324 +0,0 @@
-<?php
-/**
- * NavigationTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Support;
-
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Support\Navigation;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class NavigationTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NavigationTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Navigation
- */
- public function testAddPeriod(): void
- {
- $tests = [
- // period, skip, start, expected end
- ['1D', 0, '2018-01-01', '2018-01-02'],
- ['1D', 1, '2018-01-01', '2018-01-03'],
- ['1D', 1, '2018-02-28', '2018-03-02'],
- ['1W', 0, '2015-02-28', '2015-03-07'],
- ['1W', 0, '2016-02-28', '2016-03-06'], // leap year
- ['1W', 1, '2015-02-28', '2015-03-14'],
- ['1W', 1, '2016-02-28', '2016-03-13'], // leap year
- ['1W', 0, '2018-01-01', '2018-01-08'],
-
- ['1M', 0, '2018-01-01', '2018-02-01'],
- ['1M', 0, '2018-02-01', '2018-03-01'],
- ['1M', 0, '2018-01-28', '2018-02-28'],
- ['1M', 0, '2016-01-29', '2016-02-29'], // leap year makes it work
- ['1M', 0, '2019-01-29', '2019-02-28'], // jump to end of next month.
- ['1M', 0, '2019-01-30', '2019-02-28'], // jump to end of next month.
- ['1M', 0, '2019-01-31', '2019-02-28'], // jump to end of next month.
- ['1M', 0, '2019-02-01', '2019-03-01'],
- ['1M', 1, '2019-02-01', '2019-04-01'], // fixed
- ['1M', 2, '2019-01-01', '2019-04-01'],
-
- ['quarter', 0, '2019-01-01', '2019-04-01'],
- ['quarter', 1, '2019-01-01', '2019-07-01'],
-
- ['6M', 0, '2019-01-01', '2019-07-01'],
- ['6M', 1, '2019-01-01', '2020-01-01'],
- ['6M', 0, '2019-08-01', '2020-02-01'],
-
- ['year', 0, '2019-01-01', '2020-01-01'],
- ['year', 1, '2019-01-01', '2021-01-01'],
- ['custom', 1, '2019-01-01', '2019-03-01'],
-
- ];
-
- /** @var array $test */
- foreach ($tests as $test) {
-
- $freq = $test[0];
- /** @noinspection MultiAssignmentUsageInspection */
- $skip = $test[1];
- $start = new Carbon($test[2]);
- $expected = new Carbon($test[3]);
- $nav = new Navigation;
- try {
- $result = $nav->addPeriod($start, $freq, $skip);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
-
- $this->assertEquals($expected->format('Y-m-d'), $result->format('Y-m-d'));
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Navigation
- */
- public function testBlockPeriods(): void
- {
- $tests = [
- [
- 'start' => '2014-01-01',
- 'end' => '2018-12-31',
- 'range' => '1M',
- 'expected' =>
- [
- [
- 'start' => '2018-12-01',
- 'end' => '2018-12-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-11-01',
- 'end' => '2018-11-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-10-01',
- 'end' => '2018-10-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-09-01',
- 'end' => '2018-09-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-08-01',
- 'end' => '2018-08-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-07-01',
- 'end' => '2018-07-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-06-01',
- 'end' => '2018-06-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-05-01',
- 'end' => '2018-05-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-04-01',
- 'end' => '2018-04-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-03-01',
- 'end' => '2018-03-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-02-01',
- 'end' => '2018-02-28',
- 'period' => '1M',
- ],
- [
- 'start' => '2018-01-01',
- 'end' => '2018-01-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-12-01',
- 'end' => '2017-12-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-11-01',
- 'end' => '2017-11-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-10-01',
- 'end' => '2017-10-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-09-01',
- 'end' => '2017-09-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-08-01',
- 'end' => '2017-08-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-07-01',
- 'end' => '2017-07-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-06-01',
- 'end' => '2017-06-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-05-01',
- 'end' => '2017-05-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-04-01',
- 'end' => '2017-04-30',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-03-01',
- 'end' => '2017-03-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-02-01',
- 'end' => '2017-02-28',
- 'period' => '1M',
- ],
- [
- 'start' => '2017-01-01',
- 'end' => '2017-01-31',
- 'period' => '1M',
- ],
- [
- 'start' => '2016-01-01',
- 'end' => '2016-12-31',
- 'period' => '1Y',
- ],
- [
- 'start' => '2015-01-01',
- 'end' => '2015-12-31',
- 'period' => '1Y',
- ],
- [
- 'start' => '2014-01-01',
- 'end' => '2014-12-31',
- 'period' => '1Y',
- ],
- ]
-
- ,
- ],
- ];
-
- /** @var array $test */
- foreach ($tests as $test) {
-
- $start = new Carbon($test['start']);
- $end = new Carbon($test['end']);
- $range = $test['range'];
- $nav = new Navigation;
- try {
- $result = $nav->blockPeriods($start, $end, $range);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- $parsedResult = [];
- foreach ($result as $entry) {
- $parsedResult[] = [
- 'start' => $entry['start']->format('Y-m-d'),
- 'end' => $entry['end']->format('Y-m-d'),
- 'period' => $entry['period'],
- ];
- }
- $this->assertEquals($test['expected'], $parsedResult);
-
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Navigation
- */
- public function testEndOfPeriod(): void
- {
-
- $tests = [
- ['1D', '2018-01-01 00:00:00', '2018-01-01 23:59:59'],
- ['1W', '2018-01-01 00:00:00', '2018-01-07 23:59:59'],
- ['1M', '2018-01-01 00:00:00', '2018-01-31 23:59:59'],
- ['3M', '2018-01-01 00:00:00', '2018-03-31 23:59:59'],
- ['6M', '2018-01-01 00:00:00', '2018-06-30 23:59:59'],
- ['1Y', '2018-01-01 00:00:00', '2018-12-31 23:59:59'],
- ];
-
- /** @var array $test */
- foreach ($tests as $test) {
-
- $freq = $test[0];
- /** @noinspection MultiAssignmentUsageInspection */
- $start = new Carbon($test[1]);
- $expected = new Carbon($test[2]);
- $nav = new Navigation;
- try {
- $result = $nav->endOfPeriod($start, $freq);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
-
- $this->assertEquals($expected->format('Y-m-d H:i:s'), $result->format('Y-m-d H:i:s'));
- }
- }
-}
diff --git a/tests/Unit/Support/Search/OperatorQuerySearchTest.php b/tests/Unit/Support/Search/OperatorQuerySearchTest.php
deleted file mode 100644
index 50bc64101f..0000000000
--- a/tests/Unit/Support/Search/OperatorQuerySearchTest.php
+++ /dev/null
@@ -1,2579 +0,0 @@
-<?php
-/*
- * OperatorQuerySearchTest.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace Tests\Unit\Support\Search;
-
-
-use DB;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\Account;
-use FireflyIII\Support\Search\OperatorQuerySearch;
-use Log;
-use Tests\TestCase;
-
-/**
- * Test:
- *
- * - each combination
- * - some weird combi's
- * - invalid stuff?
- */
-class OperatorQuerySearchTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testParseQuery(): void
- {
- $this->be($this->user());
- // mock some of the used classes to verify results.
-
- $ops = array_keys(config('firefly.search.operators'));
-
- $values = [
- 'user_action' => 'empty',
-
- // source account
- 'from_account_starts' => 'test',
- 'source_account_starts' => 'start',
- 'from_account_ends' => 'test',
- 'source_account_ends' => 'x',
- 'source_account_is' => '1',
- 'from_account_is' => '1',
- 'source_account_contains' => 'test',
- 'from_account_contains' => 'test',
- 'source' => 'test',
- 'from' => 'test',
- 'source_account_id' => '1',
- 'from_account_id' => '1',
- 'source_is_cash' => true,
- 'destination_is_cash' => true,
- 'account_is_cash' => true,
-
- // source account nr
- 'from_account_nr_starts' => 'test',
- 'source_account_nr_starts' => 'test',
- 'from_account_nr_ends' => 'test',
- 'source_account_nr_ends' => 'test',
- 'from_account_nr_is' => 'test',
- 'source_account_nr_is' => 'test',
- 'from_account_nr_contains' => 'test',
- 'source_account_nr_contains' => 'test',
-
- // destination account
- 'to_account_starts' => 'test',
- 'destination_account_starts' => 'test',
- 'to_account_ends' => 'test',
- 'destination_account_ends' => 'test',
- 'to_account_contains' => 'test',
- 'destination_account_contains' => 'test',
- 'to_account_is' => 'test',
- 'destination_account_is' => 'test',
- 'destination' => 'test',
- 'to' => 'test',
- 'destination_account_id' => '1',
- 'to_account_id' => '1',
-
- // journal test
- 'journal_id' => '1',
-
- // destination account nr
- 'to_account_nr_starts' => 'test',
- 'destination_account_nr_starts' => 'test',
- 'to_account_nr_ends' => 'test',
- 'destination_account_nr_ends' => 'test',
- 'to_account_nr_is' => 'test',
- 'destination_account_nr_is' => 'test',
- 'to_account_nr_contains' => 'test',
- 'destination_account_nr_contains' => 'test',
-
- // account
- 'account_id' => '1',
-
- // the rest
- 'description_starts' => 'test',
- 'description_ends' => 'test',
- 'description_contains' => 'test',
- 'description_is' => 'test',
- 'currency_is' => 'test',
- 'foreign_currency_is' => 'test',
- 'has_attachments' => 'test',
- 'has_no_category' => 'test',
- 'has_any_category' => 'test',
- 'has_no_budget' => 'test',
- 'has_any_budget' => 'test',
- 'has_no_tag' => 'test',
- 'has_any_tag' => 'test',
- 'notes_contain' => 'test',
- 'notes_start' => 'test',
- 'notes_end' => 'test',
- 'notes_are' => 'test',
- 'no_notes' => 'test',
- 'any_notes' => 'test',
-
-
- // exact amount
- 'amount_exactly' => '0',
- 'amount_is' => '0',
- 'amount' => '0',
-
- // is less than
- 'amount_less' => '0',
- 'amount_max' => '0',
-
- // is more than
- 'amount_more' => '0',
- 'amount_min' => '0',
-
-
- // category
- 'category_is' => 'test',
- 'category' => 'test',
-
- // budget
- 'budget_is' => 'test',
- 'budget' => 'test',
-
- // bill
- 'bill_is' => 'test',
- 'bill' => 'test',
-
- // type
- 'transaction_type' => 'test',
- 'type' => 'test',
-
- // date:
- 'date_is' => '2020-01-01',
- 'date' => '2020-01-01',
- 'on' => '2020-01-01',
- 'date_before' => '2020-01-01',
- 'before' => '2020-01-01',
- 'date_after' => '2020-01-01',
- 'after' => '2020-01-01',
- // other interesting fields
- 'tag_is' => 'abc',
- 'tag' => 'abc',
- 'created_on' => '2020-01-01',
- 'updated_on' => '2020-01-01',
- 'created_at' => '2020-01-01',
- 'updated_at' => '2020-01-01',
- 'external_id' => 'abc',
- 'internal_reference' => 'def',
- ];
-
- foreach ($ops as $operator) {
- if (!array_key_exists($operator, $values)) {
- $this->assertTrue(false, sprintf('No value for operator "%s"', $operator));
- }
-
- $query = sprintf('test %s:%s', $operator, $values[$operator]);
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- try {
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue(true);
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testUserAction(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'user_action:anything';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be ignored.
- $this->assertCount(0, $object->getOperators());
-
- // execute search should throw error:
- try {
- $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertEquals('Search query is empty.', $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testFromAccountStarts(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_starts:from_acct_strts_9';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_strts_928_ends_Test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testAmountIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'amount_exactly:23.45';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries test exact amount', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testAmountLess(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'amount_less:5.55';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries test small amount', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testAmountMore(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'amount_more:555.55';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries test large amount', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testTransactionType(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'transaction_type:withdrawal';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // not sure but should find plenty
- // TODO compare count to DB search by hand.
- $this->assertTrue(count($result) > 10);
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountStarts(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_starts:Dest1A';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest1Acct2Test3Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDateExact(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'on:2019-02-02';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(2, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Transaction on feb 2, 2019.', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDateBefore(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'before:2018-02-02';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Transaction on feb 2, 2018.', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testCreatedAt(): void
- {
- $this->be($this->user());
-
- // update one journal to have a very specific created_on date:
- DB::table('transaction_journals')->where('id', 1)->update(['created_at' => '2020-08-12 00:00:00']);
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'created_at:2020-08-12';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals(1, $transaction['transaction_journal_id'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testUpdatedAt(): void
- {
- $this->be($this->user());
-
- // update one journal to have a very specific created_on date:
- DB::table('transaction_journals')->where('id', 1)->update(['updated_at' => '2020-08-12 00:00:00']);
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'updated_at:2020-08-12';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals(1, $transaction['transaction_journal_id'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testExternalId(): void
- {
- $this->be($this->user());
-
- // update one journal to have a very specific created_on date:
- DB::table('transaction_journals')->where('id', 1)->update(['updated_at' => '2020-08-12 00:00:00']);
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'external_id:some_ext_id';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testJournalId(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'journal_id:1,2';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // two results
- $this->assertCount(2, $result);
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testInternalReference(): void
- {
- $this->be($this->user());
-
- // update one journal to have a very specific created_on date:
- DB::table('transaction_journals')->where('id', 1)->update(['updated_at' => '2020-08-12 00:00:00']);
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'internal_reference:some_internal_ref';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDateAfter(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'after:2018-05-02';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- // TODO should find all transactions but one.
- $this->assertTrue(count($result) > 3);
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountEnds(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_ends:3Thing';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest1Acct2Test3Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountContains(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_contains:2Test3';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest1Acct2Test3Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestination(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'destination:2Test3';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest1Acct2Test3Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_is:Dest1Acct2Test3Thing';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest1Acct2Test3Thing', $transaction['destination_account_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasAttachments(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_attachments:empty';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries with attachment', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasAnyCategory(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_any_category:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertTrue(count($result) > 2);
- // TODO better verification.
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasAnyTag(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_any_tag:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, tricky to verify.
- $this->assertCount(1, $result);
-
- // the first one should say "Groceries".
- $transaction = array_shift($result->first()['transactions']);
- $tags = $transaction['tags'] ?? [];
- $singleTag = array_shift($tags);
- $this->assertEquals('searchTestTag', $singleTag['name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasAnyBudget(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_any_budget:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertTrue(count($result) > 2);
- // todo verify
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testCategory(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'category:"Search cat thing"';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertCount(1, $result);
-
- // the first one should say "Groceries".
- $transaction = array_shift($result->first()['transactions']);
- $this->assertEquals('Search cat thing', $transaction['category_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testTag(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'tag:searchTestTag';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertCount(1, $result);
-
- // the first one should hav this tag.
- $transaction = array_shift($result->first()['transactions']);
- $tags = $transaction['tags'] ?? [];
- $singleTag = array_shift($tags);
- $this->assertEquals('searchTestTag', $singleTag['name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testBudget(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'budget:"Search budget thing"';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertCount(1, $result);
-
- // the first one should say "Groceries".
- $transaction = array_shift($result->first()['transactions']);
- $this->assertEquals('Search budget thing', $transaction['budget_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testBill(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'bill:TestBill';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // many results, tricky to verify.
- $this->assertCount(1, $result);
-
- // the first one should say "Groceries".
- $transaction = array_shift($result->first()['transactions']);
- $this->assertEquals('TestBill', $transaction['bill_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasNoCategory(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_no_category:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries with no category', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasNoBudget(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_no_budget:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries with no budget', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testHasNoTag(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'has_no_tag:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // could have many results, grab first transaction:
- $this->assertTrue(count($result) > 1);
-
- // todo better verification
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountIdIs(): void
- {
- $this->be($this->user());
-
- /** @var Account $account */
- $account = $this->user()->accounts()->where('name', 'Dest2Acct3Test4Thing')->first();
- $accountId = (int) $account->id;
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = sprintf('destination_account_id:%d', $accountId);
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest2Acct3Test4Thing', $transaction['destination_account_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountIdIs(): void
- {
- $this->be($this->user());
-
- /** @var Account $account */
- $account = $this->user()->accounts()->where('name', 'from_acct_NL30ABNA_test')->first();
- $accountId = (int) $account->id;
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = sprintf('source_account_id:%d', $accountId);
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL30ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testAccountIdIs(): void
- {
- $this->be($this->user());
-
- /** @var Account $account */
- $account = $this->user()->accounts()->where('name', 'from_acct_NL30ABNA_test')->first();
- $accountId = (int) $account->id;
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = sprintf('account_id:%d', $accountId);
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL30ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrStartsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_starts:NL45RABO';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL45RABO_ends', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrStartsNumber(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_starts:NL30AB';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL30ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrEndsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_ends:29221';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL45RABO_ends', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrEndsNumber(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_ends:8035321';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL28ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrIsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_is:NL45RABO5319829221';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL45RABO_ends', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrIsNumber(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_is:NL28ABNA1938035321';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL28ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrContainsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_contains:O53198';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL45RABO_ends', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountNrContainsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_nr_contains:L98RABO';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest2Acct3Test4Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountNrIsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_nr_is:NL98RABO9223011655';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest2Acct3Test4Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountNrStartsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_nr_starts:NL98RABO';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest2Acct3Test4Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDestinationAccountNrEndsIban(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'to_account_nr_ends:011655';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Dest2Acct3Test4Thing', $transaction['destination_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountNrContainsNumber(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_nr_contains:8ABNA1';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_NL28ABNA_test', $transaction['source_account_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_is:from_acct_strts_928_ends_Test';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_strts_928_ends_Test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountContains(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_contains:t_strts_928';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_strts_928_ends_Test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSource(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'source:t_strts_928';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_strts_928_ends_Test', $transaction['source_account_name'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDescriptionStarts(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'description_starts:8uStartTest';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('8uStartTest Groceries', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDescriptionEnds(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'description_ends:22end33';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries 22end33', $transaction['description'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDescriptionContains(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'description_contains:76tte32';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(1, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(0, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groc 76tte32 eries', $transaction['description'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testNotesContain(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'notes_contain:rch5No';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Test4Search5Notes6Thing', $transaction['notes'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testNotesStart(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'notes_start:Test4';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Test4Search5Notes6Thing', $transaction['notes'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testNotesEnd(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'notes_end:6Thing';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Test4Search5Notes6Thing', $transaction['notes'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testNotesAre(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'notes_are:Test4Search5Notes6Thing';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Test4Search5Notes6Thing', $transaction['notes'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testAnyNotes(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'any_notes:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Test4Search5Notes6Thing', $transaction['notes'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testNoNotes(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'no_notes:true';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // should have more than 1 result.
- $this->assertTrue(count($result) > 2);
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testDescriptionIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'description_is:"Groceries descr is 3291"';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('Groceries descr is 3291', $transaction['description'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testCurrencyIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'currency_is:HUF';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('HUF', $transaction['currency_code'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testCurrencyNameIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'currency_is:"Hungarian forint"';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('HUF', $transaction['currency_code'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testForeignCurrencyIs(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'foreign_currency_is:USD';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('USD', $transaction['foreign_currency_code'] ?? '');
- }
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testSourceAccountEnds(): void
- {
- $this->be($this->user());
-
- $object = new OperatorQuerySearch;
- $object->setUser($this->user());
- $object->setPage(1);
- $query = 'from_account_ends:28_ends_Test';
- Log::debug(sprintf('Trying to parse query "%s"', $query));
- try {
- $object->parseQuery($query);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $object->getWords());
-
- // operator is assumed to be included.
- $this->assertCount(1, $object->getOperators());
-
- $result = ['transactions' => []];
- // execute search should work:
- try {
- $result = $object->searchTransactions();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // one result, grab first transaction:
- $this->assertCount(1, $result);
- $transaction = array_shift($result->first()['transactions']);
-
- // check if result is as expected.
- $this->assertEquals('from_acct_strts_928_ends_Test', $transaction['source_account_name'] ?? '');
- }
-
-
- /**
- * @covers \FireflyIII\Support\Search\OperatorQuerySearch
- */
- public function testGetWordsAsString(): void
- {
-
- $object = new OperatorQuerySearch();
- $this->assertEquals('', $object->getWordsAsString());
- }
-}
\ No newline at end of file
diff --git a/tests/Unit/TransactionRules/Actions/AddTagTest.php b/tests/Unit/TransactionRules/Actions/AddTagTest.php
deleted file mode 100644
index a3381bed2f..0000000000
--- a/tests/Unit/TransactionRules/Actions/AddTagTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-/**
- * AddTagTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\Tag;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\AddTag;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AddTagTest
- */
-class AddTagTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\AddTag
- */
- public function testActExistingTag(): void
- {
- /** @var Tag $tag */
- $tag = $this->user()->tags()->where('tag', 'RuleActionTag')->first();
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
-
- // make sure journal has no tags:
- $journal->tags()->sync([]);
- $journal->save();
-
- // add single existing tag:
- $journal->tags()->sync([$tag->id]);
-
- // assert connection exists.
- $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
-
- // array with data required:
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $journal->id,
- ];
-
- // run the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $tag->tag;
- $action = new AddTag($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertFalse($result);
-
- // assert DB is unchanged.
- $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
- }
-
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\AddTag
- */
- public function testActNewTag(): void
- {
- /** @var Tag $tag */
- $tag = $this->user()->tags()->where('tag', 'RuleActionTag')->first();
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
-
- // make sure journal has no tags:
- $journal->tags()->sync([]);
- $journal->save();
-
- // array with data required:
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $journal->id,
- ];
-
- // run the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $tag->tag;
- $action = new AddTag($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // assert DB is updated! Yay!
- $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\AddTag
- */
- public function testActNullTag(): void
- {
- $newTagName = sprintf('TestTag-%d', $this->randomInt());
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
-
- // make sure journal has no tags:
- $journal->tags()->sync([]);
- $journal->save();
-
- // array with data required:
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $journal->id,
- ];
-
- // run the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $newTagName;
- $action = new AddTag($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // find the tag in the DB:
- $this->assertDatabaseHas('tags', ['tag' => $newTagName]);
-
- $tag = Tag::whereTag($newTagName)->first();
-
- // assert DB is updated! Yay!
- $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/AppendDescriptionTest.php b/tests/Unit/TransactionRules/Actions/AppendDescriptionTest.php
deleted file mode 100644
index 0cdfd8613f..0000000000
--- a/tests/Unit/TransactionRules/Actions/AppendDescriptionTest.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * AppendDescriptionTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\AppendDescription;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AppendDescriptionTest
- */
-class AppendDescriptionTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\AppendDescription
- */
- public function testAct(): void
- {
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
- $original = $journal->description;
-
-
- $array = [
- 'transaction_journal_id' => $journal->id,
- 'description' => $original,
- ];
-
- $ruleAction = new RuleAction;
- $ruleAction->action_value = 'APPEND';
- $action = new AppendDescription($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $journal = TransactionJournal::find($journal->id);
- $this->assertEquals(sprintf('%s%s', $original, $ruleAction->action_value), $journal->description);
-
- $journal->description = $original;
- $journal->save();
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/AppendNotesTest.php b/tests/Unit/TransactionRules/Actions/AppendNotesTest.php
deleted file mode 100644
index 0fab9f113b..0000000000
--- a/tests/Unit/TransactionRules/Actions/AppendNotesTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/**
- * AppendNotesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\AppendNotes;
-use Log;
-use Tests\TestCase;
-use DB;
-/**
- * Class AppendNotesTest
- */
-class AppendNotesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\AppendNotes
- */
- public function testActOnArray(): void
- {
- // give journal some notes.
- $journal = $this->user()->transactionJournals()->where('description','Rule action note test transaction.')->first();
-
- // make sure all notes deleted:
- DB::table('notes')->where('noteable_id', $journal->id)->where('noteable_type', TransactionJournal::class)->delete();
-
- // array for action:
- $array = [
- 'transaction_journal_id' => $journal->id
- ];
- $toAppend = 'Text to append to note.';
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $toAppend;
- $action = new AppendNotes($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $newNote = $journal->notes()->first();
- $this->assertEquals($toAppend, $newNote->text);
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/ClearBudgetTest.php b/tests/Unit/TransactionRules/Actions/ClearBudgetTest.php
deleted file mode 100644
index 812d450e8f..0000000000
--- a/tests/Unit/TransactionRules/Actions/ClearBudgetTest.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * ClearBudgetTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\Transaction;
-use FireflyIII\TransactionRules\Actions\ClearBudget;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ClearBudgetTest
- */
-class ClearBudgetTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\ClearBudget
- */
- public function testAct(): void
- {
- // associate budget with journal:
- $journal = $this->user()->transactionJournals()->where('description','Rule action test transaction.')->first();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
-
- // link a budget.
- $journal->budgets()->save($budget);
- $this->assertGreaterThan(0, $journal->budgets()->count());
-
- $array = [
- 'transaction_journal_id' => $journal->id
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = null;
- $action = new ClearBudget($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // assert result
- $this->assertEquals(0, $journal->budgets()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/ClearCategoryTest.php b/tests/Unit/TransactionRules/Actions/ClearCategoryTest.php
deleted file mode 100644
index 42ec63b5c2..0000000000
--- a/tests/Unit/TransactionRules/Actions/ClearCategoryTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/**
- * ClearCategoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\ClearCategory;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ClearCategoryTest
- */
-class ClearCategoryTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\ClearCategory
- */
- public function testAct(): void
- {
- // associate budget with journal:
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
-
- // link a budget.
- $journal->categories()->save($category);
- $this->assertGreaterThan(0, $journal->categories()->count());
-
- $array = [
- 'transaction_journal_id' => $journal->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = null;
- $action = new ClearCategory($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // assert result
- $this->assertEquals(0, $journal->categories()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/ClearNotesTest.php b/tests/Unit/TransactionRules/Actions/ClearNotesTest.php
deleted file mode 100644
index 857bf16d3b..0000000000
--- a/tests/Unit/TransactionRules/Actions/ClearNotesTest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * ClearNotesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use Exception;
-use FireflyIII\Models\Note;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\ClearNotes;
-use Log;
-use Tests\TestCase;
-
-
-/**
- * Class ClearNotesTest
- */
-class ClearNotesTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\ClearNotes
- */
- public function testAct(): void
- {
- // give journal a note:
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
- $note = $journal->notes()->first();
- if (null === $note) {
- $note = new Note;
- $note->noteable()->associate($journal);
- }
- $note->text = 'Hello test note';
- $note->save();
- $this->assertEquals(1, $journal->notes()->count());
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = null;
- $action = new ClearNotes($ruleAction);
-
- $array = [
- 'transaction_journal_id' => $journal->id
- ];
-
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // assert result
- $this->assertEquals(0, $journal->notes()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php b/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php
deleted file mode 100644
index 6053b99196..0000000000
--- a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-/**
- * ConvertToDepositTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-
-use Exception;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\TransactionRules\Actions\ConvertToDeposit;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class ConvertToDepositTest
- */
-class ConvertToDepositTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Convert a transfer to a deposit.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
- */
- public function testActTransfer(): void
- {
- /** @var TransactionJournal $transfer */
- $transfer = $this->user()->transactionJournals()->where('description', 'Transfer for convertToDeposit.')->first();
- $name = sprintf('Random revenue #%d', $this->randomInt());
-
- // journal is a transfer:
- $this->assertEquals(TransactionType::TRANSFER, $transfer->transactionType->type);
-
- // make array for action:
- $array = [
- 'transaction_journal_id' => $transfer->id,
- 'transaction_type_type' => $transfer->transactionType->type,
- 'user_id' => $this->user()->id,
- 'source_account_name' => 'Checking Account',
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $name;
- $action = new ConvertToDeposit($ruleAction);
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
- // get journal:
- $transfer->refresh();
- $this->assertEquals(TransactionType::DEPOSIT, $transfer->transactionType->type);
- }
-
- /**
- * Convert a withdrawal to a deposit.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
- */
- public function testActWithdrawal(): void
- {
- /** @var TransactionJournal $withdrawal */
- $withdrawal = $this->user()->transactionJournals()->where('description', 'Withdrawal for convertToDeposit.')->first();
- $name = sprintf('Random revenue #%d', $this->randomInt());
-
- // journal is a withdrawal:
- $this->assertEquals(TransactionType::WITHDRAWAL, $withdrawal->transactionType->type);
-
- // quick DB search for original source:
- $source = Account::where('name', 'Checking Account')->first();
-
- // make array for action:
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'transaction_type_type' => $withdrawal->transactionType->type,
- 'user_id' => $this->user()->id,
- 'destination_account_name' => 'SuperMarket',
- 'source_account_id' => $source->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $name;
- $action = new ConvertToDeposit($ruleAction);
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
- // get journal:
- $withdrawal->refresh();
- $this->assertEquals(TransactionType::DEPOSIT, $withdrawal->transactionType->type);
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php b/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php
deleted file mode 100644
index d3d1aa42ac..0000000000
--- a/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php
+++ /dev/null
@@ -1,142 +0,0 @@
-<?php
-/**
- * ConvertToTransferTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-
-use Exception;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\Rule;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\TransactionRules\Actions\ConvertToTransfer;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class ConvertToTransferTest
- */
-class ConvertToTransferTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Convert a deposit to a transfer.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToTransfer
- */
- public function testActDeposit(): void
- {
- /** @var TransactionJournal $deposit */
- $deposit = $this->user()->transactionJournals()->where('description', 'Deposit for ConvertToTransferTest.')->first();
-
- // get new source account (replaces the revenue account):
- $newSource = Account::whereName('Savings Account')->first();
- $destination = Account::whereName('Checking Account')->first();
- // journal is a withdrawal:
- $this->assertEquals(TransactionType::DEPOSIT, $deposit->transactionType->type);
-
- // make the required array:
- $array = [
- 'transaction_journal_id' => $deposit->id,
- 'transaction_type_type' => $deposit->transactionType->type,
- 'user_id' => 1,
- 'destination_account_id' => $destination->id,
- ];
-
- // fire the action:
- $rule = new Rule;
- $rule->title = 'OK';
- $ruleAction = new RuleAction;
- $ruleAction->action_value = 'Savings Account';
- $ruleAction->rule = $rule;
- $action = new ConvertToTransfer($ruleAction);
-
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // journal is now a transfer.
- $deposit->refresh();
- $this->assertEquals(TransactionType::TRANSFER, $deposit->transactionType->type);
- }
-
- /**
- * Convert a withdrawal to a transfer.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToTransfer
- */
- public function testActWithdrawal(): void
- {
- /** @var TransactionJournal $withdrawal */
- $withdrawal = $this->user()->transactionJournals()->where('description', 'Withdrawal for ConvertToTransferTest.')->first();
-
- // new asset to link to destination of withdrawal:
- $newDestination = Account::whereName('Savings Account')->first();
- $source = Account::whereName('Checking Account')->first();
- // array with necessary data:
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'transaction_type_type' => $withdrawal->transactionType->type,
- 'user_id' => 1,
- 'source_account_id' => $source->id,
- ];
-
- // fire the action:
- $rule = new Rule;
- $rule->title = 'OK';
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $newDestination->name;
- $ruleAction->rule = $rule;
- $action = new ConvertToTransfer($ruleAction);
-
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // journal is now a transfer.
- $withdrawal->refresh();
- $this->assertEquals(TransactionType::TRANSFER, $withdrawal->transactionType->type);
- }
-
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php b/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php
deleted file mode 100644
index 67a01bbc0e..0000000000
--- a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php
+++ /dev/null
@@ -1,146 +0,0 @@
-<?php
-/**
- * ConvertToWithdrawalTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-
-use Exception;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\TransactionRules\Actions\ConvertToWithdrawal;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class ConvertToWithdrawalTest
- */
-class ConvertToWithdrawalTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Convert a deposit to a withdrawal.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToWithdrawal
- */
- public function testActDeposit()
- {
- /** @var TransactionJournal $deposit */
- $deposit = $this->user()->transactionJournals()->where('description', 'Deposit for ConvertToWithdrawalTest.')->first();
-
- // new expense account:
- $name = sprintf('Random expense #%d', $this->randomInt());
-
- // original destination:
- $destination = Account::where('name','Checking Account')->first();
-
- // journal is a deposit:
- $this->assertEquals(TransactionType::DEPOSIT, $deposit->transactionType->type);
-
- // array:
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $deposit->id,
- 'transaction_type_type' => $deposit->transactionType->type,
- 'source_account_name' => 'Boss',
- 'destination_account_id' => $destination->id
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $name;
- $action = new ConvertToWithdrawal($ruleAction);
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // journal is now a withdrawal.
- $deposit->refresh();
- $this->assertEquals(TransactionType::WITHDRAWAL, $deposit->transactionType->type);
- }
-
- /**
- * Convert a transfer to a withdrawal.
- *
- * @covers \FireflyIII\TransactionRules\Actions\ConvertToWithdrawal
- */
- public function testActTransfer()
- {
- /** @var TransactionJournal $transfer */
- $transfer = $this->user()->transactionJournals()->where('description', 'Transfer for ConvertToWithdrawalTest.')->first();
-
- // new expense account:
- $name = sprintf('Random new expense #%d', $this->randomInt());
-
- $destination = Account::whereName('Checking Account')->first();
-
- // journal is a transfer:
- $this->assertEquals(TransactionType::TRANSFER, $transfer->transactionType->type);
-
- // array:
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $transfer->id,
- 'transaction_type_type' => $transfer->transactionType->type,
- 'destination_account_name' => $destination->name,
- //'source_account_name' => 'Boss',
- //'destination_account_id' => $destination->id
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $name;
- $action = new ConvertToWithdrawal($ruleAction);
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // journal is now a withdrawal.
- $transfer->refresh();
- $this->assertEquals(TransactionType::WITHDRAWAL, $transfer->transactionType->type);
- }
-
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/DeleteTransactionTest.php b/tests/Unit/TransactionRules/Actions/DeleteTransactionTest.php
deleted file mode 100644
index c095c9d22c..0000000000
--- a/tests/Unit/TransactionRules/Actions/DeleteTransactionTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * DeleteTransactionTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use Exception;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\DeleteTransaction;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AddTagTest
- */
-class DeleteTransactionTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\DeleteTransaction
- */
- public function testAct(): void
- {
- $journal = TransactionJournal::whereDescription('Withdrawal to DELETE.')->first();
-
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = null;
- $action = new DeleteTransaction($ruleAction);
-
- $array = [
- 'transaction_journal_id' => $journal->id,
- 'transaction_group_id' => $journal->transaction_group_id,
- 'description' => $journal->description,
- ];
-
- try {
- $result = $action->actOnArray($array);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue($result);
-
- // assert result
- $journal->refresh();
- $this->assertNotNull($journal->deleted_at);
- }
-
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/LinkToBillTest.php b/tests/Unit/TransactionRules/Actions/LinkToBillTest.php
deleted file mode 100644
index 176040ff89..0000000000
--- a/tests/Unit/TransactionRules/Actions/LinkToBillTest.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
- * LinkToBillTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\LinkToBill;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class LinkToBillTest
- */
-class LinkToBillTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\LinkToBill
- */
- public function testBasic(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $bill = $this->getRandomBill();
-
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'transaction_type_type' => $withdrawal->transactionType->type,
- 'user_id' => $this->user()->id,
- ];
-
- $ruleAction = new RuleAction;
- $ruleAction->action_type = 'link_to_bill';
- $ruleAction->action_value = $bill->name;
-
- $action = new LinkToBill($ruleAction);
- $result = $action->actOnArray($array);
-
- $this->assertTrue($result);
- // withdrawal has bill id.
- $withdrawal->refresh();
- $this->assertEquals($bill->id, $withdrawal->bill_id);
-
- $withdrawal->bill_id = null;
- $withdrawal->save();
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php b/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php
deleted file mode 100644
index 7777ea7f9f..0000000000
--- a/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/**
- * PrependDescriptionTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\AppendDescription;
-use FireflyIII\TransactionRules\Actions\PrependDescription;
-use Tests\TestCase;
-
-/**
- * Class PrependDescriptionTest
- */
-class PrependDescriptionTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\PrependDescription
- */
- public function testAct(): void
- {
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('description', 'Rule action test transaction.')->first();
- $original = $journal->description;
-
-
- $array = [
- 'transaction_journal_id' => $journal->id,
- 'description' => $original,
- ];
-
- $ruleAction = new RuleAction;
- $ruleAction->action_value = 'PREPEND';
- $action = new PrependDescription($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $journal = TransactionJournal::find($journal->id);
- $this->assertEquals(sprintf('%s%s', $ruleAction->action_value, $original), $journal->description);
-
- $journal->description = $original;
- $journal->save();
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/PrependNotesTest.php b/tests/Unit/TransactionRules/Actions/PrependNotesTest.php
deleted file mode 100644
index 156a739c5e..0000000000
--- a/tests/Unit/TransactionRules/Actions/PrependNotesTest.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-/**
- * PrependNotesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\PrependNotes;
-use Tests\TestCase;
-use DB;
-
-/**
- * Class PrependNotesTest
- * TODO doesnt test if prepends or appends.
- */
-class PrependNotesTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\PrependNotes
- */
- public function testAct(): void
- {
- // give journal some notes.
- $journal = $this->user()->transactionJournals()->where('description','Rule action note test transaction.')->first();
-
- // make sure all notes deleted:
- DB::table('notes')->where('noteable_id', $journal->id)->where('noteable_type', TransactionJournal::class)->delete();
-
- // array for action:
- $array = [
- 'transaction_journal_id' => $journal->id
- ];
- $toAppend = 'Text to append to note.';
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $toAppend;
- $action = new PrependNotes($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $newNote = $journal->notes()->first();
- $this->assertEquals($toAppend, $newNote->text);
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/RemoveAllTagsTest.php b/tests/Unit/TransactionRules/Actions/RemoveAllTagsTest.php
deleted file mode 100644
index 656e470858..0000000000
--- a/tests/Unit/TransactionRules/Actions/RemoveAllTagsTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * RemoveAllTagsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\RemoveAllTags;
-use Tests\TestCase;
-
-/**
- * Class RemoveAllTagsTest
- */
-class RemoveAllTagsTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\RemoveAllTags
- */
- public function testAct(): void
- {
- // find journal
- $withdrawal = $this->getRandomWithdrawal();
- $tag = $this->getRandomTag();
-
- $withdrawal->tags()->sync([$tag->id]);
-
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = null;
- $action = new RemoveAllTags($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $this->assertEquals(0, $withdrawal->tags()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/RemoveTagTest.php b/tests/Unit/TransactionRules/Actions/RemoveTagTest.php
deleted file mode 100644
index 98dec1db93..0000000000
--- a/tests/Unit/TransactionRules/Actions/RemoveTagTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-/**
- * RemoveTagTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\RemoveTag;
-use Tests\TestCase;
-
-/**
- * Class RemoveTagTest
- */
-class RemoveTagTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\RemoveTag
- */
- public function testAct(): void
- { // find journal
- $withdrawal = $this->getRandomWithdrawal();
- $tag = $this->getRandomTag();
-
- $withdrawal->tags()->sync([$tag->id]);
-
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'user_id' => 1,
- ];
-
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $tag->tag;
- $action = new RemoveTag($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $this->assertEquals(0, $withdrawal->tags()->count());
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetBudgetTest.php b/tests/Unit/TransactionRules/Actions/SetBudgetTest.php
deleted file mode 100644
index 3f7f0779a2..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetBudgetTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * SetBudgetTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\TransactionRules\Actions\SetBudget;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class SetBudgetTest
- */
-class SetBudgetTest extends TestCase
-{
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\SetBudget
- */
- public function testAct(): void
- {
- // get journal, remove all budgets
- $journal = $this->user()->transactionJournals()->where('description','Groceries with no budget')->first();
- $budget = $this->getRandomBudget();
-
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $journal->id,
- 'transaction_type_type' => $journal->transactionType->type,
- ];
-
- $journal->budgets()->sync([]);
- $this->assertEquals(0, $journal->budgets()->count());
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $budget->name;
- $action = new SetBudget($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
- $this->assertEquals(1, $journal->budgets()->count());
-
- $journal->budgets()->sync([]);
- $this->assertEquals(0, $journal->budgets()->count());
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetCategoryTest.php b/tests/Unit/TransactionRules/Actions/SetCategoryTest.php
deleted file mode 100644
index a556a9f6b2..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetCategoryTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/**
- * SetCategoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\SetCategory;
-use Tests\TestCase;
-
-/**
- * Class SetCategoryTest
- */
-class SetCategoryTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\SetCategory
- */
- public function testAct(): void
- {
- // get journal, remove all budgets
- $journal = $this->user()->transactionJournals()->where('description','Groceries with no category')->first();
- $category = $this->getRandomCategory();
-
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $journal->id,
- 'transaction_type_type' => $journal->transactionType->type,
- ];
-
- $journal->budgets()->sync([]);
- $this->assertEquals(0, $journal->categories()->count());
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $category->name;
- $action = new SetCategory($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
- $this->assertEquals(1, $journal->categories()->count());
-
- $journal->categories()->sync([]);
- $this->assertEquals(0, $journal->categories()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php b/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php
deleted file mode 100644
index 8139621098..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/**
- * SetDescriptionTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\SetDescription;
-use Tests\TestCase;
-
-/**
- * Class SetDescriptionTest
- */
-class SetDescriptionTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\SetDescription
- */
- public function testAct(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $newDescription = sprintf('new description #%d', $this->randomInt());
- $oldDescription = $withdrawal->description;
-
- // get journal, give fixed description
- $array = [
- 'description' => $oldDescription,
- 'transaction_journal_id' => $withdrawal->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $newDescription;
- $action = new SetDescription($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- $withdrawal->refresh();
-
- // assert result
- $this->assertEquals($newDescription, $withdrawal->description);
-
- $withdrawal->description = $oldDescription;
- $withdrawal->save();
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php b/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php
deleted file mode 100644
index 13af9ace8a..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php
+++ /dev/null
@@ -1,183 +0,0 @@
-<?php
-/**
- * SetDestinationAccountTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\TransactionRules\Actions\SetDestinationAccount;
-use Tests\TestCase;
-
-/**
- * Try split journal
- *
- * Class SetDestinationAccountTest
- */
-class SetDestinationAccountTest extends TestCase
-{
- /**
- * Give deposit existing asset account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount
- */
- public function testActDepositExisting(): void
- {
- // get random deposit:
- $deposit = $this->getRandomDeposit();
- $destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
- $destination = $destinationTr->account;
- $oldDestination = $destinationTr->account_id;
-
- // grab unused asset account:
- $user = $deposit->user;
- $accountType = AccountType::whereType(AccountType::ASSET)->first();
- $newDestination = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
- $this->assertNotEquals($destination->id, $newDestination->id);
-
- // array with info:
- $array = [
- 'transaction_journal_id' => $deposit->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::DEPOSIT,
- 'source_account_type' => AccountType::REVENUE,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $newDestination->name;
- $action = new SetDestinationAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // test journal for new account
- $destinationTr->refresh();
- $updatedDestination = $destinationTr->account;
- $this->assertEquals($newDestination->id, $updatedDestination->id);
- $this->assertEquals($destinationTr->account_id, $newDestination->id);
-
- $destinationTr->account_id = $oldDestination;
- $destinationTr->save();
- }
-
- /**
- * Give deposit not existing asset account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount
- */
- public function testActDepositNotExisting(): void
- {
- // get random deposit:
- $deposit = $this->getRandomDeposit();
- $destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
- $oldDestination = $destinationTr->account;
-
- // array with info:
- $array = [
- 'transaction_journal_id' => $deposit->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::DEPOSIT,
- 'source_account_type' => AccountType::REVENUE,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = sprintf('Not existing asset account #%d', $this->randomInt());
- $action = new SetDestinationAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertFalse($result);
-
- // test journal for new account
- $destinationTr->refresh();
- $this->assertEquals($destinationTr->account_id, $oldDestination->id);
- }
-
- /**
- * Give withdrawal not existing expense account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount
- */
- public function testActWithDrawalNotExisting(): void
- {
- // get random withdrawal:
- $withdrawal = $this->getRandomWithdrawal();
- $destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
- $oldDestination = $destinationTr->account;
- // array with info:
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::WITHDRAWAL,
- 'source_account_type' => AccountType::ASSET,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = sprintf('Not existing expense account #%d', $this->randomInt());
- $action = new SetDestinationAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // test journal for new account
- $destinationTr->refresh();
- $newDestination = $destinationTr->account;
- $this->assertEquals($newDestination->name, $ruleAction->action_value);
-
- $destinationTr->account_id = $oldDestination;
- $destinationTr->save();
- }
-
- /**
- * Give withdrawal existing expense account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount
- */
- public function testActWithdrawalExisting(): void
- {
- // get random withdrawal:
- $withdrawal = $this->getRandomWithdrawal();
- $destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
- $oldDestination = $destinationTr->account;
- $newDestination = $this->user()->accounts()->where('id', '!=', $oldDestination->id)->first();
-
- // array with info:
- $array = [
- 'transaction_journal_id' => $withdrawal->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::WITHDRAWAL,
- 'source_account_type' => AccountType::ASSET,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $newDestination->name;
- $action = new SetDestinationAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // test journal for new account
- $destinationTr->refresh();
- $newDestination = $destinationTr->account;
- $this->assertEquals($newDestination->name, $ruleAction->action_value);
- }
-
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetNotesTest.php b/tests/Unit/TransactionRules/Actions/SetNotesTest.php
deleted file mode 100644
index 53eb0fbd12..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetNotesTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * SetNotesTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Actions\SetNotes;
-use Tests\TestCase;
-
-/**
- * Class SetNotesTest
- */
-class SetNotesTest extends TestCase
-{
- /**
- * @covers \FireflyIII\TransactionRules\Actions\SetNotes
- */
- public function testAct(): void
- {
- // give journal a note:
- $journal = $this->getRandomWithdrawal();
- $note = $journal->notes()->first();
- if (null === $note) {
- $note = new Note;
- $note->noteable()->associate($journal);
- }
- $note->text = 'Hello test note';
- $note->save();
- $this->assertEquals(1, $journal->notes()->count());
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = sprintf('These are new notes #%d', $this->randomInt());
- $action = new SetNotes($ruleAction);
- $result = $action->act($journal);
- $this->assertTrue($result);
-
- // assert result
- $this->assertEquals(1, $journal->notes()->count());
- $this->assertEquals($note->id, $journal->notes()->first()->id);
- $journal->notes()->delete();
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\SetNotes()
- * @covers \FireflyIII\TransactionRules\Actions\SetNotes
- */
- public function testActNoNotes(): void
- {
- // give journal a note:
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->forceDelete();
- $this->assertEquals(0, $journal->notes()->count());
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = 'These are new notes ' . $this->randomInt();
- $action = new SetNotes($ruleAction);
- $result = $action->act($journal);
- $this->assertTrue($result);
-
- // assert result
- $this->assertEquals(1, $journal->notes()->count());
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php b/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php
deleted file mode 100644
index c30aab8cef..0000000000
--- a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php
+++ /dev/null
@@ -1,157 +0,0 @@
-<?php
-/**
- * SetSourceAccountTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Actions;
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\TransactionRules\Actions\SetSourceAccount;
-use Tests\TestCase;
-
-/**
- * Class SetSourceAccountTest
- */
-class SetSourceAccountTest extends TestCase
-{
- /**
- * Give deposit existing revenue account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount
- */
- public function testActDepositExistingUpdated(): void
- {
- $deposit = $this->getRandomDeposit();
- $sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
- $source = $sourceTr->account;
- $user = $deposit->user;
- $accountType = AccountType::whereType(AccountType::REVENUE)->first();
- $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
- $this->assertNotEquals($source->id, $account->id);
-
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_journal_id' => $deposit->id,
- 'transaction_type_type' => TransactionType::DEPOSIT,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $account->name;
- $action = new SetSourceAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // test journal for new account
- $sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
- $newSource = $sourceTr->account;
- $this->assertNotEquals($source->id, $newSource->id);
- $this->assertEquals($newSource->id, $account->id);
-
- $sourceTr->account_id = $source->id;
- $sourceTr->save();
- }
-
- /**
- * Give deposit new revenueaccount.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount
- */
- public function testActDepositRevenue(): void
- {
- $deposit = $this->getRandomDeposit();
-
- $array = [
- 'transaction_journal_id' => $deposit->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::DEPOSIT,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = sprintf('Some new revenue #%d', $this->randomInt());
- $action = new SetSourceAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
- }
-
- /**
- * Give withdrawal existing asset account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount
- */
- public function testActWithdrawalExistingUpdated(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
- $source = $sourceTr->account;
- $user = $withdrawal->user;
- $accountType = AccountType::whereType(AccountType::ASSET)->first();
- $account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
- $this->assertNotEquals($source->id, $account->id);
-
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::WITHDRAWAL,
- 'transaction_journal_id' => $withdrawal->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $account->name;
- $action = new SetSourceAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
-
- // test journal for new account
- $sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
- $newSource = $sourceTr->account;
- $this->assertNotEquals($source->id, $newSource->id);
- $this->assertEquals($newSource->id, $account->id);
-
- $sourceTr->account_id = $source->id;
- $sourceTr->save();
- }
-
- /**
- * Give withdrawal not existing asset account.
- *
- * @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount
- */
- public function testActWithdrawalNotExisting(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
-
- $array = [
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => TransactionType::WITHDRAWAL,
- 'transaction_journal_id' => $withdrawal->id,
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = sprintf('Some new account #%d', $this->randomInt());
- $action = new SetSourceAccount($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Actions/UpdatePiggybankTest.php b/tests/Unit/TransactionRules/Actions/UpdatePiggybankTest.php
deleted file mode 100644
index a2c948d4a8..0000000000
--- a/tests/Unit/TransactionRules/Actions/UpdatePiggybankTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/*
- * UpdatePiggybankTest.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-namespace Tests\Unit\TransactionRules\Actions;
-
-
-use FireflyIII\Models\RuleAction;
-use FireflyIII\TransactionRules\Actions\UpdatePiggybank;
-use Log;
-use Tests\TestCase;
-
-class UpdatePiggybankTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\UpdatePiggybank
- */
- public function testActOnArraySource(): void
- {
- // from saving to checking
- $transfer = $this->user()->transactionJournals()->where('description', 'Transfer for piggy bank 1')->first();
- // update (the only) piggy to belong to source:
- $piggy = $this->user()->piggyBanks()->where('piggy_banks.name', 'Action test 1')->first();
-
-
- $array = [
- 'transaction_journal_id' => $transfer->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => 'Transfer',
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $piggy->name;
- $action = new UpdatePiggybank($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Actions\UpdatePiggybank
- */
- public function testActOnArrayDestination(): void
- {
- // from saving to checking
- $transfer = $this->user()->transactionJournals()->where('description', 'Transfer for piggy bank 2')->first();
- // update (the only) piggy to belong to source:
- $piggy = $this->user()->piggyBanks()->where('piggy_banks.name', 'Action test 1')->first();
-
-
- $array = [
- 'transaction_journal_id' => $transfer->id,
- 'user_id' => $this->user()->id,
- 'transaction_type_type' => 'Transfer',
- ];
-
- // fire the action:
- $ruleAction = new RuleAction;
- $ruleAction->action_value = $piggy->name;
- $action = new UpdatePiggybank($ruleAction);
- $result = $action->actOnArray($array);
- $this->assertTrue($result);
- }
-}
\ No newline at end of file
diff --git a/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php b/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php
deleted file mode 100644
index b34a22aaf2..0000000000
--- a/tests/Unit/TransactionRules/Triggers/AmountExactlyTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * AmountExactlyTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\AmountExactly;
-use Tests\TestCase;
-
-/**
- * Class AmountExactlyTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AmountExactlyTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountExactly
- */
- public function testTriggeredExact(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34');
- $journal = new TransactionJournal;
- $journal->user = $this->user();
- $journal->destination_amount = '12.34';
- $trigger = AmountExactly::makeFromStrings('12.340', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountExactly
- */
- public function testTriggeredNotExact(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34');
- $journal = new TransactionJournal;
- $journal->user = $this->user();
- $journal->destination_amount = '12.35';
- $trigger = AmountExactly::makeFromStrings('12.340', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountExactly
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = AmountExactly::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountExactly
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = AmountExactly::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/AmountLessTest.php b/tests/Unit/TransactionRules/Triggers/AmountLessTest.php
deleted file mode 100644
index a7693a2d54..0000000000
--- a/tests/Unit/TransactionRules/Triggers/AmountLessTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * AmountLessTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\AmountLess;
-use Tests\TestCase;
-
-/**
- * Class AmountLessTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AmountLessTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountLess
- */
- public function testTriggeredExact(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35');
-
- $journal = new TransactionJournal;
- $journal->destination_amount = '12.35';
- $journal->user = $this->user();
- $trigger = AmountLess::makeFromStrings('12.35', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountLess
- */
- public function testTriggeredLess(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34');
-
- $journal = new TransactionJournal;
- $journal->destination_amount = '12.34';
- $journal->user = $this->user();
- $trigger = AmountLess::makeFromStrings('12.50', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountLess
- */
- public function testTriggeredNotLess(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35');
-
- $journal = new TransactionJournal;
- $journal->destination_amount = '12.35';
- $journal->user = $this->user();
- $trigger = AmountLess::makeFromStrings('12.00', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountLess
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = AmountLess::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountLess
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = AmountLess::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php b/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php
deleted file mode 100644
index 9d33e38aeb..0000000000
--- a/tests/Unit/TransactionRules/Triggers/AmountMoreTest.php
+++ /dev/null
@@ -1,127 +0,0 @@
-<?php
-/**
- * AmountMoreTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\AmountMore;
-use Tests\TestCase;
-
-/**
- * Class AmountMoreTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AmountMoreTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testTriggeredExact(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35');
-
- $journal = new TransactionJournal;
- $journal->user = $this->user();
- $journal->destination_amount = '12.35';
- $trigger = AmountMore::makeFromStrings('12.35', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testTriggeredMore(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.34');
-
- $journal = new TransactionJournal;
- $journal->user = $this->user();
- $journal->destination_amount = '12.34';
- $trigger = AmountMore::makeFromStrings('12.10', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testTriggeredNotMore(): void
- {
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $journalRepos->shouldReceive('setUser');
- $journalRepos->shouldReceive('getJournalTotal')->andReturn('12.35');
-
- $journal = new TransactionJournal;
- $journal->user = $this->user();
- $journal->destination_amount = '12.35';
- $trigger = AmountMore::makeFromStrings('12.50', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = '1';
- $result = AmountMore::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = AmountMore::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\AmountMore
- */
- public function testWillMatchEverythingZero(): void
- {
- $value = '0';
- $result = AmountMore::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/BudgetIsTest.php b/tests/Unit/TransactionRules/Triggers/BudgetIsTest.php
deleted file mode 100644
index 09e9783b82..0000000000
--- a/tests/Unit/TransactionRules/Triggers/BudgetIsTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * BudgetIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\TransactionRules\Triggers\BudgetIs;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class BudgetIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\BudgetIs
- */
- public function testTriggeredJournal(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $budget = $withdrawal->user->budgets()->first();
- $withdrawal->budgets()->detach();
- $withdrawal->budgets()->save($budget);
- $this->assertEquals(1, $withdrawal->budgets()->count());
-
- $trigger = BudgetIs::makeFromStrings($budget->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\BudgetIs
- */
- public function testTriggeredNotJournal(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $budget = $withdrawal->user->budgets()->first();
- $otherBudget = $withdrawal->user->budgets()->where('id', '!=', $budget->id)->first();
- $withdrawal->budgets()->detach();
- $withdrawal->budgets()->save($budget);
- $this->assertEquals(1, $withdrawal->budgets()->count());
-
- $trigger = BudgetIs::makeFromStrings($otherBudget->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\BudgetIs
- */
- public function testTriggeredTransaction(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- /** @var Collection $transactions */
- $transactions = $withdrawal->transactions()->get();
- $budget = $withdrawal->user->budgets()->first();
-
- $withdrawal->budgets()->detach();
- /** @var Transaction $transaction */
- foreach ($transactions as $transaction) {
- $transaction->budgets()->detach();
- $transaction->budgets()->save($budget);
- $this->assertEquals(1, $transaction->budgets()->count());
- }
-
- $this->assertEquals(0, $withdrawal->budgets()->count());
-
- $trigger = BudgetIs::makeFromStrings($budget->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\BudgetIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = BudgetIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\BudgetIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = BudgetIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/CategoryIsTest.php b/tests/Unit/TransactionRules/Triggers/CategoryIsTest.php
deleted file mode 100644
index 82ec8230e9..0000000000
--- a/tests/Unit/TransactionRules/Triggers/CategoryIsTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * CategoryIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\TransactionRules\Triggers\CategoryIs;
-use Tests\TestCase;
-
-/**
- * Class CategoryIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs
- */
- public function testTriggeredJournal(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $category = $withdrawal->user->categories()->first();
- $withdrawal->categories()->detach();
- $withdrawal->categories()->save($category);
- $this->assertEquals(1, $withdrawal->categories()->count());
-
- $trigger = CategoryIs::makeFromStrings($category->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs
- */
- public function testTriggeredNotJournal(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $category = $withdrawal->user->categories()->first();
- $otherCategory = $withdrawal->user->categories()->where('id', '!=', $category->id)->first();
- $withdrawal->categories()->detach();
- $withdrawal->categories()->save($category);
- $this->assertEquals(1, $withdrawal->categories()->count());
-
- $trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs
- */
- public function testTriggeredTransaction(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $transaction = $withdrawal->transactions()->first();
- $category = $withdrawal->user->categories()->first();
-
- $withdrawal->categories()->detach();
- $transaction->categories()->detach();
- $transaction->categories()->save($category);
- $this->assertEquals(0, $withdrawal->categories()->count());
- $this->assertEquals(1, $transaction->categories()->count());
-
- $trigger = CategoryIs::makeFromStrings($category->name, false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = CategoryIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\CategoryIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = CategoryIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/DescriptionContainsTest.php b/tests/Unit/TransactionRules/Triggers/DescriptionContainsTest.php
deleted file mode 100644
index 7e5c353bae..0000000000
--- a/tests/Unit/TransactionRules/Triggers/DescriptionContainsTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * DescriptionContainsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\DescriptionContains;
-use Tests\TestCase;
-
-/**
- * Class DescriptionContains
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DescriptionContainsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testTriggeredCase(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUM bla bla ';
- $trigger = DescriptionContains::makeFromStrings('ipsum', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testTriggeredDefault(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Should contain test string';
- $trigger = DescriptionContains::makeFromStrings('cont', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testTriggeredEnd(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionContains::makeFromStrings('pen', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testTriggeredNot(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUM bla bla ';
- $trigger = DescriptionContains::makeFromStrings('blurb', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testTriggeredStart(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionContains::makeFromStrings('somet', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = DescriptionContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = DescriptionContains::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionContains
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = DescriptionContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/DescriptionEndsTest.php b/tests/Unit/TransactionRules/Triggers/DescriptionEndsTest.php
deleted file mode 100644
index 2e393a4560..0000000000
--- a/tests/Unit/TransactionRules/Triggers/DescriptionEndsTest.php
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-/**
- * DescriptionEndsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\DescriptionEnds;
-use Tests\TestCase;
-
-/**
- * Class DescriptionEnds
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DescriptionEndsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredCase(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUMbla';
- $trigger = DescriptionEnds::makeFromStrings('umbla', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredClose(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionEnds::makeFromStrings('happe', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredDefault(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Should contain test string';
- $trigger = DescriptionEnds::makeFromStrings('string', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredLongSearch(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something';
- $trigger = DescriptionEnds::makeFromStrings('Something is', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredLonger(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionEnds::makeFromStrings('xhappen', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testTriggeredNot(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUM blabla';
- $trigger = DescriptionEnds::makeFromStrings('lorem', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = DescriptionEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = DescriptionEnds::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionEnds
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = DescriptionEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/DescriptionIsTest.php b/tests/Unit/TransactionRules/Triggers/DescriptionIsTest.php
deleted file mode 100644
index 3ef66ce213..0000000000
--- a/tests/Unit/TransactionRules/Triggers/DescriptionIsTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * DescriptionIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\DescriptionIs;
-use Tests\TestCase;
-
-/**
- * Class DescriptionIs
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DescriptionIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testTriggeredCase(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUMbla';
- $trigger = DescriptionIs::makeFromStrings('lorem ipsumbla', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testTriggeredClose(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionIs::makeFromStrings('Something is going to happe', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testTriggeredDefault(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Should be test string';
- $trigger = DescriptionIs::makeFromStrings('Should be test string', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testTriggeredNot(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUM blabla';
- $trigger = DescriptionIs::makeFromStrings('lorem', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = DescriptionIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = DescriptionIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/DescriptionStartsTest.php b/tests/Unit/TransactionRules/Triggers/DescriptionStartsTest.php
deleted file mode 100644
index a965214e81..0000000000
--- a/tests/Unit/TransactionRules/Triggers/DescriptionStartsTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * DescriptionStartsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\DescriptionStarts;
-use Tests\TestCase;
-
-/**
- * Class DescriptionStarts
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DescriptionStartsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testTriggeredCase(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUMbla';
- $trigger = DescriptionStarts::makeFromStrings('lorem', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testTriggeredClose(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something is going to happen';
- $trigger = DescriptionStarts::makeFromStrings('omething', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testTriggeredDefault(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Should contain test string';
- $trigger = DescriptionStarts::makeFromStrings('Should', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testTriggeredLongSearch(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Something';
- $trigger = DescriptionStarts::makeFromStrings('Something is', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testTriggeredNot(): void
- {
- $journal = new TransactionJournal;
- $journal->description = 'Lorem IPSUM blabla';
- $trigger = DescriptionStarts::makeFromStrings('blabla', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = DescriptionStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = DescriptionStarts::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\DescriptionStarts
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = DescriptionStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php
deleted file mode 100644
index 5112834643..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * FromAccountContainsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountContains;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class FromAccountContainsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountContainsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountContains::makeFromStrings($account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountContains::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php
deleted file mode 100644
index a3a774550f..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-/**
- * FromAccountEndsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class FromAccountEndsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountEndsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountEnds::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountEnds::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountEnds
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php
deleted file mode 100644
index 578d0720a8..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/**
- * FromAccountIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountIs;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class FromAccountIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
-
- $trigger = FromAccountIs::makeFromStrings($account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php
deleted file mode 100644
index 582e2cef52..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php
+++ /dev/null
@@ -1,170 +0,0 @@
-<?php
-/**
- * FromAccountNumberContainsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountNumberContains;
-use Tests\TestCase;
-
-/**
- * Class FromAccountNumberContainsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountNumberContainsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberContains::makeFromStrings('7027', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
-
- $meta->forceDelete();
-
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberContains::makeFromStrings('7027', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
-
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberContains::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $trigger = FromAccountNumberContains::makeFromStrings('276251', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- $meta->forceDelete();
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountNumberContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountNumberContains::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberContains
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountNumberContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountNumberEndsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountNumberEndsTest.php
deleted file mode 100644
index 07d4736f1f..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountNumberEndsTest.php
+++ /dev/null
@@ -1,167 +0,0 @@
-<?php
-/**
- * FromAccountNumberEndsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds;
-use Tests\TestCase;
-
-/**
- * Class FromAccountNumberEndsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountNumberEndsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberEnds::makeFromStrings('1234', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountNumberEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountNumberEnds::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountNumberEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountNumberIsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountNumberIsTest.php
deleted file mode 100644
index df370fe01a..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountNumberIsTest.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-/**
- * FromAccountNumberIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountNumberIs;
-use Tests\TestCase;
-
-/**
- * Class FromAccountNumberIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountNumberIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
-
- $trigger = FromAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
-
- $trigger = FromAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
-
- $trigger = FromAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberIs::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = FromAccountNumberIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = FromAccountNumberIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = FromAccountNumberIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountNumberStartsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountNumberStartsTest.php
deleted file mode 100644
index 0ca6cfb975..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountNumberStartsTest.php
+++ /dev/null
@@ -1,189 +0,0 @@
-<?php
-/**
- * FromAccountNumberStartsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class FromAccountNumberStartsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountNumberStartsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberStarts::makeFromStrings('FR76x', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = '';
- $result = FromAccountNumberStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = 'x';
- $result = FromAccountNumberStarts::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = null;
- $result = FromAccountNumberStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php
deleted file mode 100644
index c0c190309f..0000000000
--- a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php
+++ /dev/null
@@ -1,143 +0,0 @@
-<?php
-/**
- * FromAccountStartsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class FromAccountStartsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class FromAccountStartsTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
-
- $trigger = FromAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = '';
- $result = FromAccountStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = 'x';
- $result = FromAccountStarts::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\FromAccountStarts
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $value = null;
- $result = FromAccountStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasAnyBudgetTest.php b/tests/Unit/TransactionRules/Triggers/HasAnyBudgetTest.php
deleted file mode 100644
index d41797b95d..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasAnyBudgetTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * HasAnyBudgetTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\TransactionRules\Triggers\HasAnyBudget;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class HasAnyBudgetTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasAnyBudgetTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget
- */
- public function testTriggered(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
-
- $budget = $withdrawal->user->budgets()->first();
- $withdrawal->budgets()->detach();
- $withdrawal->budgets()->save($budget);
-
- $this->assertEquals(1, $withdrawal->budgets()->count());
- $trigger = HasAnyBudget::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
-
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget
- */
- public function testTriggeredNot(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $withdrawal->budgets()->detach();
- $this->assertEquals(0, $withdrawal->budgets()->count());
-
- // also detach all transactions:
- /** @var Transaction $transaction */
- foreach ($withdrawal->transactions()->get() as $transaction) {
- $transaction->budgets()->detach();
- }
-
- $trigger = HasAnyBudget::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget
- */
- public function testTriggeredTransactions(): void
- {
- Log::debug('Now in testTriggeredTransactions()');
- $withdrawal = $this->getRandomWithdrawal();
-
- $budget = $withdrawal->user->budgets()->first();
- Log::debug(sprintf('First budget is %d ("%s")', $budget->id, $budget->name));
- $withdrawal->budgets()->detach();
- $this->assertEquals(0, $withdrawal->budgets()->count());
- Log::debug('Survived the assumption.');
-
- // append to transaction
- Log::debug('Do transaction loop.');
- foreach ($withdrawal->transactions()->get() as $index => $transaction) {
- Log::debug(sprintf('Now at index #%d, transaction #%d', $index, $transaction->id));
- $transaction->budgets()->detach();
- if (0 === $index) {
- Log::debug('Index is zero, attach budget.');
- $transaction->budgets()->save($budget);
- }
- }
- Log::debug('Done with loop, make trigger');
- $trigger = HasAnyBudget::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyBudget
- */
- public function testWillMatchEverything(): void
- {
- $value = '';
- $result = HasAnyBudget::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasAnyCategoryTest.php b/tests/Unit/TransactionRules/Triggers/HasAnyCategoryTest.php
deleted file mode 100644
index 742194330d..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasAnyCategoryTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/**
- * HasAnyCategoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasAnyCategory;
-use Tests\TestCase;
-
-/**
- * Class HasAnyCategoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasAnyCategoryTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $category = $this->getRandomCategory();;
- $journal->categories()->detach();
- $journal->categories()->save($category);
-
- $this->assertEquals(1, $journal->categories()->count());
- $trigger = HasAnyCategory::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory
- */
- public function testTriggeredNot(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->categories()->detach();
-
- // also detach transactions:
- /** @var Transaction $transaction */
- foreach ($journal->transactions as $transaction) {
- $transaction->categories()->detach();
- }
-
- $this->assertEquals(0, $journal->categories()->count());
- $trigger = HasAnyCategory::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory
- */
- public function testTriggeredTransactions(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
-
- $category = $withdrawal->user->categories()->first();
- $withdrawal->categories()->detach();
- $this->assertEquals(0, $withdrawal->categories()->count());
-
- // append to transaction, not to journal.
- foreach ($withdrawal->transactions()->get() as $index => $transaction) {
- $transaction->categories()->sync([$category->id]);
- $this->assertEquals(1, $transaction->categories()->count());
- }
- $this->assertEquals(0, $withdrawal->categories()->count());
-
- $trigger = HasAnyCategory::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyCategory
- */
- public function testWillMatchEverything(): void
- {
- $value = '';
- $result = HasAnyCategory::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasAnyTagTest.php b/tests/Unit/TransactionRules/Triggers/HasAnyTagTest.php
deleted file mode 100644
index a56b4446f2..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasAnyTagTest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * HasAnyTagTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasAnyTag;
-use Tests\TestCase;
-
-/**
- * Class HasAnyTagTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasAnyTagTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $tag = $journal->user->tags()->first();
- $journal->tags()->detach();
- $journal->tags()->save($tag);
-
- $this->assertEquals(1, $journal->tags()->count());
- $trigger = HasAnyTag::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag
- */
- public function testTriggeredNot(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->tags()->detach();
- $this->assertEquals(0, $journal->tags()->count());
- $trigger = HasAnyTag::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAnyTag
- */
- public function testWillMatchEverything(): void
- {
- $value = '';
- $result = HasAnyTag::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php b/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php
deleted file mode 100644
index 89f341668d..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/**
- * HasAttachmentTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use DB;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasAttachment;
-use Tests\TestCase;
-
-/**
- * Class HasAttachmentTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasAttachmentTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAttachment
- */
- public function testTriggered(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
-
- $attachment = $withdrawal->user->attachments()->first();
- $withdrawal->attachments()->save($attachment);
- $this->assertGreaterThanOrEqual(1, $withdrawal->attachments()->count());
-
- $trigger = HasAttachment::makeFromStrings('1', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAttachment
- */
- public function testTriggeredFalse(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $attachment = $withdrawal->user->attachments()->first();
- $withdrawal->attachments()->save($attachment);
-
- DB::table('attachments')
- ->where('attachable_type', TransactionJournal::class)
- ->where('attachable_id', $withdrawal->id)->delete();
-
- $withdrawal->attachments()->saveMany([]);
- $this->assertEquals(0, $withdrawal->attachments()->count());
-
- $trigger = HasAttachment::makeFromStrings('1', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAttachment
- */
- public function testWillMatchEverything(): void
- {
- $value = '5';
- $result = HasAttachment::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasAttachment
- */
- public function testWillMatchEverythingTrue(): void
- {
- $value = -1;
- $result = HasAttachment::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasNoBudgetTest.php b/tests/Unit/TransactionRules/Triggers/HasNoBudgetTest.php
deleted file mode 100644
index 62309a08fc..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasNoBudgetTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * HasNoBudgetTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasNoBudget;
-use Tests\TestCase;
-
-/**
- * Class HasNoBudgetTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasNoBudgetTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget
- */
- public function testTriggeredBudget(): void
- {
- $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
- $budget = $this->getRandomBudget();
- $journal->budgets()->detach();
- $journal->budgets()->save($budget);
- $this->assertEquals(1, $journal->budgets()->count());
-
- $trigger = HasNoBudget::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget
- */
- public function testTriggeredNoBudget(): void
- {
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
- $journal->budgets()->detach();
- /** @var Transaction $transaction */
- foreach ($journal->transactions as $transaction) {
- $transaction->budgets()->detach();
- }
- $this->assertEquals(0, $journal->budgets()->count());
-
- $trigger = HasNoBudget::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget
- */
- public function testTriggeredTransaction(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
-
- $transactions = $withdrawal->transactions()->get();
- $budget = $withdrawal->user->budgets()->first();
-
- $withdrawal->budgets()->detach();
- /** @var Transaction $transaction */
- foreach ($transactions as $transaction) {
- $transaction->budgets()->sync([$budget->id]);
- $this->assertEquals(1, $transaction->budgets()->count());
- }
- $this->assertEquals(0, $withdrawal->budgets()->count());
-
- $trigger = HasNoBudget::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoBudget
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = HasNoBudget::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasNoCategoryTest.php b/tests/Unit/TransactionRules/Triggers/HasNoCategoryTest.php
deleted file mode 100644
index b10a2c6186..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasNoCategoryTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * HasNoCategoryTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasNoCategory;
-use Tests\TestCase;
-
-/**
- * Class HasNoCategoryTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasNoCategoryTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory
- */
- public function testTriggeredCategory(): void
- {
- $journal = $this->getRandomWithdrawal();
- $category = $this->getRandomCategory();;
- $journal->categories()->detach();
- $journal->categories()->save($category);
- $this->assertEquals(1, $journal->categories()->count());
-
- $trigger = HasNoCategory::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory
- */
- public function testTriggeredNoCategory(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->categories()->detach();
-
- // also detach transactions:
- /** @var Transaction $transaction */
- foreach ($journal->transactions as $transaction) {
- $transaction->categories()->detach();
- $this->assertEquals(0, $transaction->categories()->count());
- }
-
- $this->assertEquals(0, $journal->categories()->count());
-
- $trigger = HasNoCategory::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory
- */
- public function testTriggeredTransaction(): void
- {
- $withdrawal = $this->getRandomWithdrawal();
- $transaction = $withdrawal->transactions()->first();
- $category = $withdrawal->user->categories()->first();
-
- $withdrawal->categories()->detach();
- $transaction->categories()->sync([$category->id]);
- $this->assertEquals(0, $withdrawal->categories()->count());
- $this->assertEquals(1, $transaction->categories()->count());
-
- $trigger = HasNoCategory::makeFromStrings('', false);
- $result = $trigger->triggered($withdrawal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoCategory
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = HasNoCategory::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/HasNoTagTest.php b/tests/Unit/TransactionRules/Triggers/HasNoTagTest.php
deleted file mode 100644
index 0d41124103..0000000000
--- a/tests/Unit/TransactionRules/Triggers/HasNoTagTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * HasNoTagTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\HasNoTag;
-use Tests\TestCase;
-
-/**
- * Class HasNoTagTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class HasNoTagTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoTag
- */
- public function testTriggeredNoTag(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->tags()->detach();
- $this->assertEquals(0, $journal->tags()->count());
-
- $trigger = HasNoTag::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoTag
- */
- public function testTriggeredTag(): void
- {
- $journal = $this->getRandomWithdrawal();
- $tag = $journal->user->tags()->first();
- $journal->tags()->detach();
- $journal->tags()->save($tag);
- $this->assertEquals(1, $journal->tags()->count());
-
- $trigger = HasNoTag::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\HasNoTag
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = HasNoTag::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesAnyTest.php b/tests/Unit/TransactionRules/Triggers/NotesAnyTest.php
deleted file mode 100644
index 2dc4710f1e..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesAnyTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * NotesAnyTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesAny;
-use Tests\TestCase;
-
-/**
- * Class NotesAnyTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesAnyTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAny
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Bla bla bla';
- $note->save();
- $trigger = NotesAny::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAny
- */
- public function testTriggeredEmpty(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = '';
- $note->save();
- $trigger = NotesAny::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAny
- */
- public function testTriggeredNone(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $trigger = NotesAny::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAny
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = NotesAny::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesAreTest.php b/tests/Unit/TransactionRules/Triggers/NotesAreTest.php
deleted file mode 100644
index c362b02915..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesAreTest.php
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-/**
- * NotesAreTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesAre;
-use Tests\TestCase;
-
-/**
- * Class NotesAreTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesAreTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Bla bla bla';
- $note->save();
- $trigger = NotesAre::makeFromStrings('Bla bla bla', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testTriggeredDifferent(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Some note';
- $note->save();
- $trigger = NotesAre::makeFromStrings('Not the note', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testTriggeredEmpty(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = '';
- $note->save();
- $trigger = NotesAre::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testTriggeredNone(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $trigger = NotesAre::makeFromStrings('Bla bla', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = NotesAre::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesAre
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = NotesAre::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesContainTest.php b/tests/Unit/TransactionRules/Triggers/NotesContainTest.php
deleted file mode 100644
index 668e649f41..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesContainTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-/**
- * NotesContainTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesContain;
-use Tests\TestCase;
-
-/**
- * Class NotesContainTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesContainTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Bla bliepbla bla';
- $note->save();
- $trigger = NotesContain::makeFromStrings('blIEp', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testTriggeredDifferent(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Some note';
- $note->save();
- $trigger = NotesContain::makeFromStrings('82991911', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testTriggeredEmpty(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = '';
- $note->save();
- $trigger = NotesContain::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testTriggeredNone(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $trigger = NotesContain::makeFromStrings('Bla bla', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testTriggeredPartial(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Some note';
- $note->save();
- $trigger = NotesContain::makeFromStrings('Some note contains', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = NotesContain::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = NotesContain::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesContain
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = NotesContain::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesEmptyTest.php b/tests/Unit/TransactionRules/Triggers/NotesEmptyTest.php
deleted file mode 100644
index 943cb62493..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesEmptyTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * NotesEmptyTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesEmpty;
-use Tests\TestCase;
-
-/**
- * Class NotesEmptyTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesEmptyTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $trigger = NotesEmpty::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty
- */
- public function testTriggeredEmpty(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = '';
- $note->save();
- $trigger = NotesEmpty::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty
- */
- public function testTriggeredPartial(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Some note';
- $note->save();
- $trigger = NotesEmpty::makeFromStrings('', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEmpty
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = NotesEmpty::willMatchEverything($value);
- $this->assertFalse($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesEndTest.php b/tests/Unit/TransactionRules/Triggers/NotesEndTest.php
deleted file mode 100644
index 94b00d11a2..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesEndTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * NotesEndTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesEnd;
-use Tests\TestCase;
-
-/**
- * Class NotesEndTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesEndTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Bla bliepblabla';
- $note->save();
- $trigger = NotesEnd::makeFromStrings('blaBla', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testTriggeredLonger(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'blabla';
- $note->save();
- $trigger = NotesEnd::makeFromStrings('Blablabla', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testTriggeredNoMatch(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'blabla';
- $note->save();
- $trigger = NotesEnd::makeFromStrings('12345', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = NotesEnd::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = NotesEnd::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesEnd
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = NotesEnd::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/NotesStartTest.php b/tests/Unit/TransactionRules/Triggers/NotesStartTest.php
deleted file mode 100644
index 04d45a006b..0000000000
--- a/tests/Unit/TransactionRules/Triggers/NotesStartTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * NotesStartTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\Note;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\NotesStart;
-use Tests\TestCase;
-
-/**
- * Class NotesStartTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NotesStartTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'Blabliepblabla';
- $note->save();
- $trigger = NotesStart::makeFromStrings('blaBlie', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testTriggeredLonger(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'blabla';
- $note->save();
- $trigger = NotesStart::makeFromStrings('Blablabla', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testTriggeredNoMatch(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->notes()->delete();
- $note = new Note();
- $note->noteable()->associate($journal);
- $note->text = 'blabla';
- $note->save();
- $trigger = NotesStart::makeFromStrings('12345', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = NotesStart::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = NotesStart::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\NotesStart
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = NotesStart::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/TagIsTest.php b/tests/Unit/TransactionRules/Triggers/TagIsTest.php
deleted file mode 100644
index ceb99d186f..0000000000
--- a/tests/Unit/TransactionRules/Triggers/TagIsTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/**
- * TagIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\TagIs;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class TagIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TagIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TagIs
- */
- public function testNotTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->tags()->detach();
- $this->assertEquals(0, $journal->tags()->count());
-
- $trigger = TagIs::makeFromStrings('SomeTag', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TagIs
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $journal->tags()->detach();
- /** @var Collection $tags */
- $tags = $journal->user->tags()->take(3)->get();
- $search = '';
- foreach ($tags as $index => $tag) {
- $journal->tags()->save($tag);
- if (1 === $index) {
- $search = $tag->tag;
- }
- }
- $this->assertEquals(3, $journal->tags()->count());
-
- $trigger = TagIs::makeFromStrings($search, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TagIs
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $value = '';
- $result = TagIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TagIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = TagIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TagIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = TagIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php
deleted file mode 100644
index da67c4ea59..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-/**
- * ToAccountContainsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountContains;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountContainsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountContainsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountContains::makeFromStrings($account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountContains::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountContains
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php
deleted file mode 100644
index f57547ddc5..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * ToAccountEndsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountEndsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountEndsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountEnds::makeFromStrings((string)$this->randomInt(), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountEnds::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountEnds
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php
deleted file mode 100644
index b0083d6d4f..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/**
- * ToAccountIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountIs;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountIs::makeFromStrings($account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountNumberContainsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountNumberContainsTest.php
deleted file mode 100644
index cd3c107c68..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountNumberContainsTest.php
+++ /dev/null
@@ -1,174 +0,0 @@
-<?php
-/**
- * ToAccountNumberContainsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountNumberContains;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountNumberContainsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountNumberContainsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberContains::makeFromStrings('7027', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberContains::makeFromStrings('7027', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberContains::makeFromStrings('7027', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberContains::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountNumberContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountNumberContains::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberContains
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountNumberContains::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountNumberEndsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountNumberEndsTest.php
deleted file mode 100644
index 802ad1a6fe..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountNumberEndsTest.php
+++ /dev/null
@@ -1,195 +0,0 @@
-<?php
-/**
- * ToAccountNumberEndsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountNumberEndsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountNumberEndsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberEnds::makeFromStrings('5181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data= '7027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberEnds::makeFromStrings((string)$this->randomInt(), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountNumberEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountNumberEnds::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountNumberEnds::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountNumberIsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountNumberIsTest.php
deleted file mode 100644
index ae09b3ee47..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountNumberIsTest.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-/**
- * ToAccountNumberIsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountNumberIs;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountNumberIsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountNumberIsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberIs::makeFromStrings('FR7620041010053537027625181', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberIs::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountNumberIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountNumberIs::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberIs
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountNumberIs::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountNumberStartsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountNumberStartsTest.php
deleted file mode 100644
index 567406b0d1..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountNumberStartsTest.php
+++ /dev/null
@@ -1,189 +0,0 @@
-<?php
-/**
- * ToAccountNumberStartsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\AccountMeta;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountNumberStartsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountNumberStartsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testTriggeredBoth(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testTriggeredIban(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $account->iban = 'FR7620041010053537027625181';
- $account->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testTriggeredNumber(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $meta = new AccountMeta;
- $meta->account_id = $account->id;
- $meta->name = 'account_number';
- $meta->data = 'FR7620041010053537027625181';
- $meta->save();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountNumberStarts::makeFromStrings('FR76', false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountNumberStarts::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountNumberStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountNumberStarts::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountNumberStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php
deleted file mode 100644
index 52ac47cf74..0000000000
--- a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * ToAccountStartsTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
-use Illuminate\Support\Collection;
-use Tests\TestCase;
-
-/**
- * Class ToAccountStartsTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ToAccountStartsTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testTriggered(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
-
- $trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testTriggeredLonger(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testTriggeredNot(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
- $account = $this->user()->accounts()->inRandomOrder()->first();
- $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
-
- $trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testWillMatchEverythingEmpty(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = '';
- $result = ToAccountStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = 'x';
- $result = ToAccountStarts::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts
- */
- public function testWillMatchEverythingNull(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
- $value = null;
- $result = ToAccountStarts::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/TransactionRules/Triggers/TransactionTypeTest.php b/tests/Unit/TransactionRules/Triggers/TransactionTypeTest.php
deleted file mode 100644
index 77644afc71..0000000000
--- a/tests/Unit/TransactionRules/Triggers/TransactionTypeTest.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/**
- * TransactionTypeTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\TransactionRules\Triggers;
-
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\TransactionRules\Triggers\TransactionType;
-use Tests\TestCase;
-
-/**
- * Class TransactionTypeTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionTypeTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TransactionType
- */
- public function testTriggered(): void
- {
- $journal = $this->getRandomWithdrawal();
- $type = $journal->transactionType->type;
- $trigger = TransactionType::makeFromStrings($type, false);
- $result = $trigger->triggered($journal);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TransactionType
- */
- public function testTriggeredFalse(): void
- {
- $journal = $this->getRandomWithdrawal();
- $trigger = TransactionType::makeFromStrings('NonExisting', false);
- $result = $trigger->triggered($journal);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TransactionType
- */
- public function testWillMatchEverythingNotNull(): void
- {
- $value = 'x';
- $result = TransactionType::willMatchEverything($value);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\TransactionRules\Triggers\TransactionType
- */
- public function testWillMatchEverythingNull(): void
- {
- $value = null;
- $result = TransactionType::willMatchEverything($value);
- $this->assertTrue($result);
- }
-}
diff --git a/tests/Unit/Transformers/AccountTransformerTest.php b/tests/Unit/Transformers/AccountTransformerTest.php
deleted file mode 100644
index 80ecd2bd55..0000000000
--- a/tests/Unit/Transformers/AccountTransformerTest.php
+++ /dev/null
@@ -1,410 +0,0 @@
-<?php
-/**
- * AccountTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Transformers\AccountTransformer;
-use Log;
-use Mockery;
-use Steam;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class AccountTransformerTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AccountTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Check balance on a different date.
- *
- * @covers \FireflyIII\Transformers\AccountTransformer
- */
- public function testBalanceDate(): void
- {
- // mock stuff and get object:
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $parameters = new ParameterBag;
- $parameters->set('date', new Carbon('2018-01-01'));
-
- $transformer = app(AccountTransformer::class);
- $transformer->setParameters($parameters);
-
- // following calls are expected:
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all kinds of meta values:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
-
- // opening balance:
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
-
-
- // steam is also called for the account balance:
- Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();
-
-
- $result = $transformer->transform($account);
-
- // verify all fields.
- $this->assertEquals($account->id, $result['id']);
- $this->assertEquals($account->active, $result['active']);
- $this->assertEquals($account->name, $result['name']);
- $this->assertEquals('asset', $result['type']);
- $this->assertEquals('defaultAsset', $result['account_role']);
- $this->assertEquals(1, $result['currency_id']);
- $this->assertEquals('EUR', $result['currency_code']);
- $this->assertEquals('€', $result['currency_symbol']);
- $this->assertEquals(2, $result['currency_decimal_places']);
-
- // date given, so it must match.
- $this->assertEquals('2018-01-01', $result['current_balance_date']);
- $this->assertEquals(123.45, $result['current_balance']);
-
- $this->assertEquals('I am a note', $result['notes']);
- $this->assertNull($result['monthly_payment_date']);
- $this->assertNull($result['credit_card_type']);
- $this->assertEquals('12345', $result['account_number']);
- $this->assertEquals($account->iban, $result['iban']);
- $this->assertEquals('NL5X', $result['bic']);
- $this->assertNull($result['liability_type']);
- $this->assertNull($result['liability_amount']);
- $this->assertNull($result['liability_start_date']);
- $this->assertNull($result['interest']);
- $this->assertNull($result['interest_period']);
- $this->assertTrue($result['include_net_worth']);
-
- }
-
- /**
- * Load a basic asset account, and verify the result in the transformer.
- *
- * @covers \FireflyIII\Transformers\AccountTransformer
- */
- public function testBasicAsset(): void
- {
- // mock stuff and get object:
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = app(AccountTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- // following calls are expected:
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all kinds of meta values:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
-
- // opening balance:
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
-
-
- // steam is also called for the account balance:
- Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();
-
-
- $result = $transformer->transform($account);
-
- // verify all fields.
- $this->assertEquals($account->id, $result['id']);
- $this->assertEquals($account->active, $result['active']);
- $this->assertEquals($account->name, $result['name']);
- $this->assertEquals('asset', $result['type']);
- $this->assertEquals('defaultAsset', $result['account_role']);
- $this->assertEquals(1, $result['currency_id']);
- $this->assertEquals('EUR', $result['currency_code']);
- $this->assertEquals('€', $result['currency_symbol']);
- $this->assertEquals(2, $result['currency_decimal_places']);
-
- // no date given, so must be today:
- $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);
- $this->assertEquals(123.45, $result['current_balance']);
-
- $this->assertEquals('I am a note', $result['notes']);
- $this->assertNull($result['monthly_payment_date']);
- $this->assertNull($result['credit_card_type']);
- $this->assertEquals('12345', $result['account_number']);
- $this->assertEquals($account->iban, $result['iban']);
- $this->assertEquals('NL5X', $result['bic']);
- $this->assertNull($result['liability_type']);
- $this->assertNull($result['liability_amount']);
- $this->assertNull($result['liability_start_date']);
- $this->assertNull($result['interest']);
- $this->assertNull($result['interest_period']);
- $this->assertTrue($result['include_net_worth']);
-
- }
-
- /**
- * Credit card asset has some extra fields
- *
- * @covers \FireflyIII\Transformers\AccountTransformer
- */
- public function testCreditCardAsset(): void
- {
- // mock stuff and get object:
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = app(AccountTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- // following calls are expected:
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all kinds of meta values:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('ccAsset')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
-
- // credit card fields:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('monthlyFull')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('2018-01-01')->atLeast()->once();
-
-
- // opening balance:
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();
-
-
- // steam is also called for the account balance:
- Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();
-
-
- $result = $transformer->transform($account);
-
- // verify all fields.
- $this->assertEquals($account->id, $result['id']);
- $this->assertEquals($account->active, $result['active']);
- $this->assertEquals($account->name, $result['name']);
- $this->assertEquals('asset', $result['type']);
- $this->assertEquals('ccAsset', $result['account_role']);
- $this->assertEquals(1, $result['currency_id']);
- $this->assertEquals('EUR', $result['currency_code']);
- $this->assertEquals('€', $result['currency_symbol']);
- $this->assertEquals(2, $result['currency_decimal_places']);
-
- // no date given, so must be today:
- $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);
- $this->assertEquals(123.45, $result['current_balance']);
-
- $this->assertEquals('I am a note', $result['notes']);
-
- // cc fields must be filled in:
- $this->assertEquals('2018-01-01', $result['monthly_payment_date']);
- $this->assertEquals('monthlyFull', $result['credit_card_type']);
- $this->assertEquals('12345', $result['account_number']);
- $this->assertEquals($account->iban, $result['iban']);
- $this->assertEquals('NL5X', $result['bic']);
- $this->assertNull($result['liability_type']);
- $this->assertNull($result['liability_amount']);
- $this->assertNull($result['liability_start_date']);
- $this->assertNull($result['interest']);
- $this->assertNull($result['interest_period']);
- $this->assertTrue($result['include_net_worth']);
-
- }
-
- /**
- * Liability also has some extra fields.
- *
- * @covers \FireflyIII\Transformers\AccountTransformer
- */
- public function testLiability(): void
- {
- // mock stuff and get object:
- $account = $this->getRandomAsset();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = app(AccountTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- // following calls are expected:
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountType')->andReturn('Mortgage')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all kinds of meta values:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
-
- // data for liability
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('3')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly')->atLeast()->once();
-
- // opening balance:
- $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturn('-1000')->atLeast()->once();
- $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturn('2018-01-01')->atLeast()->once();
-
-
- // steam is also called for the account balance:
- Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();
-
-
- $result = $transformer->transform($account);
-
- // verify all fields.
- $this->assertEquals($account->id, $result['id']);
- $this->assertEquals($account->active, $result['active']);
- $this->assertEquals($account->name, $result['name']);
- $this->assertEquals('liabilities', $result['type']);
- $this->assertNull($result['account_role']);
- $this->assertEquals(1, $result['currency_id']);
- $this->assertEquals('EUR', $result['currency_code']);
- $this->assertEquals('€', $result['currency_symbol']);
- $this->assertEquals(2, $result['currency_decimal_places']);
-
- // no date given, so must be today:
- $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);
- $this->assertEquals(123.45, $result['current_balance']);
- $this->assertEquals('I am a note', $result['notes']);
- $this->assertNull($result['monthly_payment_date']);
- $this->assertNull($result['credit_card_type']);
- $this->assertEquals('12345', $result['account_number']);
- $this->assertEquals($account->iban, $result['iban']);
- $this->assertEquals('NL5X', $result['bic']);
-
- // liability fields
- $this->assertEquals('mortgage', $result['liability_type']);
- $this->assertEquals('-1000', $result['liability_amount']);
- $this->assertEquals('2018-01-01', $result['liability_start_date']);
- $this->assertEquals('3', $result['interest']);
- $this->assertEquals('monthly', $result['interest_period']);
-
- $this->assertTrue($result['include_net_worth']);
-
- }
-
- /**
- * If the account is not an asset account, the role must always be NULL.
- *
- * @covers \FireflyIII\Transformers\AccountTransformer
- */
- public function testRoleEmpty(): void
- {
- // mock stuff and get object:
- $account = $this->getRandomExpense();
- $euro = $this->getEuro();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $transformer = app(AccountTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- // following calls are expected:
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountType')->andReturn('Expense account')->atLeast()->once();
- $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
- $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
- $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();
-
- // get all kinds of meta values:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
-
- // steam is also called for the account balance:
- Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();
-
-
- $result = $transformer->transform($account);
-
- // verify all fields.
- $this->assertEquals($account->id, $result['id']);
- $this->assertEquals($account->active, $result['active']);
- $this->assertEquals($account->name, $result['name']);
- $this->assertEquals('expense', $result['type']);
- $this->assertNull($result['account_role']);
- $this->assertEquals(1, $result['currency_id']);
- $this->assertEquals('EUR', $result['currency_code']);
- $this->assertEquals('€', $result['currency_symbol']);
- $this->assertEquals(2, $result['currency_decimal_places']);
-
- // no date given, so must be today:
- $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);
- $this->assertEquals(123.45, $result['current_balance']);
-
- $this->assertEquals('I am a note', $result['notes']);
- $this->assertNull($result['monthly_payment_date']);
- $this->assertNull($result['credit_card_type']);
- $this->assertEquals('12345', $result['account_number']);
- $this->assertEquals($account->iban, $result['iban']);
- $this->assertEquals('NL5X', $result['bic']);
- $this->assertNull($result['liability_type']);
- $this->assertNull($result['liability_amount']);
- $this->assertNull($result['liability_start_date']);
- $this->assertNull($result['interest']);
- $this->assertNull($result['interest_period']);
- $this->assertTrue($result['include_net_worth']);
- }
-}
diff --git a/tests/Unit/Transformers/AttachmentTransformerTest.php b/tests/Unit/Transformers/AttachmentTransformerTest.php
deleted file mode 100644
index 96fc76052a..0000000000
--- a/tests/Unit/Transformers/AttachmentTransformerTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-/**
- * AttachmentTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
-use FireflyIII\Transformers\AttachmentTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class AttachmentTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AttachmentTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test basic transformer
- *
- * @covers \FireflyIII\Transformers\AttachmentTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(AttachmentRepositoryInterface::class);
- $md5 = md5('hello' . $this->randomInt());
- $attachment = Attachment::create(
- [
- 'user_id' => $this->user()->id,
- 'attachable_id' => 1,
- 'attachable_type' => TransactionJournal::class,
- 'md5' => $md5,
- 'filename' => 'hello.txt',
- 'mime' => 'text/plain',
- 'size' => 101,
- 'uploaded' => 1,
- ]
- );
-
- // expected calls:
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getNoteText')->once()->andReturn('I am a note');
-
- // make transformer
- $transformer = app(AttachmentTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($attachment);
-
- // test results
- $this->assertEquals($attachment->id, $result['id']);
- $this->assertEquals('TransactionJournal', $result['attachable_type']);
- $this->assertEquals('I am a note', $result['notes']);
-
- }
-
-}
diff --git a/tests/Unit/Transformers/AvailableBudgetTransformerTest.php b/tests/Unit/Transformers/AvailableBudgetTransformerTest.php
deleted file mode 100644
index 80d5c157db..0000000000
--- a/tests/Unit/Transformers/AvailableBudgetTransformerTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * AvailableBudgetTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Models\AvailableBudget;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Transformers\AvailableBudgetTransformer;
-use Illuminate\Support\Collection;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class AvailableBudgetTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AvailableBudgetTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test basic transformer
- *
- * @covers \FireflyIII\Transformers\AvailableBudgetTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
- $repository->shouldReceive('setUser')->atLeast()->once();
-
- /** @var AvailableBudget $availableBudget */
- $availableBudget = AvailableBudget::first();
- $currency = $availableBudget->transactionCurrency;
- // make transformer
- $transformer = app(AvailableBudgetTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($availableBudget);
-
- // test results
- $this->assertEquals($availableBudget->id, $result['id']);
- $this->assertEquals($currency->id, $result['currency_id']);
- $this->assertEquals($availableBudget->start_date->format('Y-m-d'), $result['start']);
- $this->assertEquals(round($availableBudget->amount, 2), $result['amount']);
- }
-
- /**
- * Test basic transformer
- *
- * @covers \FireflyIII\Transformers\AvailableBudgetTransformer
- */
- public function testBasicDates(): void
- {
- $euro = $this->getEuro();
- $data= [
- [
- 'currency_id' => $euro->id,
- 'currency_code' => $euro->code,
- 'currency_symbol' => $euro->symbol,
- 'currency_decimal_places' => $euro->decimal_places,
- 'amount' => '12.45',
- ]
- ];
-
-
- $budget = $this->getRandomBudget();
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- $opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn($data);
- $nbRepos->shouldReceive('spentInPeriodWoBudgetMc')->atLeast()->once()->andReturn($data);
-
- // spentInPeriodWoBudgetMc
-
- $start = new Carbon;
- $end = new Carbon;
- $parameterBag = new ParameterBag;
- $parameterBag->set('start', $start);
- $parameterBag->set('end', $end);
-
- /** @var AvailableBudget $availableBudget */
- $availableBudget = AvailableBudget::first();
- $currency = $availableBudget->transactionCurrency;
- // make transformer
- $transformer = app(AvailableBudgetTransformer::class);
- $transformer->setParameters($parameterBag);
- $result = $transformer->transform($availableBudget);
-
- // test results
- $this->assertEquals($availableBudget->id, $result['id']);
- $this->assertEquals($currency->id, $result['currency_id']);
- $this->assertEquals($availableBudget->start_date->format('Y-m-d'), $result['start']);
- $this->assertEquals(round($availableBudget->amount, 2), $result['amount']);
- }
-
-}
diff --git a/tests/Unit/Transformers/BillTransformerTest.php b/tests/Unit/Transformers/BillTransformerTest.php
deleted file mode 100644
index 5091be9522..0000000000
--- a/tests/Unit/Transformers/BillTransformerTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * BillTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Models\Bill;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Transformers\BillTransformer;
-use Illuminate\Support\Collection;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class BillTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BillTransformerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\BillTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(BillRepositoryInterface::class);
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('');
-
-
- /** @var Bill $bill */
- $bill = Bill::first();
- $transformer = app(BillTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($bill);
-
- // assert fields.
- $this->assertEquals($bill->name, $result['name']);
- $this->assertEquals($bill->transactionCurrency->decimal_places, $result['currency_decimal_places']);
- $this->assertEquals($bill->active, $result['active']);
- $this->assertNull($result['notes']);
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\BillTransformer
- */
- public function testWithDates(): void
- {
- $repository = $this->mock(BillRepositoryInterface::class);
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('');
-
- // repos should also receive call for dates:
- $list = new Collection(
- [
- (object)['date' => new Carbon('2018-01-02'), 'id' => 1, 'transaction_group_id' => 1,],
- (object)['date' => new Carbon('2018-01-09'), 'id' => 1, 'transaction_group_id' => 1,],
- (object)['date' => new Carbon('2018-01-16'), 'id' => 1, 'transaction_group_id' => 1,],
- (object)['date' => new Carbon('2018-01-21'), 'id' => 1, 'transaction_group_id' => 1,],
- (object)['date' => new Carbon('2018-01-30'), 'id' => 1, 'transaction_group_id' => 1,],
- ]
- );
- $repository->shouldReceive('getPaidDatesInRange')->atLeast()->once()->andReturn($list);
-
- $parameters = new ParameterBag;
- $parameters->set('start', new Carbon('2018-01-01'));
- $parameters->set('end', new Carbon('2018-01-31'));
-
- /** @var Bill $bill */
- $bill = Bill::first();
- $transformer = app(BillTransformer::class);
- $transformer->setParameters($parameters);
- $result = $transformer->transform($bill);
-
- // assert fields.
- $this->assertEquals($bill->name, $result['name']);
- $this->assertEquals($bill->transactionCurrency->decimal_places, $result['currency_decimal_places']);
- $this->assertEquals($bill->active, $result['active']);
- $this->assertNull($result['notes']);
-
- $this->assertEquals('2018-03-01', $result['next_expected_match']);
- //$this->assertEquals(['2018-01-01'], $result['pay_dates']);
- $this->assertEquals(['2019-11-01'], $result['pay_dates']);
- $this->assertEquals(
- [
- ['date' => '2018-01-02', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
-// ['date' => '2019-11-01', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
- ['date' => '2018-01-09', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
- ['date' => '2018-01-16', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
- ['date' => '2018-01-21', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
- ['date' => '2018-01-30', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
- ], $result['paid_dates']
- );
- }
-
-}
diff --git a/tests/Unit/Transformers/BudgetLimitTransformerTest.php b/tests/Unit/Transformers/BudgetLimitTransformerTest.php
deleted file mode 100644
index ac4f08c433..0000000000
--- a/tests/Unit/Transformers/BudgetLimitTransformerTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/**
- * BudgetLimitTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Transformers\BudgetLimitTransformer;
-use Log;
-use Tests\TestCase;
-
-/**
- *
- * Class BudgetLimitTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetLimitTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Transformers\BudgetLimitTransformer
- */
- public function testBasic(): void
- {
- /** @var BudgetLimit $budgetLimit */
- $budgetLimit = BudgetLimit::first();
-
- /** @var BudgetLimitTransformer $transformer */
- $transformer = app(BudgetLimitTransformer::class);
- $result = $transformer->transform($budgetLimit);
-
- // compare results:
- $this->assertEquals($budgetLimit->id, $result['id']);
- $this->assertEquals($budgetLimit->start_date->format('Y-m-d'), $result['start']);
- $this->assertGreaterThanOrEqual(0, $result['amount']);
- }
-
-}
diff --git a/tests/Unit/Transformers/BudgetTransformerTest.php b/tests/Unit/Transformers/BudgetTransformerTest.php
deleted file mode 100644
index d4104a84f5..0000000000
--- a/tests/Unit/Transformers/BudgetTransformerTest.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-/**
- * BudgetTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Models\Budget;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use FireflyIII\Transformers\BudgetTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-
-/**
- * Class BudgetTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class BudgetTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\BudgetTransformer
- */
- public function testBasic(): void
- {
- // mocks and prep:
- $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
-
- $parameters = new ParameterBag;
- $budget = Budget::first();
- $transformer = app(BudgetTransformer::class);
- $transformer->setParameters($parameters);
-
- // mocks
- $opsRepository->shouldReceive('setUser')->once();
-
- // action
- $result = $transformer->transform($budget);
-
-
- $this->assertEquals($budget->id, $result['id']);
- $this->assertEquals((bool)$budget->active, $result['active']);
- $this->assertEquals([], $result['spent']);
-
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\BudgetTransformer
- */
- public function testSpentArray(): void
- {
- // mocks and prep:
- $this->mock(BudgetRepositoryInterface::class);
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
-
- $parameters = new ParameterBag;
-
- // set parameters
- $parameters->set('start', new Carbon('2018-01-01'));
- $parameters->set('end', new Carbon('2018-01-31'));
-
- $budget = Budget::first();
- $transformer = app(BudgetTransformer::class);
- $transformer->setParameters($parameters);
-
- // spent data
- $spent = [
- [
- 'currency_id' => 1,
- 'currency_code' => 'AKC',
- 'currency_symbol' => 'x',
- 'currency_decimal_places' => 2,
- 'amount' => 1000,
- ],
- ];
-
- // mocks
- $opsRepository->shouldReceive('sumExpenses')->atLeast()->once()->andReturn($spent);
- $opsRepository->shouldReceive('setUser')->once();
-
- // action
- $result = $transformer->transform($budget);
-
- $this->assertEquals($budget->id, $result['id']);
- $this->assertEquals((bool)$budget->active, $result['active']);
- $this->assertEquals($spent, $result['spent']);
-
- }
-}
diff --git a/tests/Unit/Transformers/CategoryTransformerTest.php b/tests/Unit/Transformers/CategoryTransformerTest.php
deleted file mode 100644
index dca71868be..0000000000
--- a/tests/Unit/Transformers/CategoryTransformerTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-/**
- * CategoryTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Models\Category;
-use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
-use FireflyIII\Transformers\CategoryTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\Support\TestDataTrait;
-use Tests\TestCase;
-
-
-/**
- * Class CategoryTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CategoryTransformerTest extends TestCase
-{
-
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\CategoryTransformer
- */
- public function testBasic(): void
- {
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $opsRepository->shouldReceive('setUser')->once();
-
- /** @var Category $category */
- $category = Category::first();
- $transformer = app(CategoryTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($category);
-
- $this->assertEquals($category->name, $result['name']);
- $this->assertEquals([], $result['spent']);
- $this->assertEquals([], $result['earned']);
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\CategoryTransformer
- */
- public function testWithDates(): void
- {
- $opsRepository = $this->mock(OperationsRepositoryInterface::class);
- $opsRepository->shouldReceive('setUser')->once();
-
- $parameters = new ParameterBag;
- $parameters->set('start', new Carbon('2018-01-01'));
- $parameters->set('end', new Carbon('2018-01-31'));
-
- $income = $this->categorySumIncome();
- $expense = $this->categorySumExpenses();
- $opsRepository->shouldReceive('sumIncome')
- ->atLeast()->once()->andReturn($income);
-
- $opsRepository->shouldReceive('sumExpenses')
- ->atLeast()->once()->andReturn($expense);
-
- /** @var Category $category */
- $category = Category::first();
- $transformer = app(CategoryTransformer::class);
- $transformer->setParameters($parameters);
- $result = $transformer->transform($category);
-
- $this->assertEquals($category->name, $result['name']);
- }
-}
diff --git a/tests/Unit/Transformers/CurrencyExchangeRateTransformerTest.php b/tests/Unit/Transformers/CurrencyExchangeRateTransformerTest.php
deleted file mode 100644
index 0dfd683ef3..0000000000
--- a/tests/Unit/Transformers/CurrencyExchangeRateTransformerTest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * CurrencyExchangeRateTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use Carbon\Carbon;
-use FireflyIII\Models\CurrencyExchangeRate;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Transformers\CurrencyExchangeRateTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- *
- * Class CurrencyExchangeRateTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CurrencyExchangeRateTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Transformers\CurrencyExchangeRateTransformer
- */
- public function testBasic()
- {
- $date = new Carbon;
- $eur = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- $cer = new CurrencyExchangeRate;
- $cer->from_currency_id = $eur->id;
- $cer->to_currency_id = $usd->id;
- $cer->created_at = new Carbon;
- $cer->updated_at = new Carbon;
- $cer->rate = 1.5;
- $cer->date = $date;
-
- $parameters = new ParameterBag;
- $parameters->set('amount', '100');
-
- $transformer = app(CurrencyExchangeRateTransformer::class);
- $transformer->setParameters($parameters);
- $result = $transformer->transform($cer);
-
- $this->assertEquals($cer->from_currency_id, $result['from_currency_id']);
- $this->assertEquals(150, $result['amount']);
-
-
- }
-}
diff --git a/tests/Unit/Transformers/CurrencyTransformerTest.php b/tests/Unit/Transformers/CurrencyTransformerTest.php
deleted file mode 100644
index 718d883ca2..0000000000
--- a/tests/Unit/Transformers/CurrencyTransformerTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * CurrencyTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use FireflyIII\Transformers\CurrencyTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-
-/**
- * Class CurrencyTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CurrencyTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\CurrencyTransformer
- */
- public function testBasic(): void
- {
- // mocks and prep:
- $parameters = new ParameterBag;
- $currency = $this->getEuro();
- $transformer = app(CurrencyTransformer::class);
- $transformer->setParameters($parameters);
-
- // action
- $result = $transformer->transform($currency);
-
-
- $this->assertEquals($currency->code, $result['code']);
- $this->assertFalse($result['default']);
-
- }
-
- /**
- * Basic coverage with default currency
- *
- * @covers \FireflyIII\Transformers\CurrencyTransformer
- */
- public function testDefaultCurrency(): void
- {
- // mocks and prep:
- $parameters = new ParameterBag;
- $currency = $this->getEuro();
- $parameters->set('defaultCurrency', $currency);
- $transformer = app(CurrencyTransformer::class);
- $transformer->setParameters($parameters);
-
-
- // action
- $result = $transformer->transform($currency);
-
-
- $this->assertEquals($currency->code, $result['code']);
- $this->assertTrue($result['default']);
-
- }
-
-}
diff --git a/tests/Unit/Transformers/LinkTypeTransformerTest.php b/tests/Unit/Transformers/LinkTypeTransformerTest.php
deleted file mode 100644
index 35b4b78158..0000000000
--- a/tests/Unit/Transformers/LinkTypeTransformerTest.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * LinkTypeTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\LinkType;
-use FireflyIII\Transformers\LinkTypeTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- *
- * Class LinkTypeTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class LinkTypeTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic coverage
- *
- * @covers \FireflyIII\Transformers\LinkTypeTransformer
- */
- public function testBasic(): void
- {
-
- $linkType = LinkType::first();
- $parameters = new ParameterBag;
- $transformer = app(LinkTypeTransformer::class);
- $transformer->setParameters($parameters);
-
- $result = $transformer->transform($linkType);
-
- $this->assertEquals($linkType->inward, $result['inward']);
-
- }
-}
diff --git a/tests/Unit/Transformers/PiggyBankEventTransformerTest.php b/tests/Unit/Transformers/PiggyBankEventTransformerTest.php
deleted file mode 100644
index ed68bb357a..0000000000
--- a/tests/Unit/Transformers/PiggyBankEventTransformerTest.php
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-/**
- * PiggyBankEventTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Amount;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Transformers\PiggyBankEventTransformer;
-use Log;
-use Mockery;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankEventTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankEventTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test with no meta data.
- *
- * @covers \FireflyIII\Transformers\PiggyBankEventTransformer
- */
- public function testBasic(): void
- {
- // repositories
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());
-
- $event = $this->getRandomPiggyBankEvent();
-
-
-
- $transformer = app(PiggyBankEventTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- $result = $transformer->transform($event);
- $this->assertEquals($event->id, $result['id']);
- $this->assertEquals($event->amount, $result['amount']);
- $this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);
-
- }
-
- /**
- * Basic test with no currency info.
- *
- * @covers \FireflyIII\Transformers\PiggyBankEventTransformer
- */
- public function testNoCurrency(): void
- {
- // repositories
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
-
- // mock calls:
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);
-
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->atLeast()->once();
-
- $event = $this->getRandomPiggyBankEvent();
- $transformer = app(PiggyBankEventTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- $result = $transformer->transform($event);
- $this->assertEquals($event->id, $result['id']);
- $this->assertEquals($event->amount, $result['amount']);
- $this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);
-
- }
-}
diff --git a/tests/Unit/Transformers/PiggyBankTransformerTest.php b/tests/Unit/Transformers/PiggyBankTransformerTest.php
deleted file mode 100644
index 0c4fbec4ea..0000000000
--- a/tests/Unit/Transformers/PiggyBankTransformerTest.php
+++ /dev/null
@@ -1,138 +0,0 @@
-<?php
-/**
- * PiggyBankTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Amount;
-use FireflyIII\Models\PiggyBank;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Transformers\PiggyBankTransformer;
-use Log;
-use Mockery;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class PiggyBankTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PiggyBankTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test basic transformer.
- *
- * @covers \FireflyIII\Transformers\PiggyBankTransformer
- */
- public function testBasic(): void
- {
- // mock repositories
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls:
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
-
- // return a currency
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());
-
- // get a note
- $piggyRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('I am a note.');
-
- // get some amounts
- $piggyRepos->shouldReceive('getCurrentAmount')->atLeast()->once()->andReturn('123.45');
- $piggyRepos->shouldReceive('getSuggestedMonthlyAmount')->atLeast()->once()->andReturn('12.45');
-
- /** @var PiggyBankTransformer $transformer */
- $transformer = app(PiggyBankTransformer::class);
- $transformer->setParameters(new ParameterBag());
-
- $piggy = PiggyBank::first();
- $result = $transformer->transform($piggy);
-
- $this->assertEquals(12.45, $result['save_per_month']);
- $this->assertEquals($piggy->name, $result['name']);
- $this->assertEquals(1, $result['currency_id']);
- }
-
- /**
- * Test basic transformer.
- *
- * @covers \FireflyIII\Transformers\PiggyBankTransformer
- */
- public function testNoCurrency(): void
- {
- // mock repositories
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls:
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $accountRepos->shouldReceive('setUser')->atLeast()->once();
- $currencyRepos->shouldReceive('setUser')->atLeast()->once();
-
- // return a currency
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);
- Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($this->getEuro());
-
- // get a note
- $piggyRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('I am a note.');
-
- // get some amounts
- $piggyRepos->shouldReceive('getCurrentAmount')->atLeast()->once()->andReturn('123.45');
- $piggyRepos->shouldReceive('getSuggestedMonthlyAmount')->atLeast()->once()->andReturn('12.45');
-
- /** @var PiggyBankTransformer $transformer */
- $transformer = app(PiggyBankTransformer::class);
- $transformer->setParameters(new ParameterBag());
-
- $piggy = PiggyBank::first();
- $result = $transformer->transform($piggy);
-
- $this->assertEquals(12.45, $result['save_per_month']);
- $this->assertEquals($piggy->name, $result['name']);
- $this->assertEquals(1, $result['currency_id']);
- }
-
-}
diff --git a/tests/Unit/Transformers/PreferenceTransformerTest.php b/tests/Unit/Transformers/PreferenceTransformerTest.php
deleted file mode 100644
index 849e0316b7..0000000000
--- a/tests/Unit/Transformers/PreferenceTransformerTest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * PreferenceTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\Preference;
-use FireflyIII\Transformers\PreferenceTransformer;
-use Log;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class PreferenceTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class PreferenceTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test basic tag transformer
- *
- * @covers \FireflyIII\Transformers\PreferenceTransformer
- */
- public function testBasic(): void
- {
- /** @var Preference $preference */
- $preference = Preference::first();
- $transformer = app(PreferenceTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- $result = $transformer->transform($preference);
-
- $this->assertEquals($preference->name, $result['name']);
- }
-
-}
diff --git a/tests/Unit/Transformers/RecurrenceTransformerTest.php b/tests/Unit/Transformers/RecurrenceTransformerTest.php
deleted file mode 100644
index b7fbd67dc7..0000000000
--- a/tests/Unit/Transformers/RecurrenceTransformerTest.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-/**
- * RecurrenceTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-use Carbon\Carbon;
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
-use FireflyIII\Transformers\RecurrenceTransformer;
-use FireflyIII\Transformers\RuleGroupTransformer;
-use FireflyIII\Transformers\RuleTransformer;
-use FireflyIII\Transformers\TagTransformer;
-use Log;
-use Mockery;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- *
- * Class RecurrenceTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RecurrenceTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Transformers\RecurrenceTransformer
- */
- public function testBasic(): void
- {
- $recurrenceRepos = $this->mock(RecurringRepositoryInterface::class);
- $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
- $factory = $this->mock(CategoryFactory::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
-
- $ruleGroupTransformer = $this->mock(RuleGroupTransformer::class);
- $ruleTransformer = $this->mock(RuleTransformer::class);
- $tagTransformer = $this->mock(TagTransformer::class);
-
- $category = $this->getRandomCategory();
- $budget = $this->getRandomBudget();
- $piggy = $this->getRandomPiggyBank();
- $ranges = [new Carbon];
- $recurrence = $this->getRandomRecurrence();
- // mock calls:
- $recurrenceRepos->shouldReceive('setUser')->atLeast()->once();
- $piggyRepos->shouldReceive('setUser')->atLeast()->once();
- $factory->shouldReceive('setUser')->atLeast()->once();
- $budgetRepos->shouldReceive('setUser')->atLeast()->once();
-
- // default calls:
- $recurrenceRepos->shouldReceive('getNoteText')->once()->andReturn('Hi there');
- $recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr');
- //$recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once();
- $recurrenceRepos->shouldReceive('getXOccurrencesSince')->andReturn($ranges)->atLeast()->once();
- $factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null, Mockery::any()])->andReturn($category);
- $budgetRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($budget);
- $piggyRepos->shouldReceive('findNull')->andReturn($piggy);
-
- // basic transformation:
-
- $transformer = app(RecurrenceTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- $result = $transformer->transform($recurrence);
-
- $this->assertEquals($recurrence->id, $result['id']);
- //$this->assertEquals('deposit', $result['transaction_type']);
- $this->assertEquals(true, $result['apply_rules']);
- $this->assertEquals('Rep descr', $result['repetitions'][0]['description']);
-
-
- }
-
-}
diff --git a/tests/Unit/Transformers/RuleGroupTransformerTest.php b/tests/Unit/Transformers/RuleGroupTransformerTest.php
deleted file mode 100644
index 42f8e34fef..0000000000
--- a/tests/Unit/Transformers/RuleGroupTransformerTest.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-/**
- * RuleGroupTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\RuleGroup;
-use FireflyIII\Transformers\RuleGroupTransformer;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class RuleGroupTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RuleGroupTransformerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * Test basic tag transformer
- *
- * @covers \FireflyIII\Transformers\RuleGroupTransformer
- */
- public function testBasic(): void
- {
- /** @var RuleGroup $ruleGroup */
- $ruleGroup = RuleGroup::first();
-
-
- $transformer = app(RuleGroupTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($ruleGroup);
- $this->assertEquals($ruleGroup->title, $result['title']);
- }
-
-}
diff --git a/tests/Unit/Transformers/RuleTransformerTest.php b/tests/Unit/Transformers/RuleTransformerTest.php
deleted file mode 100644
index 7bdcf8dfc5..0000000000
--- a/tests/Unit/Transformers/RuleTransformerTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * RuleTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\Rule;
-use FireflyIII\Models\RuleAction;
-use FireflyIII\Models\RuleTrigger;
-use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
-use FireflyIII\Transformers\RuleTransformer;
-use Illuminate\Support\Collection;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class RuleTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class RuleTransformerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * Test basic tag transformer
- *
- * @covers \FireflyIII\Transformers\RuleTransformer
- */
- public function testBasic(): void
- {
- /** @var Rule $rule */
- $rule = Rule::first();
-
- $repository = $this->mock(RuleRepositoryInterface::class);
- /** @var RuleTrigger $ruleTrigger */
- $ruleTrigger = RuleTrigger::where('trigger_type', '!=', 'user_action')->first();
-
- /** @var RuleTrigger $ruleTrigger */
- $moment = RuleTrigger::where('trigger_type', '=', 'user_action')->first();
-
- /** @var RuleAction $ruleAction */
- $ruleAction = RuleAction::first();
- // mock stuff
- $repository->shouldReceive('setUser')->atLeast()->once();
- $repository->shouldReceive('getRuleActions')->atLeast()->once()->andReturn(new Collection([$ruleAction]));
- $repository->shouldReceive('getRuleTriggers')->atLeast()->once()->andReturn(new Collection([$moment]), new Collection([$ruleTrigger]));
-
- $transformer = app(RuleTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($rule);
- $this->assertEquals($rule->title, $result['title']);
-
- $this->assertEquals($ruleTrigger->trigger_type, $result['triggers'][0]['type']);
- $this->assertEquals($ruleAction->action_type, $result['actions'][0]['type']);
- }
-
-}
diff --git a/tests/Unit/Transformers/TagTransformerTest.php b/tests/Unit/Transformers/TagTransformerTest.php
deleted file mode 100644
index b52c408b9b..0000000000
--- a/tests/Unit/Transformers/TagTransformerTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-/**
- * TagTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\Location;
-use FireflyIII\Models\Tag;
-use FireflyIII\Transformers\TagTransformer;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class TagTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TagTransformerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * Test basic tag transformer
- *
- * @covers \FireflyIII\Transformers\TagTransformer
- */
- public function testBasic(): void
- {
- $tag = Tag::create(
- [
- 'user_id' => $this->user()->id,
- 'tag' => 'Some tag ' . $this->randomInt(),
- 'tagMode' => 'nothing',
- 'date' => '2018-01-01',
- 'description' => 'Some tag',
- ]
- );
- $location = new Location;
- $location->latitude = 5.5;
- $location->longitude = 6.6;
- $location->zoom_level = 3;
- $location->locatable()->associate($tag);
- $location->save();
-
- $transformer = app(TagTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($tag);
-
- $this->assertEquals($tag->tag, $result['tag']);
- $this->assertEquals(5.5, $result['latitude']);
- $this->assertEquals(6.6, $result['longitude']);
- }
-
-}
diff --git a/tests/Unit/Transformers/TransactionGroupTransformerTest.php b/tests/Unit/Transformers/TransactionGroupTransformerTest.php
deleted file mode 100644
index b5bff66b53..0000000000
--- a/tests/Unit/Transformers/TransactionGroupTransformerTest.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-/**
- * TransactionGroupTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
-use FireflyIII\Support\NullArrayObject;
-use FireflyIII\Transformers\TransactionGroupTransformer;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class TransactionGroupTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionGroupTransformerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Transformers\TransactionGroupTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $group = $this->getRandomWithdrawalGroup();
- $first = $group->transactionJournals()->first();
-
- // mock calls
- $repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
- $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- $transformer = new TransactionGroupTransformer;
- $result = $transformer->transformObject($group);
-
- }
-
- /**
- * @covers \FireflyIII\Transformers\TransactionGroupTransformer
- */
- public function testArray(): void {
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $group = $this->getRandomWithdrawalGroupAsArray();
-
- // mock calls
- $repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
- $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- $transformer = new TransactionGroupTransformer;
- $result = $transformer->transform($group);
- }
-
-
- /**
- * @covers \FireflyIII\Transformers\TransactionGroupTransformer
- */
- public function testArrayDeposit(): void {
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $group = $this->getRandomDepositGroupAsArray();
-
- // mock calls
- $repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
- $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- $transformer = new TransactionGroupTransformer;
- $result = $transformer->transform($group);
- }
-
- /**
- * @covers \FireflyIII\Transformers\TransactionGroupTransformer
- */
- public function testDeposit(): void
- {
- $repository = $this->mock(TransactionGroupRepositoryInterface::class);
- $group = $this->getRandomDepositGroup();
- $first = $group->transactionJournals()->first();
-
- // mock calls
- $repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
- $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
- $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
-
- $transformer = new TransactionGroupTransformer;
- $result = $transformer->transformObject($group);
-
- }
-}
diff --git a/tests/Unit/Transformers/TransactionLinkTransformerTest.php b/tests/Unit/Transformers/TransactionLinkTransformerTest.php
deleted file mode 100644
index ce3e86a0ca..0000000000
--- a/tests/Unit/Transformers/TransactionLinkTransformerTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/**
- * TransactionLinkTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Models\TransactionJournalLink;
-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
-use FireflyIII\Transformers\TransactionLinkTransformer;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class TransactionLinkTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class TransactionLinkTransformerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * Test basic tag transformer
- *
- * @covers \FireflyIII\Transformers\TransactionLinkTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(JournalRepositoryInterface::class);
-
- $repository->shouldReceive('getLinkNoteText')->atLeast()->once()->andReturn('abc');
-
- /** @var TransactionJournalLink $link */
- $link = TransactionJournalLink::first();
-
- $transformer = app(TransactionLinkTransformer::class);
- $transformer->setParameters(new ParameterBag);
-
- $result = $transformer->transform($link);
-
- $this->assertEquals($link->source_id, $result['inward_id']);
- $this->assertEquals('abc', $result['notes']);
-
- }
-
-}
diff --git a/tests/Unit/Transformers/UserTransformerTest.php b/tests/Unit/Transformers/UserTransformerTest.php
deleted file mode 100644
index fcfab0819b..0000000000
--- a/tests/Unit/Transformers/UserTransformerTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * UserTransformerTest.php
- * Copyright (c) 2019 [email protected]
- *
- * 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\Unit\Transformers;
-
-
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use FireflyIII\Transformers\UserTransformer;
-use Symfony\Component\HttpFoundation\ParameterBag;
-use Tests\TestCase;
-
-/**
- * Class UserTransformerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class UserTransformerTest extends TestCase
-{
- /**
- * Set up test
- */
- public function setUp(): void
- {
- self::markTestIncomplete('Incomplete for refactor.');
-
- return;
- }
- /**
- * Test basic transformer.
- *
- * @covers \FireflyIII\Transformers\UserTransformer
- */
- public function testBasic(): void
- {
- $repository = $this->mock(UserRepositoryInterface::class);
- $repository->shouldReceive('getRoleByUser')->atLeast()->once()->andReturn('owner');
- $user = $this->user();
-
- $transformer = app(UserTransformer::class);
- $transformer->setParameters(new ParameterBag);
- $result = $transformer->transform($user);
-
- $this->assertEquals($user->email, $result['email']);
- $this->assertEquals('owner', $result['role']);
- }
-}