Update tests.

This commit is contained in:
James Cole
2017-04-28 20:17:10 +02:00
parent 7e11691ea4
commit dc5215e41e
9 changed files with 202 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;

View File

@@ -13,6 +13,7 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@@ -138,7 +139,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
Steam::shouldReceive('positive')->once()->andReturn('1');
@@ -174,7 +175,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$this->be($this->user());
@@ -208,7 +209,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
Steam::shouldReceive('positive')->once()->andReturn('1');
@@ -249,7 +250,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->twice();
$collector->shouldReceive('setRange')->andReturnSelf()->twice();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf()->twice();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->twice();
$collector->shouldReceive('setTypes')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
@@ -287,7 +288,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf()->once();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();
@@ -326,7 +327,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->twice();
$collector->shouldReceive('setRange')->andReturnSelf()->twice();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf()->twice();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->twice();
$collector->shouldReceive('setTypes')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
@@ -375,7 +376,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(4);
$collector->shouldReceive('setRange')->andReturnSelf()->times(4);
$collector->shouldReceive('setTypes')->andReturnSelf()->times(1);
$collector->shouldReceive('disableInternalFilter')->andReturnSelf()->times(4);
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->times(4);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(4);

View File

@@ -16,6 +16,7 @@ use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
@@ -102,7 +103,7 @@ class BudgetReportControllerTest extends TestCase
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('disableFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setBudgets')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]));

View File

@@ -15,6 +15,7 @@ namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
@@ -129,7 +130,7 @@ class CategoryReportControllerTest extends TestCase
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('disableFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setCategories')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($transactions);

View File

@@ -15,6 +15,7 @@ namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
@@ -139,7 +140,7 @@ class TagReportControllerTest extends TestCase
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('disableFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
$collector->shouldReceive('setTags')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($set);

View File

@@ -13,6 +13,7 @@ namespace Tests\Feature\Controllers\Report;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Tests\TestCase;
@@ -36,7 +37,7 @@ class OperationsControllerTest extends TestCase
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('enableInternalFilter')->andReturnSelf();
$collector->shouldReceive('addFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($transactions);
@@ -57,7 +58,7 @@ class OperationsControllerTest extends TestCase
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('enableInternalFilter')->andReturnSelf();
$collector->shouldReceive('addFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($transactions);
$this->be($this->user());
@@ -78,7 +79,7 @@ class OperationsControllerTest extends TestCase
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('enableInternalFilter')->andReturnSelf();
$collector->shouldReceive('addFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn($transactions);
$this->be($this->user());

View File

@@ -13,6 +13,7 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
@@ -45,7 +46,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
@@ -76,7 +77,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
@@ -106,7 +107,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
@@ -139,7 +140,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
@@ -170,7 +171,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);

View File

@@ -0,0 +1,136 @@
<?php
/**
* AttachmentHelperTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\Helpers;
use FireflyIII\Helpers\Attachments\AttachmentHelper;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* Class AttachmentHelperTest
*
* @package Tests\Unit\Helpers
*/
class AttachmentHelperTest extends TestCase
{
/**
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getAttachmentLocation
*/
public function testGetAttachmentLocation()
{
$attachment = Attachment::first();
$helper = new AttachmentHelper;
$path = $path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, intval($attachment->id));
$this->assertEquals($helper->getAttachmentLocation($attachment), $path);
}
/**
* Test invalid mime thing
*
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::__construct
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::saveAttachmentsForModel
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::processFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validateUpload
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validMime
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::hasFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getMessages
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getErrors
*
*/
public function testInvalidMime()
{
$journal = TransactionJournal::first();
$helper = new AttachmentHelper;
$path = resource_path('stubs/csv.csv');
$file = new UploadedFile($path, 'csv.csv', 'text/plain', filesize($path), null, true);
$helper->saveAttachmentsForModel($journal, [$file]);
$errors = $helper->getErrors();
$messages = $helper->getMessages();
$this->assertCount(1, $errors);
$this->assertCount(0, $messages);
$this->assertEquals('File "csv.csv" is of type "text/plain" which is not accepted as a new upload.', $errors->first());
}
/**
* Test valid file upload.
*
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::__construct
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::saveAttachmentsForModel
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::processFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validateUpload
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validMime
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::hasFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getMessages
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getErrors
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getAttachments
*
*/
public function testSave()
{
Storage::fake('upload');
$journal = TransactionJournal::first();
$helper = new AttachmentHelper;
$path = public_path('apple-touch-icon.png');
$file = new UploadedFile($path, 'apple-touch-icon.png', 'image/png', filesize($path), null, true);
$helper->saveAttachmentsForModel($journal, [$file]);
$errors = $helper->getErrors();
$messages = $helper->getMessages();
$attachments = $helper->getAttachments();
$this->assertCount(0, $errors);
$this->assertCount(1, $messages);
$this->assertEquals('Succesfully uploaded file "apple-touch-icon.png".', $messages->first());
// Assert the file was stored...
Storage::disk('upload')->assertExists(sprintf('at-%d.data', $attachments->first()->id));
}
/**
* Test double file upload. Needs to be after testSave.
*
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::__construct
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::saveAttachmentsForModel
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::processFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validateUpload
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::validMime
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::hasFile
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getMessages
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getErrors
* @covers \FireflyIII\Helpers\Attachments\AttachmentHelper::getAttachments
*
*/
public function testSaveSecond()
{
$journal = TransactionJournal::first();
$helper = new AttachmentHelper;
$path = public_path('apple-touch-icon.png');
$file = new UploadedFile($path, 'apple-touch-icon.png', 'image/png', filesize($path), null, true);
$helper->saveAttachmentsForModel($journal, [$file]);
$errors = $helper->getErrors();
$messages = $helper->getMessages();
$this->assertCount(1, $errors);
$this->assertCount(0, $messages);
$this->assertEquals('Uploaded file "apple-touch-icon.png" is already attached to this object.', $errors->first());
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* MetaPieChartTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace Tests\Unit\Helpers;
use Carbon\Carbon;
use FireflyIII\Helpers\Chart\MetaPieChart;
use Tests\TestCase;
class MetaPieChartTest extends TestCase
{
/**
* @covers \FireflyIII\Helpers\Chart\MetaPieChart::__construct
* @covers \FireflyIII\Helpers\Chart\MetaPieChart::generate
* @covers \FireflyIII\Helpers\Chart\MetaPieChart::getTransactions
* @covers \FireflyIII\Helpers\Chart\MetaPieChart::groupByFields
* @covers \FireflyIII\Helpers\Chart\MetaPieChart::organizeByType
*/
public function testGenerateIncomeAccount()
{
$som = (new Carbon())->startOfMonth();
$eom = (new Carbon())->endOfMonth();
$helper = new MetaPieChart();
$helper->setUser($this->user());
$helper->setStart($som);
$helper->setEnd($eom);
$chart = $helper->generate('income', 'account');
$this->assertTrue(true);
}
}