Files
firefly-iii/tests/Feature/Controllers/Recurring/IndexControllerTest.php

149 lines
4.9 KiB
PHP
Raw Normal View History

2018-09-02 20:13:25 +02:00
<?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\Recurring;
2018-12-12 20:30:25 +01:00
use FireflyIII\Factory\CategoryFactory;
2018-09-02 20:13:25 +02:00
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
2018-09-02 20:13:25 +02:00
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
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;
use Mockery;
use Preferences;
2018-09-02 20:13:25 +02:00
use Tests\TestCase;
/**
*
* Class IndexControllerTest
*/
class IndexControllerTest 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\IndexController
*/
public function testIndex(): void
{
2018-12-12 20:30:25 +01:00
$repository = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
2018-12-17 07:09:44 +01:00
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$this->mockDefaultSession();
2018-12-17 07:09:44 +01:00
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' => null,
'latest_date' => null,
2018-12-17 07:09:44 +01:00
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
2018-09-02 20:13:25 +02:00
$config = new Configuration;
$config->data = 0;
$falseConfig = new Configuration;
$falseConfig->data = false;
$collection = $this->user()->recurrences()->take(2)->get();
// mock cron job config:
\FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
$repository->shouldReceive('get')->andReturn($collection)->once();
$this->be($this->user());
$response = $this->get(route('recurring.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
*/
2018-09-02 20:13:25 +02:00
public function testShow(): void
{
2018-12-12 20:30:25 +01:00
$repository = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
2018-12-17 07:09:44 +01:00
$transformer = $this->mock(RecurrenceTransformer::class);
$this->mockDefaultSession();
2018-12-17 07:09:44 +01:00
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' => null,
'latest_date' => null,
'recurrence_repetitions' => [
[
'occurrences' => [
'2019-01-01'
]
]
],
2018-12-17 07:09:44 +01:00
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
2018-09-02 20:13:25 +02:00
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
2018-12-17 07:09:44 +01:00
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
2018-09-02 20:13:25 +02:00
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
2018-12-31 07:48:23 +01:00
}