2018-09-02 20:13:25 +02:00
|
|
|
<?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\Recurring;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2018-12-12 20:30:25 +01:00
|
|
|
use FireflyIII\Factory\CategoryFactory;
|
2018-09-04 16:47:01 +02:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2018-09-02 20:13:25 +02:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
2018-09-04 16:47:01 +02:00
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2018-12-12 20:30:25 +01:00
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
2018-09-02 20:13:25 +02:00
|
|
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
2018-09-04 16:47:01 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2018-12-17 07:09:44 +01:00
|
|
|
use FireflyIII\Transformers\RecurrenceTransformer;
|
2018-09-02 20:13:25 +02:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Log;
|
2018-09-04 16:47:01 +02:00
|
|
|
use Mockery;
|
2018-09-02 20:13:25 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class EditControllerTest
|
|
|
|
*/
|
|
|
|
class EditControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-09-02 20:13:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
|
|
|
*/
|
|
|
|
public function testEdit(): void
|
|
|
|
{
|
2019-04-09 20:05:20 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-12-12 20:30:25 +01:00
|
|
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
|
|
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$categoryFactory = $this->mock(CategoryFactory::class);
|
|
|
|
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
2018-12-17 07:09:44 +01:00
|
|
|
$transformer = $this->mock(RecurrenceTransformer::class);
|
|
|
|
|
|
|
|
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
|
|
|
$transformer->shouldReceive('transform')->atLeast()->once();
|
2018-09-04 16:47:01 +02:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
2018-09-02 20:13:25 +02:00
|
|
|
|
|
|
|
$recurringRepos->shouldReceive('setUser');
|
|
|
|
$recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
|
|
|
|
$recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
|
|
|
|
$recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
|
|
|
|
$budgetRepos->shouldReceive('findNull')->andReturn($this->user()->budgets()->first());
|
|
|
|
|
|
|
|
|
|
|
|
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
|
|
|
//\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('recurring.edit', [1]));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
|
|
|
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
|
|
|
*/
|
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
2019-04-09 20:05:20 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-12-17 07:09:44 +01:00
|
|
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
|
|
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2018-12-12 20:30:25 +01:00
|
|
|
$categoryFactory = $this->mock(CategoryFactory::class);
|
|
|
|
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
2018-12-17 07:09:44 +01:00
|
|
|
$transformer = $this->mock(RecurrenceTransformer::class);
|
2018-09-02 20:13:25 +02:00
|
|
|
|
|
|
|
$recurringRepos->shouldReceive('update')->once();
|
|
|
|
|
2019-03-02 21:18:26 +01:00
|
|
|
$tomorrow = Carbon::now()->addDays(2);
|
2018-09-02 20:13:25 +02:00
|
|
|
$recurrence = $this->user()->recurrences()->first();
|
|
|
|
$data = [
|
|
|
|
'id' => $recurrence->id,
|
|
|
|
'title' => 'hello',
|
|
|
|
'first_date' => $tomorrow->format('Y-m-d'),
|
|
|
|
'repetition_type' => 'daily',
|
|
|
|
'skip' => 0,
|
|
|
|
'recurring_description' => 'Some descr',
|
|
|
|
'active' => '1',
|
|
|
|
'apply_rules' => '1',
|
|
|
|
'return_to_edit' => '1',
|
|
|
|
// mandatory for transaction:
|
|
|
|
'transaction_description' => 'Some descr',
|
|
|
|
'transaction_type' => 'withdrawal',
|
|
|
|
'transaction_currency_id' => '1',
|
|
|
|
'amount' => '30',
|
|
|
|
// mandatory account info:
|
|
|
|
'source_id' => '1',
|
|
|
|
'source_name' => '',
|
|
|
|
'destination_id' => '',
|
|
|
|
'destination_name' => 'Some Expense',
|
|
|
|
|
|
|
|
// optional fields:
|
|
|
|
'budget_id' => '1',
|
|
|
|
'category' => 'CategoryA',
|
|
|
|
'tags' => 'A,B,C',
|
|
|
|
'create_another' => '1',
|
|
|
|
'repetition_end' => 'times',
|
|
|
|
'repetitions' => 3,
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('recurring.update', [1]), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
2018-12-31 07:48:23 +01:00
|
|
|
}
|