Files
firefly-iii/tests/acceptance/Controllers/BudgetControllerTest.php
2016-12-15 17:16:46 +01:00

230 lines
6.4 KiB
PHP

<?php
/**
* 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.
*/
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:40.
*/
class BudgetControllerTest extends TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
parent::setUp();
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::amount
*/
public function testAmount()
{
$data = [
'amount' => 200,
];
$this->be($this->user());
$this->call('post', route('budgets.amount', [1]), $data);
$this->assertResponseStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::create
*/
public function testCreate()
{
$this->be($this->user());
$this->call('GET', route('budgets.create'));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::delete
*/
public function testDelete()
{
$this->be($this->user());
$this->call('GET', route('budgets.delete', [1]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::destroy
*/
public function testDestroy()
{
$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');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::edit
*/
public function testEdit()
{
$this->be($this->user());
$this->call('GET', route('budgets.edit', [1]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::index
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testIndex(string $range)
{
$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">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::noBudget
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testNoBudget(string $range)
{
$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">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::postUpdateIncome
*/
public function testPostUpdateIncome()
{
$data = [
'amount' => 200,
];
$this->be($this->user());
$this->call('post', route('budgets.income.post', [1]), $data);
$this->assertResponseStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::show
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShow(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('budgets.show', [1]));
$this->assertResponseStatus(200);
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::showByRepetition
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowByRepetition(string $range)
{
$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">');
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::store
*/
public function testStore()
{
$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']);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::update
*/
public function testUpdate()
{
$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']);
}
/**
* @covers \FireflyIII\Http\Controllers\BudgetController::updateIncome
*/
public function testUpdateIncome()
{
// must be in list
$this->be($this->user());
$this->call('GET', route('budgets.income', [1]));
$this->assertResponseStatus(200);
}
}