Files
firefly-iii/tests/acceptance/Controllers/Transaction/MassControllerTest.php

116 lines
4.1 KiB
PHP
Raw Normal View History

2016-11-19 20:30:30 +01:00
<?php
2016-12-06 09:16:36 +01:00
/**
* MassControllerTest.php
* Copyright (C) 2016 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.
*/
2016-11-19 20:30:30 +01:00
namespace Transaction;
2016-12-10 06:54:50 +01:00
2016-12-21 20:32:02 +01:00
use FireflyIII\Models\TransactionJournal;
2016-11-19 20:30:30 +01:00
use TestCase;
/**
2016-12-10 06:54:50 +01:00
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:44.
2016-11-19 20:30:30 +01:00
*/
class MassControllerTest extends TestCase
{
2016-11-20 07:24:18 +01:00
2016-11-19 20:30:30 +01:00
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
2016-11-20 08:30:25 +01:00
parent::setUp();
2016-11-19 20:30:30 +01:00
}
2016-12-07 19:53:41 +01:00
/**
2016-12-11 10:38:06 +01:00
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::delete
2016-11-19 20:30:30 +01:00
*/
2016-12-11 10:38:06 +01:00
public function testDelete()
2016-11-19 20:30:30 +01:00
{
2016-12-21 20:32:02 +01:00
$withdrawals = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
2016-12-11 10:38:06 +01:00
$this->be($this->user());
2016-12-21 20:32:02 +01:00
$this->call('get', route('transactions.mass.delete', $withdrawals));
2016-12-11 10:38:06 +01:00
$this->assertResponseStatus(200);
$this->see('Delete a number of transactions');
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-11 10:38:06 +01:00
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::destroy
2016-11-19 20:30:30 +01:00
*/
2016-12-11 10:38:06 +01:00
public function testDestroy()
2016-11-19 20:30:30 +01:00
{
2016-12-11 10:38:06 +01:00
$this->session(['transactions.mass-delete.url' => 'http://localhost']);
2016-12-21 20:32:02 +01:00
$deposits = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
$data = [
'confirm_mass_delete' => $deposits,
2016-12-11 10:38:06 +01:00
];
$this->be($this->user());
$this->call('post', route('transactions.mass.destroy'), $data);
$this->assertSessionHas('success');
$this->assertResponseStatus(302);
// visit them should give 404.
2016-12-21 20:32:02 +01:00
$this->call('get', route('transactions.show', [$deposits[0]]));
2016-12-11 10:38:06 +01:00
$this->assertResponseStatus(404);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-11 10:38:06 +01:00
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit
2016-11-19 20:30:30 +01:00
*/
2016-12-11 10:38:06 +01:00
public function testEdit()
2016-11-19 20:30:30 +01:00
{
2016-12-21 20:32:02 +01:00
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
2016-12-11 10:38:06 +01:00
$this->be($this->user());
2016-12-21 20:32:02 +01:00
$this->call('get', route('transactions.mass.delete', $transfers));
2016-12-11 10:38:06 +01:00
$this->assertResponseStatus(200);
$this->see('Edit a number of transactions');
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
2016-12-10 06:54:50 +01:00
/**
2016-12-11 10:38:06 +01:00
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::update
2016-12-10 06:54:50 +01:00
*/
2016-12-11 10:38:06 +01:00
public function testUpdate()
2016-12-10 06:54:50 +01:00
{
2016-12-21 20:32:02 +01:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)
->whereNull('deleted_at')
->first();
2016-12-11 10:38:06 +01:00
$this->session(['transactions.mass-edit.url' => 'http://localhost']);
$data = [
2016-12-21 20:32:02 +01:00
'journals' => [$deposit->id],
'description' => [$deposit->id => 'Updated salary thing'],
'amount' => [$deposit->id => 1600],
'amount_currency_id_amount_' . $deposit->id => 1,
'date' => [$deposit->id => '2014-07-24'],
'source_account_name' => [$deposit->id => 'Job'],
'destination_account_id' => [$deposit->id => 1],
'category' => [$deposit->id => 'Salary'],
2016-12-11 10:38:06 +01:00
];
$this->be($this->user());
2016-12-21 20:32:02 +01:00
$this->call('post', route('transactions.mass.update', [$deposit->id]), $data);
2016-12-11 10:38:06 +01:00
$this->assertSessionHas('success');
$this->assertResponseStatus(302);
// visit them should show updated content
2016-12-21 20:32:02 +01:00
$this->call('get', route('transactions.show', [$deposit->id]));
2016-12-11 10:38:06 +01:00
$this->assertResponseStatus(200);
$this->see('Updated salary thing');
2016-12-10 06:54:50 +01:00
}
2016-12-11 10:38:06 +01:00
2016-11-19 20:30:30 +01:00
}