firefly-iii/tests/acceptance/Controllers/TransactionControllerTest.php

158 lines
5.0 KiB
PHP
Raw Normal View History

2016-01-19 23:20:09 -06:00
<?php
/**
* TransactionControllerTest.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.
*/
2016-02-06 02:52:31 -06:00
use Illuminate\Pagination\LengthAwarePaginator;
2016-01-19 23:20:09 -06:00
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:29.
*/
class TransactionControllerTest extends TestCase
{
/**
* @covers FireflyIII\Http\Controllers\TransactionController::create
2016-02-04 00:30:48 -06:00
* @covers FireflyIII\Http\Controllers\TransactionController::__construct
2016-01-19 23:20:09 -06:00
*/
public function testCreate()
{
2016-02-04 00:30:48 -06:00
$this->be($this->user());
$this->call('GET', '/transactions/create/withdrawal');
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::delete
*/
public function testDelete()
{
2016-02-04 00:30:48 -06:00
$this->be($this->user());
$this->call('GET', '/transaction/delete/1');
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::destroy
*/
public function testDestroy()
{
2016-02-04 00:30:48 -06:00
$this->session(['transactions.delete.url' => 'http://localhost']);
$this->be($this->user());
$this->call('POST', '/transaction/destroy/1');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
*/
public function testEdit()
{
2016-02-04 00:30:48 -06:00
$this->be($this->user());
$this->call('GET', '/transaction/edit/1');
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
2016-02-05 08:41:40 -06:00
* @covers FireflyIII\Http\Controllers\TransactionController::index
* @dataProvider dateRangeProvider
2016-02-05 08:41:40 -06:00
*
* @param $range
2016-01-19 23:20:09 -06:00
*/
public function testIndex($range)
2016-01-19 23:20:09 -06:00
{
2016-02-06 02:52:31 -06:00
$journals = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
$journals->shouldReceive('getJournalsOfTypes')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
2016-02-04 00:30:48 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-02-04 00:30:48 -06:00
$this->call('GET', '/transactions/deposit');
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::reorder
*/
public function testReorder()
{
2016-02-04 00:30:48 -06:00
$args = [
'ids' => [1],
'date' => '2015-01-01',
];
$this->be($this->user());
$this->call('POST', '/transaction/reorder', $args);
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
2016-02-05 08:41:40 -06:00
* @covers FireflyIII\Http\Controllers\TransactionController::show
* @dataProvider dateRangeProvider
2016-02-05 08:41:40 -06:00
*
* @param $range
2016-01-19 23:20:09 -06:00
*/
public function testShow($range)
2016-01-19 23:20:09 -06:00
{
2016-02-04 00:30:48 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-02-04 00:30:48 -06:00
$this->call('GET', '/transaction/show/1');
$this->assertResponseStatus(200);
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::store
2016-02-04 00:30:48 -06:00
* @covers FireflyIII\Http\Requests\JournalFormRequest::authorize
* @covers FireflyIII\Http\Requests\JournalFormRequest::rules
* @covers FireflyIII\Http\Requests\JournalFormRequest::getJournalData
2016-01-19 23:20:09 -06:00
*/
public function testStore()
{
2016-02-04 00:30:48 -06:00
$this->session(['transactions.create.url' => 'http://localhost']);
$args = [
'what' => 'withdrawal',
'description' => 'Something',
'account_id' => '1',
'expense_account' => 'Some expense',
'amount' => 100,
'amount_currency_id_amount' => 1,
'date' => '2015-01-01',
];
$this->be($this->user());
$this->call('POST', '/transactions/store/withdrawal', $args);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
2016-01-19 23:20:09 -06:00
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::update
2016-02-04 00:30:48 -06:00
* @covers FireflyIII\Http\Requests\JournalFormRequest::authorize
* @covers FireflyIII\Http\Requests\JournalFormRequest::rules
* @covers FireflyIII\Http\Requests\JournalFormRequest::getJournalData
2016-01-19 23:20:09 -06:00
*/
public function testUpdate()
{
2016-02-04 00:30:48 -06:00
$this->session(['transactions.edit.url' => 'http://localhost']);
$args = [
'what' => 'withdrawal',
'id' => 2,
'description' => 'Something new',
'account_id' => '1',
'expense_account' => 'Some expense',
'amount' => 100,
'amount_currency_id_amount' => 1,
'date' => '2015-01-01',
];
$this->be($this->user());
$this->call('POST', '/transaction/update/1', $args);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
2016-01-19 23:20:09 -06:00
}
}