mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 05:03:13 +00:00
The net worth chart will respect net worth preferences.
This commit is contained in:
171
tests/Unit/Helpers/FiscalHelperTest.php
Normal file
171
tests/Unit/Helpers/FiscalHelperTest.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* FiscalHelperTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\FiscalHelper;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class FiscalHelperTest
|
||||
*/
|
||||
class FiscalHelperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fiscal year starts on April 1st.
|
||||
* Current date is June 6th.
|
||||
*
|
||||
* Fiscal year ends next year on Mar 31.
|
||||
*
|
||||
* @covers \FireflyIII\Helpers\FiscalHelper
|
||||
*/
|
||||
public function testEndOfFiscalYear(): void
|
||||
{
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = true;
|
||||
|
||||
$datePref = new Preference;
|
||||
$datePref->data = '04-01';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
|
||||
|
||||
$helper = new FiscalHelper;
|
||||
$date = new Carbon('2018-06-06');
|
||||
$result = $helper->endOfFiscalYear($date);
|
||||
$this->assertEquals('2019-03-31', $result->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* No fiscal year
|
||||
* Current date is June 6th.
|
||||
*
|
||||
* Fiscal year ends next year on Dec 31.
|
||||
*
|
||||
* @covers \FireflyIII\Helpers\FiscalHelper
|
||||
*/
|
||||
public function testEndOfFiscalYearNoPref(): void
|
||||
{
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = false;
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
|
||||
|
||||
$helper = new FiscalHelper;
|
||||
$date = new Carbon('2018-06-06');
|
||||
$result = $helper->endOfFiscalYear($date);
|
||||
$this->assertEquals('2018-12-31', $result->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fiscal year starts on April 1st.
|
||||
* Current date is June 6th.
|
||||
*
|
||||
* Fiscal year starts in current year.
|
||||
*
|
||||
* @covers \FireflyIII\Helpers\FiscalHelper
|
||||
*/
|
||||
public function testStartOfFiscalYear(): void
|
||||
{
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = true;
|
||||
|
||||
$datePref = new Preference;
|
||||
$datePref->data = '04-01';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
|
||||
|
||||
$helper = new FiscalHelper;
|
||||
$date = new Carbon('2018-06-06');
|
||||
$result = $helper->startOfFiscalYear($date);
|
||||
$this->assertEquals('2018-04-01', $result->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* No fiscal year
|
||||
* Current date is June 6th.
|
||||
*
|
||||
* Fiscal year starts Jan 1st.
|
||||
*
|
||||
* @covers \FireflyIII\Helpers\FiscalHelper
|
||||
*/
|
||||
public function testStartOfFiscalYearNoPref(): void
|
||||
{
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = false;
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
|
||||
|
||||
$helper = new FiscalHelper;
|
||||
$date = new Carbon('2018-06-06');
|
||||
$result = $helper->startOfFiscalYear($date);
|
||||
$this->assertEquals('2018-01-01', $result->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fiscal year starts on April 1st.
|
||||
* Current date is Feb 6th.
|
||||
*
|
||||
* Fiscal year starts in previous year.
|
||||
*
|
||||
* @covers \FireflyIII\Helpers\FiscalHelper
|
||||
*/
|
||||
public function testStartOfFiscalYearPrev(): void
|
||||
{
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = true;
|
||||
|
||||
$datePref = new Preference;
|
||||
$datePref->data = '04-01';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
|
||||
|
||||
$helper = new FiscalHelper;
|
||||
$date = new Carbon('2018-02-06');
|
||||
$result = $helper->startOfFiscalYear($date);
|
||||
$this->assertEquals('2017-04-01', $result->format('Y-m-d'));
|
||||
}
|
||||
}
|
||||
95
tests/Unit/Helpers/Help/HelpTest.php
Normal file
95
tests/Unit/Helpers/Help/HelpTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* HelpTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers\Help;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Help\Help;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class HelpTest
|
||||
*/
|
||||
class HelpTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Helpers\Help\Help
|
||||
*/
|
||||
public function testGetFromGitHub(): void
|
||||
{
|
||||
$headers = ['Content-Type' => 'application/json'];
|
||||
$response = new Response(200, $headers, 'Some help text.');
|
||||
$mock = new MockHandler([$response]);
|
||||
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
//client instance is bound to the mock here.
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
|
||||
// now let's see what happens:
|
||||
$help = new Help;
|
||||
$result = $help->getFromGitHub('test-route', 'en_US');
|
||||
$this->assertEquals('<p>Some help text.</p>'."\n", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Helpers\Help\Help
|
||||
*/
|
||||
public function testGetFromGitHubError(): void
|
||||
{
|
||||
$headers = ['Content-Type' => 'application/json'];
|
||||
$response = new Response(500, $headers, 'Big bad error.');
|
||||
$mock = new MockHandler([$response]);
|
||||
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
//client instance is bound to the mock here.
|
||||
$this->app->instance(Client::class, $client);
|
||||
|
||||
|
||||
// now let's see what happens:
|
||||
$help = new Help;
|
||||
$result = $help->getFromGitHub('test-route', 'en_US');
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user