firefly-iii/tests/Feature/Controllers/Budget/CreateControllerTest.php

103 lines
3.0 KiB
PHP
Raw Normal View History

2018-07-14 08:22:21 -05:00
<?php
/**
* CreateControllerTest.php
2020-02-16 06:59:55 -06:00
* Copyright (c) 2019 james@firefly-iii.org
2018-07-14 08:22:21 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-14 08:22:21 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-07-14 08:22:21 -05:00
*
* This program is distributed in the hope that it will be useful,
2018-07-14 08:22:21 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-07-14 08:22:21 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-14 08:22:21 -05:00
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
2018-09-03 11:52:46 -05:00
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-07-14 08:22:21 -05:00
use Log;
2018-09-03 11:52:46 -05:00
use Mockery;
use Preferences;
2018-07-14 08:22:21 -05:00
use Tests\TestCase;
/**
*
* Class CreateControllerTest
2019-08-17 03:48:28 -05:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-07-14 08:22:21 -05:00
*/
class CreateControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-07-14 08:22:21 -05:00
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\CreateController
*/
public function testCreate(): void
{
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
2018-09-03 11:52:46 -05:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$this->mockDefaultSession();
2018-07-14 08:22:21 -05:00
$this->be($this->user());
$response = $this->get(route('budgets.create'));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\CreateController
*/
public function testStore(): void
{
Log::debug('Now in testStore()');
// mock stuff
$budget = $this->getRandomBudget();
$repository = $this->mock(BudgetRepositoryInterface::class);
2018-09-03 11:52:46 -05:00
2018-07-14 08:22:21 -05:00
$repository->shouldReceive('findNull')->andReturn($budget);
$repository->shouldReceive('store')->andReturn($budget);
$repository->shouldReceive('cleanupBudgets');
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once();
2018-07-14 08:22:21 -05:00
$this->session(['budgets.create.uri' => 'http://localhost']);
$data = [
'name' => sprintf('New Budget %s', $this->randomInt()),
2018-07-14 08:22:21 -05:00
];
$this->be($this->user());
$response = $this->post(route('budgets.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
2018-07-22 13:33:17 -05:00
}