2018-07-14 15:22:21 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CreateControllerTest.php
|
2020-02-16 13:59:55 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02: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 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-07-14 15:22:21 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:45:03 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02: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 15:22:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers\Budget;
|
|
|
|
|
|
|
|
|
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
2018-09-03 18:52:46 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2018-07-14 15:22:21 +02:00
|
|
|
use Log;
|
2018-09-03 18:52:46 +02:00
|
|
|
use Mockery;
|
2019-06-23 11:13:36 +02:00
|
|
|
use Preferences;
|
2018-07-14 15:22:21 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class CreateControllerTest
|
2019-08-17 10:48:28 +02:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
|
|
|
class CreateControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2020-07-30 20:49:40 +02:00
|
|
|
self::markTestIncomplete('Incomplete for refactor.');
|
|
|
|
return;
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-07-14 15:22:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Budget\CreateController
|
|
|
|
*/
|
|
|
|
public function testCreate(): void
|
|
|
|
{
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-07-14 15:22:21 +02: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
|
2019-06-23 11:13:36 +02:00
|
|
|
$budget = $this->getRandomBudget();
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
$repository->shouldReceive('findNull')->andReturn($budget);
|
|
|
|
$repository->shouldReceive('store')->andReturn($budget);
|
|
|
|
$repository->shouldReceive('cleanupBudgets');
|
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
$this->session(['budgets.create.uri' => 'http://localhost']);
|
|
|
|
|
|
|
|
$data = [
|
2019-06-23 11:13:36 +02:00
|
|
|
'name' => sprintf('New Budget %s', $this->randomInt()),
|
2018-07-14 15:22:21 +02:00
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('budgets.store'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
2018-07-22 20:33:17 +02:00
|
|
|
}
|