2017-02-12 12:00:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CurrencyControllerTest.php
|
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* 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
|
2017-12-17 14:42:21 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-12 12:00:11 +01:00
|
|
|
*/
|
2017-07-08 06:28:44 +02:00
|
|
|
declare(strict_types=1);
|
2017-02-12 12:00:11 +01:00
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers;
|
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
use FireflyIII\Models\Preference;
|
2017-03-05 13:21:36 +01:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2017-02-12 12:21:44 +01:00
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2017-03-19 17:54:21 +01:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2017-03-05 13:21:36 +01:00
|
|
|
use Illuminate\Support\Collection;
|
2018-03-24 06:08:50 +01:00
|
|
|
use Log;
|
2018-07-31 20:39:36 +02:00
|
|
|
use Mockery;
|
2019-07-21 17:15:06 +02:00
|
|
|
use Preferences;
|
2018-08-06 19:14:30 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
/**
|
|
|
|
* Class CurrencyControllerTest
|
|
|
|
*
|
2017-08-12 10:27:45 +02:00
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
2017-03-05 13:21:36 +01:00
|
|
|
*/
|
2017-02-12 12:00:11 +01:00
|
|
|
class CurrencyControllerTest extends TestCase
|
|
|
|
{
|
2018-03-24 06:08:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-09-02 20:27:26 +02:00
|
|
|
public function setUp(): void
|
2018-03-24 06:08:50 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-03-24 06:08:50 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 06:28:44 +02:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-07-08 06:28:44 +02:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCannotCreate(): void
|
2017-07-08 06:28:44 +02:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
$this->mockIntroPreference('shown_demo_currencies_create');
|
|
|
|
|
2017-07-08 06:28:44 +02:00
|
|
|
// mock stuff
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-07-08 06:28:44 +02:00
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(false);
|
2017-07-08 06:28:44 +02:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('currencies.create'));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('error');
|
|
|
|
}
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCannotDelete(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
// mock stuff
|
2019-07-21 17:15:06 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
|
|
|
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('currencyInUse')->andReturn(true);
|
2017-03-19 17:54:21 +01:00
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.delete', [$euro->id]));
|
2017-03-19 17:54:21 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSessionHas('error');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCannotDestroy(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
// mock stuff
|
2019-07-21 17:15:06 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('currencyInUse')->andReturn(true);
|
2017-03-19 17:54:21 +01:00
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$this->session(['currencies.delete.uri' => 'http://localhost']);
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->post(route('currencies.destroy', [$euro->id]));
|
2017-03-19 17:54:21 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('error');
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreate(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
$this->mockIntroPreference('shown_demo_currencies_create');
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('currencies.create'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testDefaultCurrency(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2018-02-28 15:50:00 +01:00
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2018-11-10 15:15:29 +01:00
|
|
|
$currencyRepos->shouldReceive('enable')->once();
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
|
|
|
Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.default', [$euro->id]));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testDelete(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('currencyInUse')->andReturn(false);
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.delete', [$euro->id]));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testDestroy(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('currencyInUse')->andReturn(false);
|
2017-03-19 17:54:21 +01:00
|
|
|
$repository->shouldReceive('destroy')->andReturn(true)->once();
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(1)->andReturn(true);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['currencies.delete.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->post(route('currencies.destroy', [$euro->id]));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
*/
|
|
|
|
public function testDisable(): void
|
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$euro = $this->getEuro();
|
|
|
|
|
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
|
|
|
|
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
|
|
|
|
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
|
2019-07-21 17:15:06 +02:00
|
|
|
$repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection([$euro]));
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.disable', [$euro->id]));
|
2018-12-12 20:30:25 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
*/
|
2019-04-09 15:32:48 +02:00
|
|
|
public function testDisableEnableFirst(): void
|
2018-12-12 20:30:25 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$euro = $this->getEuro();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
|
2019-04-09 15:32:48 +02:00
|
|
|
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
|
|
|
|
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
|
|
|
|
$repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
|
2019-07-21 17:15:06 +02:00
|
|
|
$repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$euro]));
|
2019-04-09 15:32:48 +02:00
|
|
|
$repository->shouldReceive('enable')->atLeast()->once()->andReturn(true);
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
|
|
|
Preferences::shouldReceive('set')->withArgs(['currencyPreference', $euro->code])->atLeast()->once();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.disable', [$euro->id]));
|
2018-12-12 20:30:25 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
*/
|
2019-04-09 15:32:48 +02:00
|
|
|
public function testDisableInUse(): void
|
2018-12-12 20:30:25 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$euro = $this->getEuro();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
|
2019-04-09 15:32:48 +02:00
|
|
|
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(true);
|
2019-08-23 09:41:31 +02:00
|
|
|
$repository->shouldReceive('currencyInUseAt')->atLeast()->once()->andReturn('accounts');
|
|
|
|
|
2019-04-09 15:32:48 +02:00
|
|
|
$repository->shouldNotReceive('disable');
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.disable', [$euro->id]));
|
2019-04-09 15:32:48 +02:00
|
|
|
$response->assertStatus(302);
|
2018-12-12 20:30:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
*/
|
2019-04-09 15:32:48 +02:00
|
|
|
public function testDisableNothingLeft(): void
|
2018-12-12 20:30:25 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$euro = $this->getEuro();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);
|
|
|
|
$repository->shouldReceive('currencyInuse')->atLeast()->once()->andReturn(false);
|
|
|
|
$repository->shouldReceive('disable')->atLeast()->once()->andReturn(false);
|
|
|
|
$repository->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
|
2019-04-09 15:32:48 +02:00
|
|
|
$repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.disable', [$euro->id]));
|
2019-04-09 15:32:48 +02:00
|
|
|
$response->assertStatus(500);
|
|
|
|
$response->assertSee('No currencies found.');
|
2018-12-12 20:30:25 +01:00
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testEdit(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
// mock stuff
|
|
|
|
$this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.edit', [$euro->id]));
|
2017-02-12 12:21:44 +01:00
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
*/
|
|
|
|
public function testEnable(): void
|
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-12-12 20:30:25 +01:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mock(UserRepositoryInterface::class);
|
|
|
|
$euro = $this->getEuro();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$repository->shouldReceive('enable')->atLeast()->once();
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
2018-12-12 20:30:25 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-07-21 17:15:06 +02:00
|
|
|
$response = $this->get(route('currencies.enable', [$euro->id]));
|
2018-12-12 20:30:25 +01:00
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndex(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
$this->mockIntroPreference('shown_demo_currencies_index');
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2018-03-08 21:02:46 +01:00
|
|
|
$currencies = TransactionCurrency::get();
|
2017-12-17 14:06:14 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2018-03-08 21:02:46 +01:00
|
|
|
$repository->shouldReceive('getCurrencyByPreference')->andReturn($currencies->first());
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('getAll')->andReturn($currencies);
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 50;
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
|
|
|
|
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 'EUR';
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('currencies.index'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndexNoRights(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
$this->mockIntroPreference('shown_demo_currencies_index');
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
|
2018-11-10 15:15:29 +01:00
|
|
|
$repository->shouldReceive('getAll')->andReturn(new Collection);
|
2018-07-31 20:39:36 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(false);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2019-07-21 17:15:06 +02:00
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 50;
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
|
|
|
|
|
|
|
$pref = new Preference;
|
|
|
|
$pref->data = 'EUR';
|
|
|
|
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('currencies.index'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
2017-03-19 17:54:21 +01:00
|
|
|
$response->assertSessionHas('info');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2018-03-03 17:16:47 +01:00
|
|
|
* @covers \FireflyIII\Http\Requests\CurrencyFormRequest
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testStore(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$repository->shouldReceive('store')->andReturn(new TransactionCurrency);
|
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->session(['currencies.create.uri' => 'http://localhost']);
|
|
|
|
$data = [
|
|
|
|
'name' => 'XX',
|
|
|
|
'code' => 'XXX',
|
|
|
|
'symbol' => 'x',
|
|
|
|
'decimal_places' => 2,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('currencies.store'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
2017-02-12 12:21:44 +01:00
|
|
|
}
|
|
|
|
|
2018-08-30 20:58:07 +02:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
|
|
|
* @covers \FireflyIII\Http\Requests\CurrencyFormRequest
|
|
|
|
*/
|
|
|
|
public function testStoreError(): void
|
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2018-08-30 20:58:07 +02:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2018-08-30 20:58:07 +02:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2018-08-30 20:58:07 +02:00
|
|
|
$repository->shouldReceive('store')->andReturnNull();
|
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->session(['currencies.create.uri' => 'http://localhost']);
|
|
|
|
$data = [
|
|
|
|
'name' => 'XX',
|
|
|
|
'code' => 'XXX',
|
|
|
|
'symbol' => 'x',
|
|
|
|
'decimal_places' => 2,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('currencies.store'), $data);
|
|
|
|
$response->assertStatus(302);
|
2018-09-02 20:27:26 +02:00
|
|
|
$response->assertSessionHas('error', 'Could not store the new currency.');
|
2018-08-30 20:58:07 +02:00
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2018-03-03 17:16:47 +01:00
|
|
|
* @covers \FireflyIII\Http\Requests\CurrencyFormRequest
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testStoreNoRights(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
$repository->shouldReceive('store')->andReturn(new TransactionCurrency);
|
2017-03-19 17:54:21 +01:00
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['currencies.create.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
$data = [
|
|
|
|
'name' => 'XX',
|
|
|
|
'code' => 'XXX',
|
|
|
|
'symbol' => 'x',
|
|
|
|
'decimal_places' => 2,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('currencies.store'), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CurrencyController
|
2018-03-03 17:16:47 +01:00
|
|
|
* @covers \FireflyIII\Http\Requests\CurrencyFormRequest
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdate(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
// mock stuff
|
2019-07-25 14:19:49 +02:00
|
|
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
2017-03-19 17:54:21 +01:00
|
|
|
|
2019-07-23 17:33:23 +02:00
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
$repository->shouldReceive('update')->andReturn(new TransactionCurrency);
|
2017-03-19 17:54:21 +01:00
|
|
|
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
|
2019-08-03 10:50:43 +02:00
|
|
|
$repository->shouldReceive('currencyInUse')->atLeast()->once()->andReturn(true);
|
2019-07-21 17:15:06 +02:00
|
|
|
Preferences::shouldReceive('mark')->atLeast()->once();
|
2017-03-05 13:21:36 +01:00
|
|
|
|
2017-03-18 20:53:44 +01:00
|
|
|
$this->session(['currencies.edit.uri' => 'http://localhost']);
|
2017-02-12 12:21:44 +01:00
|
|
|
$data = [
|
2018-03-03 17:16:47 +01:00
|
|
|
'id' => 2,
|
2017-02-12 12:21:44 +01:00
|
|
|
'name' => 'XA',
|
|
|
|
'code' => 'XAX',
|
|
|
|
'symbol' => 'a',
|
|
|
|
'decimal_places' => 2,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('currencies.update', [2]), $data);
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
}
|
2017-02-16 22:33:32 +01:00
|
|
|
}
|