firefly-iii/tests/Feature/Controllers/JavascriptControllerTest.php

117 lines
4.3 KiB
PHP
Raw Normal View History

2017-03-12 15:24:34 -05:00
<?php
/**
* JavascriptControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05: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 07:42:21 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-03-12 15:24:34 -05:00
*/
2017-07-07 23:28:44 -05:00
declare(strict_types=1);
2017-03-12 15:24:34 -05:00
namespace Tests\Feature\Controllers;
2018-02-28 08:50:00 -06:00
use FireflyIII\Factory\AccountFactory;
2017-03-12 15:24:34 -05:00
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
* Class JavascriptControllerTest
*
2017-08-12 03:27:45 -05:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-03-12 15:24:34 -05:00
*/
class JavascriptControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\JavascriptController::accounts
*/
public function testAccounts()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$account = factory(Account::class)->make();
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))
->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once();
2018-02-28 08:50:00 -06:00
$currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency);
2017-03-12 15:24:34 -05:00
$this->be($this->user());
$response = $this->get(route('javascript.accounts'));
$response->assertStatus(200);
}
2017-07-07 23:28:44 -05:00
/**
* @covers \FireflyIII\Http\Controllers\JavascriptController::currencies
*/
public function testCurrencies()
{
$repository = $this->mock(CurrencyRepositoryInterface::class);
$currency = factory(TransactionCurrency::class)->make();
$repository->shouldReceive('get')->andReturn(new Collection([$currency]));
$this->be($this->user());
$response = $this->get(route('javascript.currencies'));
$response->assertStatus(200);
}
2017-03-12 15:24:34 -05:00
/**
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
2017-10-05 04:49:06 -05:00
* @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
2017-03-12 15:24:34 -05:00
*
* @param string $range
*
* @dataProvider dateRangeProvider
*/
public function testVariables(string $range)
{
2018-02-28 08:50:00 -06:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
2017-03-12 15:24:34 -05:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('javascript.variables'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
* @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
*
* @param string $range
*
* @dataProvider dateRangeProvider
*/
public function testVariablesCustom(string $range)
{
2018-02-28 08:50:00 -06:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->session(['is_custom_range' => true]);
$response = $this->get(route('javascript.variables'));
$response->assertStatus(200);
}
2017-03-12 15:24:34 -05:00
}