Skip to content

Firefly III: a personal finances manager

Wrote export tests.

James Colea67f10c99eeb
diff --git a/app/Export/Processor.php b/app/Export/Processor.php
index 62fbe7a6a0..15960d63f6 100644
--- a/app/Export/Processor.php
+++ b/app/Export/Processor.php
@@ -30,7 +30,7 @@ use ZipArchive;
*
* @package FireflyIII\Export
*/
-class Processor
+class Processor implements ProcessorInterface
{
/** @var Collection */
diff --git a/app/Export/ProcessorInterface.php b/app/Export/ProcessorInterface.php
new file mode 100644
index 0000000000..364f4730d4
--- /dev/null
+++ b/app/Export/ProcessorInterface.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * ProcessorInterface.php
+ * Copyright (C) 2016 [email protected]
+ *
+ * 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 FireflyIII\Export;
+
+use Illuminate\Support\Collection;
+
+/**
+ * Interface ProcessorInterface
+ *
+ * @package FireflyIII\Export
+ */
+interface ProcessorInterface
+{
+
+ /**
+ * Processor constructor.
+ *
+ * @param array $settings
+ */
+ public function __construct(array $settings);
+
+ /**
+ * @return bool
+ */
+ public function collectAttachments(): bool;
+
+ /**
+ * @return bool
+ */
+ public function collectJournals(): bool;
+
+ /**
+ * @return bool
+ */
+ public function collectOldUploads(): bool;
+
+ /**
+ * @return bool
+ */
+ public function convertJournals(): bool;
+
+ /**
+ * @return bool
+ */
+ public function createZipFile(): bool;
+
+ /**
+ * @return bool
+ */
+ public function exportJournals(): bool;
+
+ /**
+ * @return Collection
+ */
+ public function getFiles(): Collection;
+}
\ No newline at end of file
diff --git a/app/Generator/Chart/Bill/BillChartGeneratorInterface.php b/app/Generator/Chart/Bill/BillChartGeneratorInterface.php
deleted file mode 100644
index 27b1c11cef..0000000000
--- a/app/Generator/Chart/Bill/BillChartGeneratorInterface.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * BillChartGeneratorInterface.php
- * Copyright (C) 2016 [email protected]
- *
- * 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 FireflyIII\Generator\Chart\Bill;
-
-
-use FireflyIII\Models\Bill;
-use Illuminate\Support\Collection;
-
-/**
- * Interface BillChartGeneratorInterface
- *
- * @package FireflyIII\Generator\Chart\Bill
- */
-interface BillChartGeneratorInterface
-{
-
- /**
- * @param string $paid
- * @param string $unpaid
- *
- * @return array
- */
- public function frontpage(string $paid, string $unpaid): array;
-
- /**
- * @param Bill $bill
- * @param Collection $entries
- *
- * @return array
- */
- public function single(Bill $bill, Collection $entries): array;
-
-}
diff --git a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php b/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
deleted file mode 100644
index 3e1a2ea4bc..0000000000
--- a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * ChartJsBillChartGenerator.php
- * Copyright (C) 2016 [email protected]
- *
- * 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 FireflyIII\Generator\Chart\Bill;
-
-use FireflyIII\Models\Bill;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Support\ChartColour;
-use Illuminate\Support\Collection;
-
-/**
- * Class ChartJsBillChartGenerator
- *
- * @package FireflyIII\Generator\Chart\Bill
- */
-class ChartJsBillChartGenerator implements BillChartGeneratorInterface
-{
-
- /**
- * @param string $paid
- * @param string $unpaid
- *
- * @return array
- */
- public function frontpage(string $paid, string $unpaid): array
- {
- $data = [
- 'datasets' => [
- [
- 'data' => [round($unpaid, 2), round(bcmul($paid, '-1'), 2)],
- 'backgroundColor' => [ChartColour::getColour(0), ChartColour::getColour(1)],
- ],
-
- ],
- 'labels' => [strval(trans('firefly.unpaid')), strval(trans('firefly.paid'))],
-
- ];
-
- return $data;
- }
-
- /**
- * @param Bill $bill
- * @param Collection $entries
- *
- * @return array
- */
- public function single(Bill $bill, Collection $entries): array
- {
- $format = (string)trans('config.month');
- $data = ['count' => 3, 'labels' => [], 'datasets' => [],];
- $minAmount = [];
- $maxAmount = [];
- $actualAmount = [];
- /** @var Transaction $entry */
- foreach ($entries as $entry) {
- $data['labels'][] = $entry->date->formatLocalized($format);
- $minAmount[] = round($bill->amount_min, 2);
- $maxAmount[] = round($bill->amount_max, 2);
- // journalAmount has been collected in BillRepository::getJournals
- $actualAmount[] = bcmul($entry->transaction_amount, '-1');
- }
-
- $data['datasets'][] = [
- 'type' => 'bar',
- 'label' => trans('firefly.minAmount'),
- 'data' => $minAmount,
- ];
- $data['datasets'][] = [
- 'type' => 'line',
- 'label' => trans('firefly.billEntry'),
- 'data' => $actualAmount,
- ];
- $data['datasets'][] = [
- 'type' => 'bar',
- 'label' => trans('firefly.maxAmount'),
- 'data' => $maxAmount,
- ];
-
- $data['count'] = count($data['datasets']);
-
- return $data;
- }
-}
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index 79b0a75d0c..f6aa7e35a1 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Bill;
@@ -33,7 +32,7 @@ use Response;
class BillController extends Controller
{
- /** @var \FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface */
+ /** @var GeneratorInterface */
protected $generator;
/**
@@ -42,8 +41,7 @@ class BillController extends Controller
public function __construct()
{
parent::__construct();
- // create chart generator:
- $this->generator = app(BillChartGeneratorInterface::class);
+ $this->generator = app(GeneratorInterface::class);
}
/**
@@ -72,9 +70,7 @@ class BillController extends Controller
strval(trans('firefly.paid')) => $paid,
];
- /** @var GeneratorInterface $generator */
- $generator = app(GeneratorInterface::class);
- $data = $generator->pieChart($chartData);
+ $data = $this->generator->pieChart($chartData);
$cache->store($data);
return Response::json($data);
@@ -131,9 +127,7 @@ class BillController extends Controller
$chartData[2]['entries'][$date] = bcmul($entry->transaction_amount, '-1');
}
- /** @var GeneratorInterface $generator */
- $generator = app(GeneratorInterface::class);
- $data = $generator->multiSet($chartData);
+ $data = $this->generator->multiSet($chartData);
$cache->store($data);
return Response::json($data);
diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php
index 35920e268f..dc3240b982 100644
--- a/app/Http/Controllers/ExportController.php
+++ b/app/Http/Controllers/ExportController.php
@@ -18,6 +18,7 @@ use Carbon\Carbon;
use ExpandedForm;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Export\Processor;
+use FireflyIII\Export\ProcessorInterface;
use FireflyIII\Http\Requests\ExportFormRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ExportJob;
@@ -71,7 +72,6 @@ class ExportController extends Controller
throw new FireflyException('Against all expectations, zip file "' . $file . '" does not exist.');
}
-
$job->change('export_downloaded');
return response($disk->get($file), 200)
@@ -133,7 +133,6 @@ class ExportController extends Controller
*/
public function postIndex(ExportFormRequest $request, AccountRepositoryInterface $repository, EJRI $jobs)
{
- set_time_limit(0);
$job = $jobs->findByKey($request->get('job'));
$settings = [
'accounts' => $repository->getAccountsById($request->get('accounts')),
@@ -146,7 +145,9 @@ class ExportController extends Controller
];
$job->change('export_status_make_exporter');
- $processor = new Processor($settings);
+
+ /** @var ProcessorInterface $processor */
+ $processor = app(ProcessorInterface::class, [$settings]);
/*
* Collect journals:
diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php
index c41fe8b87f..048c45c713 100644
--- a/app/Providers/FireflyServiceProvider.php
+++ b/app/Providers/FireflyServiceProvider.php
@@ -97,6 +97,7 @@ class FireflyServiceProvider extends ServiceProvider
$this->app->bind('FireflyIII\Generator\Chart\Basic\GeneratorInterface', 'FireflyIII\Generator\Chart\Basic\ChartJsGenerator');
// other generators
+ $this->app->bind('FireflyIII\Export\ProcessorInterface', 'FireflyIII\Export\Processor');
$this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository');
$this->app->bind('FireflyIII\Helpers\Attachments\AttachmentHelperInterface', 'FireflyIII\Helpers\Attachments\AttachmentHelper');
$this->app->bind('FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface', 'FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator');
diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php
index 12a45be67a..d6f510642f 100644
--- a/app/Support/Migration/TestData.php
+++ b/app/Support/Migration/TestData.php
@@ -264,6 +264,29 @@ class TestData
DB::table('transaction_currencies')->insert($insert);
}
+ /**
+ *
+ */
+ private function createExportJobs()
+ {
+ $insert = [];
+ $disk = Storage::disk('export');
+ foreach ($this->data['export-jobs'] as $job) {
+ $insert[] = [
+ 'created_at' => $this->time,
+ 'updated_at' => $this->time,
+ 'user_id' => $job['user_id'],
+ 'key' => $job['key'],
+ 'status' => $job['status'],
+ ];
+ $disk->put($job['key'] . '.zip', 'Nonsense data for "ziP" file.');
+ }
+ DB::table('export_jobs')->insert($insert);
+
+ // store fake export file:
+
+ }
+
/**
*
*/
@@ -863,6 +886,7 @@ class TestData
$this->createMultiTransfers();
$this->createImportJobs();
$this->createCurrencies();
+ $this->createExportJobs();
}
}
diff --git a/resources/seeds/seed.testing.json b/resources/seeds/seed.testing.json
index d6f9dfe2ea..2ff87151c1 100644
--- a/resources/seeds/seed.testing.json
+++ b/resources/seeds/seed.testing.json
@@ -995,6 +995,89 @@
]
}
],
- "import-jobs": [],
+ "import-jobs": [
+ {
+ "user_id": 1,
+ "key": "testImport",
+ "file_type": "csv",
+ "status": "settings_complete",
+ "extended_status": {
+ "steps_done": 0,
+ "total_steps": 0,
+ "errors": [],
+ "import_count": 0,
+ "importTag": 0
+ },
+ "configuration": {
+ "has-headers": false,
+ "date-format": "Ymd",
+ "delimiter": ",",
+ "import-account": 1,
+ "specifics": {
+ "RabobankDescription": 1
+ },
+ "column-count": 19,
+ "column-roles": [
+ "account-iban",
+ "currency-code",
+ "date-interest",
+ "rabo-debet-credit",
+ "amount",
+ "opposing-iban",
+ "opposing-name",
+ "date-book",
+ "description",
+ "_ignore",
+ "description",
+ "description",
+ "description",
+ "description",
+ "description",
+ "description",
+ "sepa-ct-id",
+ "sepa-ct-op",
+ "sepa-db"
+ ],
+ "column-do-mapping": [
+ true,
+ true,
+ false,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ],
+ "column-roles-complete": false,
+ "column-mapping-config": {
+ "0": [],
+ "1": {
+ "EUR": 1
+ },
+ "5": [],
+ "6": []
+ },
+ "column-mapping-complete": false
+ }
+ }
+ ],
+ "export-jobs": [
+ {
+ "user_id": 1,
+ "key": "testExport",
+ "status": "unknown"
+ }
+ ],
"currencies": []
}
\ No newline at end of file
diff --git a/tests/acceptance/Controllers/ExportControllerTest.php b/tests/acceptance/Controllers/ExportControllerTest.php
index ae8cc95e3f..97c6fa9325 100644
--- a/tests/acceptance/Controllers/ExportControllerTest.php
+++ b/tests/acceptance/Controllers/ExportControllerTest.php
@@ -8,6 +8,7 @@
*
* See the LICENSE file for details.
*/
+use FireflyIII\Export\Processor;
/**
@@ -28,57 +29,61 @@ class ExportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ExportController::download
- * Implement testDownload().
*/
public function testDownload()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->be($this->user());
+ $this->call('GET', route('export.download', ['testExport']));
+ $this->assertResponseStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ExportController::getStatus
- * Implement testGetStatus().
*/
public function testGetStatus()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->be($this->user());
+ $this->call('GET', route('export.status', ['testExport']));
+ $this->assertResponseStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\ExportController::index
- * Implement testIndex().
*/
public function testIndex()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->be($this->user());
+ $this->call('GET', route('export.index'));
+ $this->assertResponseStatus(200);
+
+ // has bread crumb
+ $this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\ExportController::postIndex
- * Implement testPostIndex().
*/
public function testPostIndex()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
+ $data = [
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
+ 'export_start_range' => '2015-01-01',
+ 'export_end_range' => '2015-01-21',
+ 'exportFormat' => 'csv',
+ 'accounts' => [1],
+ 'job' => 'testExport',
+ ];
+ $processor = $this->mock(Processor::class);
+ $processor->shouldReceive('collectJournals')->once();
+ $processor->shouldReceive('convertJournals')->once();
+ $processor->shouldReceive('exportJournals')->once();
+ $processor->shouldReceive('createZipFile')->once();
+
+
+ $this->be($this->user());
+ $this->call('post', route('export.export'), $data);
+ $this->assertResponseStatus(200);
+ $this->see('ok');
}
+
}