diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.php index ebd9f0b7fd..7b5dd68f9e 100644 --- a/app/Http/Controllers/CsvController.php +++ b/app/Http/Controllers/CsvController.php @@ -13,6 +13,7 @@ use Illuminate\Http\Request; use Input; use Log; use Preferences; +use Request as RequestFacade; use Session; use View; @@ -57,8 +58,9 @@ class CsvController extends Controller public function columnRoles() { - $fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account', 'csv-delimiter']; + $fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account', 'csv-specifix', 'csv-delimiter']; if (!$this->wizard->sessionHasValues($fields)) { + Log::error('Could not recover upload.'); Session::flash('warning', 'Could not recover upload.'); return redirect(route('csv.index')); @@ -122,13 +124,18 @@ class CsvController extends Controller } $result = json_encode($data, JSON_PRETTY_PRINT); - $name = 'csv-configuration-' . date('Y-m-d') . '.json'; + $name = sprintf('"%s"', addcslashes('csv-configuration-' . date('Y-m-d') . '.json', '"\\')); - header('Content-disposition: attachment; filename=' . $name); - header('Content-type: application/json'); - echo $result; + RequestFacade::header('Content-disposition: attachment; filename=' . $name); + RequestFacade::header('Content-Type: application/json'); + RequestFacade::header('Content-Description: File Transfer'); + RequestFacade::header('Connection: Keep-Alive'); + RequestFacade::header('Expires: 0'); + RequestFacade::header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + RequestFacade::header('Pragma: public'); + RequestFacade::header('Content-Length: ' . strlen($result)); - return ''; + return $result; } /** @@ -136,6 +143,13 @@ class CsvController extends Controller */ public function downloadConfigPage() { + $fields = ['csv-date-format', 'csv-has-headers', 'csv-delimiter']; + if (!$this->wizard->sessionHasValues($fields)) { + Session::flash('warning', 'Could not recover upload.'); + + return redirect(route('csv.index')); + } + $subTitle = trans('firefly.csv_download_config_title'); return view('csv.download-config', compact('subTitle')); @@ -266,6 +280,8 @@ class CsvController extends Controller try { $options = $this->wizard->showOptions($this->data->getMap()); } catch (FireflyException $e) { + Log::error($e->getMessage()); + return view('error', ['message' => $e->getMessage()]); } diff --git a/cover.sh b/cover.sh index 8b085fce28..111bdf08d6 100755 --- a/cover.sh +++ b/cover.sh @@ -38,14 +38,12 @@ then # run it! echo "Now running $firstFile" phpunit --verbose $firstFile - exit $? fi if [ -f "$secondFile" ] then # run it! echo "Now running $secondFile" phpunit --verbose $secondFile - exit $? fi diff --git a/phpunit.xml b/phpunit.xml index 04f27f97f4..cc0841c1d3 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,14 +18,6 @@ app/ - - diff --git a/pu.sh b/pu.sh index f3f73b9540..d1b96546f1 100755 --- a/pu.sh +++ b/pu.sh @@ -43,14 +43,12 @@ then # run it! echo "Now running $firstFile" phpunit --verbose $firstFile - exit $? fi if [ -f "$secondFile" ] then # run it! echo "Now running $secondFile" phpunit --verbose $secondFile - exit $? fi diff --git a/storage/build/test-upload.csv b/storage/build/test-upload.csv index 6bb456c657..1ad0102bb6 100644 --- a/storage/build/test-upload.csv +++ b/storage/build/test-upload.csv @@ -1,65 +1,65 @@ -NL11XOLA6707795988,NL10PTJB2963674082,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160122,18.17,cash,household -NL11XOLA6707795988,NL43PCCF0336398891,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,29.47,bike,household -NL11XOLA6707795988,NL43FVSK2306325839,"Morbi quis mauris nec tortor egestas blandit.",20160122,45.42,car,household -NL11XOLA6707795988,NL35MKIY9736938778,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,37.3,dinner,clothes -NL11XOLA6707795988,NL79YXIG5127509172,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,12.02,bike,groceries -NL11XOLA6707795988,NL50BBGH8090225241,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,19.05,bike,studies -NL11XOLA6707795988,NL69SILM0484853589,"In scelerisque velit eget ante pharetra pretium.",20160122,13.43,gifts,bills -NL11XOLA6707795988,NL48MJPV7247585684,"Morbi quis mauris nec tortor egestas blandit.",20160122,47.31,car,studies -NL11XOLA6707795988,NL41KITW7622223212,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160122,33.57,taxes,clothes -NL11XOLA6707795988,NL27WOWN6072969151,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,21.34,cash,groceries -NL11XOLA6707795988,NL29FVTD1470732785,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,42.71,bike,holiday -NL11XOLA6707795988,NL45YBAF5167045592,"Morbi quis mauris nec tortor egestas blandit.",20160122,49.72,car,studies -NL11XOLA6707795988,NL04TNIP4218080631,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,17.37,food,groceries -NL11XOLA6707795988,NL62WGZO5809991173,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,47.58,taxes,clothes -NL11XOLA6707795988,NL08RUWQ3946442994,"Nulla a dui euismod nulla convallis dictum.",20160122,13.6,taxes,holiday -NL11XOLA6707795988,NL35MKIY9736938778,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160122,45.45,bike,groceries -NL11XOLA6707795988,NL32TPWJ6653031136,"Morbi quis mauris nec tortor egestas blandit.",20160122,13.47,food,studies -NL11XOLA6707795988,NL27WOWN6072969151,"Nulla a dui euismod nulla convallis dictum.",20160122,36.06,car,clothes -NL11XOLA6707795988,NL88GMSX1890703281,"Morbi quis mauris nec tortor egestas blandit.",20160122,17.71,gifts,clothes -NL11XOLA6707795988,NL57XWYZ7311027810,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,17.12,taxes,bills -NL11XOLA6707795988,NL53XXRC4353165917,"Vivamus ultrices tortor vel semper lacinia.",20160122,48.13,food,bills -NL11XOLA6707795988,NL71NZET6513049113,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160122,30.21,food,household -NL11XOLA6707795988,NL34WNPM5967636595,"Nunc sed leo scelerisque quam consectetur elementum quis consequat dui.",20160122,23.83,gifts,household -NL11XOLA6707795988,NL92QQAD9910045494,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,18.37,food,studies -NL11XOLA6707795988,NL96DQGH5594709053,"Nullam malesuada orci in vulputate imperdiet.",20160122,34.31,car,studies -NL32EMMZ6999206899,NL11XOLA6707795988,"In scelerisque velit eget ante pharetra pretium.",20160122,41.03,"books and such",clothes -NL72JOAK5065057265,NL11XOLA6707795988,"Nullam malesuada orci in vulputate imperdiet.",20160122,34.21,car,groceries -NL40KZVR5107424627,NL11XOLA6707795988,"Vivamus ultrices tortor vel semper lacinia.",20160122,34.9,taxes,clothes -NL78DRZM0805589694,NL11XOLA6707795988,"Morbi quis mauris nec tortor egestas blandit.",20160122,27.86,"books and such",household -NL68TROA2774597773,NL11XOLA6707795988,"Proin eleifend magna et ante cursus laoreet.",20160122,19.62,taxes,"other stuff" -NL46WEXF3324987229,NL11XOLA6707795988,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160122,34.12,gifts,bills -NL60TTSG7972999589,NL11XOLA6707795988,"Vivamus ultrices tortor vel semper lacinia.",20160122,36.49,dinner,"other stuff" -NL20GJDZ7286831224,NL11XOLA6707795988,"Nullam malesuada orci in vulputate imperdiet.",20160122,36.25,bike,bills -NL70NICN4864639604,NL11XOLA6707795988,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,15.29,groceries,groceries -NL66KCKB4009393114,NL11XOLA6707795988,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,45.87,taxes,holiday -NL62LELR1702168905,NL11XOLA6707795988,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160122,31.89,gifts,household -NL79PBCN6122638412,NL11XOLA6707795988,"Nulla a dui euismod nulla convallis dictum.",20160122,35.52,"books and such","other stuff" -NL16FBYT1696665639,NL11XOLA6707795988,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,18.96,"books and such",groceries -NL81QKMO3338422717,NL11XOLA6707795988,"Vivamus ultrices tortor vel semper lacinia.",20160122,24.94,taxes,studies -NL63GVZI7651340124,NL11XOLA6707795988,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,32.58,cash,"other stuff" -NL17REMH4925281321,NL11XOLA6707795988,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160122,46.01,"books and such",studies -NL54XPIH7528269468,NL11XOLA6707795988,"Vivamus ultrices tortor vel semper lacinia.",20160122,13.43,groceries,household -NL53NOPK8565452735,NL11XOLA6707795988,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160122,19.77,taxes,holiday -NL62ZZPH8329588521,NL11XOLA6707795988,"Nulla in neque sed velit ultricies placerat.",20160122,43.43,cash,clothes -NL12KOHE7606000581,NL11XOLA6707795988,"In scelerisque velit eget ante pharetra pretium.",20160122,31.07,groceries,clothes -NL37RYLJ9835423733,NL11XOLA6707795988,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,39.39,bike,clothes -NL15PQBO6144269770,NL11XOLA6707795988,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160122,20.08,car,groceries -NL27WOWN6072969151,NL11XOLA6707795988,"Vivamus ultrices tortor vel semper lacinia.",20160122,46.78,dinner,"other stuff" -NL60YKHO5522486392,NL11XOLA6707795988,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,34.91,cash,holiday -NL61AZND8571986983,NL11XOLA6707795988,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160122,12.57,groceries,groceries -NL11XOLA6707795988,NL96DZCO4665940223,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160122,22.59,groceries, -NL11XOLA6707795988,NL96DZCO4665940223,"Nullam malesuada orci in vulputate imperdiet.",20160122,36.57,dinner, -NL11XOLA6707795988,NL96DZCO4665940223,"Proin eleifend magna et ante cursus laoreet.",20160122,34.9,food, -NL11XOLA6707795988,NL96DZCO4665940223,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160122,22.87,car, -NL11XOLA6707795988,NL96DZCO4665940223,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,32.95,car, -NL11XOLA6707795988,NL96DZCO4665940223,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,35.47,bike, -NL11XOLA6707795988,NL96DZCO4665940223,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,41.43,taxes, -NL11XOLA6707795988,NL96DZCO4665940223,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,30.85,food, -NL11XOLA6707795988,NL96DZCO4665940223,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160122,29.28,groceries, -NL11XOLA6707795988,NL96DZCO4665940223,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,31.86,cash, -NL11XOLA6707795988,NL96DZCO4665940223,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160122,20.22,car, -NL11XOLA6707795988,NL96DZCO4665940223,"Vivamus ultrices tortor vel semper lacinia.",20160122,29.66,cash, -NL11XOLA6707795988,NL96DZCO4665940223,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160122,13.29,taxes, -NL11XOLA6707795988,NL96DZCO4665940223,"Vivamus ultrices tortor vel semper lacinia.",20160122,33.69,gifts, -NL11XOLA6707795988,NL96DZCO4665940223,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160122,34.7,dinner, +NL11XOLA6707795988,NL10TAPT8906262744,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160123,15.03,gifts,holiday +NL11XOLA6707795988,NL93UPSZ1261542703,"Morbi quis mauris nec tortor egestas blandit.",20160123,47.38,groceries,studies +NL11XOLA6707795988,NL86IHAL3264575116,"Proin eleifend magna et ante cursus laoreet.",20160123,43.73,"books and such",groceries +NL11XOLA6707795988,NL63BKBO9993148806,"In scelerisque velit eget ante pharetra pretium.",20160123,39.21,dinner,holiday +NL11XOLA6707795988,NL22EZVA6611573534,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160123,24.77,taxes,holiday +NL11XOLA6707795988,NL40KZVR5107424627,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,17.19,dinner,clothes +NL11XOLA6707795988,NL29RHEE6437366575,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160123,43.14,cash,studies +NL11XOLA6707795988,NL63IEPJ7437420074,"Nunc sed leo scelerisque quam consectetur elementum quis consequat dui.",20160123,35.25,gifts,bills +NL11XOLA6707795988,NL62HQWJ8837203470,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,42.07,taxes,holiday +NL11XOLA6707795988,NL89FPEA1494900858,"Vivamus ultrices tortor vel semper lacinia.",20160123,25.31,gifts,groceries +NL11XOLA6707795988,NL76MDMU3222445567,"In scelerisque velit eget ante pharetra pretium.",20160123,41.76,cash,clothes +NL11XOLA6707795988,NL07TDQA3309954056,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,10.81,food,studies +NL11XOLA6707795988,NL35MKIY9736938778,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,46.82,"books and such",bills +NL11XOLA6707795988,NL63IEPJ7437420074,"Nullam malesuada orci in vulputate imperdiet.",20160123,10.3,groceries,studies +NL11XOLA6707795988,NL56DNGY5455310496,"Morbi quis mauris nec tortor egestas blandit.",20160123,22.39,bike,bills +NL11XOLA6707795988,NL17LKFR7594179781,"Vivamus ultrices tortor vel semper lacinia.",20160123,11.45,gifts,clothes +NL11XOLA6707795988,NL76UJQI9524250446,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160123,49.23,bike,studies +NL11XOLA6707795988,NL45YTPP6157249080,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,22.6,cash,"other stuff" +NL11XOLA6707795988,NL46TFVH5548690248,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,44.34,bike,holiday +NL11XOLA6707795988,NL79XZWN0846248670,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160123,12.96,car,groceries +NL11XOLA6707795988,NL52MKIO8325583045,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,44.47,taxes,bills +NL11XOLA6707795988,NL47YVJU4419567422,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,17.51,car,bills +NL11XOLA6707795988,NL04TNIP4218080631,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160123,17.36,cash,groceries +NL11XOLA6707795988,NL68SOAC3516744723,"In scelerisque velit eget ante pharetra pretium.",20160123,34.22,taxes,groceries +NL11XOLA6707795988,NL53YVTS7223912863,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,27.9,food,"other stuff" +NL11XOLA6707795988,NL40QRBS9553175317,"Vivamus ultrices tortor vel semper lacinia.",20160123,-10.86,groceries,holiday +NL11XOLA6707795988,NL79XZWN0846248670,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,-19.57,bike,household +NL11XOLA6707795988,NL54TZNZ2922111989,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160123,-12.05,cash,holiday +NL11XOLA6707795988,NL04BAGX3284775110,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,-15.98,groceries,bills +NL11XOLA6707795988,NL49LULH7261231215,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,-35.67,food,clothes +NL11XOLA6707795988,NL11YHMI8046080217,"Nunc sed leo scelerisque quam consectetur elementum quis consequat dui.",20160123,-48.94,dinner,clothes +NL11XOLA6707795988,NL89BXNF2470379032,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,-33.82,taxes,holiday +NL11XOLA6707795988,NL74SHGG7300113478,"In scelerisque velit eget ante pharetra pretium.",20160123,-17.36,food,"other stuff" +NL11XOLA6707795988,NL48ZPLO1718215436,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,-19.31,food,holiday +NL11XOLA6707795988,NL13BJMO5341591615,"Pellentesque sit amet enim ac tortor euismod ullamcorper vel et massa.",20160123,-28.47,groceries,"other stuff" +NL11XOLA6707795988,NL59PKVU0116767154,"Proin eleifend magna et ante cursus laoreet.",20160123,-39.24,taxes,"other stuff" +NL11XOLA6707795988,NL72BQRL1220175315,"Nulla in neque sed velit ultricies placerat.",20160123,-17.53,groceries,bills +NL11XOLA6707795988,NL53QHDG0329036955,"Nulla a dui euismod nulla convallis dictum.",20160123,-39.45,"books and such",holiday +NL11XOLA6707795988,NL29RHEE6437366575,"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",20160123,-23.47,food,studies +NL11XOLA6707795988,NL48BLDJ9721843563,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,-16.56,food,"other stuff" +NL11XOLA6707795988,NL48BHXI9733658006,"Nulla in neque sed velit ultricies placerat.",20160123,-21.89,gifts,household +NL11XOLA6707795988,NL33VPSU8067103542,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,-11.71,groceries,clothes +NL11XOLA6707795988,NL62UDLY8957139303,"Nunc sed leo scelerisque quam consectetur elementum quis consequat dui.",20160123,-38.08,gifts,groceries +NL11XOLA6707795988,NL28EDMD2653501341,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,-39.57,cash,holiday +NL11XOLA6707795988,NL92QMZD6854625548,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,-48.8,car,groceries +NL11XOLA6707795988,NL37VSLJ0853659915,"Nulla a dui euismod nulla convallis dictum.",20160123,-34.55,bike,household +NL11XOLA6707795988,NL95NQHS4363870109,"Suspendisse tempus eros euismod leo consequat, non malesuada arcu pretium.",20160123,-34.95,dinner,studies +NL11XOLA6707795988,NL81LEJP9477634344,"Vivamus ultrices tortor vel semper lacinia.",20160123,-13.18,dinner,"other stuff" +NL11XOLA6707795988,NL14JYVJ1041891180,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,-12.79,groceries,bills +NL11XOLA6707795988,NL57SPBS0788124528,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,-35.53,bike,groceries +NL11XOLA6707795988,NL96DZCO4665940223,"Proin eleifend magna et ante cursus laoreet.",20160123,34.41,groceries, +NL11XOLA6707795988,NL96DZCO4665940223,"Curabitur vitae nisi consectetur, feugiat ipsum vitae, hendrerit sem.",20160123,35.8,groceries, +NL11XOLA6707795988,NL96DZCO4665940223,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,22.46,car, +NL11XOLA6707795988,NL96DZCO4665940223,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,43.74,bike, +NL11XOLA6707795988,NL96DZCO4665940223,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,28.68,dinner, +NL11XOLA6707795988,NL96DZCO4665940223,"Duis fringilla libero eget quam pharetra, non gravida ex fermentum.",20160123,32.36,car, +NL11XOLA6707795988,NL96DZCO4665940223,"Nam in purus porta, accumsan felis vitae, bibendum leo.",20160123,37.76,groceries, +NL11XOLA6707795988,NL96DZCO4665940223,"Nulla in neque sed velit ultricies placerat.",20160123,19.98,"books and such", +NL11XOLA6707795988,NL96DZCO4665940223,"Aenean dictum sem pellentesque, semper est eget, ultricies magna.",20160123,26.57,gifts, +NL11XOLA6707795988,NL96DZCO4665940223,"Morbi quis mauris nec tortor egestas blandit.",20160123,12.09,"books and such", +NL11XOLA6707795988,NL96DZCO4665940223,"Vivamus ultrices tortor vel semper lacinia.",20160123,34.96,dinner, +NL11XOLA6707795988,NL96DZCO4665940223,"Nullam malesuada orci in vulputate imperdiet.",20160123,16.62,food, +NL11XOLA6707795988,NL96DZCO4665940223,"Nulla a dui euismod nulla convallis dictum.",20160123,31.14,car, +NL11XOLA6707795988,NL96DZCO4665940223,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160123,45.1,bike, +NL11XOLA6707795988,NL96DZCO4665940223,"Donec tincidunt nibh nec diam sodales, feugiat pulvinar ante consequat.",20160123,24.92,groceries, diff --git a/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php b/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php index ac922dd8ed..9de5b324bc 100644 --- a/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php @@ -17,10 +17,13 @@ class ChartReportControllerTest extends TestCase */ public function testYearInOut() { -// $this->be($this->user()); -// $response = $this->call('GET', '/chart/report/in-out/default/20150101/20151231/1'); -// $this->assertEquals(200, $response->status()); - $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); + $repository = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface'); + $repository->shouldReceive('spentPerMonth')->once()->andReturn([]); + $repository->shouldReceive('earnedPerMonth')->once()->andReturn([]); + + $this->be($this->user()); + $response = $this->call('GET', '/chart/report/in-out/default/20150101/20151231/1'); + $this->assertEquals(200, $response->status()); } /** @@ -28,9 +31,12 @@ class ChartReportControllerTest extends TestCase */ public function testYearInOutSummarized() { -// $this->be($this->user()); -// $response = $this->call('GET', '/chart/report/in-out-sum/default/20150101/20151231/1'); -// $this->assertEquals(200, $response->status()); - $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); + $repository = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface'); + $repository->shouldReceive('spentPerMonth')->once()->andReturn([]); + $repository->shouldReceive('earnedPerMonth')->once()->andReturn([]); + + $this->be($this->user()); + $response = $this->call('GET', '/chart/report/in-out-sum/default/20150101/20151231/1'); + $this->assertEquals(200, $response->status()); } } diff --git a/tests/acceptance/Controllers/CsvControllerTest.php b/tests/acceptance/Controllers/CsvControllerTest.php index 22301ee276..ccd6a64598 100644 --- a/tests/acceptance/Controllers/CsvControllerTest.php +++ b/tests/acceptance/Controllers/CsvControllerTest.php @@ -6,6 +6,7 @@ * 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; /** @@ -15,109 +16,239 @@ class CsvControllerTest extends TestCase { /** * @covers FireflyIII\Http\Controllers\CsvController::columnRoles - * @todo Implement testColumnRoles(). */ public function testColumnRoles() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + + // create session data: + $this->session($this->getSessionData()); + + $response = $this->call('GET', '/csv/column_roles'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\CsvController::downloadConfig - * @todo Implement testDownloadConfig(). */ public function testDownloadConfig() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + $this->session($this->getSessionData()); + $response = $this->call('GET', '/csv/download-config'); + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\CsvController::downloadConfigPage - * @todo Implement testDownloadConfigPage(). */ public function testDownloadConfigPage() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + $this->session($this->getSessionData()); + $response = $this->call('GET', '/csv/download'); + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\CsvController::index - * @todo 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()); + $response = $this->call('GET', '/csv'); + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\CsvController::initialParse - * @todo Implement testInitialParse(). */ public function testInitialParse() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $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()); + + + $response = $this->call('POST', '/csv/initial_parse', $postData); + // should be redirect + $this->assertEquals(302, $response->status()); + + // 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' => [], + '_token' => Session::token(), + ]; + + // create session data: + $this->session($this->getSessionData()); + + + $response = $this->call('POST', '/csv/initial_parse', $postData); + // should be redirect + $this->assertEquals(302, $response->status()); + + // should be redirected to download config: + $this->assertRedirectedToRoute('csv.download-config-page'); } /** * @covers FireflyIII\Http\Controllers\CsvController::map - * @todo Implement testMap(). */ public function testMap() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + + $this->session($this->getSessionData()); + + $response = $this->call('GET', '/csv/map'); + $this->assertEquals(200, $response->status()); + } /** * @covers FireflyIII\Http\Controllers\CsvController::process - * @todo Implement testProcess(). */ public function testProcess() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + $this->session($this->getSessionData()); + $response = $this->call('GET', '/csv/process'); + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\CsvController::saveMapping - * @todo Implement testSaveMapping(). */ public function testSaveMapping() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + $this->session($this->getSessionData()); + $postData = [ + '_token' => Session::token(), + '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',],],]; + + $response = $this->call('POST', '/csv/save_mapping', $postData); + + $this->assertEquals(302, $response->status()); + $this->assertRedirectedToRoute('csv.download-config-page'); + } /** * @covers FireflyIII\Http\Controllers\CsvController::upload - * @todo Implement testUpload(). */ public function testUpload() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + + $file = new UploadedFile(storage_path('build/test-upload.csv'), 'test-file.csv', 'text/plain', 446); + $args = [ + '_token' => Session::token(), + 'date_format' => 'Ymd', + 'csv_import_account' => 1, + ]; + + $response = $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->assertEquals(302, $response->status()); + } + + /** + * @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',]], + ]; } }