2016-11-19 20:30:30 +01:00
|
|
|
<?php
|
2016-12-06 09:16:36 +01:00
|
|
|
/**
|
|
|
|
* BudgetControllerTest.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-12-11 14:03:30 +01:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
2016-11-19 20:30:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-10 06:54:50 +01:00
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:40.
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
class BudgetControllerTest 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
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testAmount()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$data = [
|
|
|
|
'amount' => 200,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
2016-12-15 17:16:46 +01:00
|
|
|
$this->call('post', route('budgets.amount', [1]), $data);
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->assertResponseStatus(200);
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::create
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testCreate()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.create'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::delete
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testDelete()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.delete', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::destroy
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testDestroy()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->session(['budgets.delete.url' => 'http://localhost']);
|
|
|
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('destroy')->andReturn(true);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('budgets.destroy', [1]));
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::edit
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testEdit()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.edit', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 14:03:30 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 17:16:46 +01:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
2016-12-11 14:03:30 +01:00
|
|
|
public function testIndex(string $range)
|
2016-11-19 20:30:30 +01:00
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('budgets.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 14:03:30 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::noBudget
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 17:16:46 +01:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
2016-12-11 14:03:30 +01:00
|
|
|
public function testNoBudget(string $range)
|
2016-11-19 20:30:30 +01:00
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('budgets.no-budget'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::postUpdateIncome
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testPostUpdateIncome()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$data = [
|
2016-12-22 18:19:50 +01:00
|
|
|
'amount' => '200',
|
2016-12-11 14:03:30 +01:00
|
|
|
];
|
|
|
|
$this->be($this->user());
|
2016-12-22 18:19:50 +01:00
|
|
|
$this->call('post', route('budgets.income.post'), $data);
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->assertResponseStatus(302);
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 14:03:30 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::show
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 17:16:46 +01:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
2016-12-11 14:03:30 +01:00
|
|
|
public function testShow(string $range)
|
2016-11-19 20:30:30 +01:00
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('budgets.show', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 14:03:30 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::showByRepetition
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 17:16:46 +01:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
2016-12-11 14:03:30 +01:00
|
|
|
public function testShowByRepetition(string $range)
|
2016-11-19 20:30:30 +01:00
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('budgets.show.repetition', [1, 1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::store
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testStore()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->session(['budgets.create.url' => 'http://localhost']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'New Budget ' . rand(1000, 9999),
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('budgets.store'), $data);
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
|
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
$this->see($data['name']);
|
|
|
|
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::update
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
$this->session(['budgets.edit.url' => 'http://localhost']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'Updated Budget ' . rand(1000, 9999),
|
|
|
|
'active' => 1,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('budgets.update', [1]), $data);
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
|
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
$this->see($data['name']);
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\BudgetController::updateIncome
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testUpdateIncome()
|
|
|
|
{
|
2016-12-11 14:03:30 +01:00
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('budgets.income', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
2016-11-20 11:43:19 +01:00
|
|
|
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|