Expanded test coverage.

This commit is contained in:
James Cole
2017-03-24 11:07:38 +01:00
parent 398cf0b312
commit 222b3008d5
14 changed files with 651 additions and 121 deletions

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
@@ -15,8 +15,10 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use PragmaRX\Google2FA\Contracts\Google2FA;
use Preferences;
use Tests\TestCase;
/**
@@ -81,6 +83,34 @@ class PreferencesControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
*
*/
public function testPostCode()
{
$secret = '0123456789abcde';
$key = '123456';
$google = $this->mock(Google2FA::class);
$this->withoutMiddleware();
$this->session(['two-factor-secret' => $secret]);
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthEnabled', 1])->once();
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthSecret', $secret])->once();
Preferences::shouldReceive('mark')->once();
$google->shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
$data = [
'code' => $key,
];
$this->be($this->user());
$response = $this->post(route('preferences.code.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
@@ -88,11 +118,13 @@ class PreferencesControllerTest extends TestCase
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->andReturn(false);
$data = [
'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [],
'frontPageAccounts' => [1],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
@@ -109,4 +141,80 @@ class PreferencesControllerTest extends TestCase
$response->assertRedirect(route('preferences.index'));
}
/**
* User wants 2FA and has secret already.
*
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
public function testPostIndexWith2FA()
{
$this->withoutMiddleware();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->andReturn(false);
// mock preferences (in a useful way?)
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn('12345');
Preferences::shouldReceive('set');
Preferences::shouldReceive('mark');
$data = [
'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [1],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
'transactionPageSize' => 100,
'twoFactorAuthEnabled' => 1,
'language' => 'en_US',
'tj' => [],
];
$this->be($this->user());
$response = $this->post(route('preferences.update'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// go to code to get a secret.
$response->assertRedirect(route('preferences.index'));
}
/**
* User wants 2FA and has no secret.
*
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
public function testPostIndexWithEmpty2FA()
{
$this->withoutMiddleware();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->andReturn(false);
// mock preferences (in a useful way?)
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);
Preferences::shouldReceive('set');
Preferences::shouldReceive('mark');
$data = [
'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [1],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
'transactionPageSize' => 100,
'twoFactorAuthEnabled' => 1,
'language' => 'en_US',
'tj' => [],
];
$this->be($this->user());
$response = $this->post(route('preferences.update'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// go to code to get a secret.
$response->assertRedirect(route('preferences.code'));
}
}

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
@@ -72,6 +72,7 @@ class ProfileControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePassword()
{
@@ -92,6 +93,52 @@ class ProfileControllerTest extends TestCase
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordNotCorrect()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$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::postChangePassword
* @covers \FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordSameNew()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword');
$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::postDeleteAccount
*/
@@ -101,7 +148,7 @@ class ProfileControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('destroy');
$repository->shouldReceive('destroy')->once();
$data = [
'password' => 'james',
];
@@ -111,4 +158,23 @@ class ProfileControllerTest extends TestCase
$response->assertRedirect(route('index'));
}
/**
* @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
*/
public function testPostDeleteAccountWrong()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(UserRepositoryInterface::class);
$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');
}
}

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
@@ -51,7 +51,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report');
$generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user());
@@ -71,7 +71,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('setBudgets')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report');
$generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user());
$response = $this->get(route('reports.report.budget', [1, 1, '20160101', '20160131']));
@@ -90,7 +90,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('setCategories')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report');
$generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user());
$response = $this->get(route('reports.report.category', [1, 1, '20160101', '20160131']));
@@ -108,13 +108,28 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('setStartDate')->once();
$generator->shouldReceive('setEndDate')->once();
$generator->shouldReceive('setAccounts')->once();
$generator->shouldReceive('generate')->andReturn('here-be-report');
$generator->shouldReceive('generate')->andReturn('here-be-report')->once();
$this->be($this->user());
$response = $this->get(route('reports.report.default', [1, '20160101', '20160131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::defaultReport
*/
public function testDefaultReportBadDate()
{
$generator = $this->mock(SYRG::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::index
* @covers \FireflyIII\Http\Controllers\ReportController::__construct
@@ -204,14 +219,211 @@ class ReportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndex()
public function testPostIndexAuditOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'daterange' => '2016-01-01 - 2016-01-31',
'report_type' => 'audit',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'));
$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::postIndex
*/
public function testPostIndexBudgetError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexBudgetOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexCategoryError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexCategoryOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexDefaultOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexDefaultStartEnd()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexTagError()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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::postIndex
*/
public function testPostIndexTagOK()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = [
'accounts' => ['1'],
'tag' => ['housing'],
'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', 'housing', '20160101', '20160131']));
}
/**
* @covers \FireflyIII\Http\Controllers\ReportController::postIndex
*/
public function testPostIndexZeroAccounts()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$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');
}
/**

View File

@@ -7,16 +7,18 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Rules\TransactionMatcher;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -30,13 +32,39 @@ class RuleControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\RuleController::create
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
*/
public function testCreate()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('rules.create', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::create
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
*/
public function testCreatePreviousInput()
{
$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
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@@ -51,7 +79,7 @@ class RuleControllerTest extends TestCase
public function testDelete()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@@ -66,8 +94,8 @@ class RuleControllerTest extends TestCase
public function testDestroy()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('destroy');
@@ -85,8 +113,8 @@ class RuleControllerTest extends TestCase
public function testDown()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('moveDown');
@@ -98,12 +126,43 @@ class RuleControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\RuleController::edit
* @covers \FireflyIII\Http\Controllers\RuleController::getCurrentActions
* @covers \FireflyIII\Http\Controllers\RuleController::getCurrentTriggers
*/
public function testEdit()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
$this->be($this->user());
$response = $this->get(route('rules.edit', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::edit
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions
* @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers
*/
public function testEditPreviousInput()
{
$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
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
@@ -116,6 +175,8 @@ class RuleControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\RuleController::index
* @covers \FireflyIII\Http\Controllers\RuleController::__construct
* @covers \FireflyIII\Http\Controllers\RuleController::createDefaultRule
* @covers \FireflyIII\Http\Controllers\RuleController::createDefaultRuleGroup
*/
public function testIndex()
{
@@ -143,12 +204,12 @@ class RuleControllerTest extends TestCase
public function testReorderRuleActions()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = ['triggers' => [1, 2, 3],];
$repository->shouldReceive('reorderRuleActions');
$data = ['actions' => [1, 2, 3],];
$repository->shouldReceive('reorderRuleActions')->once();
$this->be($this->user());
$response = $this->post(route('rules.reorder-actions', [1]), $data);
@@ -161,12 +222,12 @@ class RuleControllerTest extends TestCase
public function testReorderRuleTriggers()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$data = ['triggers' => [1, 2, 3],];
$repository->shouldReceive('reorderRuleTriggers');
$repository->shouldReceive('reorderRuleTriggers')->once();
$this->be($this->user());
$response = $this->post(route('rules.reorder-triggers', [1]), $data);
@@ -179,8 +240,8 @@ class RuleControllerTest extends TestCase
public function testStore()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -217,15 +278,73 @@ class RuleControllerTest extends TestCase
* This actually hits an error and not the actually code but OK.
*
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/
public function testTestTriggers()
public function testTestTriggersError()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('rules.test-triggers', [1]));
$uri = route('rules.test-triggers');
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
*
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/
public function testTestTriggers()
{
$data = [
'rule-trigger' => ['description_is'],
'rule-trigger-value' => ['Bla bla'],
'rule-trigger-stop' => ['1'],
];
// mock stuff
$matcher = $this->mock(TransactionMatcher::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
$matcher->shouldReceive('findMatchingTransactions')->andReturn(new Collection);
$this->be($this->user());
$uri = route('rules.test-triggers') . '?' . http_build_query($data);
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* @covers \FireflyIII\Http\Controllers\RuleController::getValidTriggerList
*/
public function testTestTriggersMax()
{
$data = [
'rule-trigger' => ['description_is'],
'rule-trigger-value' => ['Bla bla'],
'rule-trigger-stop' => ['1'],
];
$set = factory(Transaction::class, 10)->make();
// mock stuff
$matcher = $this->mock(TransactionMatcher::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
$matcher->shouldReceive('findMatchingTransactions')->andReturn($set);
$this->be($this->user());
$uri = route('rules.test-triggers') . '?' . http_build_query($data);
$response = $this->get($uri);
$response->assertStatus(200);
}
@@ -252,8 +371,8 @@ class RuleControllerTest extends TestCase
public function testUpdate()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@@ -25,7 +25,7 @@ class SearchControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\SearchController::index
* Implement testIndex().
* @covers \FireflyIII\Http\Controllers\SearchController::__construct
*/
public function testIndex()
{