Fixed a lot of tests and associated code.

This commit is contained in:
James Cole
2017-12-17 14:06:14 +01:00
parent 7d348f25ac
commit b08af77c98
42 changed files with 579 additions and 442 deletions

View File

@@ -110,6 +110,7 @@ class BillControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\BillController::index
* @covers \FireflyIII\Http\Controllers\BillController::__construct
* @covers \FireflyIII\Http\Controllers\BillController::lastPaidDate
*/
public function testIndex()
{

View File

@@ -43,6 +43,21 @@ use Tests\TestCase;
*/
class BudgetControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::infoIncome
*/
public function testInfoIncome() {
// mock stuff
$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->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
*/

View File

@@ -206,9 +206,11 @@ class CurrencyControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencies = factory(TransactionCurrency::class, 3)->make();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
$repository->shouldReceive('get')->andReturn(new Collection);
$repository->shouldReceive('get')->andReturn($currencies);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$this->be($this->user());

View File

@@ -86,6 +86,16 @@ class HomeControllerTest extends TestCase
$response->assertSessionHas('warning', '91 days of data may take a while to load.');
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController::displayDebug()
*/
public function testDisplayDebug()
{
$this->be($this->user());
$response = $this->get(route('debug'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController::displayError
*/
@@ -170,6 +180,16 @@ class HomeControllerTest extends TestCase
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController::routes()
*/
public function testRoutes()
{
$this->be($this->user());
$response = $this->get(route('routes'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController::testFlash
*/

View File

@@ -1,225 +0,0 @@
<?php
/**
* FileControllerTest.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\Configurator\CsvConfigurator;
use FireflyIII\Import\Routine\ImportRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
/**
* Class FileControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class FileControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::__construct
* @covers \FireflyIII\Http\Controllers\Import\FileController::configure
* @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator
*/
public function testConfigure()
{
// mock stuff.
$configurator = $this->mock(CsvConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
$configurator->shouldReceive('getNextView')->once()->andReturn('import.csv.initial');
$configurator->shouldReceive('getNextData')->andReturn(['specifics' => [], 'delimiters' => [], 'accounts' => []])->once();
$this->be($this->user());
$response = $this->get(route('import.file.configure', ['configure']));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::__construct
* @covers \FireflyIII\Http\Controllers\Import\FileController::configure
* @covers \FireflyIII\Http\Controllers\Import\FileController::makeConfigurator
*/
public function testConfigured()
{
// mock stuff.
$configurator = $this->mock(CsvConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
$this->be($this->user());
$response = $this->get(route('import.file.configure', ['configure']));
$response->assertStatus(302);
$response->assertRedirect(route('import.file.status', ['configure']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::download
*/
public function testDownload()
{
$this->be($this->user());
$response = $this->get(route('import.file.download', ['configure']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::initialize
*/
public function testInitialize()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$path = resource_path('stubs/csv.csv');
$file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);
$configPath = resource_path('stubs/demo-configuration.json');
$configFile = new UploadedFile($path, 'configuration.json', filesize($configPath), 'application/json', null, true);
$job = new ImportJob;
$job->key = 'hello';
$repository->shouldReceive('create')->once()->andReturn($job);
$repository->shouldReceive('processFile')->once();
$repository->shouldReceive('processConfiguration')->once();
$repository->shouldReceive('updateStatus')->once();
$this->be($this->user());
$response = $this->post(route('import.file.initialize'), ['import_file_type' => 'csv', 'import_file' => $file, 'configuration_file' => $configFile]);
$response->assertStatus(302);
$response->assertRedirect(route('import.file.configure', ['hello']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::json
*/
public function testJson()
{
$this->be($this->user());
$response = $this->get(route('import.file.json', ['configure']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::json
*/
public function testJsonFinished()
{
$this->be($this->user());
$response = $this->get(route('import.file.json', ['finished']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::json
*/
public function testJsonRunning()
{
$this->be($this->user());
$response = $this->get(route('import.file.json', ['running']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure
*/
public function testPostConfigure()
{
$configurator = $this->mock(CsvConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(false);
$configurator->shouldReceive('configureJob')->once()->andReturn(false);
$configurator->shouldReceive('getWarningMessage')->once()->andReturn('');
$this->be($this->user());
$response = $this->post(route('import.file.process-configuration', ['running']));
$response->assertStatus(302);
$response->assertRedirect(route('import.file.configure', ['running']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::postConfigure
*/
public function testPostConfigured()
{
$configurator = $this->mock(CsvConfigurator::class);
$configurator->shouldReceive('setJob')->once();
$configurator->shouldReceive('isJobConfigured')->once()->andReturn(true);
$this->be($this->user());
$response = $this->post(route('import.file.process-configuration', ['running']));
$response->assertStatus(302);
$response->assertRedirect(route('import.file.status', ['running']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::start
*/
public function testStart()
{
$importer = $this->mock(ImportRoutine::class);
$importer->shouldReceive('setJob')->once();
$importer->shouldReceive('run')->once()->andReturn(true);
$this->be($this->user());
$response = $this->post(route('import.file.start', ['running']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::start
* @expectedExceptionMessage Job did not complete succesfully.
*/
public function testStartFailed()
{
$importer = $this->mock(ImportRoutine::class);
$importer->shouldReceive('setJob')->once();
$importer->shouldReceive('run')->once()->andReturn(false);
$this->be($this->user());
$response = $this->post(route('import.file.start', ['running']));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::status
*/
public function testStatus()
{
$this->be($this->user());
$response = $this->get(route('import.file.status', ['running']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\FileController::status
*/
public function testStatusNew()
{
$this->be($this->user());
$response = $this->get(route('import.file.status', ['new']));
$response->assertStatus(302);
$response->assertRedirect(route('import.file.configure', ['new']));
}
}

View File

@@ -1,46 +0,0 @@
<?php
/**
* ImportControllerTest.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;
use Tests\TestCase;
/**
* Class ImportControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ImportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\ImportController::index
*/
public function testIndex()
{
$this->be($this->user());
$response = $this->get(route('import.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -86,4 +86,21 @@ class JavascriptControllerTest extends TestCase
$response = $this->get(route('javascript.variables'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
* @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
*
* @param string $range
*
* @dataProvider dateRangeProvider
*/
public function testVariablesCustom(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->session(['is_custom_range' => true]);
$response = $this->get(route('javascript.variables'));
$response->assertStatus(200);
}
}

View File

@@ -86,9 +86,10 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->times(2);
$data = [
'bank_name' => 'New bank',
'savings_balance' => '1000',
'bank_balance' => '100',
'bank_name' => 'New bank',
'savings_balance' => '1000',
'bank_balance' => '100',
'amount_currency_id_bank_balance' => 1,
];
$this->be($this->emptyUser());
$response = $this->post(route('new-user.submit'), $data);
@@ -108,8 +109,9 @@ class NewUserControllerTest extends TestCase
$accountRepos->shouldReceive('store')->twice();
$data = [
'bank_name' => 'New bank',
'bank_balance' => '100',
'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);

View File

@@ -22,9 +22,13 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Preferences;
use Tests\TestCase;
/**
@@ -36,6 +40,18 @@ use Tests\TestCase;
*/
class ProfileControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::changeEmail()
*/
public function testChangeEmail()
{
$this->be($this->user());
$response = $this->get(route('profile.change-email'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::changePassword
*/
@@ -51,6 +67,36 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::confirmEmailChange()
* @expectedExceptionMessage Invalid token
*/
public function testConfirmEmailChangeNoToken()
{
Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());
// email_change_confirm_token
$response = $this->get(route('profile.confirm-email-change', ['some-fake-token']));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::confirmEmailChange()
*/
public function testConfirmEmailWithToken()
{
$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::deleteAccount
*/
@@ -72,6 +118,8 @@ class ProfileControllerTest extends TestCase
*/
public function testIndex()
{
// delete access token.
Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->delete();
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -82,6 +130,58 @@ class ProfileControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangeEmail
*/
public function testPostChangeEmail()
{
$data = [
'email' => 'new@example.com',
];
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('findByEmail')->once()->andReturn(null);
$repository->shouldReceive('changeEmail')->once()->andReturn(true);
$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::postChangeEmail
*/
public function testPostChangeEmailExisting()
{
$data = [
'email' => 'existing@example.com',
];
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('findByEmail')->once()->andReturn(new User);
$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::postChangeEmail
*/
public function testPostChangeEmailSame()
{
$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::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
@@ -187,4 +287,92 @@ class ProfileControllerTest extends TestCase
$response->assertRedirect(route('profile.delete-account'));
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::regenerate()
*/
public function testRegenerate()
{
$token = '';
$currentToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
if (!is_null($currentToken)) {
$token = $currentToken->data;
}
$this->be($this->user());
$response = $this->post(route('profile.regenerate'));
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertRedirect(route('profile.index'));
$newToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first();
$this->assertNotEquals($newToken->data, $token);
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::undoEmailChange()
*/
public function testUndoEmailChange()
{
$hash = hash('sha256', 'previous@example.com');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @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::undoEmailChange()
* @expectedExceptionMessage Invalid token
*/
public function testUndoEmailChangeBadHash()
{
$hash = hash('sha256', 'previous@example.comX');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @var \stdClass $hashPreference */
$hashPreference->user = $this->user();
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));
$response = $this->get(route('profile.undo-email-change', ['token', $hash]));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::undoEmailChange()
* @expectedExceptionMessage Invalid token
*/
public function testUndoEmailChangeBadToken()
{
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection);
$response = $this->get(route('profile.undo-email-change', ['token', 'some-hash']));
$response->assertStatus(500);
}
}

View File

@@ -22,12 +22,14 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
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\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
@@ -50,6 +52,26 @@ use Tests\TestCase;
*/
class ReportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\ReportController::accountReport()
*/
public function testAccountReport()
{
$generator = $this->mock(AcYRG::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('setExpense')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user());
$response = $this->get(route('reports.report.account', [1, 2, '20160101', '20160131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::auditReport
*/
@@ -172,6 +194,28 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::options
* @covers \FireflyIII\Http\Controllers\ReportController::accountReportOptions()
*/
public function testOptionsAccount()
{
$account = new Account();
$account->name = 'Something';
$account->id = 3;
$collection = new Collection([$account]);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE]])->once()->andReturn($collection);
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('reports.options', ['account']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::options
* @covers \FireflyIII\Http\Controllers\ReportController::budgetReportOptions
@@ -224,6 +268,27 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexAccountOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'exp_rev' => ['4'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'account',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('reports.report.account', ['1', '4', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/

View File

@@ -22,15 +22,19 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Jobs\Job;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher;
use Illuminate\Support\Collection;
use Queue;
use Tests\TestCase;
/**
@@ -183,6 +187,31 @@ class RuleControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::execute
*/
public function testExecute()
{
Queue::fake();
$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');
Queue::assertPushed(
ExecuteRuleOnExistingTransactions::class, function (Job $job) {
return $job->getRule()->id === 1;
}
);
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::index
* @covers \FireflyIII\Http\Controllers\RuleController::__construct
@@ -245,6 +274,20 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::selectTransactions()
*/
public function testSelectTransactions()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$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\RuleController::store
*/
@@ -312,6 +355,25 @@ class RuleControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggersByRule()
*/
public function testTestTriggersByRule()
{
$matcher = $this->mock(TransactionMatcher::class);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setRule')->andReturnSelf()->once();
$matcher->shouldReceive('findTransactionsByRule')->andReturn(new Collection);
$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.
*