mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Fix tests.
This commit is contained in:
@@ -104,7 +104,7 @@ class HomeController extends Controller
|
||||
}
|
||||
$subTitle = (string)trans('firefly.welcomeBack');
|
||||
$transactions = [];
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray());
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
|
@@ -264,7 +264,7 @@ class ReportController extends Controller
|
||||
try {
|
||||
$attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
Log::debug('Not important error message: %s', $e->getMessage());
|
||||
Log::debug(sprintf('Not important error message: %s', $e->getMessage()));
|
||||
$date = new Carbon;
|
||||
$date->startOfMonth();
|
||||
$attributes['startDate'] = $date;
|
||||
|
@@ -80,10 +80,7 @@ class IndexControllerTest extends TestCase
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.create', ['bad']));
|
||||
$response->assertStatus(302);
|
||||
// expect a redirect to index
|
||||
$response->assertSessionHas('warning', 'Firefly III cannot create a job for the "bad"-provider.');
|
||||
$response->assertRedirect(route('import.index'));
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,10 +103,10 @@ class IndexControllerTest extends TestCase
|
||||
$importJob->user_id = 1;
|
||||
|
||||
// mock calls
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->once();
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(2);
|
||||
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
|
||||
$fakePrerequisites->shouldReceive('isComplete')->twice()->andReturn(false);
|
||||
$fakePrerequisites->shouldReceive('setUser')->twice();
|
||||
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(false);
|
||||
$fakePrerequisites->shouldReceive('setUser')->times(3);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -139,10 +136,10 @@ class IndexControllerTest extends TestCase
|
||||
$importJob->user_id = 1;
|
||||
|
||||
// mock call:
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->once();
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(2);
|
||||
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
|
||||
$fakePrerequisites->shouldReceive('isComplete')->twice()->andReturn(true);
|
||||
$fakePrerequisites->shouldReceive('setUser')->twice();
|
||||
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true);
|
||||
$fakePrerequisites->shouldReceive('setUser')->times(3);
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
|
||||
|
||||
|
||||
@@ -173,17 +170,16 @@ class IndexControllerTest extends TestCase
|
||||
$importJob->user_id =1;
|
||||
|
||||
// mock calls
|
||||
$fakePrerequisites->shouldReceive('setUser')->once();
|
||||
$bunqPrerequisites->shouldReceive('setUser')->once();
|
||||
$spectrePrerequisites->shouldReceive('setUser')->once();
|
||||
$fakePrerequisites->shouldReceive('setUser')->times(2);
|
||||
$bunqPrerequisites->shouldReceive('setUser')->times(2);
|
||||
$spectrePrerequisites->shouldReceive('setUser')->times(2);
|
||||
|
||||
$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
|
||||
$bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
|
||||
$spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
|
||||
$fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
|
||||
$bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
|
||||
$spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
|
||||
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->once();
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->times(2);
|
||||
$repository->shouldReceive('create')->withArgs(['file'])->andReturn($importJob);
|
||||
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
|
||||
|
||||
|
||||
@@ -224,6 +220,17 @@ class IndexControllerTest extends TestCase
|
||||
];
|
||||
|
||||
$repository->shouldReceive('getConfiguration')->andReturn($fakeConfig)->once();
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
|
||||
$fakePrerequisites->shouldReceive('setUser')->times(1);
|
||||
$bunqPrerequisites->shouldReceive('setUser')->times(1);
|
||||
$spectrePrerequisites->shouldReceive('setUser')->times(1);
|
||||
//$filePrerequisites->shouldReceive('setUser')->times(1);
|
||||
|
||||
$fakePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
|
||||
$bunqPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
|
||||
$spectrePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
|
||||
//$filePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.job.download', [$job->key]));
|
||||
|
@@ -42,7 +42,7 @@ class PrerequisitesControllerTest extends TestCase
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
@@ -66,8 +66,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('isComplete')->once()->andReturn(false);
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('isComplete')->times(2)->andReturn(false);
|
||||
$prereq->shouldReceive('getView')->once()->andReturn('import.fake.prerequisites');
|
||||
$prereq->shouldReceive('getViewParameters')->once()->andReturn(['api_key' => '']);
|
||||
|
||||
@@ -117,8 +117,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('isComplete')->once()->andReturn(true);
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('isComplete')->times(2)->andReturn(true);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.prerequisites.index', ['fake', $job->key]));
|
||||
@@ -147,9 +147,10 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
|
||||
$prereq->shouldReceive('isComplete')->times(1)->andReturn(false);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.prerequisites.post', ['fake', $job->key]));
|
||||
@@ -177,6 +178,9 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(1);
|
||||
$prereq->shouldReceive('isComplete')->times(1)->andReturn(false);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.prerequisites.post', ['fake', $job->key]));
|
||||
$response->assertStatus(302);
|
||||
@@ -198,6 +202,9 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag);
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(1);
|
||||
$prereq->shouldReceive('isComplete')->times(1)->andReturn(false);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.prerequisites.post', ['fake']));
|
||||
$response->assertStatus(302);
|
||||
@@ -227,6 +234,9 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(1);
|
||||
$prereq->shouldReceive('isComplete')->times(1)->andReturn(false);
|
||||
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('storePrerequisites')->once()->andReturn($messages);
|
||||
|
||||
|
@@ -98,7 +98,7 @@ class ReportControllerTest extends TestCase
|
||||
];
|
||||
$uri = route('popup.general') . '?' . http_build_query($arguments);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(500);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ class ReportControllerTest extends TestCase
|
||||
|
||||
$uri = route('popup.general') . '?' . http_build_query($arguments);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(500);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,6 +364,6 @@ class ReportControllerTest extends TestCase
|
||||
];
|
||||
$uri = route('popup.general') . '?' . http_build_query($arguments);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(500);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
169
tests/Feature/Controllers/Rule/CreateControllerTest.php
Normal file
169
tests/Feature/Controllers/Rule/CreateControllerTest.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateControllerTest.php
|
||||
* Copyright (c) 2018 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\Rule;
|
||||
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class CreateControllerTest
|
||||
*/
|
||||
class CreateControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', false);
|
||||
$response->assertViewHas('bill', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
*/
|
||||
public function testCreateBill(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$billRepos->shouldReceive('find')->withArgs([1])->andReturn(Bill::find(1))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]) . '?return=true&fromBill=1');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
*/
|
||||
public function testCreatePreviousInput(): void
|
||||
{
|
||||
$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('firstNull')->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\Rule\CreateController
|
||||
*/
|
||||
public function testCreateReturn(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]) . '?return=true');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\RuleFormRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('store')->andReturn(new Rule);
|
||||
$repository->shouldReceive('find')->withArgs([0])->andReturn(new Rule)->once();
|
||||
|
||||
$this->session(['rules.create.uri' => 'http://localhost']);
|
||||
$data = [
|
||||
'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',
|
||||
],
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.store', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
78
tests/Feature/Controllers/Rule/DeleteControllerTest.php
Normal file
78
tests/Feature/Controllers/Rule/DeleteControllerTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* DeleteControllerTest.php
|
||||
* Copyright (c) 2018 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\Rule;
|
||||
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\DeleteController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\DeleteController
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('destroy');
|
||||
|
||||
$this->session(['rules.delete.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
}
|
138
tests/Feature/Controllers/Rule/EditControllerTest.php
Normal file
138
tests/Feature/Controllers/Rule/EditControllerTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* EditControllerTest.php
|
||||
* Copyright (c) 2018 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\Rule;
|
||||
|
||||
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class EditControllerTest
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\EditController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
// mock stuff
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
|
||||
$groupRepos->shouldReceive('get')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\EditController
|
||||
*/
|
||||
public function testEditPreviousInput(): void
|
||||
{
|
||||
$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
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
|
||||
$groupRepos->shouldReceive('get')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\EditController
|
||||
* @covers \FireflyIII\Http\Requests\RuleFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$rule = Rule::find(1);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('find')->withArgs([1])->andReturn($rule)->once();
|
||||
$repository->shouldReceive('update');
|
||||
|
||||
$data = [
|
||||
'rule_group_id' => 1,
|
||||
'id' => 1,
|
||||
'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.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
148
tests/Feature/Controllers/Rule/IndexControllerTest.php
Normal file
148
tests/Feature/Controllers/Rule/IndexControllerTest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexControllerTest.php
|
||||
* Copyright (c) 2018 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\Rule;
|
||||
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IndexControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\IndexController
|
||||
*/
|
||||
public function testDown(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('moveDown');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.down', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('rules.index'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\IndexController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$ruleGroupRepos->shouldReceive('count')->andReturn(0);
|
||||
$ruleGroupRepos->shouldReceive('store');
|
||||
$repository->shouldReceive('getFirstRuleGroup')->andReturn(new RuleGroup);
|
||||
$ruleGroupRepos->shouldReceive('getRuleGroupsWithRules')->andReturn(new Collection);
|
||||
$repository->shouldReceive('count')->andReturn(0);
|
||||
$repository->shouldReceive('store');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\IndexController
|
||||
*/
|
||||
public function testReorderRuleActions(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$data = ['actions' => [1, 2, 3]];
|
||||
$repository->shouldReceive('reorderRuleActions')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.reorder-actions', [1]), $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\IndexController
|
||||
*/
|
||||
public function testReorderRuleTriggers(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$data = ['triggers' => [1, 2, 3]];
|
||||
$repository->shouldReceive('reorderRuleTriggers')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.reorder-triggers', [1]), $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\IndexController
|
||||
*/
|
||||
public function testUp(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('moveUp');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.up', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('rules.index'));
|
||||
}
|
||||
|
||||
}
|
189
tests/Feature/Controllers/Rule/SelectControllerTest.php
Normal file
189
tests/Feature/Controllers/Rule/SelectControllerTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* SelectControllerTest.php
|
||||
* Copyright (c) 2018 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\Rule;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||
use FireflyIII\Jobs\Job;
|
||||
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\TransactionRules\TransactionMatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Class SelectControllerTest
|
||||
*/
|
||||
class SelectControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\SelectController
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$account = $this->user()->accounts()->find(1);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$this->session(['first' => new Carbon('2010-01-01')]);
|
||||
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
|
||||
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\Rule\SelectController
|
||||
*/
|
||||
public function testSelectTransactions(): void
|
||||
{
|
||||
$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\Rule\SelectController
|
||||
*/
|
||||
public function testTestTriggers(): void
|
||||
{
|
||||
$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('firstNull')->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('findTransactionsByTriggers')->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\Rule\SelectController
|
||||
*/
|
||||
public function testTestTriggersByRule(): void
|
||||
{
|
||||
|
||||
$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.
|
||||
*
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\SelectController
|
||||
*/
|
||||
public function testTestTriggersError(): void
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$uri = route('rules.test-triggers');
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\SelectController
|
||||
*/
|
||||
public function testTestTriggersMax(): void
|
||||
{
|
||||
$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('firstNull')->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('findTransactionsByTriggers')->andReturn($set);
|
||||
|
||||
$this->be($this->user());
|
||||
$uri = route('rules.test-triggers') . '?' . http_build_query($data);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
@@ -1,542 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* RuleControllerTest.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 Carbon\Carbon;
|
||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||
use FireflyIII\Jobs\Job;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\TransactionMatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RuleControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class RuleControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', false);
|
||||
$response->assertViewHas('bill', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testCreateBill(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$billRepos->shouldReceive('find')->withArgs([1])->andReturn(Bill::find(1))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]) . '?return=true&fromBill=1');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testCreatePreviousInput(): void
|
||||
{
|
||||
$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('firstNull')->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
|
||||
*/
|
||||
public function testCreateReturn(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create', [1]) . '?return=true');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertViewHas('returnToBill', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('destroy');
|
||||
|
||||
$this->session(['rules.delete.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testDown(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('moveDown');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.down', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('rules.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
// mock stuff
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
|
||||
$groupRepos->shouldReceive('get')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testEditPreviousInput(): void
|
||||
{
|
||||
$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
|
||||
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule);
|
||||
$groupRepos->shouldReceive('get')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$account = $this->user()->accounts()->find(1);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$this->session(['first' => new Carbon('2010-01-01')]);
|
||||
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
|
||||
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
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$ruleGroupRepos->shouldReceive('count')->andReturn(0);
|
||||
$ruleGroupRepos->shouldReceive('store');
|
||||
$repository->shouldReceive('getFirstRuleGroup')->andReturn(new RuleGroup);
|
||||
$ruleGroupRepos->shouldReceive('getRuleGroupsWithRules')->andReturn(new Collection);
|
||||
$repository->shouldReceive('count')->andReturn(0);
|
||||
$repository->shouldReceive('store');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testReorderRuleActions(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$data = ['actions' => [1, 2, 3]];
|
||||
$repository->shouldReceive('reorderRuleActions')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.reorder-actions', [1]), $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testReorderRuleTriggers(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$data = ['triggers' => [1, 2, 3]];
|
||||
$repository->shouldReceive('reorderRuleTriggers')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.reorder-triggers', [1]), $data);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testSelectTransactions(): void
|
||||
{
|
||||
$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
|
||||
* @covers \FireflyIII\Http\Requests\RuleFormRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('store')->andReturn(new Rule);
|
||||
$repository->shouldReceive('find')->withArgs([0])->andReturn(new Rule)->once();
|
||||
|
||||
$this->session(['rules.create.uri' => 'http://localhost']);
|
||||
$data = [
|
||||
'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',
|
||||
],
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.store', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testTestTriggers(): void
|
||||
{
|
||||
$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('firstNull')->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('findTransactionsByTriggers')->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
|
||||
*/
|
||||
public function testTestTriggersByRule(): void
|
||||
{
|
||||
|
||||
$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.
|
||||
*
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testTestTriggersError(): void
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$uri = route('rules.test-triggers');
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
*/
|
||||
public function testTestTriggersMax(): void
|
||||
{
|
||||
$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('firstNull')->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('findTransactionsByTriggers')->andReturn($set);
|
||||
|
||||
$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
|
||||
*/
|
||||
public function testUp(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('moveUp');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.up', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('rules.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\RuleController
|
||||
* @covers \FireflyIII\Http\Requests\RuleFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(RuleRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$rule = Rule::find(1);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('find')->withArgs([1])->andReturn($rule)->once();
|
||||
$repository->shouldReceive('update');
|
||||
|
||||
$data = [
|
||||
'rule_group_id' => 1,
|
||||
'id' => 1,
|
||||
'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.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('rules.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
@@ -38,7 +38,7 @@ class LinkControllerTest extends TestCase
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
@@ -167,14 +167,14 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreInvalid(): void
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$data = [
|
||||
'link_other' => 0,
|
||||
'link_type' => '1_inward',
|
||||
];
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(null);
|
||||
$journalRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.link.store', [1]), $data);
|
||||
|
@@ -40,7 +40,9 @@ class AddTagTest extends TestCase
|
||||
public function testActExistingTag(): void
|
||||
{
|
||||
$tag = $this->user()->tags()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$journal->tags()->sync([]);
|
||||
$journal->tags()->sync([$tag->id]);
|
||||
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
|
||||
$ruleAction = new RuleAction;
|
||||
|
@@ -25,7 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
|
||||
use Tests\TestCase;
|
||||
|
||||
use Log;
|
||||
/**
|
||||
* Class FromAccountIsTest
|
||||
*/
|
||||
@@ -36,13 +36,21 @@ class FromAccountIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$count = 0;
|
||||
while ($count === 0) {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$count = $journal->transactions()->where('amount', '<', 0)->count();
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
$account = $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
|
||||
|
||||
$trigger = FromAccountIs::makeFromStrings($account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
Reference in New Issue
Block a user