mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand test coverage.
This commit is contained in:
@@ -294,9 +294,25 @@ class BudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
|
||||
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']), $data);
|
||||
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BudgetController::infoIncome
|
||||
* @dataProvider dateRangeProvider
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testInfoIncomeExpanded(string $range)
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('budgets.income.info', ['20170301', '20170430']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -306,6 +322,8 @@ class BudgetControllerTest extends TestCase
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testNoBudget(string $range)
|
||||
{
|
||||
|
||||
119
tests/Feature/Controllers/Import/ConfigurationControllerTest.php
Normal file
119
tests/Feature/Controllers/Import/ConfigurationControllerTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* ConfigurationControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Import;
|
||||
|
||||
use FireflyIII\Import\Configuration\FileConfigurator;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ConfigurationControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::index
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::makeConfigurator
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
|
||||
$configurator = $this->mock(FileConfigurator::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator->shouldReceive('setJob')->once();
|
||||
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
|
||||
$configurator->shouldReceive('getNextView')->once()->andReturn('error'); // does not matter which view is returned.
|
||||
$configurator->shouldReceive('getNextData')->once()->andReturn([]);
|
||||
$repository->shouldReceive('updateStatus')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.configure', [$job->key]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::index
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::makeConfigurator
|
||||
*/
|
||||
public function testIndexConfigured()
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->where('key', 'configured')->first();
|
||||
$configurator = $this->mock(FileConfigurator::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator->shouldReceive('setJob')->once();
|
||||
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
|
||||
$repository->shouldReceive('updateStatus')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.configure', [$job->key]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.status', [$job->key]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::post
|
||||
*/
|
||||
public function testPost()
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
|
||||
$data = ['some' => 'config'];
|
||||
$configurator = $this->mock(FileConfigurator::class);
|
||||
$configurator->shouldReceive('setJob')->once();
|
||||
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
|
||||
$configurator->shouldReceive('configureJob')->once()->withArgs([$data]);
|
||||
$configurator->shouldReceive('getWarningMessage')->once()->andReturn('Some warning');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.configure.post', [$job->key]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.configure', [$job->key]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\ConfigurationController::post
|
||||
*/
|
||||
public function testPostConfigured()
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->where('key', 'configuring')->first();
|
||||
$data = ['some' => 'config'];
|
||||
$configurator = $this->mock(FileConfigurator::class);
|
||||
$configurator->shouldReceive('setJob')->once();
|
||||
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.configure.post', [$job->key]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.status', [$job->key]));
|
||||
}
|
||||
}
|
||||
105
tests/Feature/Controllers/Import/IndexControllerTest.php
Normal file
105
tests/Feature/Controllers/Import/IndexControllerTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Import;
|
||||
|
||||
use FireflyIII\Import\Routine\FileRoutine;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$job = $this->user()->importJobs()->where('key', 'new')->first();
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$repository->shouldReceive('create')->withArgs(['file'])->andReturn($job);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.create-job', ['file']));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.configure', ['new']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::download
|
||||
*/
|
||||
public function testDownload()
|
||||
{
|
||||
//$job = $this->user()->importJobs()->where('key', 'testImport')->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.download', ['testImport']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.index'));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::start
|
||||
*/
|
||||
public function testStart()
|
||||
{
|
||||
$routine = $this->mock(FileRoutine::class);
|
||||
$routine->shouldReceive('setJob')->once();
|
||||
$routine->shouldReceive('run')->once()->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.start', ['configured']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\IndexController::start
|
||||
* @expectedExceptionMessage Job did not complete successfully.
|
||||
*/
|
||||
public function testStartFailed()
|
||||
{
|
||||
$routine = $this->mock(FileRoutine::class);
|
||||
$routine->shouldReceive('setJob')->once();
|
||||
$routine->shouldReceive('run')->once()->andReturn(false);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.start', ['configured']));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
}
|
||||
109
tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
Normal file
109
tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* PrerequisitesControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Import;
|
||||
|
||||
use FireflyIII\Import\Prerequisites\FilePrerequisites;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PrerequisitesControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$object = $this->mock(FilePrerequisites::class);
|
||||
$object->shouldReceive('setUser');
|
||||
$object->shouldReceive('hasPrerequisites')->andReturn(true);
|
||||
$object->shouldReceive('getView')->andReturn('error'); // does not matter which view is returned
|
||||
$object->shouldReceive('getViewParameters')->andReturn([]);
|
||||
$this->be($this->user());
|
||||
|
||||
$response = $this->get(route('import.prerequisites', ['file']));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::index
|
||||
*/
|
||||
public function testIndexRedirect()
|
||||
{
|
||||
$object = $this->mock(FilePrerequisites::class);
|
||||
$object->shouldReceive('setUser');
|
||||
$object->shouldReceive('hasPrerequisites')->andReturn(false);
|
||||
$this->be($this->user());
|
||||
|
||||
$response = $this->get(route('import.prerequisites', ['file']));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.create-job', ['file']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::post
|
||||
*/
|
||||
public function testPost()
|
||||
{
|
||||
$messageBag = new MessageBag;
|
||||
$messageBag->add('nomessage', 'nothing');
|
||||
$object = $this->mock(FilePrerequisites::class);
|
||||
$object->shouldReceive('setUser');
|
||||
$object->shouldReceive('hasPrerequisites')->andReturn(true);
|
||||
$object->shouldReceive('storePrerequisites')->andReturn($messageBag);
|
||||
$this->be($this->user());
|
||||
|
||||
$response = $this->post(route('import.prerequisites.post', ['file']), []);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertRedirect(route('import.prerequisites', ['file']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController::post
|
||||
*/
|
||||
public function testPostDone()
|
||||
{
|
||||
$messageBag = new MessageBag;
|
||||
$messageBag->add('nomessage', 'nothing');
|
||||
$object = $this->mock(FilePrerequisites::class);
|
||||
$object->shouldReceive('setUser');
|
||||
$object->shouldReceive('hasPrerequisites')->andReturn(false);
|
||||
$this->be($this->user());
|
||||
|
||||
$response = $this->post(route('import.prerequisites.post', ['file']), []);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.create-job', ['file']));
|
||||
|
||||
}
|
||||
}
|
||||
86
tests/Feature/Controllers/Import/StatusControllerTest.php
Normal file
86
tests/Feature/Controllers/Import/StatusControllerTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Import;
|
||||
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class StatusControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.status', ['configured']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::index
|
||||
*/
|
||||
public function testIndexRedirect()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.status', ['new']));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('import.configure', ['new']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::json
|
||||
*/
|
||||
public function testStatusFinished()
|
||||
{
|
||||
$tag = $this->user()->tags()->first();
|
||||
$repository = $this->mock(TagRepositoryInterface::class);
|
||||
$repository->shouldReceive('find')->andReturn($tag);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.status.json', ['finished']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Import\StatusController::json
|
||||
*/
|
||||
public function testStatusRunning()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.status.json', ['running']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,14 +41,19 @@ class AutoCompleteControllerTest extends TestCase
|
||||
*/
|
||||
public function testAllAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$collection = new Collection([$accountA]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])
|
||||
->andReturn(new Collection);
|
||||
->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.all-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,18 +77,39 @@ class AutoCompleteControllerTest extends TestCase
|
||||
public function testExpenseAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(
|
||||
new Collection([$account])
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.expense-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$account->name]);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::journalsWithId
|
||||
*/
|
||||
public function testJournalsWithId()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('id', '!=', 1)->first();
|
||||
$journal->journal_id = $journal->id;
|
||||
$collection = new Collection([$journal]);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$collector->shouldReceive('setLimit')->withArgs([400])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->withArgs([1])->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.journals-with-id', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([['id' => $journal->id, 'name' => $journal->id . ': ' . $journal->description]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,18 +118,20 @@ class AutoCompleteControllerTest extends TestCase
|
||||
public function testRevenueAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(
|
||||
new Collection([$account])
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.revenue-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$account->name]);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
100
tests/Feature/Controllers/Json/BoxControllerTest.php
Normal file
100
tests/Feature/Controllers/Json/BoxControllerTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class BoxControllerTest
|
||||
*/
|
||||
class BoxControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::available
|
||||
*/
|
||||
public function testAvailable()
|
||||
{
|
||||
$return = [
|
||||
0 => [
|
||||
'spent' => '-1200', // more than budgeted.
|
||||
],
|
||||
];
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('1000');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($return);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.available'));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::balance
|
||||
*/
|
||||
public function testBalance()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.balance'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::bills
|
||||
*/
|
||||
public function testBills()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.bills'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorth()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorthFuture()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
51
tests/Feature/Controllers/Json/FrontpageControllerTest.php
Normal file
51
tests/Feature/Controllers/Json/FrontpageControllerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* FrontpageControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FrontpageControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class FrontpageControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\FrontpageController::piggyBanks
|
||||
*/
|
||||
public function testPiggyBanks()
|
||||
{
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy]));
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.fp.piggy-banks'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
95
tests/Feature/Controllers/Json/IntroControllerTest.php
Normal file
95
tests/Feature/Controllers/Json/IntroControllerTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* IntroControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IntroControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class IntroControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroSteps()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['index']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroStepsAsset()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroStepsOutro()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['reports_report', 'category']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::postEnable
|
||||
*/
|
||||
public function testPostEnable()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('json.intro.enable', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::postFinished
|
||||
*/
|
||||
public function testPostFinished()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('json.intro.finished', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class PreferencesControllerTest extends TestCase
|
||||
'viewRange' => '1M',
|
||||
'customFiscalYear' => 0,
|
||||
'showDepositsFrontpage' => 0,
|
||||
'transactionPageSize' => 100,
|
||||
'listPageSize' => 100,
|
||||
'twoFactorAuthEnabled' => 0,
|
||||
'language' => 'en_US',
|
||||
'tj' => [],
|
||||
@@ -176,7 +176,7 @@ class PreferencesControllerTest extends TestCase
|
||||
'viewRange' => '1M',
|
||||
'customFiscalYear' => 0,
|
||||
'showDepositsFrontpage' => 0,
|
||||
'transactionPageSize' => 100,
|
||||
'listPageSize' => 100,
|
||||
'twoFactorAuthEnabled' => 1,
|
||||
'language' => 'en_US',
|
||||
'tj' => [],
|
||||
@@ -214,7 +214,7 @@ class PreferencesControllerTest extends TestCase
|
||||
'viewRange' => '1M',
|
||||
'customFiscalYear' => 0,
|
||||
'showDepositsFrontpage' => 0,
|
||||
'transactionPageSize' => 100,
|
||||
'listPageSize' => 100,
|
||||
'twoFactorAuthEnabled' => 1,
|
||||
'language' => 'en_US',
|
||||
'tj' => [],
|
||||
|
||||
252
tests/Feature/Controllers/Report/ExpenseControllerTest.php
Normal file
252
tests/Feature/Controllers/Report/ExpenseControllerTest.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/**
|
||||
* ExpenseControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Report;
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ExpenseControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ExpenseControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::budget
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::combineAccounts
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::spentByBudget
|
||||
*/
|
||||
public function testBudget()
|
||||
{
|
||||
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
// fake collection:
|
||||
$transA = new Transaction;
|
||||
$transA->transaction_currency_id = 1;
|
||||
$transA->transaction_budget_name = 'Budget';
|
||||
$transA->transaction_budget_id = 1;
|
||||
$transA->transaction_currency_symbol = 'A';
|
||||
$transA->transaction_currency_dp = 2;
|
||||
$transA->transaction_amount = '100';
|
||||
$transB = new Transaction;
|
||||
$transB->transaction_currency_id = 2;
|
||||
$transB->transaction_budget_name = null;
|
||||
$transB->transaction_budget_id = 0;
|
||||
$transB->transaction_journal_budget_name = 'Budget2';
|
||||
$transB->transaction_journal_budget_id = 2;
|
||||
$transB->transaction_currency_symbol = 'A';
|
||||
$transB->transaction_currency_dp = 2;
|
||||
$transB->transaction_amount = '100';
|
||||
$collection = new Collection([$transA, $transB]);
|
||||
|
||||
// mock collector for spentByBudget (complex)
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
// dont care about any calls, just return a default set of fake transactions:
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.budget', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::category
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::spentByCategory
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::earnedByCategory
|
||||
*/
|
||||
public function testCategory()
|
||||
{
|
||||
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
// fake collection:
|
||||
$transA = new Transaction;
|
||||
$transA->transaction_currency_id = 1;
|
||||
$transA->transaction_category_name = 'Category';
|
||||
$transA->transaction_category_id = 1;
|
||||
$transA->transaction_currency_symbol = 'A';
|
||||
$transA->transaction_currency_dp = 2;
|
||||
$transA->transaction_amount = '100';
|
||||
$transB = new Transaction;
|
||||
$transB->transaction_currency_id = 2;
|
||||
$transB->transaction_category_name = null;
|
||||
$transB->transaction_category_id = 0;
|
||||
$transB->transaction_journal_category_name = 'Category2';
|
||||
$transB->transaction_journal_category_id = 2;
|
||||
$transB->transaction_currency_symbol = 'A';
|
||||
$transB->transaction_currency_dp = 2;
|
||||
$transB->transaction_amount = '100';
|
||||
$collection = new Collection([$transA, $transB]);
|
||||
$transC = new Transaction;
|
||||
$transC->transaction_currency_id = 3;
|
||||
$transC->transaction_category_name = null;
|
||||
$transC->transaction_category_id = 0;
|
||||
$transC->transaction_journal_category_name = 'Category3';
|
||||
$transC->transaction_journal_category_id = 3;
|
||||
$transC->transaction_currency_symbol = 'A';
|
||||
$transC->transaction_currency_dp = 2;
|
||||
$transC->transaction_amount = '100';
|
||||
$secondCollection = new Collection([$transC]);
|
||||
|
||||
// mock collector for spentByCategory and earnedByCategory (complex)
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
// dont care about any calls, just return a default set of fake transactions:
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection, $secondCollection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.category', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::spent
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::spentInPeriod
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::earnedInPeriod
|
||||
*/
|
||||
public function testSpent()
|
||||
{
|
||||
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
// fake collection:
|
||||
$transA = new Transaction;
|
||||
$transA->transaction_currency_id = 1;
|
||||
$transA->transaction_category_name = 'Category';
|
||||
$transA->transaction_category_id = 1;
|
||||
$transA->transaction_currency_symbol = 'A';
|
||||
$transA->transaction_currency_dp = 2;
|
||||
$transA->transaction_amount = '100';
|
||||
$transB = new Transaction;
|
||||
$transB->transaction_currency_id = 2;
|
||||
$transB->transaction_category_name = null;
|
||||
$transB->transaction_category_id = 0;
|
||||
$transB->transaction_journal_budget_name = 'Category2';
|
||||
$transB->transaction_journal_budget_id = 2;
|
||||
$transB->transaction_currency_symbol = 'A';
|
||||
$transB->transaction_currency_dp = 2;
|
||||
$transB->transaction_amount = '100';
|
||||
$collection = new Collection([$transA, $transB]);
|
||||
|
||||
// mock collector for spentInPeriod and earnedInPeriod (complex)
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
// dont care about any calls, just return a default set of fake transactions:
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.spent', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::topExpense
|
||||
*/
|
||||
public function testTopExpense()
|
||||
{
|
||||
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
// fake collection:
|
||||
$transA = new Transaction;
|
||||
$transA->transaction_currency_id = 1;
|
||||
$transA->transaction_category_name = 'Category';
|
||||
$transA->transaction_category_id = 1;
|
||||
$transA->transaction_currency_symbol = 'A';
|
||||
$transA->transaction_currency_dp = 2;
|
||||
$transA->transaction_amount = '100';
|
||||
$transB = new Transaction;
|
||||
$transB->transaction_currency_id = 2;
|
||||
$transB->transaction_category_name = null;
|
||||
$transB->transaction_category_id = 0;
|
||||
$transB->transaction_journal_budget_name = 'Category2';
|
||||
$transB->transaction_journal_budget_id = 2;
|
||||
$transB->transaction_currency_symbol = 'A';
|
||||
$transB->transaction_currency_dp = 2;
|
||||
$transB->transaction_amount = '100';
|
||||
$collection = new Collection([$transA, $transB]);
|
||||
|
||||
// mock collector for topExpense (complex)
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
// dont care about any calls, just return a default set of fake transactions:
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\ExpenseController::topIncome
|
||||
*/
|
||||
public function testTopIncome()
|
||||
{
|
||||
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
||||
147
tests/Feature/Controllers/Transaction/LinkControllerTest.php
Normal file
147
tests/Feature/Controllers/Transaction/LinkControllerTest.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* LinkControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Class LinkControllerTest
|
||||
*/
|
||||
class LinkControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.link.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$repository->shouldReceive('destroyLink');
|
||||
$this->be($this->user());
|
||||
|
||||
$this->session(['journal_links.delete.uri' => 'http://localhost/']);
|
||||
|
||||
$response = $this->post(route('transactions.link.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
|
||||
*/
|
||||
public function testStoreAlreadyLinked()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$data = [
|
||||
'link_other' => 8,
|
||||
'link_type' => '1_inward',
|
||||
];
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findLink')->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.link.store', [1]), $data);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertRedirect(route('transactions.show', [1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$data = [
|
||||
'link_other' => 8,
|
||||
'link_type' => '1_inward',
|
||||
];
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findLink')->andReturn(false);
|
||||
$repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.link.store', [1]), $data);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertRedirect(route('transactions.show', [1]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
|
||||
*/
|
||||
public function testStoreInvalid()
|
||||
{
|
||||
$data = [
|
||||
'link_other' => 0,
|
||||
'link_type' => '1_inward',
|
||||
];
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.link.store', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertRedirect(route('transactions.show', [1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::switchLink
|
||||
*/
|
||||
public function testSwitchLink()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$repository->shouldReceive('switchLink')->andReturn(false);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.link.switch', [1]));
|
||||
|
||||
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,16 @@ class MassControllerTest extends TestCase
|
||||
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
|
||||
);
|
||||
|
||||
// add reconcile transaction
|
||||
$collection->push(
|
||||
TransactionJournal::where('transaction_type_id', 5)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->orderBy('ct', 'DESC')
|
||||
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
|
||||
);
|
||||
|
||||
// add opening balance:
|
||||
$collection->push(TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first());
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
|
||||
@@ -27,6 +27,7 @@ use FireflyIII\Events\StoredTransactionJournal;
|
||||
use FireflyIII\Events\UpdatedTransactionJournal;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
@@ -54,6 +55,13 @@ class SingleControllerTest extends TestCase
|
||||
*/
|
||||
public function testCloneTransaction()
|
||||
{
|
||||
$note = new Note();
|
||||
$note->id = 5;
|
||||
$note->text = 'I see you...';
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$response = $this->get(route('transactions.clone', [$withdrawal->id]));
|
||||
@@ -63,6 +71,7 @@ class SingleControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
@@ -124,6 +133,14 @@ class SingleControllerTest extends TestCase
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
|
||||
|
||||
$note = new Note();
|
||||
$note->id = 5;
|
||||
$note->text = 'I see you...';
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('countTransactions')->andReturn(2);
|
||||
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
|
||||
@@ -201,6 +218,23 @@ class SingleControllerTest extends TestCase
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedAccountList
|
||||
*/
|
||||
public function testEditReconcile()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 5)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->orderBy('ct', 'DESC')
|
||||
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
|
||||
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedAccountList
|
||||
@@ -295,8 +329,6 @@ class SingleControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreSuccess()
|
||||
{
|
||||
$this->markTestIncomplete('Mockery cannot yet handle PHP7.1 null argument method things.');
|
||||
|
||||
// mock results:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = new TransactionJournal();
|
||||
|
||||
Reference in New Issue
Block a user