mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
197 lines
5.6 KiB
PHP
197 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* BudgetControllerTest.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 Carbon\Carbon;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:27.
|
|
*/
|
|
class BudgetControllerTest extends TestCase
|
|
{
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::amount
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::__construct
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testAmount($range)
|
|
{
|
|
$args = [
|
|
'amount' => 1200,
|
|
];
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('POST', '/budgets/amount/1', $args);
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::create
|
|
*/
|
|
public function testCreate()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', '/budgets/create');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::delete
|
|
*/
|
|
public function testDelete()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', '/budgets/delete/1');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::destroy
|
|
*/
|
|
public function testDestroy()
|
|
{
|
|
$this->be($this->user());
|
|
|
|
$this->session(['budgets.delete.url' => 'http://localhost']);
|
|
$this->call('POST', '/budgets/destroy/2');
|
|
$this->assertSessionHas('success');
|
|
$this->assertResponseStatus(302);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::edit
|
|
*/
|
|
public function testEdit()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', '/budgets/edit/1');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::index
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testIndex($range)
|
|
{
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', '/budgets');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::noBudget
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testNoBudget($range)
|
|
{
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', '/budgets/list/noBudget');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::postUpdateIncome
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testPostUpdateIncome($range)
|
|
{
|
|
$args = [
|
|
'amount' => 1200,
|
|
];
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('POST', '/budgets/income', $args);
|
|
$this->assertResponseStatus(302);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::show
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testShow($range)
|
|
{
|
|
// mock some stuff:
|
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
|
$repository->shouldReceive('getJournals')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
|
|
$repository->shouldReceive('firstActivity')->once()->andReturn(new Carbon);
|
|
$repository->shouldReceive('spentPerDay')->once()->andReturn([]);
|
|
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', '/budgets/show/1');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::store
|
|
* @covers FireflyIII\Http\Requests\BudgetFormRequest::authorize
|
|
* @covers FireflyIII\Http\Requests\BudgetFormRequest::rules
|
|
*/
|
|
public function testStore()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session(['budgets.create.url' => 'http://localhost']);
|
|
$args = [
|
|
'name' => 'Some kind of test budget.',
|
|
];
|
|
|
|
$this->call('POST', '/budgets/store', $args);
|
|
$this->assertResponseStatus(302);
|
|
$this->assertSessionHas('success');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::update
|
|
* @covers FireflyIII\Http\Requests\BudgetFormRequest::authorize
|
|
* @covers FireflyIII\Http\Requests\BudgetFormRequest::rules
|
|
*/
|
|
public function testUpdate()
|
|
{
|
|
$this->be($this->user());
|
|
$this->session(['budgets.edit.url' => 'http://localhost']);
|
|
$args = [
|
|
'name' => 'Some kind of test budget.',
|
|
'id' => 1,
|
|
];
|
|
|
|
$this->call('POST', '/budgets/update/1', $args);
|
|
$this->assertResponseStatus(302);
|
|
$this->assertSessionHas('success');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\BudgetController::updateIncome
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param $range
|
|
*/
|
|
public function testUpdateIncome($range)
|
|
{
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', '/budgets/income');
|
|
$this->assertResponseStatus(200);
|
|
}
|
|
}
|