Files
firefly-iii/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php

179 lines
6.1 KiB
PHP
Raw Normal View History

2017-08-18 15:32:11 +02:00
<?php
/**
* AutoCompleteControllerTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2017-08-18 15:32:11 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 08:40:00 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-08-18 15:32:11 +02:00
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Json;
2019-06-29 19:47:31 +02:00
2017-08-18 15:32:11 +02:00
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2019-08-29 17:53:25 +02:00
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
2017-08-18 15:32:11 +02:00
use Illuminate\Support\Collection;
2018-03-24 06:08:50 +01:00
use Log;
2017-08-18 15:32:11 +02:00
use Tests\TestCase;
/**
* Class AutoCompleteControllerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2017-08-18 15:32:11 +02:00
*/
class AutoCompleteControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
2018-03-24 06:08:50 +01:00
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-08-18 15:32:11 +02:00
/**
2019-06-29 19:47:31 +02:00
* Request a list of asset accounts
*
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
2017-08-18 15:32:11 +02:00
*/
2019-06-29 19:47:31 +02:00
public function testAccounts(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2019-06-29 19:47:31 +02:00
$account = $this->getRandomAsset();
$euro = $this->getEuro();
2018-06-01 22:04:52 +02:00
2019-06-29 19:47:31 +02:00
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
$this->mockDefaultSession();
2018-09-30 11:57:51 +02:00
$this->be($this->user());
2019-06-29 19:47:31 +02:00
$httpQuery = http_build_query(['types' => AccountType::ASSET]);
$response = $this->get(route('json.autocomplete.accounts') . '?' . $httpQuery);
2018-06-01 22:04:52 +02:00
$response->assertStatus(200);
2019-06-29 19:47:31 +02:00
$response->assertSee($account->name);
2018-06-01 22:04:52 +02:00
}
2018-08-06 19:14:30 +02:00
2019-07-24 19:02:41 +02:00
/**
* 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
{
2019-08-29 17:53:25 +02:00
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
2019-07-24 19:02:41 +02:00
$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
{
2019-08-29 17:53:25 +02:00
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
2019-07-24 19:02:41 +02:00
$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
{
2019-08-29 17:53:25 +02:00
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
2019-07-24 19:02:41 +02:00
$journalRepos = $this->mockDefaultSession();
$journal = $this->getRandomWithdrawalAsArray();
2019-08-29 17:53:25 +02:00
$journalObject = $this->getRandomWithdrawalGroup();
2019-07-24 19:02:41 +02:00
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
2019-08-29 17:53:25 +02:00
$groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject);
2019-07-24 19:02:41 +02:00
$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']);
}
2017-08-31 06:47:18 +02:00
}