Files
firefly-iii/tests/Feature/Controllers/Budget/DeleteControllerTest.php

98 lines
3.0 KiB
PHP
Raw Normal View History

2018-07-14 15:22:21 +02:00
<?php
/**
* DeleteControllerTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-07-14 15:22:21 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-14 15:22:21 +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
*
* 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
* GNU Affero General Public License for more details.
2018-07-14 15:22:21 +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;
use Preferences;
2018-07-14 15:22:21 +02:00
use Tests\TestCase;
/**
*
* Class DeleteControllerTest
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 DeleteControllerTest 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-07-14 15:22:21 +02:00
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\DeleteController
*/
public function testDelete(): void
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$budget = $this->getRandomBudget();
2018-07-14 15:22:21 +02:00
Log::debug('Now in testDelete()');
// mock stuff
$this->mock(BudgetRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
2019-07-25 14:19:49 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2018-07-14 15:22:21 +02:00
$this->be($this->user());
2019-07-21 17:15:06 +02:00
$response = $this->get(route('budgets.delete', [$budget->id]));
2018-07-14 15:22:21 +02:00
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\DeleteController
*/
public function testDestroy(): void
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$budget = $this->getRandomBudget();
2018-07-14 15:22:21 +02:00
Log::debug('Now in testDestroy()');
// mock stuff
2019-07-25 14:19:49 +02:00
$repository = $this->mock(BudgetRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->once();
2018-07-14 15:22:21 +02:00
$repository->shouldReceive('destroy')->andReturn(true);
$this->session(['budgets.delete.uri' => 'http://localhost']);
$this->be($this->user());
2019-07-21 17:15:06 +02:00
$response = $this->post(route('budgets.destroy', [$budget->id]));
2018-07-14 15:22:21 +02:00
$response->assertStatus(302);
$response->assertSessionHas('success');
}
2018-07-22 20:33:17 +02:00
}