firefly-iii/tests/acceptance/Controllers/TransactionControllerTest.php
2016-04-01 16:46:11 +02:00

158 lines
5.0 KiB
PHP

<?php
/**
* TransactionControllerTest.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
use Illuminate\Pagination\LengthAwarePaginator;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:29.
*/
class TransactionControllerTest extends TestCase
{
/**
* @covers FireflyIII\Http\Controllers\TransactionController::create
* @covers FireflyIII\Http\Controllers\TransactionController::__construct
*/
public function testCreate()
{
$this->be($this->user());
$this->call('GET', '/transactions/create/withdrawal');
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::delete
*/
public function testDelete()
{
$this->be($this->user());
$this->call('GET', '/transaction/delete/1');
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::destroy
*/
public function testDestroy()
{
$this->session(['transactions.delete.url' => 'http://localhost']);
$this->be($this->user());
$this->call('POST', '/transaction/destroy/1');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
*/
public function testEdit()
{
$this->be($this->user());
$this->call('GET', '/transaction/edit/1');
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::index
* @dataProvider dateRangeProvider
*
* @param $range
*/
public function testIndex($range)
{
$journals = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
$journals->shouldReceive('getJournalsOfTypes')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/transactions/deposit');
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::reorder
*/
public function testReorder()
{
$args = [
'ids' => [1],
'date' => '2015-01-01',
];
$this->be($this->user());
$this->call('POST', '/transaction/reorder', $args);
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::show
* @dataProvider dateRangeProvider
*
* @param $range
*/
public function testShow($range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/transaction/show/1');
$this->assertResponseStatus(200);
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::store
* @covers FireflyIII\Http\Requests\JournalFormRequest::authorize
* @covers FireflyIII\Http\Requests\JournalFormRequest::rules
* @covers FireflyIII\Http\Requests\JournalFormRequest::getJournalData
*/
public function testStore()
{
$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');
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::update
* @covers FireflyIII\Http\Requests\JournalFormRequest::authorize
* @covers FireflyIII\Http\Requests\JournalFormRequest::rules
* @covers FireflyIII\Http\Requests\JournalFormRequest::getJournalData
*/
public function testUpdate()
{
$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');
}
}