More tests.

This commit is contained in:
James Cole
2016-12-18 19:34:03 +01:00
parent 5c28adf266
commit 8deb92c3e5
7 changed files with 155 additions and 79 deletions

View File

@@ -262,7 +262,6 @@ class CategoryController extends Controller
$journals = $collector->getPaginatedJournals(); $journals = $collector->getPaginatedJournals();
$journals->setPath('categories/show/' . $category->id . '/' . $date); $journals->setPath('categories/show/' . $category->id . '/' . $date);
return view('categories.show-by-date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon')); return view('categories.show-by-date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
} }

View File

@@ -22,6 +22,7 @@ use FireflyIII\Models\RuleTrigger;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Rules\TransactionMatcher; use FireflyIII\Rules\TransactionMatcher;
use Illuminate\Http\Request;
use Input; use Input;
use Preferences; use Preferences;
use Response; use Response;
@@ -87,7 +88,7 @@ class RuleController extends Controller
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
if (session('rules.rule.create.fromStore') !== true) { if (session('rules.rule.create.fromStore') !== true) {
Session::put('rules.rule.create.url', URL::previous()); Session::put('rules.create.url', URL::previous());
} }
Session::forget('rules.rule.create.fromStore'); Session::forget('rules.rule.create.fromStore');
Session::flash('gaEventCategory', 'rules'); Session::flash('gaEventCategory', 'rules');
@@ -110,7 +111,7 @@ class RuleController extends Controller
$subTitle = trans('firefly.delete_rule', ['title' => $rule->title]); $subTitle = trans('firefly.delete_rule', ['title' => $rule->title]);
// put previous url in session // put previous url in session
Session::put('rules.rule.delete.url', URL::previous()); Session::put('rules.delete.url', URL::previous());
Session::flash('gaEventCategory', 'rules'); Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'delete-rule'); Session::flash('gaEventAction', 'delete-rule');
@@ -135,7 +136,7 @@ class RuleController extends Controller
Preferences::mark(); Preferences::mark();
return redirect(session('rules.rule.delete.url')); return redirect(session('rules.delete.url'));
} }
/** /**
@@ -179,7 +180,7 @@ class RuleController extends Controller
// put previous url in session if not redirect from store (not "return_to_edit"). // put previous url in session if not redirect from store (not "return_to_edit").
if (session('rules.rule.edit.fromUpdate') !== true) { if (session('rules.rule.edit.fromUpdate') !== true) {
Session::put('rules.rule.edit.url', URL::previous()); Session::put('rules.edit.url', URL::previous());
} }
Session::forget('rules.rule.edit.fromUpdate'); Session::forget('rules.rule.edit.fromUpdate');
Session::flash('gaEventCategory', 'rules'); Session::flash('gaEventCategory', 'rules');
@@ -203,14 +204,15 @@ class RuleController extends Controller
} }
/** /**
* @param Request $request
* @param RuleRepositoryInterface $repository * @param RuleRepositoryInterface $repository
* @param Rule $rule * @param Rule $rule
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function reorderRuleActions(RuleRepositoryInterface $repository, Rule $rule) public function reorderRuleActions(Request $request, RuleRepositoryInterface $repository, Rule $rule)
{ {
$ids = Input::get('actions'); $ids = $request->get('actions');
if (is_array($ids)) { if (is_array($ids)) {
$repository->reorderRuleActions($rule, $ids); $repository->reorderRuleActions($rule, $ids);
} }
@@ -220,14 +222,15 @@ class RuleController extends Controller
} }
/** /**
* @param Request $request
* @param RuleRepositoryInterface $repository * @param RuleRepositoryInterface $repository
* @param Rule $rule * @param Rule $rule
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function reorderRuleTriggers(RuleRepositoryInterface $repository, Rule $rule) public function reorderRuleTriggers(Request $request, RuleRepositoryInterface $repository, Rule $rule)
{ {
$ids = Input::get('triggers'); $ids = $request->get('triggers');
if (is_array($ids)) { if (is_array($ids)) {
$repository->reorderRuleTriggers($rule, $ids); $repository->reorderRuleTriggers($rule, $ids);
} }
@@ -260,7 +263,7 @@ class RuleController extends Controller
} }
// redirect to previous URL. // redirect to previous URL.
return redirect(session('rules.rule.create.url')); return redirect(session('rules.create.url'));
} }
@@ -347,7 +350,7 @@ class RuleController extends Controller
} }
// redirect to previous URL. // redirect to previous URL.
return redirect(session('rules.rule.edit.url')); return redirect(session('rules.edit.url'));
} }
private function createDefaultRule() private function createDefaultRule()

View File

@@ -586,21 +586,21 @@ Breadcrumbs::register(
); );
Breadcrumbs::register( Breadcrumbs::register(
'rules.rule.create', function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) { 'rules.create', function (BreadCrumbGenerator $breadcrumbs, RuleGroup $ruleGroup) {
$breadcrumbs->parent('rules.index'); $breadcrumbs->parent('rules.index');
$breadcrumbs->push(trans('firefly.make_new_rule', ['title' => $ruleGroup->title]), route('rules.rule.create', [$ruleGroup])); $breadcrumbs->push(trans('firefly.make_new_rule', ['title' => $ruleGroup->title]), route('rules.create', [$ruleGroup]));
} }
); );
Breadcrumbs::register( Breadcrumbs::register(
'rules.rule.edit', function (BreadCrumbGenerator $breadcrumbs, Rule $rule) { 'rules.edit', function (BreadCrumbGenerator $breadcrumbs, Rule $rule) {
$breadcrumbs->parent('rules.index'); $breadcrumbs->parent('rules.index');
$breadcrumbs->push(trans('firefly.edit_rule', ['title' => $rule->title]), route('rules.rule.edit', [$rule])); $breadcrumbs->push(trans('firefly.edit_rule', ['title' => $rule->title]), route('rules.edit', [$rule]));
} }
); );
Breadcrumbs::register( Breadcrumbs::register(
'rules.rule.delete', function (BreadCrumbGenerator $breadcrumbs, Rule $rule) { 'rules.delete', function (BreadCrumbGenerator $breadcrumbs, Rule $rule) {
$breadcrumbs->parent('rules.index'); $breadcrumbs->parent('rules.index');
$breadcrumbs->push(trans('firefly.delete_rule', ['title' => $rule->title]), route('rules.rule.delete', [$rule])); $breadcrumbs->push(trans('firefly.delete_rule', ['title' => $rule->title]), route('rules.delete', [$rule]));
} }
); );
Breadcrumbs::register( Breadcrumbs::register(

View File

@@ -168,7 +168,7 @@ class CategoryControllerTest extends TestCase
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$this->call('GET', route('categories.show', [1, '2015-01-01'])); $this->call('GET', route('categories.show.date', [1, '2015-01-01']));
$this->assertResponseStatus(200); $this->assertResponseStatus(200);
$this->see('<ol class="breadcrumb">'); $this->see('<ol class="breadcrumb">');
} }

View File

@@ -11,6 +11,8 @@
namespace Chart; namespace Chart;
use Carbon\Carbon;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use TestCase; use TestCase;
/** /**
@@ -37,6 +39,13 @@ class CategoryControllerTest extends TestCase
*/ */
public function testAll(string $range) public function testAll(string $range)
{ {
$catRepository = $this->mock(CategoryRepositoryInterface::class);
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$catRepository->shouldReceive('firstUseDate')->andReturn(new Carbon);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.all', [1])); $this->call('get', route('chart.category.all', [1]));

View File

@@ -67,8 +67,17 @@ class PreferencesControllerTest extends TestCase
public function testPostIndex() public function testPostIndex()
{ {
$data = [ $data = [
'fiscalYearStart' => '2016-01-01' 'fiscalYearStart' => '2016-01-01',
'frontPageAccounts' => [],
'viewRange' => '1M',
'customFiscalYear' => 0,
'showDepositsFrontpage' => 0,
'transactionPageSize' => 100,
'twoFactorAuthEnabled' => 0,
'language' => 'en_US',
'tj' => [],
]; ];
$this->be($this->user()); $this->be($this->user());
$this->call('post', route('preferences.update'), $data); $this->call('post', route('preferences.update'), $data);
$this->assertResponseStatus(302); $this->assertResponseStatus(302);

View File

@@ -8,6 +8,8 @@
* *
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
/** /**
@@ -28,145 +30,199 @@ class RuleControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::create * @covers \FireflyIII\Http\Controllers\RuleController::create
* Implement testCreate().
*/ */
public function testCreate() public function testCreate()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.create', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::delete * @covers \FireflyIII\Http\Controllers\RuleController::delete
* Implement testDelete().
*/ */
public function testDelete() public function testDelete()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.delete', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::destroy * @covers \FireflyIII\Http\Controllers\RuleController::destroy
* Implement testDestroy().
*/ */
public function testDestroy() public function testDestroy()
{ {
// Remove the following lines when you implement this test. $repository = $this->mock(RuleRepositoryInterface::class);
$this->markTestIncomplete( $repository->shouldReceive('destroy');
'This test has not been implemented yet.'
); $this->session(['rules.delete.url' => 'http://localhost']);
$this->be($this->user());
$this->call('post', route('rules.destroy', [1]));
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('index');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::down * @covers \FireflyIII\Http\Controllers\RuleController::down
* Implement testDown().
*/ */
public function testDown() public function testDown()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.down', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(302);
); $this->assertRedirectedToRoute('rules.index');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::edit * @covers \FireflyIII\Http\Controllers\RuleController::edit
* Implement testEdit().
*/ */
public function testEdit() public function testEdit()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.edit', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::index * @covers \FireflyIII\Http\Controllers\RuleController::index
* Implement testIndex().
*/ */
public function testIndex() public function testIndex()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.index'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::reorderRuleActions * @covers \FireflyIII\Http\Controllers\RuleController::reorderRuleActions
* Implement testReorderRuleActions().
*/ */
public function testReorderRuleActions() public function testReorderRuleActions()
{ {
// Remove the following lines when you implement this test. $data = [
$this->markTestIncomplete( 'triggers' => [1, 2, 3],
'This test has not been implemented yet.' ];
);
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('reorderRuleActions');
$this->be($this->user());
$this->call('post', route('rules.reorder-actions', [1]), $data);
$this->assertResponseStatus(200);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::reorderRuleTriggers * @covers \FireflyIII\Http\Controllers\RuleController::reorderRuleTriggers
* Implement testReorderRuleTriggers().
*/ */
public function testReorderRuleTriggers() public function testReorderRuleTriggers()
{ {
// Remove the following lines when you implement this test. $data = [
$this->markTestIncomplete( 'triggers' => [1, 2, 3],
'This test has not been implemented yet.' ];
);
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('reorderRuleTriggers');
$this->be($this->user());
$this->call('post', route('rules.reorder-triggers', [1]), $data);
$this->assertResponseStatus(200);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::store * @covers \FireflyIII\Http\Controllers\RuleController::store
* Implement testStore().
*/ */
public function testStore() public function testStore()
{ {
// Remove the following lines when you implement this test. $this->session(['rules.create.url' => 'http://localhost']);
$this->markTestIncomplete( $data = [
'This test has not been implemented yet.' 'rule_group_id' => 1,
); 'active' => 1,
'title' => 'A',
'trigger' => 'store-journal',
'description' => 'D',
'rule-trigger' => [
1 => 'from_account_starts',
],
'rule-trigger-value' => [
1 => 'B',
],
'rule-action' => [
1 => 'set_category',
],
'rule-action-value' => [
1 => 'C',
],
];
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('store')->andReturn(new Rule);
$this->be($this->user());
$this->call('post', route('rules.store', [1]), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
} }
/** /**
* This actually hits an error and not the actually code but OK.
*
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers * @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
* Implement testTestTriggers().
*/ */
public function testTestTriggers() public function testTestTriggers()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.test-triggers', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::up * @covers \FireflyIII\Http\Controllers\RuleController::up
* Implement testUp().
*/ */
public function testUp() public function testUp()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('rules.up', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(302);
); $this->assertRedirectedToRoute('rules.index');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\RuleController::update * @covers \FireflyIII\Http\Controllers\RuleController::update
* Implement testUpdate().
*/ */
public function testUpdate() public function testUpdate()
{ {
// Remove the following lines when you implement this test. $data = [
$this->markTestIncomplete( 'rule_group_id' => 1,
'This test has not been implemented yet.' 'title' => 'Your first default rule',
); 'trigger' => 'store-journal',
'active' => 1,
'description' => 'This rule is an example. You can safely delete it.',
'rule-trigger' => [
1 => 'description_is',
],
'rule-trigger-value' => [
1 => 'something',
],
'rule-action' => [
1 => 'prepend_description',
],
'rule-action-value' => [
1 => 'Bla bla',
],
];
$this->session(['rules.edit.url' => 'http://localhost']);
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('update');
$this->be($this->user());
$this->call('post', route('rules.update', [1]), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
} }
} }