mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
253 lines
8.6 KiB
PHP
253 lines
8.6 KiB
PHP
<?php
|
|
/**
|
|
* CsvControllerTest.php
|
|
* Copyright (C) 2016 Sander Dorigo
|
|
*
|
|
* This software may be modified and distributed under the terms
|
|
* of the MIT license. See the LICENSE file for details.
|
|
*/
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:28.
|
|
*/
|
|
class CsvControllerTest extends TestCase
|
|
{
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::columnRoles
|
|
* @covers FireflyIII\Http\Controllers\CsvController::__construct
|
|
*/
|
|
public function testColumnRoles()
|
|
{
|
|
$this->be($this->user());
|
|
|
|
// create session data:
|
|
$this->session($this->getSessionData());
|
|
|
|
$this->call('GET', '/csv/column_roles');
|
|
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::downloadConfig
|
|
*/
|
|
public function testDownloadConfig()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session($this->getSessionData());
|
|
$this->call('GET', '/csv/download-config');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::downloadConfigPage
|
|
*/
|
|
public function testDownloadConfigPage()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session($this->getSessionData());
|
|
$this->call('GET', '/csv/download');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::index
|
|
*/
|
|
public function testIndex()
|
|
{
|
|
|
|
$this->be($this->user());
|
|
$this->call('GET', '/csv');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::initialParse
|
|
*/
|
|
public function testInitialParse()
|
|
{
|
|
$this->be($this->user());
|
|
// post data:
|
|
$postData = [
|
|
'role' => [
|
|
0 => 'account-iban',
|
|
1 => 'opposing-iban',
|
|
2 => 'description',
|
|
3 => 'date-transaction',
|
|
4 => 'amount',
|
|
5 => 'category-name',
|
|
6 => 'budget-name',
|
|
],
|
|
'map' => [0 => 1, 1 => 1],
|
|
];
|
|
|
|
// create session data:
|
|
$this->session($this->getSessionData());
|
|
|
|
|
|
$this->call('POST', '/csv/initial_parse', $postData);
|
|
// should be redirect
|
|
$this->assertResponseStatus(302);
|
|
|
|
// should be redirected to mapping:
|
|
$this->assertRedirectedToRoute('csv.map');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::initialParse
|
|
*/
|
|
public function testInitialParseNoMap()
|
|
{
|
|
$this->be($this->user());
|
|
// post data:
|
|
$postData = [
|
|
'role' => [
|
|
0 => 'account-iban',
|
|
1 => 'opposing-iban',
|
|
2 => 'description',
|
|
3 => 'date-transaction',
|
|
4 => 'amount',
|
|
5 => 'category-name',
|
|
6 => 'budget-name',
|
|
],
|
|
'map' => [],
|
|
];
|
|
|
|
// create session data:
|
|
$this->session($this->getSessionData());
|
|
|
|
|
|
$this->call('POST', '/csv/initial_parse', $postData);
|
|
// should be redirect
|
|
$this->assertResponseStatus(302);
|
|
|
|
// should be redirected to download config:
|
|
$this->assertRedirectedToRoute('csv.download-config-page');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::map
|
|
*/
|
|
public function testMap()
|
|
{
|
|
$this->be($this->user());
|
|
|
|
$this->session($this->getSessionData());
|
|
|
|
$this->call('GET', '/csv/map');
|
|
$this->assertResponseStatus(200);
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::process
|
|
*/
|
|
public function testProcess()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session($this->getSessionData());
|
|
$this->call('GET', '/csv/process');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::saveMapping
|
|
*/
|
|
public function testSaveMapping()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session($this->getSessionData());
|
|
$postData = [
|
|
'mapping'
|
|
=> [0 => ['NL11XOLA6707795988' => '1',],
|
|
1 => ['NL10TAPT8906262744' => '0', 'NL93UPSZ1261542703' => '0', 'NL86IHAL3264575116' => '0', 'NL63BKBO9993148806' => '0',
|
|
'NL22EZVA6611573534' => '0', 'NL40KZVR5107424627' => '0', 'NL29RHEE6437366575' => '0', 'NL63IEPJ7437420074' => '0',
|
|
'NL62HQWJ8837203470' => '0', 'NL89FPEA1494900858' => '0', 'NL76MDMU3222445567' => '0', 'NL07TDQA3309954056' => '0',
|
|
'NL35MKIY9736938778' => '0', 'NL56DNGY5455310496' => '0', 'NL17LKFR7594179781' => '0', 'NL76UJQI9524250446' => '0',
|
|
'NL45YTPP6157249080' => '0', 'NL46TFVH5548690248' => '0', 'NL79XZWN0846248670' => '0', 'NL52MKIO8325583045' => '0',
|
|
'NL47YVJU4419567422' => '0', 'NL04TNIP4218080631' => '0', 'NL68SOAC3516744723' => '0', 'NL53YVTS7223912863' => '0',
|
|
'NL40QRBS9553175317' => '0', 'NL54TZNZ2922111989' => '0', 'NL04BAGX3284775110' => '0', 'NL49LULH7261231215' => '0',
|
|
'NL11YHMI8046080217' => '0', 'NL89BXNF2470379032' => '0', 'NL74SHGG7300113478' => '0', 'NL48ZPLO1718215436' => '0',
|
|
'NL13BJMO5341591615' => '0', 'NL59PKVU0116767154' => '0', 'NL72BQRL1220175315' => '0', 'NL53QHDG0329036955' => '0',
|
|
'NL48BLDJ9721843563' => '0', 'NL48BHXI9733658006' => '0', 'NL33VPSU8067103542' => '0', 'NL62UDLY8957139303' => '0',
|
|
'NL28EDMD2653501341' => '0', 'NL92QMZD6854625548' => '0', 'NL37VSLJ0853659915' => '0', 'NL95NQHS4363870109' => '0',
|
|
'NL81LEJP9477634344' => '0', 'NL14JYVJ1041891180' => '0', 'NL57SPBS0788124528' => '0',
|
|
'NL96DZCO4665940223' => '2',],],];
|
|
|
|
$this->call('POST', '/csv/save_mapping', $postData);
|
|
|
|
$this->assertResponseStatus(302);
|
|
$this->assertRedirectedToRoute('csv.download-config-page');
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\CsvController::upload
|
|
*/
|
|
public function testUpload()
|
|
{
|
|
$this->be($this->user());
|
|
|
|
$file = new UploadedFile(storage_path('build/test-upload.csv'), 'test-file.csv', 'text/plain', 446);
|
|
$args = [
|
|
'date_format' => 'Ymd',
|
|
'csv_import_account' => 1,
|
|
];
|
|
|
|
$this->call('POST', '/csv/upload', $args, [], ['csv' => $file]);
|
|
|
|
// csv data set:
|
|
//$this->assertSessionHas('csv-file', 'abc');
|
|
$this->assertSessionHas('csv-date-format', 'Ymd');
|
|
$this->assertSessionHas('csv-has-headers', false);
|
|
$this->assertSessionHas('csv-map', []);
|
|
$this->assertSessionHas('csv-mapped', []);
|
|
$this->assertSessionHas('csv-roles', []);
|
|
$this->assertSessionHas('csv-specifix', []);
|
|
$this->assertSessionHas('csv-import-account', 1);
|
|
$this->assertSessionHas('csv-delimiter', ',');
|
|
|
|
$this->assertResponseStatus(302);
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected function createUploadedFile()
|
|
{
|
|
$original = storage_path('build/test-upload.csv');
|
|
$time = '12345';
|
|
$fileName = 'csv-upload-' . $this->user()->id . '-' . $time . '.csv.encrypted';
|
|
$fullPath = storage_path('build') . DIRECTORY_SEPARATOR . $fileName;
|
|
|
|
if (!file_exists($fullPath)) {
|
|
$content = file_get_contents($original);
|
|
$contentEncrypted = Crypt::encrypt($content);
|
|
file_put_contents($fullPath, $contentEncrypted);
|
|
}
|
|
|
|
return $fullPath;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function getSessionData()
|
|
{
|
|
return [
|
|
'csv-file' => $this->createUploadedFile(),
|
|
'csv-date-format' => 'Ymd',
|
|
'csv-has-headers' => false,
|
|
'csv-import-account' => 1,
|
|
'csv-delimiter' => ',',
|
|
'csv-specifix' => ['Dummy'],
|
|
'csv-roles' => [0 => 'account-iban', 1 => 'opposing-iban', 2 => 'description', 3 => 'date-transaction', 4 => 'amount',
|
|
5 => 'category-name', 6 => 'budget-name',],
|
|
'csv-map' => [0 => 'account-iban', 1 => 'opposing-iban',],
|
|
'csv-mapped' => [0 => ['NL11XOLA6707795988' => '1',], 1 => ['NL96DZCO4665940223' => '2',]],
|
|
];
|
|
}
|
|
}
|