2019-07-21 17:15:06 +02:00
|
|
|
<?php
|
2019-08-17 12:09:03 +02:00
|
|
|
declare(strict_types=1);
|
2019-07-21 17:15:06 +02:00
|
|
|
/**
|
|
|
|
* ExecutionControllerTest.php
|
|
|
|
* Copyright (c) 2019 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers\RuleGroup;
|
|
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2019-07-31 16:53:09 +02:00
|
|
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
2019-07-21 17:15:06 +02:00
|
|
|
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2019-08-29 17:53:25 +02:00
|
|
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
2019-07-21 17:15:06 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2019-07-31 16:53:09 +02:00
|
|
|
use FireflyIII\TransactionRules\Engine\RuleEngine;
|
2019-07-21 17:15:06 +02:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Log;
|
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2019-07-31 16:53:09 +02:00
|
|
|
/**
|
|
|
|
* Class ExecutionControllerTest
|
2019-08-17 10:48:28 +02:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2019-07-31 16:53:09 +02:00
|
|
|
*/
|
2019-07-21 17:15:06 +02:00
|
|
|
class ExecutionControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
|
|
|
|
*/
|
|
|
|
public function testExecute(): void
|
|
|
|
{
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2019-08-29 17:53:25 +02:00
|
|
|
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
2019-07-31 16:53:09 +02:00
|
|
|
$collector = $this->mock(GroupCollectorInterface::class);
|
|
|
|
$ruleEngine = $this->mock(RuleEngine::class);
|
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
|
2019-08-29 17:53:25 +02:00
|
|
|
$groupRepos->shouldReceive('getActiveRules')->atLeast()->once()->andReturn(new Collection);
|
2019-07-31 16:53:09 +02:00
|
|
|
// new mocks for ruleEngine
|
|
|
|
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
|
|
|
|
$ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
|
|
|
|
$ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
|
|
|
|
|
|
|
|
$collector->shouldReceive('setAccounts')->atLeast()->once();
|
|
|
|
$collector->shouldReceive('setRange')->atLeast()->once();
|
|
|
|
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
|
2019-07-21 17:15:06 +02:00
|
|
|
|
|
|
|
$this->session(['first' => new Carbon('2010-01-01')]);
|
|
|
|
$data = [
|
|
|
|
'accounts' => [1],
|
|
|
|
'start_date' => '2010-01-02',
|
|
|
|
'end_date' => '2010-01-02',
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('rule-groups.execute', [1]), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
$response->assertRedirect(route('rules.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\RuleGroup\ExecutionController
|
|
|
|
*/
|
|
|
|
public function testSelectTransactions(): void
|
|
|
|
{
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-08-29 17:53:25 +02:00
|
|
|
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('rule-groups.select-transactions', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2019-08-17 12:09:03 +02:00
|
|
|
}
|